/* Automatically generated file. Do not edit. 
 * Format:     ANSI C source code
 * Creator:    McXtrace <http://www.mcxtrace.org>
 * Instrument: SOLEIL.instr (SOLEIL)
 * Date:       Tue Oct 27 03:35:33 2026
 * File:       ./SOLEIL.c
 * CFLAGS= -std=c99  @XRLFLAGS@ -DUSE_OFF  -DFUNNEL   @GSLFLAGS@   -DMCSX_REFL_SLIST_SIZE=1024 
 */

#ifndef WIN32
#  ifndef OPENACC
#    define _GNU_SOURCE
#  endif
#  define _POSIX_C_SOURCE 200809L
#endif
/* In case of cl.exe on Windows, supppress warnings about #pragma acc */
#ifdef _MSC_EXTENSIONS
#pragma warning(disable: 4068)
#endif

#define MCCODE_STRING " 3.99.99, git"
#define FLAVOR        "mcxtrace"
#define FLAVOR_UPPER  "MCXTRACE"

#define MC_USE_DEFAULT_MAIN
#define MC_TRACE_ENABLED

#include <string.h>
#include <inttypes.h>

typedef double MCNUM;
typedef struct {MCNUM x, y, z;} Coords;
typedef MCNUM Rotation[3][3];
#define MCCODE_BASE_TYPES

/* available random number generators */
#define _RNG_ALG_MT         1
#define _RNG_ALG_KISS       2
/* selection of random number generator */
#ifndef RNG_ALG
#  define RNG_ALG  _RNG_ALG_KISS
#endif
#if RNG_ALG == _RNG_ALG_MT // MT 
#define randstate_t uint32_t
#define RANDSTATE_LEN 1
#elif RNG_ALG == _RNG_ALG_KISS  // KISS
#define randstate_t uint64_t
#define RANDSTATE_LEN 7
#endif

#ifndef MC_NUSERVAR
#define MC_NUSERVAR 10
#endif

/* Particle JUMP control logic */
struct particle_logic_struct {
int dummy;
};

struct _struct_particle {
  double x,y,z; /* position [m] */
  double kx,ky,kz; /* wave-vector */
  double phi, Ex,Ey,Ez; /* phase and electrical field */
  int allow_backprop; /* allow backprop */
  /* Generic Temporaries: */
  /* May be used internally by components e.g. for special */
  /* return-values from functions used in trace, thusreturned via */
  /* particle struct. (Example: Wolter Conics from McStas, silicon slabs.) */
  double _mctmp_a; /* temp a */
  double _mctmp_b; /* temp b */
  double _mctmp_c; /* temp c */
  randstate_t randstate[RANDSTATE_LEN];
  double t, p;     /* time, event weight */
  long long _uid;  /* Unique event ID */
  long _index;     /* component index where to send this event */
  long _absorbed;  /* flag set to TRUE when this event is to be removed/ignored */
  long _scattered; /* flag set to TRUE when this event has interacted with the last component instance */
  long _restore;   /* set to true if neutron event must be restored */
  long flag_nocoordschange;   /* set to true if particle is jumping */
  struct particle_logic_struct _logic;
  // user variables and comp-injections:
  int  PUMA_scat_before_VFM;
  int  flag_scatt;
  int     flag_hfm;
  int     flag_vfm;
  int     PX2a_flag_hfm;
  int     PX2a_flag_vfm;
  int     SWING_flag_hfm;
  int     SWING_flag_vfm;
  int     SIXS_flag_scatt;
  int  beamline;
};
typedef struct _struct_particle _class_particle;

_class_particle _particle_global_randnbuse_var;
_class_particle* _particle = &_particle_global_randnbuse_var;

#pragma acc routine
_class_particle mcgenstate(void);
#pragma acc routine
_class_particle mcsetstate(double x, double y, double z, double kx, double ky, double kz,
			   double phi, double t, double Ex, double Ey, double Ez, double p, int mcgravitation, void *mcMagnet, int mcallowbackprop);
#pragma acc routine
_class_particle mcgetstate(_class_particle mcphoton, double *x, double *y, double *z, double *kx, double *ky, double *kz,
			   double *phi, double *t, double *Ex, double *Ey, double *Ez, double *p);

extern int mcgravitation;      /* flag to enable gravitation */
#pragma acc declare create ( mcgravitation )

_class_particle mcgenstate(void) {
  _class_particle particle = mcsetstate(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, mcgravitation, NULL, 0);
  return(particle);
}
/*Generated user variable handlers:*/

#pragma acc routine
double particle_getvar(_class_particle *p, char *name, int *suc);

#ifdef OPENACC
#pragma acc routine
int str_comp(char *str1, char *str2);
#endif

double particle_getvar(_class_particle *p, char *name, int *suc){
#ifndef OPENACC
#define str_comp strcmp
#endif
  int s=1;
  double rval=0;
  if(!str_comp("x",name)){rval=p->x;s=0;}
  if(!str_comp("y",name)){rval=p->y;s=0;}
  if(!str_comp("z",name)){rval=p->z;s=0;}
  if(!str_comp("phi",name)){rval=p->phi;s=0;}
  if(!str_comp("kx",name)){rval=p->kx;s=0;}
  if(!str_comp("ky",name)){rval=p->ky;s=0;}
  if(!str_comp("kz",name)){rval=p->kz;s=0;}
  if(!str_comp("Ex",name)){rval=p->Ex;s=0;}
  if(!str_comp("Ey",name)){rval=p->Ey;s=0;}
  if(!str_comp("Ez",name)){rval=p->Ez;s=0;}
  if(!str_comp("t",name)){rval=p->t;s=0;}
  if(!str_comp("p",name)){rval=p->p;s=0;}
  if(!str_comp("_mctmp_a",name)){rval=p->_mctmp_a;s=0;}
  if(!str_comp("_mctmp_b",name)){rval=p->_mctmp_b;s=0;}
  if(!str_comp("_mctmp_c",name)){rval=p->_mctmp_c;s=0;}
  if(!str_comp("PUMA_scat_before_VFM",name)){rval=(double)(p->PUMA_scat_before_VFM);s=0;}
  if(!str_comp("flag_scatt",name)){rval=(double)(p->flag_scatt);s=0;}
  if(!str_comp("flag_hfm",name)){rval=(double)(p->flag_hfm);s=0;}
  if(!str_comp("flag_vfm",name)){rval=(double)(p->flag_vfm);s=0;}
  if(!str_comp("PX2a_flag_hfm",name)){rval=(double)(p->PX2a_flag_hfm);s=0;}
  if(!str_comp("PX2a_flag_vfm",name)){rval=(double)(p->PX2a_flag_vfm);s=0;}
  if(!str_comp("SWING_flag_hfm",name)){rval=(double)(p->SWING_flag_hfm);s=0;}
  if(!str_comp("SWING_flag_vfm",name)){rval=(double)(p->SWING_flag_vfm);s=0;}
  if(!str_comp("SIXS_flag_scatt",name)){rval=(double)(p->SIXS_flag_scatt);s=0;}
  if(!str_comp("beamline",name)){rval=(double)(p->beamline);s=0;}
  if (suc!=0x0) {*suc=s;}
  return rval;
}

#pragma acc routine
void* particle_getvar_void(_class_particle *p, char *name, int *suc);

#ifdef OPENACC
#pragma acc routine
int str_comp(char *str1, char *str2);
#endif

void* particle_getvar_void(_class_particle *p, char *name, int *suc){
#ifndef OPENACC
#define str_comp strcmp
#endif
  int s=1;
  void* rval=0;
  if(!str_comp("x",name)) {rval=(void*)&(p->x); s=0;}
  if(!str_comp("y",name)) {rval=(void*)&(p->y); s=0;}
  if(!str_comp("z",name)) {rval=(void*)&(p->z); s=0;}
  if(!str_comp("kx",name)){rval=(void*)&(p->kx);s=0;}
  if(!str_comp("ky",name)){rval=(void*)&(p->ky);s=0;}
  if(!str_comp("kz",name)){rval=(void*)&(p->kz);s=0;}
  if(!str_comp("Ex",name)){rval=(void*)&(p->Ex);s=0;}
  if(!str_comp("Ey",name)){rval=(void*)&(p->Ey);s=0;}
  if(!str_comp("Ez",name)){rval=(void*)&(p->Ez);s=0;}
  if(!str_comp("phi",name)){rval=(void*)&(p->phi);s=0;}
  if(!str_comp("t",name)) {rval=(void*)&(p->t); s=0;}
  if(!str_comp("p",name)) {rval=(void*)&(p->p); s=0;}
  if(!str_comp("PUMA_scat_before_VFM",name)){rval=(void*)&(p->PUMA_scat_before_VFM);s=0;}
  if(!str_comp("flag_scatt",name)){rval=(void*)&(p->flag_scatt);s=0;}
  if(!str_comp("flag_hfm",name)){rval=(void*)&(p->flag_hfm);s=0;}
  if(!str_comp("flag_vfm",name)){rval=(void*)&(p->flag_vfm);s=0;}
  if(!str_comp("PX2a_flag_hfm",name)){rval=(void*)&(p->PX2a_flag_hfm);s=0;}
  if(!str_comp("PX2a_flag_vfm",name)){rval=(void*)&(p->PX2a_flag_vfm);s=0;}
  if(!str_comp("SWING_flag_hfm",name)){rval=(void*)&(p->SWING_flag_hfm);s=0;}
  if(!str_comp("SWING_flag_vfm",name)){rval=(void*)&(p->SWING_flag_vfm);s=0;}
  if(!str_comp("SIXS_flag_scatt",name)){rval=(void*)&(p->SIXS_flag_scatt);s=0;}
  if(!str_comp("beamline",name)){rval=(void*)&(p->beamline);s=0;}
  if (suc!=0x0) {*suc=s;}
  return rval;
}

#pragma acc routine
int particle_setvar_void(_class_particle *, char *, void*);

int particle_setvar_void(_class_particle *p, char *name, void* value){
#ifndef OPENACC
#define str_comp strcmp
#endif
  int rval=1;
  if(!str_comp("x",name)) {memcpy(&(p->x),  value, sizeof(double)); rval=0;}
  if(!str_comp("y",name)) {memcpy(&(p->y),  value, sizeof(double)); rval=0;}
  if(!str_comp("z",name)) {memcpy(&(p->z),  value, sizeof(double)); rval=0;}
  if(!str_comp("kx",name)){memcpy(&(p->kx), value, sizeof(double)); rval=0;}
  if(!str_comp("ky",name)){memcpy(&(p->ky), value, sizeof(double)); rval=0;}
  if(!str_comp("kz",name)){memcpy(&(p->kz), value, sizeof(double)); rval=0;}
  if(!str_comp("Ex",name)){memcpy(&(p->Ex), value, sizeof(double)); rval=0;}
  if(!str_comp("Ey",name)){memcpy(&(p->Ey), value, sizeof(double)); rval=0;}
  if(!str_comp("Ez",name)){memcpy(&(p->Ez), value, sizeof(double)); rval=0;}
  if(!str_comp("phi",name)){memcpy(&(p->phi), value, sizeof(double)); rval=0;}
  if(!str_comp("p",name)) {memcpy(&(p->p),  value, sizeof(double)); rval=0;}
  if(!str_comp("t",name)) {memcpy(&(p->t),  value, sizeof(double)); rval=0;}
  if(!str_comp("PUMA_scat_before_VFM",name)){memcpy(&(p->PUMA_scat_before_VFM), value, sizeof(int )); rval=0;}
  if(!str_comp("flag_scatt",name)){memcpy(&(p->flag_scatt), value, sizeof(int )); rval=0;}
  if(!str_comp("flag_hfm",name)){memcpy(&(p->flag_hfm), value, sizeof(int    )); rval=0;}
  if(!str_comp("flag_vfm",name)){memcpy(&(p->flag_vfm), value, sizeof(int    )); rval=0;}
  if(!str_comp("PX2a_flag_hfm",name)){memcpy(&(p->PX2a_flag_hfm), value, sizeof(int    )); rval=0;}
  if(!str_comp("PX2a_flag_vfm",name)){memcpy(&(p->PX2a_flag_vfm), value, sizeof(int    )); rval=0;}
  if(!str_comp("SWING_flag_hfm",name)){memcpy(&(p->SWING_flag_hfm), value, sizeof(int    )); rval=0;}
  if(!str_comp("SWING_flag_vfm",name)){memcpy(&(p->SWING_flag_vfm), value, sizeof(int    )); rval=0;}
  if(!str_comp("SIXS_flag_scatt",name)){memcpy(&(p->SIXS_flag_scatt), value, sizeof(int    )); rval=0;}
  if(!str_comp("beamline",name)){memcpy(&(p->beamline), value, sizeof(int )); rval=0;}
  return rval;
}

#pragma acc routine
int particle_setvar_void_array(_class_particle *, char *, void*, int);

int particle_setvar_void_array(_class_particle *p, char *name, void* value, int elements){
#ifndef OPENACC
#define str_comp strcmp
#endif
  int rval=1;
  return rval;
}

#pragma acc routine
void particle_restore(_class_particle *p, _class_particle *p0);

void particle_restore(_class_particle *p, _class_particle *p0) {
  p->x  = p0->x;  p->y  = p0->y;  p->z  = p0->z;
  p->kx = p0->kx; p->ky = p0->ky; p->kz = p0->kz;
  p->Ex = p0->Ex; p->Ey = p0->Ey; p->Ez = p0->Ez;
  p->t = p0->t;   p->p  = p0->p;  p->phi  = p0->phi;
  p->_absorbed=0; p->_restore=0;
}

#pragma acc routine
double particle_getuservar_byid(_class_particle *p, int id, int *suc){
  int s=1;
  double rval=0;
  switch(id){
  case 0: { rval=(double)(p->PUMA_scat_before_VFM);s=0;break;}
  case 1: { rval=(double)(p->flag_scatt);s=0;break;}
  case 2: { rval=(double)(p->flag_hfm);s=0;break;}
  case 3: { rval=(double)(p->flag_vfm);s=0;break;}
  case 4: { rval=(double)(p->PX2a_flag_hfm);s=0;break;}
  case 5: { rval=(double)(p->PX2a_flag_vfm);s=0;break;}
  case 6: { rval=(double)(p->SWING_flag_hfm);s=0;break;}
  case 7: { rval=(double)(p->SWING_flag_vfm);s=0;break;}
  case 8: { rval=(double)(p->SIXS_flag_scatt);s=0;break;}
  case 9: { rval=(double)(p->beamline);s=0;break;}
  }
  if (suc!=0x0) {*suc=s;}
  return rval;
}

#pragma acc routine
void particle_uservar_init(_class_particle *p){
  p->PUMA_scat_before_VFM=0;
  p->flag_scatt=0;
  p->flag_hfm=0;
  p->flag_vfm=0;
  p->PX2a_flag_hfm=0;
  p->PX2a_flag_vfm=0;
  p->SWING_flag_hfm=0;
  p->SWING_flag_vfm=0;
  p->SIXS_flag_scatt=0;
  p->beamline=0;
}

#define MC_EMBEDDED_RUNTIME
/* embedding file "mccode-r.h" */

/*******************************************************************************
*
* McCode, neutron/xray ray-tracing package
*         Copyright (C) 1997-2009, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Runtime: share/mccode-r.h
*
* %Identification
* Written by: KN
* Date:    Aug 29, 1997
* Release: mcxtrace 3.99.99
* Version: $Revision$
*
* Runtime system header for McStas/McXtrace.
*
* In order to use this library as an external library, the following variables
* and macros must be declared (see details in the code)
*
*   struct mcinputtable_struct mcinputtable[];
*   int numipar;
*   metadata_table_t metadata_table[];
*   int num_metadata;
*   char instrument_name[], instrument_source[];
*   int traceenabled, defaultmain;
*   extern MCNUM  mccomp_storein[];
*   extern MCNUM  mcAbsorbProp[];
*   extern MCNUM  mcScattered;
*   #define MCCODE_STRING "the McStas/McXtrace version"
*
* Usage: Automatically embbeded in the c code.
*
* $Id$
*
*******************************************************************************/

#ifndef MCCODE_R_H
#define MCCODE_R_H "$Revision$"

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#ifndef _MSC_EXTENSIONS
#include <sys/time.h>
#endif
#include <float.h>
#include <inttypes.h>
#include <stdint.h>
#ifdef OPENACC
#include <openacc.h>
#ifndef GCCOFFLOAD
#include <accelmath.h>
#else
#include <math.h>
#endif
#pragma acc routine
int noprintf();
#pragma acc routine
size_t str_len(const char *s);
#else
#include <math.h>
#endif

/* In case of gcc / clang, ensure to use
   the built-in isnan/isinf functions */
#if defined(__GNUC__) || defined(__clang__)
#  ifdef isnan
#    undef isnan
#  endif
#  ifdef isinf
#    undef isinf
#  endif
#  define isnan(x) __builtin_isnan(x)
#  define isinf(x) __builtin_isinf(x)
#endif

#ifdef _MSC_EXTENSIONS
#ifndef _TIMES_H
#define _TIMES_H

#if defined(WIN32) || defined(_WIN32)
#include <sys/timeb.h>
#include <sys/types.h>
#include <winsock2.h>

int gettimeofday(struct timeval* t,void* timezone);

#define __need_clock_t
#include <time.h>


/* Structure describing CPU time used by a process and its children.  */
struct tms
  {
    clock_t tms_utime;          /* User CPU time.  */
    clock_t tms_stime;          /* System CPU time.  */

    clock_t tms_cutime;         /* User CPU time of dead children.  */
    clock_t tms_cstime;         /* System CPU time of dead children.  */
  };

/* Store the CPU time used by this process and all its
   dead children (and their dead children) in BUFFER.
   Return the elapsed real time, or (clock_t) -1 for errors.
   All times are in CLK_TCKths of a second.  */
clock_t times (struct tms *__buffer);

typedef long long suseconds_t ;



int gettimeofday(struct timeval* t,void* timezone)
{       struct _timeb timebuffer;
        _ftime( &timebuffer );
        t->tv_sec=timebuffer.time;
        t->tv_usec=1000*timebuffer.millitm;
		return 0;
}

clock_t times (struct tms *__buffer) {

	__buffer->tms_utime = clock();
	__buffer->tms_stime = 0;
	__buffer->tms_cstime = 0;
	__buffer->tms_cutime = 0;
	return __buffer->tms_utime;
}


#endif
#endif
#endif

/* If the runtime is embedded in the simulation program, some definitions can
   be made static. */

#ifdef MC_EMBEDDED_RUNTIME
#  define mcstatic
#else
#  define mcstatic
#endif

#ifdef __dest_os
#  if (__dest_os == __mac_os)
#    define MAC
#  endif
#endif

#ifdef __FreeBSD__
#  define NEED_STAT_H
#endif

#if defined(__APPLE__) && defined(__GNUC__)
#  define NEED_STAT_H
#endif

#if defined(WIN32) || defined(_WIN32)
#  define NEED_STAT_H
#  define NEED_TYPES_H
#endif

#ifdef NEED_STAT_H
#  include <sys/stat.h>
#endif

#ifdef NEED_TYPES_H
#  include <sys/types.h>
#endif

#ifndef MC_PATHSEP_C
#if defined(WIN32) || defined(_WIN32)
#    define MC_PATHSEP_C '\\'
#    define MC_PATHSEP_S "\\"
#  else  /* !WIN32 */
#    define MC_PATHSEP_C '/'
#    define MC_PATHSEP_S "/"
#  endif /* !WIN32 */
#endif /* MC_PATHSEP_C */

#if defined(WIN32) || defined(_WIN32)
#if defined _MSC_VER
#include <direct.h>
#elif defined __GNUC__
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#define mkdir(a,b) mkdir(a)
#define getpid() _getpid()
#endif

/* the version string is replaced when building distribution with mkdist */
#ifndef MCCODE_STRING
#  define MCCODE_STRING " 3.99.99, git"
#endif

#ifndef MCCODE_DATE
#  define MCCODE_DATE "git"
#endif

#ifndef MCCODE_VERSION
#  define MCCODE_VERSION "3.99.99"
#endif

#ifndef __MCCODE_VERSION__
#define __MCCODE_VERSION__ 399099L
#endif

#ifndef MCCODE_NAME
#  define MCCODE_NAME "mcxtrace"
#endif

#ifndef MCCODE_PARTICLE
#  define MCCODE_PARTICLE "xray"
#endif

#ifndef MCCODE_PARTICLE_CODE
#  define MCCODE_PARTICLE_CODE 22
#endif

#ifndef MCCODE_LIBENV
#  define MCCODE_LIBENV "MCXTRACE"
#endif

#ifndef FLAVOR_UPPER
#  define FLAVOR_UPPER MCCODE_NAME
#endif

#ifdef MC_PORTABLE
#  ifndef NOSIGNALS
#    define NOSIGNALS 1
#  endif
#endif

#ifdef MAC
#  ifndef NOSIGNALS
#    define NOSIGNALS 1
#  endif
#endif

#if (USE_MPI == 0)
#  undef USE_MPI
#endif

#ifdef USE_MPI  /* default is to disable signals with MPI, as MPICH uses them to communicate */
#  ifndef NOSIGNALS
#    define NOSIGNALS 1
#  endif
#endif

#ifdef OPENACC  /* default is to disable signals with PGI/OpenACC */
#  ifndef NOSIGNALS
#    define NOSIGNALS 1
#  endif
#endif

#ifndef OPENACC
#  ifndef USE_OFF  /* default is to enable OFF when not using PGI/OpenACC */
#    define USE_OFF
#  endif
#  ifndef CPUFUNNEL  /* allow to enable FUNNEL-mode on CPU */
#  ifdef FUNNEL      /* by default disable FUNNEL-mode when not using PGI/OpenACC */
#    undef FUNNEL
#  endif
#  endif
#endif

#if (NOSIGNALS == 0)
#  undef NOSIGNALS
#endif

/** Header information for metadata-r.c ----------------------------------------------------------------------------- */
struct metadata_table_struct { /* stores metadata strings from components */
  char * source;  // component name which provided the metadata
  char * name;    // the name of the metadata
  char * type;    // the MIME type of the metadata (free form, valid identifier)
  char * value;   // the metadata string contents
};
typedef struct metadata_table_struct metadata_table_t;
char * metadata_table_key_component(char* key);
char * metadata_table_key_literal(char * key);
int metadata_table_defined(int, metadata_table_t *, char *);
char * metadata_table_name(int, metadata_table_t *, char *);
char * metadata_table_type(int, metadata_table_t *, char *);
char * metadata_table_literal(int, metadata_table_t *, char *);
void metadata_table_print_all_keys(int no, metadata_table_t * tab);
int metadata_table_print_all_components(int no, metadata_table_t * tab);
int metadata_table_print_component_keys(int no, metadata_table_t * tab, char * key);
/* -------------------------------------------------------------------------- Header information for metadata-r.c --- */

/* Note: the enum instr_formal_types definition MUST be kept
   synchronized with the one in mccode.h and with the
   instr_formal_type_names array in cogen.c. */
enum instr_formal_types
  {
    instr_type_int,
    instr_type_string, instr_type_char,
    instr_type_vector, instr_type_double
  };
struct mcinputtable_struct { /* defines instrument parameters */
  char *name; /* name of parameter */
  void *par;  /* pointer to instrument parameter (variable) */
  enum instr_formal_types type;
  char *val;  /* default value */
  char *unit; /* expected unit for parameter; informational only */
};


#ifndef MCCODE_BASE_TYPES
typedef double MCNUM;
typedef struct {MCNUM x, y, z;} Coords;
typedef MCNUM Rotation[3][3];
#endif

/* the following variables are defined in the McStas generated C code
   but should be defined externally in case of independent library usage */
#ifndef DANSE
extern struct mcinputtable_struct mcinputtable[];         /* list of instrument parameters */
extern int    numipar;                                    /* number of instrument parameters */
extern metadata_table_t metadata_table[];                 /* list of component-defined string metadata */
extern int    num_metadata;                               /* number of component-defined string metadata */
extern char   instrument_name[], instrument_source[]; /* instrument name and filename */
extern char  *instrument_exe;                           /* executable path = argv[0] or NULL */
extern char   instrument_code[];                        /* contains the initial 'instr' file */

#ifndef MC_ANCIENT_COMPATIBILITY
extern int traceenabled, defaultmain;
#endif
#endif


/* Useful macros ============================================================ */


/* SECTION: Dynamic Arrays */
typedef int* IArray1d;
IArray1d create_iarr1d(int n);
void destroy_iarr1d(IArray1d a);

typedef int** IArray2d;
IArray2d create_iarr2d(int nx, int ny);
void destroy_iarr2d(IArray2d a);

typedef int*** IArray3d;
IArray3d create_iarr3d(int nx, int ny, int nz);
void destroy_iarr3d(IArray3d a);

typedef double* DArray1d;
DArray1d create_darr1d(int n);
void destroy_darr1d(DArray1d a);

typedef double** DArray2d;
DArray2d create_darr2d(int nx, int ny);
void destroy_darr2d(DArray2d a);

typedef double*** DArray3d;
DArray3d create_darr3d(int nx, int ny, int nz);
void destroy_darr3d(DArray3d a);


/* MPI stuff */
#ifdef USE_MPI
#include "mpi.h"

#ifdef OMPI_MPI_H  /* openmpi does not use signals: we may install our sighandler */
#ifndef OPENACC    /* ... but only if we are not also running on GPU */
#undef NOSIGNALS
#endif
#endif

/*
 * MPI_MASTER(i):
 * execution of i only on master node
 */
#define MPI_MASTER(statement) { \
  if(mpi_node_rank == mpi_node_root)\
  { statement; } \
}

#ifndef MPI_REDUCE_BLOCKSIZE
#define MPI_REDUCE_BLOCKSIZE 100000
#endif

int mc_MPI_Sum(double* buf, long count);
int mc_MPI_Send(void *sbuf, long count, MPI_Datatype dtype, int dest);
int mc_MPI_Recv(void *rbuf, long count, MPI_Datatype dtype, int source);

/* Evaluate the exit code first: it is often exit(fprintf(stderr, ...)), and
 * the message must be printed before MPI is torn down. MPI_Finalize is
 * collective, so it is only used for a normal (code 0) exit. An error exit
 * from a single rank (e.g. a component INITIALISE failure) must MPI_Abort,
 * otherwise that rank blocks in MPI_Finalize while the others wait for it in
 * MPI_Allreduce - a silent deadlock until the job is killed. */
#define exit(code) do {                                   \
    int mc_exit_code_ = (int)(code);                      \
    if (mc_exit_code_) MPI_Abort(MPI_COMM_WORLD, mc_exit_code_); \
    else MPI_Finalize();                                  \
    exit(mc_exit_code_);                                  \
  } while(0)

#else /* !USE_MPI */
#define MPI_MASTER(instr) instr
#endif /* USE_MPI */


#ifdef USE_MPI
static int mpi_node_count;
#endif

#ifdef USE_THREADS  /* user want threads */
#error Threading (USE_THREADS) support has been removed for very poor efficiency. Use MPI/SSH grid instead.
#endif


void   mcset_ncount(unsigned long long count);    /* wrapper to get mcncount */
#pragma acc routine
unsigned long long int mcget_ncount(void);            /* wrapper to set mcncount */
unsigned long long mcget_run_num(void);           /* wrapper to get mcrun_num=0:mcncount-1 */

/* Following part is only embedded when not redundant with mccode.h ========= */

#ifndef MCCODE_H

#ifndef NOSIGNALS
#include <signal.h>
char  *mcsig_message;
#define SIG_MESSAGE(msg) mcsig_message=(char *)(msg);
#else
#define SIG_MESSAGE(...)
#endif /* !NOSIGNALS */


/* Useful macros and constants ============================================== */


#ifndef FLT_MAX
#define FLT_MAX         3.40282347E+38F /* max decimal value of a "float" */
#endif

#ifndef MIN
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#endif
#ifndef SQR
#define SQR(x) ( (x) * (x) )
#endif
#ifndef SIGN
#define SIGN(x) (((x)>0.0)?(1):(-1))
#endif


#  ifndef M_E
#    define M_E        2.71828182845904523536  // e
#  endif
#  ifndef M_LOG2E
#    define M_LOG2E    1.44269504088896340736  //  log2(e)
#  endif
#  ifndef M_LOG10E
#    define M_LOG10E   0.434294481903251827651 //  log10(e)
#  endif
#  ifndef M_LN2
#    define M_LN2      0.693147180559945309417 //  ln(2)
#  endif
#  ifndef M_LN10
#    define M_LN10     2.30258509299404568402  //  ln(10)
#  endif
#  ifndef M_PI
#    define M_PI       3.14159265358979323846  //  pi
#  endif
#  ifndef PI
#    define PI       M_PI                      //  pi - also used in some places
#  endif
#  ifndef M_PI_2
#    define M_PI_2     1.57079632679489661923  //  pi/2
#  endif
#  ifndef M_PI_4
#    define M_PI_4     0.785398163397448309616 //  pi/4
#  endif
#  ifndef M_1_PI
#    define M_1_PI     0.318309886183790671538 //  1/pi
#  endif
#  ifndef M_2_PI
#    define M_2_PI     0.636619772367581343076 //  2/pi
#  endif
#  ifndef M_2_SQRTPI
#    define M_2_SQRTPI 1.12837916709551257390  //  2/sqrt(pi)
#  endif
#  ifndef M_SQRT2
#    define M_SQRT2    1.41421356237309504880  //  sqrt(2)
#  endif
#  ifndef M_SQRT1_2
#    define M_SQRT1_2  0.707106781186547524401 //  1/sqrt(2)
#  endif

#define RAD2MIN  ((180*60)/PI)
#define MIN2RAD  (PI/(180*60))
#define DEG2RAD  (PI/180)
#define RAD2DEG  (180/PI)
#define FWHM2RMS 0.424660900144    /* Convert between full-width-half-max and */
#define RMS2FWHM 2.35482004503     /* root-mean-square (standard deviation) */
#define HBAR     1.05457168e-34    /* [Js] h bar Planck constant CODATA 2002 */
#define MNEUTRON 1.67492728e-27    /* [kg] mass of neutron CODATA 2002 */
#define GRAVITY  9.81              /* [m/s^2] gravitational acceleration */
#define NA       6.02214179e23     /* [#atoms/g .mole] Avogadro's number*/


#define UNSET nan("0x6E6F74736574")
int nans_match(double, double);
int is_unset(double);
int is_valid(double);
int is_set(double);
int all_unset(int n, ...);
int all_set(int n, ...);
int any_unset(int n, ...);
int any_set(int n, ...);


/* wrapper to get absolute and relative position of comp */
/* mccomp_posa and mccomp_posr are defined in McStas generated C code */
#define POS_A_COMP_INDEX(index) (instrument->_position_absolute[index])
#define POS_R_COMP_INDEX(index) (instrument->_position_relative[index])

/* setting parameters based COMP_GETPAR (returned as pointer)         */
/* compname must be given as a string, type and par are symbols.      */
#define COMP_GETPAR3(type, compname, par) \
    &( ((_class_ ## type ##_parameters *) _getvar_parameters(compname))->par )
/* the body of this function depends on component instances, and is cogen'd */
void* _getvar_parameters(char* compname);

int _getcomp_index(char* compname);

/* Note: The two-stage approach to COMP_GETPAR is NOT redundant; without it,
* after #define C sample, COMP_GETPAR(C,x) would refer to component C, not to
* component sample. Such are the joys of ANSI C.

* Anyway the usage of COMP_GETPAR requires that we use sometimes bare names...
* NOTE: This can ONLY be used in instrument descriptions, not components.
*/
#define COMP_GETPAR2(comp, par) (_ ## comp ## _var._parameters.par)
#define COMP_GETPAR(comp, par) COMP_GETPAR2(comp,par)

#define INSTRUMENT_GETPAR(par) (_instrument_var._parameters.par)

/* Current component name, index, position and orientation */
/* These macros work because, using class-based functions, "comp" is usually
*  the local variable of the active/current component. */
#define INDEX_CURRENT_COMP (_comp->_index)
#define NAME_CURRENT_COMP (_comp->_name)
#define TYPE_CURRENT_COMP (_comp->_type)
#define POS_A_CURRENT_COMP (_comp->_position_absolute)
#define POS_R_CURRENT_COMP (_comp->_position_relative)
#define ROT_A_CURRENT_COMP (_comp->_rotation_absolute)
#define ROT_R_CURRENT_COMP (_comp->_rotation_relative)

#define NAME_INSTRUMENT (instrument->_name)


/* MCDISPLAY/trace and debugging message sent to stdout */
#ifdef MC_TRACE_ENABLED
#define DEBUG
#endif

#ifdef DEBUG
#define DEBUG_INSTR() if(!mcdotrace); else { printf("INSTRUMENT:\n"); printf("Instrument '%s' (%s)\n", instrument_name, instrument_source); }
#define DEBUG_COMPONENT(name,c,t) if(!mcdotrace); else {\
     printf("COMPONENT: \"%s\"\n"					  \
     "POS: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n", \
     name, c.x, c.y, c.z, t[0][0], t[0][1], t[0][2], \
     t[1][0], t[1][1], t[1][2], t[2][0], t[2][1], t[2][2]); \
     fflush(stdout);\
     printf("Component %30s AT (%g,%g,%g)\n", name, c.x, c.y, c.z);\
     fflush(stdout);}
#define DEBUG_INSTR_END() if(!mcdotrace); else printf("INSTRUMENT END:\n");
#define DEBUG_ENTER() if(!mcdotrace); else printf("ENTER:\n");
#define DEBUG_COMP(c) if(!mcdotrace); else printf("COMP: \"%s\"\n", c);
#define DEBUG_LEAVE() if(!mcdotrace); else printf("LEAVE:\n");
#define DEBUG_ABSORB() if(!mcdotrace); else printf("ABSORB:\n");
#else
#define DEBUG_INSTR()
#define DEBUG_COMPONENT(name,c,t)
#define DEBUG_INSTR_END()
#define DEBUG_ENTER()
#define DEBUG_COMP(c)
#define DEBUG_LEAVE()
#define DEBUG_ABSORB()
#endif

// mcDEBUG_STATE and mcDEBUG_SCATTER are defined by mcstas-r.h and mcxtrace-r.h



#ifdef TEST
#define test_printf printf
#else
#define test_printf while(0) printf
#endif

/* send MCDISPLAY message to stdout to show gemoetry */
void mcdis_magnify(char *what);
void mcdis_line(double x1, double y1, double z1,
                double x2, double y2, double z2);
void mcdis_dashed_line(double x1, double y1, double z1,
		       double x2, double y2, double z2, int n);
void mcdis_multiline(int count, ...);
void mcdis_rectangle(char* plane, double x, double y, double z,
		     double width, double height);
void mcdis_box(double x, double y, double z,
	       double width, double height, double length, double thickness, double nx, double ny, double nz);
void mcdis_circle(char *plane, double x, double y, double z, double r);
void mcdis_Circle(double x, double y, double z, double r, double nx, double ny, double nz);
void mcdis_cylinder( double x, double y, double z,
		     double r, double height, double thickness, double nx, double ny, double nz);
void mcdis_cone( double x, double y, double z,
        double r, double height, double nx, double ny, double nz);
void mcdis_sphere(double x, double y, double z, double r);


/* random number generation. ================================================ */

#if RNG_ALG == _RNG_ALG_MT  // MT (currently not functional for GPU)
#  define MC_RAND_MAX ((uint32_t)0xffffffffUL)
#  ifndef RANDSTATE_LEN
#    define RANDSTATE_LEN 1
#  endif
#  define srandom(seed) mt_srandom_empty()
#  define random() mt_random()
#  define _random() mt_random()
#elif RNG_ALG == _RNG_ALG_KISS  // KISS
#  ifndef UINT64_MAX
#    define UINT64_MAX ((uint64_t)0xffffffffffffffffULL)
#  endif
#  define MC_RAND_MAX UINT64_MAX
#  ifndef RANDSTATE_LEN
#    define RANDSTATE_LEN 7
#  endif
#  define srandom(seed) kiss_srandom(_particle->randstate, seed)
#  define random() kiss_random(_particle->randstate)
#  define _random() kiss_random(state)
#endif

#pragma acc routine
double _randnorm2(randstate_t* state);

// Component writer interface
#define randnorm() _randnorm2(_particle->randstate)        // NOTE: can't use _randnorm on GPU
#define rand01() _rand01(_particle->randstate)
#define randpm1() _randpm1(_particle->randstate)
#define rand0max(p1) _rand0max(p1, _particle->randstate)
#define randminmax(p1, p2) _randminmax(p1, p2, _particle->randstate)
#define randtriangle() _randtriangle(_particle->randstate)

// Mersenne Twister rng
uint32_t mt_random(void);
void mt_srandom (uint32_t x);
void mt_srandom_empty();

// KISS rng
#pragma acc routine
uint64_t *kiss_srandom(uint64_t state[7], uint64_t seed);
#pragma acc routine
uint64_t kiss_random(uint64_t state[7]);

// Scrambler / hash function
#pragma acc routine seq
randstate_t _hash(randstate_t x);

// internal RNG (transforms) interface
#pragma acc routine
double _rand01(randstate_t* state);
#pragma acc routine
double _randpm1(randstate_t* state);
#pragma acc routine
double _rand0max(double max, randstate_t* state);
#pragma acc routine
double _randminmax(double min, double max, randstate_t* state);
#pragma acc routine
double _randtriangle(randstate_t* state);
// version which pass randstate_t* as opague void*
#pragma acc routine
double _rand01_opague(void* state);


#ifdef USE_OPENCL
#include "opencl-lib.h"
#include "opencl-lib.c"
#endif

#ifndef DANSE
int init(void);
int raytrace(_class_particle*);
int save(FILE *);
int finally(void);
int display(void);
#endif


/* GPU related algorithms =================================================== */

/*
*  Divide-and-conquer strategy for parallel sort absorbed last.
*/
#ifdef FUNNEL
long sort_absorb_last(_class_particle* particles, _class_particle* pbuffer, long len, long buffer_len, long flag_split, long* multiplier);
#endif
long sort_absorb_last_serial(_class_particle* particles, long len);


/* simple vector algebra ==================================================== */


#define vec_prod(x, y, z, x1, y1, z1, x2, y2, z2) \
	vec_prod_func(&x, &y, &z, x1, y1, z1, x2, y2, z2)
#pragma acc routine seq
mcstatic void vec_prod_func(double *x, double *y, double *z,
		double x1, double y1, double z1, double x2, double y2, double z2);

#pragma acc routine seq
mcstatic double scalar_prod(
		double x1, double y1, double z1, double x2, double y2, double z2);

#pragma acc routine seq
mcstatic void norm_func(double *x, double *y, double *z);
#define NORM(x,y,z)	norm_func(&x, &y, &z)

#pragma acc routine seq
void normal_vec(double *nx, double *ny, double *nz,
    double x, double y, double z);

/**
 * Rotate the vector vx,vy,vz psi radians around the vector ax,ay,az
 * and put the result in x,y,z.
 */
#define rotate(x, y, z, vx, vy, vz, phi, ax, ay, az) \
  do { \
    double mcrt_tmpx = (ax), mcrt_tmpy = (ay), mcrt_tmpz = (az); \
    double mcrt_vp, mcrt_vpx, mcrt_vpy, mcrt_vpz; \
    double mcrt_vnx, mcrt_vny, mcrt_vnz, mcrt_vn1x, mcrt_vn1y, mcrt_vn1z; \
    double mcrt_bx, mcrt_by, mcrt_bz; \
    double mcrt_cos, mcrt_sin; \
    NORM(mcrt_tmpx, mcrt_tmpy, mcrt_tmpz); \
    mcrt_vp = scalar_prod((vx), (vy), (vz), mcrt_tmpx, mcrt_tmpy, mcrt_tmpz); \
    mcrt_vpx = mcrt_vp*mcrt_tmpx; \
    mcrt_vpy = mcrt_vp*mcrt_tmpy; \
    mcrt_vpz = mcrt_vp*mcrt_tmpz; \
    mcrt_vnx = (vx) - mcrt_vpx; \
    mcrt_vny = (vy) - mcrt_vpy; \
    mcrt_vnz = (vz) - mcrt_vpz; \
    vec_prod(mcrt_bx, mcrt_by, mcrt_bz, \
             mcrt_tmpx, mcrt_tmpy, mcrt_tmpz, mcrt_vnx, mcrt_vny, mcrt_vnz); \
    mcrt_cos = cos((phi)); mcrt_sin = sin((phi)); \
    mcrt_vn1x = mcrt_vnx*mcrt_cos + mcrt_bx*mcrt_sin; \
    mcrt_vn1y = mcrt_vny*mcrt_cos + mcrt_by*mcrt_sin; \
    mcrt_vn1z = mcrt_vnz*mcrt_cos + mcrt_bz*mcrt_sin; \
    (x) = mcrt_vpx + mcrt_vn1x; \
    (y) = mcrt_vpy + mcrt_vn1y; \
    (z) = mcrt_vpz + mcrt_vn1z; \
  } while(0)

/**
 * Mirror (xyz) in the plane given by the point (rx,ry,rz) and normal (nx,ny,nz)
 *
 * TODO: This define is seemingly never used...
 */
#define mirror(x,y,z,rx,ry,rz,nx,ny,nz) \
  do { \
    double mcrt_tmpx= (nx), mcrt_tmpy = (ny), mcrt_tmpz = (nz); \
    double mcrt_tmpt; \
    NORM(mcrt_tmpx, mcrt_tmpy, mcrt_tmpz); \
    mcrt_tmpt=scalar_prod((rx),(ry),(rz),mcrt_tmpx,mcrt_tmpy,mcrt_tmpz); \
    (x) = rx -2 * mcrt_tmpt*mcrt_rmpx; \
    (y) = ry -2 * mcrt_tmpt*mcrt_rmpy; \
    (z) = rz -2 * mcrt_tmpt*mcrt_rmpz; \
  } while (0)

#pragma acc routine
Coords coords_set(MCNUM x, MCNUM y, MCNUM z);
#pragma acc routine
Coords coords_get(Coords a, MCNUM *x, MCNUM *y, MCNUM *z);
#pragma acc routine
Coords coords_add(Coords a, Coords b);
#pragma acc routine
Coords coords_sub(Coords a, Coords b);
#pragma acc routine
Coords coords_neg(Coords a);
#pragma acc routine
Coords coords_scale(Coords b, double scale);
#pragma acc routine
double coords_sp(Coords a, Coords b);
#pragma acc routine
Coords coords_xp(Coords b, Coords c);
#pragma acc routine
double coords_len(Coords a);
#pragma acc routine seq
void   coords_print(Coords a);
#pragma acc routine seq
mcstatic void coords_norm(Coords* c);

#pragma acc routine seq
void rot_set_rotation(Rotation t, double phx, double phy, double phz);
#pragma acc routine seq
int  rot_test_identity(Rotation t);
#pragma acc routine seq
void rot_mul(Rotation t1, Rotation t2, Rotation t3);
#pragma acc routine seq
void rot_copy(Rotation dest, Rotation src);
#pragma acc routine seq
void rot_transpose(Rotation src, Rotation dst);
#pragma acc routine seq
Coords rot_apply(Rotation t, Coords a);

#pragma acc routine seq
void mccoordschange(Coords a, Rotation t, _class_particle *particle);
#pragma acc routine seq
void mccoordschange_polarisation(Rotation t, double *sx, double *sy, double *sz);

double mcestimate_error(double N, double p1, double p2);
void mcreadparams(void);

/* this is now in mcstas-r.h and mcxtrace-r.h as the number of state parameters
is no longer equal */

_class_particle mcgenstate(void);

// trajectory/shape intersection routines
#pragma acc routine seq
int inside_rectangle(double, double, double, double);
#pragma acc routine seq
int box_intersect(double *dt_in, double *dt_out, double x, double y, double z,
      double vx, double vy, double vz, double dx, double dy, double dz);
#pragma acc routine seq
int cylinder_intersect(double *t0, double *t1, double x, double y, double z,
      double vx, double vy, double vz, double r, double h);
#pragma acc routine seq
int sphere_intersect(double *t0, double *t1, double x, double y, double z,
      double vx, double vy, double vz, double r);
// second order equation roots
#pragma acc routine seq
int solve_2nd_order(double *t1, double *t2,
      double A,  double B,  double C);

// random vector generation to shape
// defines silently introducing _particle as the last argument
#define randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, radius) \
  _randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, radius, _particle)
#define randvec_target_rect_angular(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A) \
  _randvec_target_rect_angular(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A, _particle)
#define randvec_target_rect_real(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A, lx, ly, lz, order) \
  _randvec_target_rect_real(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A, lx, ly, lz, order, _particle)
// defines forwarding to "inner" functions
#define randvec_target_sphere randvec_target_circle
#define randvec_target_rect(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9) \
  randvec_target_rect_real(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,0,0,0,1)
// headers for randvec
#pragma acc routine seq
void _randvec_target_circle(double *xo, double *yo, double *zo,
  double *solid_angle, double xi, double yi, double zi, double radius,
  _class_particle* _particle);
#pragma acc routine seq
void _randvec_target_rect_angular(double *xo, double *yo, double *zo,
  double *solid_angle, double xi, double yi, double zi, double height,
  double width, Rotation A,
  _class_particle* _particle);
#pragma acc routine seq
void _randvec_target_rect_real(double *xo, double *yo, double *zo, double *solid_angle,
  double xi, double yi, double zi, double height, double width, Rotation A,
  double lx, double ly, double lz, int order,
  _class_particle* _particle);


// this is the main()
int mccode_main(int argc, char *argv[]);


#endif /* !MCCODE_H */

#ifndef MCCODE_R_IO_H
#define MCCODE_R_IO_H "$Revision$"

#if (USE_NEXUS == 0)
#undef USE_NEXUS
#endif

#ifndef CHAR_BUF_LENGTH
#define CHAR_BUF_LENGTH 1024
#endif


/* I/O section part ========================================================= */

/* ========================================================================== */

/*                               MCCODE_R_IO_C                                */

/* ========================================================================== */


/* main DETECTOR structure which stores most information to write to data files */
struct mcdetector_struct {
  char   filename[CHAR_BUF_LENGTH];   /* file name of monitor */
  double Position[3];                 /* position of detector component*/
  char   position[CHAR_BUF_LENGTH];   /* position of detector component (string)*/
  Rotation Rotation;                  /* position of detector component*/
  char   options[CHAR_BUF_LENGTH];    /* Monitor_nD style list-mode'options' (string)*/
  char   component[CHAR_BUF_LENGTH];  /* component instance name */
  char   nexuscomp[CHAR_BUF_LENGTH];  /* component naming in NeXus/HDF case */
  char   instrument[CHAR_BUF_LENGTH]; /* instrument name */
  char   type[CHAR_BUF_LENGTH];       /* data type, e.g. 0d, 1d, 2d, 3d */
  char   user[CHAR_BUF_LENGTH];       /* user name, e.g. HOME */
  char   date[CHAR_BUF_LENGTH];       /* date of simulation end/write time */
  char   title[CHAR_BUF_LENGTH];      /* title of detector */
  char   xlabel[CHAR_BUF_LENGTH];     /* X axis label */
  char   ylabel[CHAR_BUF_LENGTH];     /* Y axis label */
  char   zlabel[CHAR_BUF_LENGTH];     /* Z axis label */
  char   xvar[CHAR_BUF_LENGTH];       /* X variable name */
  char   yvar[CHAR_BUF_LENGTH];       /* Y variable name */
  char   zvar[CHAR_BUF_LENGTH];       /* Z variable name */
  char   ncount[CHAR_BUF_LENGTH];     /* number of events initially generated */
  char   limits[CHAR_BUF_LENGTH];     /* X Y Z limits, e.g. [xmin xmax ymin ymax zmin zmax] */
  char   variables[CHAR_BUF_LENGTH];  /* variables written into data block */
  char   statistics[CHAR_BUF_LENGTH]; /* center, mean and half width along axis */
  char   signal[CHAR_BUF_LENGTH];     /* min max and mean of signal (data block) */
  char   values[CHAR_BUF_LENGTH];     /* integrated values e.g. [I I_err N] */
  double xmin,xmax;                   /* min max of axes */
  double ymin,ymax;
  double zmin,zmax;
  double intensity;                   /* integrated values for data block */
  double error;
  double events;
  double min;                         /* statistics for data block */
  double max;
  double mean;
  double centerX;                     /* statistics for axes */
  double halfwidthX;
  double centerY;
  double halfwidthY;
  int    rank;                        /* dimensionaly of monitor, e.g. 0 1 2 3 */
  char   istransposed;                /* flag to transpose matrix for some formats */

  long   m,n,p;                       /* dimensions of data block and along axes */
  long   date_l;                      /* same as date, but in sec since 1970 */

  double *p0, *p1, *p2;               /* pointers to saved data, NULL when freed */
  char   format[CHAR_BUF_LENGTH];    /* format for file generation */
};

typedef struct mcdetector_struct MCDETECTOR;

static   char *dirname             = NULL;      /* name of output directory */
static   char *siminfo_name        = "mccode";  /* default output sim file name */
char    *mcformat                    = NULL;      /* NULL (default) or a specific format */
static   int   mcsave_final        = 0;         /* 1 during the final save, done by all MPI nodes together (see mccode_main) */

/* file I/O definitions and function prototypes */

#ifndef MC_EMBEDDED_RUNTIME /* the mcstatic variables (from mccode-r.c) */
extern FILE * siminfo_file;     /* handle to the output siminfo file */
extern int    mcgravitation;      /* flag to enable gravitation */
extern int    mcdotrace;          /* flag to print MCDISPLAY messages */
#else
mcstatic FILE *siminfo_file        = NULL;
#endif

/* I/O function prototypes ================================================== */

// from msysgit: https://code.google.com/p/msysgit/source/browse/compat/strcasestr.c
char *strcasestr(const char *haystack, const char *needle);

/* output functions */
MCDETECTOR mcdetector_out_0D(char *t, double p0, double p1, double p2, char *c, Coords pos, Rotation rot, int index);
MCDETECTOR mcdetector_out_1D(char *t, char *xl, char *yl,
                  char *xvar, double x1, double x2, long n,
                  double *p0, double *p1, double *p2, char *f, char *c, Coords pos, Rotation rot, int index);
MCDETECTOR mcdetector_out_2D(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2, long m,
                  long n, double *p0, double *p1, double *p2, char *f,
                  char *c, Coords pos, Rotation rot, int index);
MCDETECTOR mcdetector_out_list(char *t, char *xl, char *yl,
                  long m, long n,
                  double *p1, char *f,
	          char *c, Coords posa, Rotation rot,char* options, int index);

/* wrappers to output functions, that automatically set NAME and POSITION */
#define DETECTOR_OUT(p0,p1,p2) mcdetector_out_0D(NAME_CURRENT_COMP,p0,p1,p2,NAME_CURRENT_COMP,POS_A_CURRENT_COMP,ROT_A_CURRENT_COMP,INDEX_CURRENT_COMP)
#define DETECTOR_OUT_0D(t,p0,p1,p2) mcdetector_out_0D(t,p0,p1,p2,NAME_CURRENT_COMP,POS_A_CURRENT_COMP,ROT_A_CURRENT_COMP,INDEX_CURRENT_COMP)
#define DETECTOR_OUT_1D(t,xl,yl,xvar,x1,x2,n,p0,p1,p2,f) \
     mcdetector_out_1D(t,xl,yl,xvar,x1,x2,n,p0,p1,p2,f,NAME_CURRENT_COMP,POS_A_CURRENT_COMP,ROT_A_CURRENT_COMP,INDEX_CURRENT_COMP)
#define DETECTOR_OUT_2D(t,xl,yl,x1,x2,y1,y2,m,n,p0,p1,p2,f) \
     mcdetector_out_2D(t,xl,yl,x1,x2,y1,y2,m,n,p0,p1,p2,f,NAME_CURRENT_COMP,POS_A_CURRENT_COMP,ROT_A_CURRENT_COMP,INDEX_CURRENT_COMP)

#ifdef USE_NEXUS
#include "napi.h"
extern NXhandle nxhandle;
/* store post-INIT values of component SETTING parameters (called after init()) */
void mccomp_param_runtime_nexus_all(NXhandle f);
#endif

#endif /* ndef MCCODE_R_IO_H */

#endif /* MCCODE_R_H */
/* End of file "mccode-r.h". */

/* embedding file "mcxtrace-r.h" */

/*******************************************************************************
*
* McXtrace, X-ray ray-tracing package
*         Copyright (C) 1997-2009, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Synchrotron SOLEIL, Saint-Aubin, France
*
* Runtime: share/mcxtrace-r.h
*
* %Identification
* Written by: KN
* Date:    Aug 29, 1997
* Release: McXtrace X.Y
* Version: $Revision$
*
* Runtime system header for McXtrace.
*
* In order to use this library as an external library, the following variables
* and macros must be declared (see details in the code)
*
*   struct mcinputtable_struct mcinputtable[];
*   int mcnumipar;
*   char instrument_name[], instrument_source[];
*   int traceenabled, defaultmain;
*   extern MCNUM  mccomp_storein[];
*   extern MCNUM  instrument.counter_AbsorbProp[];
*   extern MCNUM  mcScattered;
*   #define MCCODE_STRING "the McXtrace version"
*
* Usage: Automatically embbeded in the c code.
*
*******************************************************************************/

#ifndef MCXTRACE_R_H
#define MCXTRACE_R_H "$Revision$"

/* Following part is only embedded when not redundant with mcxtrace.h */

#ifndef MCCODE_H

#define CELE     1.602176487e-19   /* [C] Elementary charge CODATA 2006*/
#define MELECTRON 9.10938291e-31    /* [kg] Electron mass CODATA 2006*/
#define M_C      299792458         /* [m/s] speed of light CODATA 2006*/
#define E2K      0.506773091264796 /* Convert E[keV] to k[1/AA] (CELE/(HBAR*M_C)*1e-10)*1e3 */
#define K2E      1.97326972808327  /* Convert k[1/AA] to E[keV] (1e10*M_C*HBAR/CELE)/1e3 */
#define RE       2.8179402894e-5   /*[AA] Thomson scattering length*/
#define ALPHA    7.2973525698e-3   /*[ ] Fine structure constant CODATA 2006*/

#define SCATTER0 do {DEBUG_SCATTER(); SCATTERED++;} while(0)
#define SCATTER SCATTER0

void SCATTER_func(_class_particle *_particle); /* provides function to SCATTER from within libaries */

#define JUMPTOCOMP(comp) mcphoton->_index = INDEX_COMP(comp);

/*magnet stuff is probably redundant*/
#define MAGNET_ON \
  do { \
  } while(0)

#define MAGNET_OFF \
  do { \
  } while(0)

#define ALLOW_BACKPROP \
  do { \
    allow_backprop = 1; \
  } while(0)

#define DISALLOW_BACKPROP \
  do { \
    allow_backprop = 0; \
  } while(0)

#define PROP_MAGNET(dt) \
  do { \
    /* change coordinates from local system to magnet system */ \
    Rotation rotLM, rotTemp; \
    Coords   posLM = coords_sub(POS_A_CURRENT_COMP, mcMagnetPos); \
    rot_transpose(ROT_A_CURRENT_COMP, rotTemp); \
    rot_mul(rotTemp, mcMagnetRot, rotLM); \
    mcMagnetPrecession(mcnlx, mcnly, mcnlz, mcnlt, mcnlvx, mcnlvy, mcnlvz, \
	   	       &mcnlsx, &mcnlsy, &mcnlsz, dt, posLM, rotLM); \
  } while(0)

#define mcPROP_DT(dt) \
  do { \
    if (mcMagnet && dt > 0) PROP_MAGNET(dt);\
    x += kx*(dt); \
    y += ky*(dt); \
    z += kz*(dt); \
    t += (dt); \
    if (isnan(p) || isinf(p)) { instrument->counter_AbsorbProp[INDEX_CURRENT_COMP]++; ABSORB; }\
  } while(0)

/*An interrupt a'la mcMagnet should be inserted below if there's non-zero permeability*/
/*perhaps some kind of PROP_POL*/

#define mcPROP_DL(dl) \
  do { \
    MCNUM mc_k=sqrt( scalar_prod(kx,ky,kz,kx,ky,kz));\
    x = x+ (dl)*kx/mc_k;\
    y = y+ (dl)*ky/mc_k;\
    z = z+ (dl)*kz/mc_k;\
    phi = phi+ 1e10*mc_k*(dl);\
    t = t + (dl)/((double)M_C);\
  }while (0)
/* this had to be taken out to avoid error 700. This may need to be atomic, but probably should be somewhere else.*/
/*    if (isnan(p) || isinf(p)) { instrument->counter_AbsorbProp[INDEX_CURRENT_COMP] =  instrument->counter_AbsorbProp[INDEX_CURRENT_COMP] + 1; ABSORB; }\
*/

/*gravity not an issue with x-rays*/
/* ADD: E. Farhi, Aug 6th, 2001 PROP_GRAV_DT propagation with acceleration. */
#define PROP_GRAV_DT(dt, Ax, Ay, Az) \
  do { \
    if(dt < 0 && allow_backprop == 0) { instrument->counter_AbsorbProp[INDEX_CURRENT_COMP]++; ABSORB; }\
    if (mcMagnet) /*printf("Spin precession gravity\n")*/; \
    x  += vx*(dt) + (Ax)*(dt)*(dt)/2; \
    y  += vy*(dt) + (Ay)*(dt)*(dt)/2; \
    z  += vz*(dt) + (Az)*(dt)*(dt)/2; \
    vx += (Ax)*(dt); \
    vy += (Ay)*(dt); \
    vz += (Az)*(dt); \
    t  += (dt); \
    DISALLOW_BACKPROP;\
  } while(0)

/*adapted from PROP_DT(dt)*/
#define PROP_DL(dl) \
  do{ \
    if(dl < 0 && allow_backprop == 0) { RESTORE=1; ABSORB; }; \
    mcPROP_DL(dl); \
    DISALLOW_BACKPROP;\
  } while (0)

#define PROP_DT(dt) \
  do { \
    if(dt < 0) { RESTORE=1; ABSORB; }; \
    if (mcgravitation) { Coords mcLocG; double mc_gx, mc_gy, mc_gz; \
    mcLocG = rot_apply(ROT_A_CURRENT_COMP, coords_set(0,-GRAVITY,0)); \
    coords_get(mcLocG, &mc_gx, &mc_gy, &mc_gz); \
    PROP_GRAV_DT(dt, mc_gx, mc_gy, mc_gz); } \
    else mcPROP_DT(dt); \
    DISALLOW_BACKPROP;\
  } while(0)

#define PROP_X0 \
  do { \
    mcPROP_X0; \
    DISALLOW_BACKPROP; \
  }while(0)

#define mcPROP_X0 \
  do { \
    MCNUM mc_dl,mc_k; \
    if(kx == 0) { ABSORB; }; \
    mc_k=sqrt(scalar_prod(kx,ky,kz,kx,ky,kz)); \
    mc_dl= -x * mc_k / kx; \
    if(mc_dl<0 && allow_backprop==0) { ABSORB; };\
    PROP_DL(mc_dl); \
  } while(0)

#define PROP_Y0 \
  do { \
    mcPROP_Y0; \
    DISALLOW_BACKPROP; \
  }while(0)

#define mcPROP_Y0 \
  do { \
    MCNUM mc_dl,mc_k; \
    if(ky == 0) { ABSORB; }; \
    mc_k=sqrt(scalar_prod(kx,ky,kz,kx,ky,kz)); \
    mc_dl= -y * mc_k / ky; \
    if(mc_dl<0 && allow_backprop==0) { ABSORB; };\
    PROP_DL(mc_dl); \
  } while(0)

#define PROP_Z0 \
  do { \
    mcPROP_Z0; \
    DISALLOW_BACKPROP; \
  }while(0)

#define mcPROP_Z0 \
  do { \
    MCNUM mc_dl,mc_k; \
    if(kz == 0) { ABSORB; }; \
    mc_k=sqrt(scalar_prod(kx,ky,kz,kx,ky,kz)); \
    mc_dl= -z * mc_k / kz; \
    if(mc_dl<0 && allow_backprop==0) { ABSORB; };\
    PROP_DL(mc_dl); \
  } while(0)

#ifdef DEBUG

#define DEBUG_STATE() if(!mcdotrace); else \
  printf("STATE: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n", \
      x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p);
#define DEBUG_SCATTER() if(!mcdotrace); else \
  printf("SCATTER: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n", \
      x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p);

#else

#define DEBUG_STATE()
#define DEBUG_SCATTER()

#endif

#endif /* !MCCODE_H */

#endif /* MCXTRACE_R_H */
/* End of file "mcxtrace-r.h". */

/* embedding file "mccode-r.c" */

/*******************************************************************************
*
* McCode, neutron/xray ray-tracing package
*         Copyright (C) 1997-2009, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Runtime: share/mccode-r.c
*
* %Identification
* Written by: KN
* Date:    Aug 29, 1997
* Release: McStas X.Y/McXtrace X.Y
* Version: $Revision$
*
* Runtime system for McStas and McXtrace.
* Embedded within instrument in runtime mode.
* Contains SECTIONS:
*   MPI handling (sum, send, recv)
*   format definitions
*   I/O
*   mcdisplay support
*   random numbers
*   coordinates handling
*   vectors math (solve 2nd order, normals, randvec...)
*   parameter handling
*   signal and main handlers
*
* Usage: Automatically embbeded in the c code whenever required.
*
* $Id$
*
*******************************************************************************/

/*******************************************************************************
* The I/O format definitions and functions
*******************************************************************************/


/** Include header files to avoid implicit declarations (not allowed on LLVM) */
#include <ctype.h>
#include <stddef.h> /* offsetof, used by NeXus runtime parameter capture */
#include <sys/types.h>
#ifndef _MSC_EXTENSIONS
#include <dirent.h>
#else
/* McCode includes its own 'dirent' for use with MSVC on Windows */
#include <windirent.h>
#define popen _popen
#define pclose _pclose
#endif
#include <errno.h>

// UNIX specific headers (non-Windows)
#if defined(__unix__) || defined(__APPLE__)
#include <unistd.h>
#include <sys/stat.h>
#endif


#ifndef DANSE
#ifdef MC_ANCIENT_COMPATIBILITY
int traceenabled = 0;
int defaultmain  = 0;
#endif
/* else defined directly in the McCode generated C code */

static   long mcseed                 = 0; /* seed for random generator */
#pragma acc declare create ( mcseed )
static   long mcstartdate            = 0; /* start simulation time */
static   int  mcdisable_output_files = 0; /* --no-output-files */
mcstatic int  mcgravitation          = 0; /* use gravitation flag, for PROP macros */
mcstatic int  mcusedefaults          = 0; /* assume default value for all parameters */
mcstatic int  mcappend               = 0; /* flag to allow append mode on datasets/directories */
mcstatic int  mcdotrace              = 0; /* flag for --trace and messages for DISPLAY */
mcstatic int  mcnexus_embed_idf      = 0; /* flag to embed xml-formatted IDF file for Mantid */
#pragma acc declare create ( mcdotrace )
int      mcallowbackprop             = 0;         /* flag to enable negative/backprop */

/* OpenACC-related segmentation parameters: */
int vecsize = 128;
int numgangs = 7813;
long gpu_innerloop = 2147483647;

/* Monitor_nD list/buffer-size default */
/* Starting value may be defined using -DND_BUFFER=N */
/* Can further be controlled dynamically using --bufsiz input */
long MONND_BUFSIZ = 10000000;
#ifdef ND_BUFFER
MONND_BUFSIZ = ND_BUFFER;
#endif
 

/* Number of particle histories to simulate. */
#ifdef NEUTRONICS
mcstatic unsigned long long int mcncount             = 1;
mcstatic unsigned long long int mcrun_num            = 0;
#else
#ifdef MCDEFAULT_NCOUNT
mcstatic unsigned long long int mcncount             = MCDEFAULT_NCOUNT;
#else
mcstatic unsigned long long int mcncount             = 1000000;
#endif
#pragma acc declare create ( mcncount )
mcstatic unsigned long long int mcrun_num            = 0;
#pragma acc declare create ( mcrun_num )
#endif /* NEUTRONICS */

#else
#include "mcstas-globals.h"
#endif /* !DANSE */

#ifndef NX_COMPRESSION
#define NX_COMPRESSION NX_COMP_NONE
#endif

#ifndef NOSIGNALS
/* a signal arriving while an event list is written (e.g. a Monitor_nD buffer
   flushed during TRACE) is replayed once the write is done, see
   mcdetector_out_2D_list and sighandler */
static volatile int mcsig_busy    = 0;    /* event list write in progress */
static volatile int mcsig_pending = 0;    /* signal to replay after it */
static volatile int mcsig_replay  = 0;    /* sighandler called for the replay */
static double      *mcsig_skip_p1 = NULL; /* block written just before the replay */
void sighandler(int sig);
#endif

/* String nullification on GPU and other replacements */
#ifdef OPENACC
int noprintf() {
  return 0;
}

int str_comp(char *str1, char *str2) {
  while (*str1 && *str1 == *str2) {
    str1++;
    str2++;
  }
  return (*str1 - *str2);
}

size_t str_len(const char *s)
{
  size_t len = 0;
  if(s != NULL)
  {
    while(*s != '\0')
    {
      ++len;
      ++s;
    }
  }
  return len;
}

#endif

/* SECTION: Predefine (component) parameters ================================= */

int nans_match(double a, double b){
  return (*(uint64_t*)&a == *(uint64_t*)&b);
}
int is_unset(double x){
  return nans_match(x, UNSET);
}
int is_set(double x){
  return !nans_match(x, UNSET);
}
int is_valid(double x){
  return !isnan(x)||is_unset(x);
}
int all_unset(int n, ...){
  va_list ptr;
  va_start(ptr, n);
  int ret=1;
  for (int i=0; i<n; ++i) if(is_set(va_arg(ptr, double))) ret=0;
  va_end(ptr);
  return ret;
}
int all_set(int n, ...){
  va_list ptr;
  va_start(ptr, n);
  int ret=1;
  for (int i=0; i<n; ++i) if(is_unset(va_arg(ptr, double))) ret=0;
  va_end(ptr);
  return ret;
}
int any_unset(int n, ...){
  va_list ptr;
  va_start(ptr, n);
  int ret=0;
  for (int i=0; i<n; ++i) if(is_unset(va_arg(ptr, double))) ret=1;
  va_end(ptr);
  return ret;
}
int any_set(int n, ...){
  va_list ptr;
  va_start(ptr, n);
  int ret=0;
  for (int i=0; i<n; ++i) if(is_set(va_arg(ptr, double))) ret=1;
  va_end(ptr);
  return ret;
}


/* SECTION: Dynamic Arrays ================================================== */
IArray1d create_iarr1d(int n){
  IArray1d arr1d;
  arr1d = calloc(n, sizeof(int));
  if (!arr1d) {
    fprintf(stderr, "Error allocating IArray1d of dimension %i\n",n);
    exit(-1);
  }
  return arr1d;
}

void destroy_iarr1d(IArray1d a){
  free(a);
}

IArray2d create_iarr2d(int nx, int ny){
  IArray2d arr2d;
  arr2d = calloc(nx, sizeof(int *));
  if (!arr2d) {
    fprintf(stderr, "Error allocating IArray2d of dimension %i x %i\n",nx,ny);
    exit(-1);
  }

  int *p1;
  p1 = calloc(nx*ny, sizeof(int));

  if (!p1) {
    fprintf(stderr, "Error allocating int* array of dimension %i\n",nx*ny);
    exit(-1);
  }
  
  int i;
  for (i=0; i<nx; i++){
    arr2d[i] = &(p1[i*ny]);
  }
  return arr2d;
}

void destroy_iarr2d(IArray2d a){
  free(a[0]);
  free(a);
}

IArray3d create_iarr3d(int nx, int ny, int nz){
  IArray3d arr3d;
  int i, j;

  // 1d
  arr3d = calloc(nx, sizeof(int **));
  if (!arr3d) {
    fprintf(stderr, "Error allocating IArray3d of dimension %i x %i x %i\n",nx,ny,nz);
    exit(-1);
  }

  // d2
  int **p1;
  p1 = calloc(nx*ny, sizeof(int *));

  if (!p1) {
    fprintf(stderr, "Error allocating int** array of dimension %i\n",nx*ny);
    exit(-1);
  }
  
  for (i=0; i<nx; i++){
    arr3d[i] = &(p1[i*ny]);
  }

  // 3d
  int *p2;
  p2 = calloc(nx*ny*nz, sizeof(int));
  if (!p2) {
    fprintf(stderr, "Error allocating int* array of dimension %i\n",nx*ny*nz);
    exit(-1);
  }
  for (i=0; i<nx; i++){
    for (j=0; j<ny; j++){
      arr3d[i][j] = &(p2[(i*ny+j)*nz]);
    }
  }
  return arr3d;
}

void destroy_iarr3d(IArray3d a){
  free(a[0][0]);
  free(a[0]);
  free(a);
}

DArray1d create_darr1d(int n){
  DArray1d arr1d;
  arr1d = calloc(n, sizeof(double));
  if (!arr1d) {
    fprintf(stderr, "Error allocating DArray1d of dimension %i\n",n);
    exit(-1);
  }
  return arr1d;
}

void destroy_darr1d(DArray1d a){
  free(a);
}

DArray2d create_darr2d(int nx, int ny){
  DArray2d arr2d;
  arr2d = calloc(nx, sizeof(double *));
  if (!arr2d) {
    fprintf(stderr, "Error allocating DArray2d of dimension %i x %i\n",nx,ny);
    exit(-1);
  }
  double *p1;
  p1 = calloc(nx*ny, sizeof(double));
  if (!p1) {
    fprintf(stderr, "Error allocating double* array of dimension %i\n",nx*ny);
    exit(-1);
  }
  int i;
  for (i=0; i<nx; i++){
    arr2d[i] = &(p1[i*ny]);
  }
  return arr2d;
}

void destroy_darr2d(DArray2d a){
  free(a[0]);
  free(a);
}

DArray3d create_darr3d(int nx, int ny, int nz){
  DArray3d arr3d;

  int i, j;

  // 1d
  arr3d = calloc(nx, sizeof(double **));
  if (!arr3d) {
    fprintf(stderr, "Error allocating DArray3d of dimension %i x %i x %i\n",nx,ny,nz);
    exit(-1);
  }
  // d2
  double **p1;
  p1 = calloc(nx*ny, sizeof(double *));
  if (!p1) {
    fprintf(stderr, "Error allocating double** array of dimension %i\n",nx*ny);
    exit(-1);
  }
  for (i=0; i<nx; i++){
    arr3d[i] = &(p1[i*ny]);
  }

  // 3d
  double *p2;
  p2 = calloc(nx*ny*nz, sizeof(double));
  if (!p2) {
    fprintf(stderr, "Error allocating double* array of dimension %i\n",nx*ny*nz);
    exit(-1);
  }
  for (i=0; i<nx; i++){
    for (j=0; j<ny; j++){
      arr3d[i][j] = &(p2[(i*ny+j)*nz]);
    }
  }
  return arr3d;
}

void destroy_darr3d(DArray3d a){
  free(a[0][0]);
  free(a[0]);
  free(a);
}


/* SECTION: MPI handling ==================================================== */

#ifdef USE_MPI
/* MPI rank */
static int mpi_node_rank;
static int mpi_node_root = 0;


/*******************************************************************************
* mc_MPI_Reduce: Gathers arrays from MPI nodes using Reduce function.
*******************************************************************************/
int mc_MPI_Sum(double *sbuf, long count)
{
  if (!sbuf || count <= 0) return(MPI_SUCCESS); /* nothing to reduce */
  else {
    /* we must cut the buffer into blocks not exceeding the MPI max buffer size of 32000 */
    long   offset=0;
    double *rbuf=NULL;
    int    length=MPI_REDUCE_BLOCKSIZE; /* defined in mccode-r.h */
    int    i=0;
    rbuf = calloc(count, sizeof(double));
    if (!rbuf)
      exit(-fprintf(stderr, "Error: Out of memory %zi (mc_MPI_Sum)\n", count*sizeof(double)));
    while (offset < count) {
      if (!length || offset+length > count-1) length=count-offset;
      else length=MPI_REDUCE_BLOCKSIZE;
      if (MPI_Allreduce((double*)(sbuf+offset), (double*)(rbuf+offset),
              length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD) != MPI_SUCCESS)
        return MPI_ERR_COUNT;
      offset += length;
    }

    for (i=0; i<count; i++) sbuf[i] = rbuf[i];
    free(rbuf);
  }
  return MPI_SUCCESS;
} /* mc_MPI_Sum */

/*******************************************************************************
* mc_MPI_Send: Send array to MPI node by blocks to avoid buffer limit
*******************************************************************************/
int mc_MPI_Send(void *sbuf,
                  long count, MPI_Datatype dtype,
                  int dest)
{
  int dsize;
  long offset=0;
  int  tag=1;
  int  length=MPI_REDUCE_BLOCKSIZE; /* defined in mccode-r.h */

  if (!sbuf || count <= 0) return(MPI_SUCCESS); /* nothing to send */
  MPI_Type_size(dtype, &dsize);

  while (offset < count) {
    if (offset+length > count-1) length=count-offset;
    else length=MPI_REDUCE_BLOCKSIZE;
    if (MPI_Send((void*)((char*)sbuf+offset*dsize), length, dtype, dest, tag++, MPI_COMM_WORLD) != MPI_SUCCESS)
      return MPI_ERR_COUNT;
    offset += length;
  }

  return MPI_SUCCESS;
} /* mc_MPI_Send */

/*******************************************************************************
* mc_MPI_Recv: Receives arrays from MPI nodes by blocks to avoid buffer limit
*             the buffer must have been allocated previously.
*******************************************************************************/
int mc_MPI_Recv(void *sbuf,
                  long count, MPI_Datatype dtype,
                  int source)
{
  int dsize;
  long offset=0;
  int  tag=1;
  int  length=MPI_REDUCE_BLOCKSIZE; /* defined in mccode-r.h */

  if (!sbuf || count <= 0) return(MPI_SUCCESS); /* nothing to recv */
  MPI_Type_size(dtype, &dsize);

  while (offset < count) {
    if (offset+length > count-1) length=count-offset;
    else length=MPI_REDUCE_BLOCKSIZE;
    if (MPI_Recv((void*)((char*)sbuf+offset*dsize), length, dtype, source, tag++,
            MPI_COMM_WORLD, MPI_STATUS_IGNORE) != MPI_SUCCESS)
      return MPI_ERR_COUNT;
    offset += length;
  }

  return MPI_SUCCESS;
} /* mc_MPI_Recv */

#endif /* USE_MPI */

/* SECTION: parameters handling ============================================= */

/* Instrument input parameter type handling. */
/*******************************************************************************
* mcparm_double: extract double value from 's' into 'vptr'
*******************************************************************************/
static int
mcparm_double(char *s, void *vptr)
{
  char *p;
  double *v = (double *)vptr;

  if (!s) { *v = 0; return(1); }
  *v = strtod(s, &p);
  if(*s == '\0' || (p != NULL && *p != '\0') || errno == ERANGE)
    return 0;                        /* Failed */
  else
    return 1;                        /* Success */
}

/*******************************************************************************
* mcparminfo_double: display parameter type double
*******************************************************************************/
static char *
mcparminfo_double(char *parmname)
{
  return "double";
}

/*******************************************************************************
* mcparmerror_double: display error message when failed extract double
*******************************************************************************/
static void
mcparmerror_double(char *parm, char *val)
{
  fprintf(stderr, "Error: Invalid value '%s' for floating point parameter %s (mcparmerror_double)\n",
          val, parm);
}

/*******************************************************************************
* mcparmprinter_double: convert double to string
*******************************************************************************/
static void
mcparmprinter_double(char *f, void *vptr)
{
  double *v = (double *)vptr;
  sprintf(f, "%g", *v);
}

/*******************************************************************************
* mcparm_int: extract int value from 's' into 'vptr'
*******************************************************************************/
static int
mcparm_int(char *s, void *vptr)
{
  char *p;
  int *v = (int *)vptr;
  long x;

  if (!s) { *v = 0; return(1); }
  *v = 0;
  x = strtol(s, &p, 10);
  if(x < INT_MIN || x > INT_MAX)
    return 0;                        /* Under/overflow */
  *v = x;
  if(*s == '\0' || (p != NULL && *p != '\0') || errno == ERANGE)
    return 0;                        /* Failed */
  else
    return 1;                        /* Success */
}

/*******************************************************************************
* mcparminfo_int: display parameter type int
*******************************************************************************/
static char *
mcparminfo_int(char *parmname)
{
  return "int";
}

/*******************************************************************************
* mcparmerror_int: display error message when failed extract int
*******************************************************************************/
static void
mcparmerror_int(char *parm, char *val)
{
  fprintf(stderr, "Error: Invalid value '%s' for integer parameter %s (mcparmerror_int)\n",
          val, parm);
}

/*******************************************************************************
* mcparmprinter_int: convert int to string
*******************************************************************************/
static void
mcparmprinter_int(char *f, void *vptr)
{
  int *v = (int *)vptr;
  sprintf(f, "%d", *v);
}

/*******************************************************************************
* mcparm_string: extract char* value from 's' into 'vptr' (copy)
*******************************************************************************/
static int
mcparm_string(char *s, void *vptr)
{
  char **v = (char **)vptr;
  if (!s) { *v = NULL; return(1); }
  *v = (char *)malloc(strlen(s) + 1);
  if(*v == NULL)
  {
    exit(-fprintf(stderr, "Error: Out of memory %li (mcparm_string).\n", (long)strlen(s) + 1));
  }
  strcpy(*v, s);
  return 1;                        /* Success */
}

/*******************************************************************************
* mcparminfo_string: display parameter type string
*******************************************************************************/
static char *
mcparminfo_string(char *parmname)
{
  return "string";
}

/*******************************************************************************
* mcparmerror_string: display error message when failed extract string
*******************************************************************************/
static void
mcparmerror_string(char *parm, char *val)
{
  fprintf(stderr, "Error: Invalid value '%s' for string parameter %s (mcparmerror_string)\n",
          val, parm);
}

/*******************************************************************************
* mcparmprinter_string: convert string to string (including esc chars)
*******************************************************************************/
static void
mcparmprinter_string(char *f, void *vptr)
{
  char **v = (char **)vptr;
  char *p;

  if (!*v) { *f='\0'; return; }
  strcpy(f, "");
  for(p = *v; *p != '\0'; p++)
  {
    switch(*p)
    {
      case '\n':
        strcat(f, "\\n");
        break;
      case '\r':
        strcat(f, "\\r");
        break;
      case '"':
        strcat(f, "\\\"");
        break;
      case '\\':
        strcat(f, "\\\\");
        break;
      default:
        strncat(f, p, 1);
    }
  }
  /* strcat(f, "\""); */
} /* mcparmprinter_string */

/* now we may define the parameter structure, using previous functions */
static struct
  {
    int (*getparm)(char *, void *);
    char * (*parminfo)(char *);
    void (*error)(char *, char *);
    void (*printer)(char *, void *);
} mcinputtypes[] = {
  {
    mcparm_int, mcparminfo_int, mcparmerror_int,
    mcparmprinter_int
  }, {
    mcparm_string, mcparminfo_string, mcparmerror_string,
    mcparmprinter_string
  }, {
    mcparm_string, mcparminfo_string, mcparmerror_string,
    mcparmprinter_string
  }, {
    mcparm_double, mcparminfo_double, mcparmerror_double,
    mcparmprinter_double
  }, {
    mcparm_double, mcparminfo_double, mcparmerror_double,
    mcparmprinter_double
  }
};

/*******************************************************************************
* mcestimate_error: compute sigma from N,p,p2 in Gaussian large numbers approx
*******************************************************************************/
double mcestimate_error(double N, double p1, double p2)
{
  double pmean, n1;
  if(N <= 1)
    return p1;
  pmean = p1 / N;
  n1 = N - 1;
  /* Note: underflow may cause p2 to become zero; the fabs() below guards
     against this. */
  return sqrt((N/n1)*fabs(p2 - pmean*pmean));
}

double (*mcestimate_error_p)
  (double V2, double psum, double p2sum)=mcestimate_error;

/* ========================================================================== */

/*                               MCCODE_R_IO_C                                */

/* ========================================================================== */

#ifndef MCCODE_R_IO_C
#define MCCODE_R_IO_C "$Revision$"

/* SECTION: file i/o handling ================================================ */

#ifndef HAVE_STRCASESTR
// from msysgit: https://code.google.com/p/msysgit/source/browse/compat/strcasestr.c
char *strcasestr(const char *haystack, const char *needle)
{
  int nlen = strlen(needle);
  int hlen = strlen(haystack) - nlen + 1;
  int i;

  for (i = 0; i < hlen; i++) {
    int j;
    for (j = 0; j < nlen; j++) {
            unsigned char c1 = haystack[i+j];
            unsigned char c2 = needle[j];
            if (toupper(c1) != toupper(c2))
                    goto next;
    }
    return (char *) haystack + i;
  next:
    ;
  }
  return NULL;
}


#endif
#ifndef HAVE_STRCASECMP
int strcasecmp( const char *s1, const char *s2 )
{
  int c1, c2;
  do {
    c1 = tolower( (unsigned char) *s1++ );
    c2 = tolower( (unsigned char) *s2++ );
  } while (c1 == c2 && c1 != 0);
  return c2 > c1 ? -1 : c1 > c2;
}
#endif

#ifndef STRACPY
/* this is a replacement to strncpy, but ensures that the copy ends with NULL */
/* http://stracpy.blogspot.fr/2011/04/stracpy-strncpy-replacement.html */
#define STRACPY
char *stracpy(char *destination, const char *source, size_t amount)
{
        if (!destination || !source || !amount) return(NULL);
        while(amount--)
          if((*destination++ = *source++) == '\0') break;
        *destination = '\0';
        return destination;
}
#endif

/*******************************************************************************
* mcfull_file: allocates a full file name=dirname+file. Catenate extension if missing.
*******************************************************************************/
char *mcfull_file(char *name, char *ext)
{
  int   dirlen=0;
  char *mem   =NULL;

  dirlen = dirname ? strlen(dirname) : 0;
  mem = (char*)malloc(dirlen + strlen(name) + CHAR_BUF_LENGTH);
  if(!mem) {
    exit(-fprintf(stderr, "Error: Out of memory %li (mcfull_file)\n", (long)(dirlen + strlen(name) + 256)));
  }
  strcpy(mem, "");

  /* prepend directory name to path if name does not contain a path */
  if (dirlen > 0 && !strchr(name, MC_PATHSEP_C)) {
    strcat(mem, dirname);
    strcat(mem, MC_PATHSEP_S);
  } /* dirlen */

  strcat(mem, name);
  if (!strchr(name, '.') && ext && strlen(ext))
  { /* add extension if not in file name already */
    strcat(mem, ".");
    strcat(mem, ext);
  }
  return(mem);
} /* mcfull_file */

/*******************************************************************************
* mcnew_file: opens a new file within dirname if non NULL
*             the file is opened in "a" (append, create if does not exist)
*             the extension 'ext' is added if the file name does not include one.
*             the last argument is set to 0 if file did not exist, else to 1.
*******************************************************************************/
FILE *mcnew_file(char *name, char *ext, int *exists)
{
  char *mem;
  FILE *file=NULL;

  if (!name || strlen(name) == 0 || mcdisable_output_files) return(NULL);

  mem  = mcfull_file(name, ext); /* create dirname/name.ext */

  /* check for existence */
  file = fopen(mem, "r"); /* for reading -> fails if does not exist */
  if (file) {
    fclose(file);
    *exists=1;
  } else
    *exists=0;

  /* open the file for writing/appending */
#ifdef USE_NEXUS
  if (mcformat && strcasestr(mcformat, "NeXus")) {
    /* NXhandle nxhandle is defined in the .h with USE_NEXUS */
    NXaccess mode = (*exists ? NXACC_RDWR : NXACC_CREATE5);

    if (NXopen(mem, mode, &nxhandle) != NX_OK)
      file = NULL;
    else
      file = (FILE*)&nxhandle; /* to make it non NULL */
  } else
#endif
    file = fopen(mem, "a+");

  if(!file)
    fprintf(stderr, "Warning: could not open output file '%s' for %s (mcnew_file)\n",
      mem, *exists ? "append" : "create");
  free(mem);

  return file;
} /* mcnew_file */

/*******************************************************************************
* mcdetector_statistics: compute detector statistics, error bars, [x I I_err N] 1D
* RETURN:            updated detector structure
* Used by: detector_import
*******************************************************************************/
MCDETECTOR mcdetector_statistics(
  MCDETECTOR detector)
{

  if (!detector.p1 || !detector.m)
    return(detector);

  /* compute statistics and update MCDETECTOR structure ===================== */
  double sum_z  = 0, min_z  = 0, max_z  = 0;
  double fmon_x =0,  smon_x = 0, fmon_y =0, smon_y=0, mean_z=0;
  double Nsum=0, P2sum=0;

  double sum_xz = 0, sum_yz = 0, sum_x = 0, sum_y = 0, sum_x2z = 0, sum_y2z = 0;
  int    i,j;
  char   hasnan=0, hasinf=0;
  char   israw = ((char*)strcasestr(detector.format,"raw") != NULL);
  double *this_p1=NULL; /* new 1D McCode array [x I E N]. Freed after writing data */

  /* if McCode/PGPLOT and rank==1 we create a new m*4 data block=[x I E N] */
  if (detector.rank == 1 && strcasestr(detector.format,"McCode")) {
    this_p1 = (double *)calloc(detector.m*detector.n*detector.p*4, sizeof(double));
    if (!this_p1)
      exit(-fprintf(stderr, "Error: Out of memory creating %zi 1D " MCCODE_STRING " data set for file '%s' (detector_import)\n",
        detector.m*detector.n*detector.p*4*sizeof(double*), detector.filename));
  }

  max_z = min_z = detector.p1[0];

  /* compute sum and moments (not for lists) */
  if (!strcasestr(detector.format,"list") && detector.m)
  for(j = 0; j < detector.n*detector.p; j++)
  {
    for(i = 0; i < detector.m; i++)
    {
      double x,y,z;
      double N, E;
      long   index= !detector.istransposed ? i*detector.n*detector.p + j : i+j*detector.m;
      char   hasnaninf=0;

      if (detector.m)
        x = detector.xmin + (i + 0.5)/detector.m*(detector.xmax - detector.xmin);
      else x = 0;
      if (detector.n && detector.p)
        y = detector.ymin + (j + 0.5)/detector.n/detector.p*(detector.ymax - detector.ymin);
      else y = 0;
      z = detector.p1[index];
      N = detector.p0 ? detector.p0[index] : 1;
      E = detector.p2 ? detector.p2[index] : 0;
      if (detector.p2 && !israw)
        detector.p2[index] = (*mcestimate_error_p)(detector.p0[index],detector.p1[index],detector.p2[index]); /* set sigma */

      if (detector.rank == 1 && this_p1 && strcasestr(detector.format,"McCode")) {
        /* fill-in 1D McCode array [x I E N] */
        this_p1[index*4]   = x;
        this_p1[index*4+1] = z;
        this_p1[index*4+2] = detector.p2 ? detector.p2[index] : 0;
        this_p1[index*4+3] = N;
      }

      if (isnan(z) || isnan(E) || isnan(N)) hasnaninf=hasnan=1;
      if (isinf(z) || isinf(E) || isinf(N)) hasnaninf=hasinf=1;

      /* compute stats integrals */
      if (!hasnaninf) {
        sum_xz += x*z;
        sum_yz += y*z;
        sum_x  += x;
        sum_y  += y;
        sum_z  += z;
        sum_x2z += x*x*z;
        sum_y2z += y*y*z;
        if (z > max_z) max_z = z;
        if (z < min_z) min_z = z;

        Nsum += N;
        P2sum += E;
      }

    }
  } /* for j */

  /* compute 1st and 2nd moments. For lists, sum_z=0 so this is skipped. */
  if (sum_z && detector.n*detector.m*detector.p)
  {
    fmon_x = sum_xz/sum_z;
    fmon_y = sum_yz/sum_z;
    smon_x = sum_x2z/sum_z-fmon_x*fmon_x; smon_x = smon_x > 0 ? sqrt(smon_x) : 0;
    smon_y = sum_y2z/sum_z-fmon_y*fmon_y; smon_y = smon_y > 0 ? sqrt(smon_y) : 0;
    mean_z = sum_z/detector.n/detector.m/detector.p;
  }
  /* store statistics into detector */
  detector.intensity = sum_z;
  detector.error     = Nsum ? (*mcestimate_error_p)(Nsum, sum_z, P2sum) : 0;
  detector.events    = Nsum;
  detector.min       = min_z;
  detector.max       = max_z;
  detector.mean      = mean_z;
  detector.centerX   = fmon_x;
  detector.halfwidthX= smon_x;
  detector.centerY   = fmon_y;
  detector.halfwidthY= smon_y;

  /* if McCode/PGPLOT and rank==1 replace p1 with new m*4 1D McCode and clear others */
  if (detector.rank == 1 && this_p1 && strcasestr(detector.format,"McCode")) {

    detector.p1 = this_p1;
    detector.n  = detector.m; detector.m  = 4;
    detector.p0 = detector.p2 = NULL;
    detector.istransposed = 1;
  }

  if (detector.n*detector.m*detector.p > 1)
    snprintf(detector.signal, CHAR_BUF_LENGTH,
      "Min=%g; Max=%g; Mean=%g;", detector.min, detector.max, detector.mean);
  else
    strcpy(detector.signal, "None");
  snprintf(detector.values, CHAR_BUF_LENGTH,
    "%g %g %g", detector.intensity, detector.error, detector.events);

  switch (detector.rank) {
    case 1:  snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g;",
      detector.centerX, detector.halfwidthX); break;
    case 2:
    case 3:  snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g; Y0=%g; dY=%g;",
      detector.centerX, detector.halfwidthX, detector.centerY, detector.halfwidthY);
      break;
    default: strcpy(detector.statistics, "None");
  }

  if (hasnan)
    printf("WARNING: Nan detected in component/file %s %s\n",
      detector.component, strlen(detector.filename) ? detector.filename : "");
  if (hasinf)
    printf("WARNING: Inf detected in component/file %s %s\n",
      detector.component, strlen(detector.filename) ? detector.filename : "");

  return(detector);

} /* mcdetector_statistics */

/*******************************************************************************
* detector_import: build detector structure, merge non-lists from MPI
*                    compute basic stat, write "Detector:" line
* RETURN:            detector structure. Invalid data if detector.p1 == NULL
*                    Invalid detector sets m=0 and filename=""
*                    Simulation data  sets m=0 and filename=siminfo_name
* This function is equivalent to the old 'mcdetector_out', returning a structure
*******************************************************************************/
MCDETECTOR detector_import(
  char *format,
  char *component, char *title,
  long m, long n,  long p,
  char *xlabel, char *ylabel, char *zlabel,
  char *xvar, char *yvar, char *zvar,
  double x1, double x2, double y1, double y2, double z1, double z2,
  char *filename,
  double *p0, double *p1, double *p2,
  Coords position, Rotation rotation, int index)
{
  time_t t;       /* for detector.date */
  long   date_l;  /* date as a long number */
  char   istransposed=0;
  char   c[CHAR_BUF_LENGTH]; /* temp var for signal label */

  MCDETECTOR detector;
  detector.options[0] = '\0'; /* only the 2D/list paths set it; the NeXus writer reads it for all */

  /* build MCDETECTOR structure ============================================= */
  /* make sure we do not have NULL for char fields */

  /* these also apply to simfile */
  strncpy (detector.filename,  filename ? filename : "",        CHAR_BUF_LENGTH);
  strncpy (detector.format,    format   ? format   : "McCode" , CHAR_BUF_LENGTH);
  /* add extension if missing */
  if (strlen(detector.filename) && !strchr(detector.filename, '.'))
  { /* add extension if not in file name already */
    strcat(detector.filename, ".dat");
  }
  strncpy (detector.component, component ? component : MCCODE_STRING " component", CHAR_BUF_LENGTH);
  #ifdef USE_NEXUS
  char pref[5];
  if (index-1 < 10) {
    sprintf(pref,"000");
  } else if (index-1 < 100) {
    sprintf(pref,"00");
  } else if (index-1 < 1000) {
    sprintf(pref,"0");
  } else if (index-1 < 10000) {
    sprintf(pref,"");
  } else {
    fprintf(stderr,"Error, no support for > 10000 comps at the moment!\n");
    exit(-1);
  }
  sprintf(detector.nexuscomp,"%s%d_%s",pref,index-1,detector.component);
  #endif

  snprintf(detector.instrument, CHAR_BUF_LENGTH, "%s (%s)", instrument_name, instrument_source);
  snprintf(detector.user, CHAR_BUF_LENGTH,      "%s on %s",
        getenv("USER") ? getenv("USER") : MCCODE_NAME,
        getenv("HOST") ? getenv("HOST") : "localhost");
  time(&t);         /* get current write time */
  date_l = (long)t; /* same but as a long */
  snprintf(detector.date, CHAR_BUF_LENGTH, "%s", ctime(&t));
  if (strlen(detector.date))   detector.date[strlen(detector.date)-1] = '\0'; /* remove last \n in date */
  detector.date_l = date_l;

  if (!mcget_run_num() || mcget_run_num() >= mcget_ncount())
    snprintf(detector.ncount, CHAR_BUF_LENGTH, "%llu", mcget_ncount()
#ifdef USE_MPI
*mpi_node_count
#endif
  );
  else
    snprintf(detector.ncount, CHAR_BUF_LENGTH, "%g/%g", (double)mcget_run_num(), (double)mcget_ncount());

  detector.p0         = p0;
  detector.p1         = p1;
  detector.p2         = p2;

  /* handle transposition (not for NeXus) */
  if (!strcasestr(detector.format, "NeXus")) {
    if (m<0 || n<0 || p<0)             istransposed = !istransposed;
    if (strcasestr(detector.format, "transpose")) istransposed = !istransposed;
    if (istransposed) { /* do the swap once for all */
      long i=m; m=n; n=i;
    }
  }

  m=labs(m); n=labs(n); p=labs(p); /* make sure dimensions are positive */
  detector.istransposed = istransposed;

  /* determine detector rank (dimensionality) */
  if (!m || !n || !p || !p1) detector.rank = 4; /* invalid: exit with m=0 filename="" */
  else if (m*n*p == 1)       detector.rank = 0; /* 0D */
  else if ((n == 1 || m == 1)
        && !strcasestr(detector.format, "list")) detector.rank = 1; /* 1D (a single-event list stays a list) */
  else if (p == 1)           detector.rank = 2; /* 2D */
  else                       detector.rank = 3; /* 3D */

  /* from rank, set type */
  switch (detector.rank) {
    case 0:  strcpy(detector.type,  "array_0d"); m=n=p=1; break;
    case 1:  snprintf(detector.type, CHAR_BUF_LENGTH, "array_1d(%ld)", m*n*p); m *= n*p; n=p=1; break;
    case 2:  if(!strcasestr(detector.format,"list")) {
               snprintf(detector.type, CHAR_BUF_LENGTH, "array_2d(%ld, %ld)", m, n*p); n *= p; p=1;
             } else {
               snprintf(detector.type, CHAR_BUF_LENGTH, "list(%ld, %ld)", m, n*p); n *= p; p=1;
             } break;
    case 3:  snprintf(detector.type, CHAR_BUF_LENGTH, "array_3d(%ld, %ld, %ld)", m, n, p); break;
    default: m=0; strcpy(detector.type, ""); strcpy(detector.filename, "");/* invalid */
  }

  detector.m    = m;
  detector.n    = n;
  detector.p    = p;

  /* these only apply to detector files ===================================== */

  detector.Position[0]=position.x;
  detector.Position[1]=position.y;
  detector.Position[2]=position.z;
  rot_copy(detector.Rotation,rotation);
  snprintf(detector.position, CHAR_BUF_LENGTH, "%g %g %g", position.x, position.y, position.z);
  /* may also store actual detector orientation in the future */

  strncpy(detector.title,      title && strlen(title) ? title : component,       CHAR_BUF_LENGTH);
  strncpy(detector.xlabel,     xlabel && strlen(xlabel) ? xlabel : "X", CHAR_BUF_LENGTH); /* axis labels */
  strncpy(detector.ylabel,     ylabel && strlen(ylabel) ? ylabel : "Y", CHAR_BUF_LENGTH);
  strncpy(detector.zlabel,     zlabel && strlen(zlabel) ? zlabel : "Z", CHAR_BUF_LENGTH);
  strncpy(detector.xvar,       xvar && strlen(xvar) ? xvar :       "x", CHAR_BUF_LENGTH); /* axis variables */
  strncpy(detector.yvar,       yvar && strlen(yvar) ? yvar :       detector.xvar, CHAR_BUF_LENGTH);
  strncpy(detector.zvar,       zvar && strlen(zvar) ? zvar :       detector.yvar, CHAR_BUF_LENGTH);

  /* set "variables" as e.g. "I I_err N" */
  strcpy(c, "I ");
  if (strlen(detector.zvar))      strncpy(c, detector.zvar,32);
  else if (strlen(detector.yvar)) strncpy(c, detector.yvar,32);
  else if (strlen(detector.xvar)) strncpy(c, detector.xvar,32);

  if (detector.rank == 1)
    snprintf(detector.variables, CHAR_BUF_LENGTH, "%s %s %s_err N", detector.xvar, c, c);
  else
    snprintf(detector.variables, CHAR_BUF_LENGTH, "%s %s_err N", c, c);

  /* limits */
  detector.xmin = x1;
  detector.xmax = x2;
  detector.ymin = y1;
  detector.ymax = y2;
  detector.zmin = z1;
  detector.zmax = z2;
  if (abs(detector.rank) == 1)
    snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g", x1, x2);
  else if (detector.rank == 2)
    snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g %g %g", x1, x2, y1, y2);
  else
    snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g %g %g %g %g", x1, x2, y1, y2, z1, z2);

  /* if MPI and nodes_nb > 1: reduce data sets when using MPI =============== */
#ifdef USE_MPI
  if (!strcasestr(detector.format,"list") && mpi_node_count > 1 && m) {
    /* we save additive data: reduce everything into mpi_node_root */
    if (p0) mc_MPI_Sum(p0, m*n*p);
    if (p1) mc_MPI_Sum(p1, m*n*p);
    if (p2) mc_MPI_Sum(p2, m*n*p);
    if (!p0) {  /* additive signal must be then divided by the number of nodes */
      int i;
      for (i=0; i<m*n*p; i++) {
        p1[i] /= mpi_node_count;
        if (p2) p2[i] /= mpi_node_count;
      }
    }
  }
#endif /* USE_MPI */

  /* compute statistics, Nsum, intensity, Error bars */
  detector = mcdetector_statistics(detector);

#ifdef USE_MPI
  /* slaves are done */
  if(mpi_node_rank != mpi_node_root) {
    return detector;
  }
#endif

  /* output "Detector:" line ================================================ */
  /* when this is a detector written by a component (not the SAVE from instrument),
     not an event lists */
  if (!m) return(detector);
  if (!strcasestr(detector.format,"list")) {
    if (!strcmp(detector.component, instrument_name)) {
      if (strlen(detector.filename))  /* we name it from its filename, or from its title */
        strncpy(c, detector.filename, CHAR_BUF_LENGTH);
      else
        snprintf(c, CHAR_BUF_LENGTH, "%s", instrument_name);
    } else
      strncpy(c, detector.component, CHAR_BUF_LENGTH);  /* usual detectors written by components */

    printf("Detector: %s_I=%g %s_ERR=%g %s_N=%g",
           c, detector.intensity,
           c, detector.error,
           c, detector.events);
    printf(" \"%s\"\n", strlen(detector.filename) ? detector.filename : detector.component);
  }


  return(detector);
} /* detector_import */

/* end MCDETECTOR import section ============================================ */

















/* ========================================================================== */

/*                               ASCII output                                 */
/*     The SIM file is YAML based, the data files have '#' headers            */

/* ========================================================================== */


/*******************************************************************************
* mcinfo_out: output instrument tags/info (only in SIM)
* Used in: siminfo_init (ascii), mcinfo(stdout)
*******************************************************************************/
static void mcinfo_out(char *pre, FILE *f)
{
  char Parameters[CHAR_BUF_LENGTH] = "";
  int  i;

  if (!f || mcdisable_output_files) return;

  /* create parameter string ================================================ */
  for(i = 0; i < numipar; i++)
  {
    char ThisParam[CHAR_BUF_LENGTH];
    if (strlen(mcinputtable[i].name) > CHAR_BUF_LENGTH) break;
    snprintf(ThisParam, CHAR_BUF_LENGTH, " %s(%s)", mcinputtable[i].name,
            (*mcinputtypes[mcinputtable[i].type].parminfo)
                (mcinputtable[i].name));
    if (strlen(Parameters) + strlen(ThisParam) + 1 >= CHAR_BUF_LENGTH) break;
    strcat(Parameters, ThisParam);
  }

  /* output data ============================================================ */
  if (f != stdout)
    fprintf(f, "%sFile: %s%c%s\n",    pre, dirname, MC_PATHSEP_C, siminfo_name);
  else
    fprintf(f, "%sCreator: %s\n",     pre, MCCODE_STRING);

  fprintf(f, "%sSource: %s\n",   pre, instrument_source);
  fprintf(f, "%sParameters: %s\n",    pre, Parameters);

  fprintf(f, "%sTrace_enabled: %s\n", pre, traceenabled ? "yes" : "no");
  fprintf(f, "%sDefault_main: %s\n",  pre, defaultmain ?  "yes" : "no");
#ifdef MC_EMBEDDED_RUNTIME
  fprintf(f, "%sEmbedded_runtime: %s\n", pre, "yes");
#else
  fprintf(f, "%sEmbedded_runtime: %s\n", pre, "no");
#endif

  fflush(f);
} /* mcinfo_out */

/*******************************************************************************
* mcruninfo_out: output simulation tags/info (both in SIM and data files)
* Used in: siminfo_init (ascii case), mcdetector_out_xD_ascii
*******************************************************************************/
static void mcruninfo_out(char *pre, FILE *f)
{
  int i;
  char Parameters[CHAR_BUF_LENGTH];

  if (!f || mcdisable_output_files) return;

  fprintf(f, "%sFormat: %s%s\n",      pre,
    mcformat && strlen(mcformat) ? mcformat : MCCODE_NAME,
    mcformat && strcasestr(mcformat,"McCode") ? " with text headers" : "");
  fprintf(f, "%sURL: %s\n",         pre, "http://www.mccode.org");
  fprintf(f, "%sCreator: %s\n",     pre, MCCODE_STRING);
  fprintf(f, "%sInstrument: %s\n", pre, instrument_source);
  fprintf(f, "%sNcount: %llu\n",        pre, mcget_ncount());
  fprintf(f, "%sTrace: %s\n",       pre, mcdotrace ? "yes" : "no");
  fprintf(f, "%sGravitation: %s\n", pre, mcgravitation ? "yes" : "no");
  snprintf(Parameters, CHAR_BUF_LENGTH, "%ld", mcseed);
  fprintf(f, "%sSeed: %s\n",        pre, Parameters);
  fprintf(f, "%sDirectory: %s\n",        pre, dirname ? dirname : ".");
#ifdef USE_MPI
  if (mpi_node_count > 1)
    fprintf(f, "%sNodes: %i\n",        pre, mpi_node_count);
#endif

  // TODO Consider replacing this by a a call to `mcparameterinfo_out(pre+"Param: ", f)`
  /* output parameter string ================================================ */
  for(i = 0; i < numipar; i++) {
      if (mcinputtable[i].par){
	/* Parameters with a default value */
	if(mcinputtable[i].val && strlen(mcinputtable[i].val)){
	  (*mcinputtypes[mcinputtable[i].type].printer)(Parameters, mcinputtable[i].par);
	  fprintf(f, "%sParam: %s=%s\n", pre, mcinputtable[i].name, Parameters);
        /* ... and those without */
	}else{
	  fprintf(f, "%sParam: %s=NULL\n", pre, mcinputtable[i].name);
	}
      }
  }
  fflush(f);
} /* mcruninfo_out */

/*******************************************************************************
 * @brief Print parameter information to the specified file
 * @param pre any beginning-of-line padding
 * @param f the output file
 */
static void mcparameterinfo_out(char * pre, FILE *f){
  if (!f || mcdisable_output_files) return;

  unsigned int nchar = 4;
  for (int i=0; i < numipar; ++i){
    if (mcinputtable[i].par && mcinputtable[i].val && strlen(mcinputtable[i].val) > nchar)
      nchar = strlen(mcinputtable[i].val);
  }
  char * buffer = calloc(nchar+1, sizeof(char));

  if (!buffer) {
    exit(1);
  }

  for (int i=0; i < numipar; ++i) {
    if (mcinputtable[i].par) {
      char * name = mcinputtable[i].name;
      if (mcinputtable[i].val && strlen(mcinputtable[i].val)) {
        mcinputtypes[mcinputtable[i].type].printer(buffer, mcinputtable[i].par);
      } else {
        strcpy(buffer, "NULL");
      }
      if (strlen(mcinputtable[i].unit)){
        //fprintf(f, "%s%s %s (\"%s\") = %s\n", pre, mcinputtypes[mcinputtable[i].type].parminfo(name), name, mcinputtable[i].unit, buffer);
        fprintf(f, "%s%s %s/\"%s\" = %s\n", pre, mcinputtypes[mcinputtable[i].type].parminfo(name), name, mcinputtable[i].unit, buffer);
      } else {
        fprintf(f, "%s%s %s = %s\n", pre, mcinputtypes[mcinputtable[i].type].parminfo(name), name, buffer);
      }
    }
  }

  free(buffer);
}

/*******************************************************************************
* siminfo_out:    wrapper to fprintf(siminfo_file)
*******************************************************************************/
void siminfo_out(char *format, ...)
{
  va_list ap;

#ifdef USE_NEXUS
  if (siminfo_file == (FILE*)&nxhandle) return; /* NeXus: not a FILE */
#endif
  if(siminfo_file && !mcdisable_output_files)
  {
    va_start(ap, format);
    vfprintf(siminfo_file, format, ap);
    va_end(ap);
  }
} /* siminfo_out */


/*******************************************************************************
* mcdatainfo_out: output detector header
*   mcdatainfo_out(prefix, file_handle, detector) writes info to data file
*******************************************************************************/
static void
mcdatainfo_out(char *pre, FILE *f, MCDETECTOR detector)
{
  if (!f || !detector.m || mcdisable_output_files) return;

  /* output data ============================================================ */
  fprintf(f, "%sDate: %s (%li)\n",       pre, detector.date, detector.date_l);
  fprintf(f, "%stype: %s\n",       pre, detector.type);
  fprintf(f, "%sSource: %s\n",     pre, detector.instrument);
  fprintf(f, "%scomponent: %s\n",  pre, detector.component);
  fprintf(f, "%sposition: %s\n",   pre, detector.position);

  fprintf(f, "%stitle: %s\n",      pre, detector.title);
  fprintf(f, !mcget_run_num() || mcget_run_num() >= mcget_ncount() ?
             "%sNcount: %s\n" :
             "%sratio: %s\n",  pre, detector.ncount);

  if (strlen(detector.filename)) {
    fprintf(f, "%sfilename: %s\n", pre, detector.filename);
  }

  fprintf(f, "%sstatistics: %s\n", pre, detector.statistics);
  fprintf(f, "%ssignal: %s\n",     pre, detector.signal);
  fprintf(f, "%svalues: %s\n",     pre, detector.values);

  if (detector.rank >= 1)
  {
    fprintf(f, "%sxvar: %s\n",     pre, detector.xvar);
    fprintf(f, "%syvar: %s\n",     pre, detector.yvar);
    fprintf(f, "%sxlabel: %s\n",   pre, detector.xlabel);
    fprintf(f, "%sylabel: %s\n",   pre, detector.ylabel);
    if (detector.rank > 1) {
      fprintf(f, "%szvar: %s\n",   pre, detector.zvar);
      fprintf(f, "%szlabel: %s\n", pre, detector.zlabel);
    }
  }

  fprintf(f,
    abs(detector.rank)==1 ?
             "%sxlimits: %s\n" :
             "%sxylimits: %s\n", pre, detector.limits);
  fprintf(f, "%svariables: %s\n", pre,
    strcasestr(detector.format, "list") ? detector.ylabel : detector.variables);

  fflush(f);

} /* mcdatainfo_out */

/* mcdetector_out_array_ascii: output a single array to a file
 *   m: columns
 *   n: rows
 *   p: array
 *   f: file handle (already opened)
 */
static void mcdetector_out_array_ascii(long m, long n, double *p, FILE *f, char istransposed)
{
  if(f)
  {
    int i,j;
    for(j = 0; j < n; j++)
    {
      for(i = 0; i < m; i++)
      {
          fprintf(f, "%.10g ", p[!istransposed ? i*n + j : j*m+i]);
      }
      fprintf(f,"\n");
    }
  }
} /* mcdetector_out_array_ascii */

/*******************************************************************************
* mcdetector_out_0D_ascii: called by mcdetector_out_0D for ascii output
*******************************************************************************/
MCDETECTOR mcdetector_out_0D_ascii(MCDETECTOR detector)
{
  int exists=0;
  FILE *outfile = NULL;

  /* Write data set information to simulation description file. */
  MPI_MASTER(
    siminfo_out("\nbegin data\n"); // detector.component
    mcdatainfo_out("  ", siminfo_file, detector);
    siminfo_out("end data\n");
    /* Don't write if filename is NULL: mcnew_file handles this (return NULL) */
    outfile = mcnew_file(detector.component, "dat", &exists);
    if(outfile)
    {
      /* write data file header and entry in simulation description file */
      mcruninfo_out( "# ", outfile);
      mcdatainfo_out("# ", outfile, detector);
      /* write I I_err N */
      fprintf(outfile, "%g %g %g\n",
        detector.intensity, detector.error, detector.events);
      fclose(outfile);
    }
  ); /* MPI_MASTER */
  return(detector);
} /* mcdetector_out_0D_ascii */

/*******************************************************************************
* mcdetector_out_1D_ascii: called by mcdetector_out_1D for ascii output
*******************************************************************************/
MCDETECTOR mcdetector_out_1D_ascii(MCDETECTOR detector)
{
  int exists=0;
  FILE *outfile = NULL;

  MPI_MASTER(
    /* Write data set information to simulation description file. */
    siminfo_out("\nbegin data\n"); // detector.filename
    mcdatainfo_out("  ", siminfo_file, detector);
    siminfo_out("end data\n");
    /* Loop over array elements, writing to file. */
    /* Don't write if filename is NULL: mcnew_file handles this (return NULL) */
    outfile = mcnew_file(detector.filename, "dat", &exists);
    if(outfile)
    {
      /* write data file header and entry in simulation description file */
      mcruninfo_out( "# ", outfile);
      mcdatainfo_out("# ", outfile, detector);
      /* output the 1D array columns */
      mcdetector_out_array_ascii(detector.m, detector.n, detector.p1, outfile, detector.istransposed);

      fclose(outfile);
    }
  ); /* MPI_MASTER */
  return(detector);

}  /* mcdetector_out_1D_ascii */

/*******************************************************************************
* mcdetector_out_2D_ascii: called by mcdetector_out_2D for ascii output
*******************************************************************************/
MCDETECTOR mcdetector_out_2D_ascii(MCDETECTOR detector)
{
  int exists=0;
  FILE *outfile = NULL;

  MPI_MASTER(
    /* Loop over array elements, writing to file. */
    /* Don't write if filename is NULL: mcnew_file handles this (return NULL) */
    outfile = mcnew_file(detector.filename, "dat", &exists);
    if(outfile)
    {
      /* write header only if file has just been created (not appending) */
      if (!exists) {
        /* Write data set information to simulation description file. */
        siminfo_out("\nbegin data\n"); // detector.filename
        mcdatainfo_out("  ", siminfo_file, detector);
        siminfo_out("end data\n");

        mcruninfo_out( "# ", outfile);
        mcdatainfo_out("# ", outfile,   detector);
      }
      /* Add # Data entry for any write to the file (e.g. via -USR2, see GitHub issue #2174 ) */
      fprintf(outfile, "# Data [%s/%s] %s:\n", detector.component, detector.filename, detector.zvar);
      mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p1,
        outfile, detector.istransposed);
      if (detector.p2) {
        fprintf(outfile, "# Errors [%s/%s] %s_err:\n", detector.component, detector.filename, detector.zvar);
        mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p2,
          outfile, detector.istransposed);
      }
      if (detector.p0) {
        fprintf(outfile, "# Events [%s/%s] N:\n", detector.component, detector.filename);
        mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p0,
          outfile, detector.istransposed);
      }
      fclose(outfile);

      if (!exists) {
        if (strcasestr(detector.format, "list"))
          printf("Events:   \"%s\"\n",
            strlen(detector.filename) ? detector.filename : detector.component);
      }
    } /* if outfile */
  ); /* MPI_MASTER */
  /* MPI list mode: rows from all nodes are written by the master in
     mcdetector_out_list_mpi (see mcdetector_out_2D_list) */
  return(detector);
} /* mcdetector_out_2D_ascii */

/*******************************************************************************
* strcpy_valid: makes a valid string for variable names.
*   copy 'original' into 'valid', replacing invalid characters by '_'
*   char arrays must be pre-allocated
*******************************************************************************/
static char *strcpy_valid(char *valid, char *original)
{
  long i;
  int  n=CHAR_BUF_LENGTH; /* max length of valid names */

  if (original == NULL || !strlen(original)) return(NULL);

  if (n > strlen(original)) n = strlen(original);
  else original += strlen(original)-n;
  strncpy(valid, original, n);

  for (i=0; i < n; i++)
  {
    if ( (valid[i] > 122)
      || (valid[i] < 32)
      || (strchr("!\"#$%&'()*+,-.:;<=>?@[\\]^`/ \n\r\t", valid[i]) != NULL) )
    {
      if (i) valid[i] = '_'; else valid[i] = 'm';
    }
  }
  valid[i] = '\0';

  return(valid);
} /* strcpy_valid */

/* end ascii output section ================================================= */







#ifdef USE_NEXUS

NXhandle nxhandle = NULL;

/* name of the NXentry opened by mcinfo_out_nexus (used by mclist_vds_write) */
static char mcnxentry[CHAR_BUF_LENGTH] = "entry1";

/* ========================================================================== */

/*                               NeXus output                                 */

/* ========================================================================== */

#define nxprintf(...)    nxstr('d', __VA_ARGS__)
#define nxprintattr(...) nxstr('a', __VA_ARGS__)

/*******************************************************************************
* nxstr: output a tag=value data set (char) in NeXus/current group
*   the value is assembled with format and following arguments: a string
*   value must be passed as nxstr(.., "%s", value). Empty values are skipped.
*   type='d' -> data set
*        'a' -> attribute for current data set
*******************************************************************************/
static int nxstr(char type, NXhandle f, char *tag, char *format, ...)
{
  va_list ap;
  char   *value;
  int     len, ret;

  if (!tag || !format || !strlen(tag) || !strlen(format)) return(NX_OK);

  /* assemble the value string */
  va_start(ap, format);
  len = vsnprintf(NULL, 0, format, ap);
  va_end(ap);
  if (len <= 0) return(NX_OK);
  if (!(value = malloc(len+1))) return(NX_ERROR);
  va_start(ap, format);
  vsnprintf(value, len+1, format, ap);
  va_end(ap);

  if (type == 'd') {
    /* create/open/put/close data set */
    ret = NXmakedata(f, tag, NX_CHAR, 1, &len);
    if (ret == NX_OK && (ret = NXopendata(f, tag)) == NX_OK) {
      ret = NXputdata(f, value);
      NXclosedata(f);
    }
  } else
    ret = NXputattr(f, tag, value, len, NX_CHAR);
  free(value);
  return(ret);

} /* nxstr */

/*******************************************************************************
* mcinfo_readfile: read a full file into a string buffer which is allocated
*   Think to free the buffer after use.
* Used in: mcinfo_out_nexus (nexus)
*******************************************************************************/
char *mcinfo_readfile(char *filename)
{
  FILE *f = fopen(filename, "rb");
  if (!f) return(NULL);
  fseek(f, 0, SEEK_END);
  long fsize = ftell(f);
  rewind(f);
  char *string = fsize >= 0 ? malloc(fsize + 1) : NULL;
  if (string) string[fread(string, 1, fsize, f)] = 0;
  fclose(f);
  return(string);
}

/*******************************************************************************
* mcinfo_out: output instrument/simulation groups in NeXus file
* Used in: siminfo_init (nexus)
*******************************************************************************/
static void mcinfo_out_nexus(NXhandle f)
{
  FILE  *fid;     /* for intrument source code/C/IDF */
  char  *buffer=NULL;
  time_t t     =time(NULL); /* for date */
  char   entry0[CHAR_BUF_LENGTH];
  int    count=0;
  char   name[CHAR_BUF_LENGTH];
  char   class[CHAR_BUF_LENGTH];

  if (!f || mcdisable_output_files) return;

  /* write NeXus NXroot attributes */
  /* automatically added: file_name, HDF5_Version, file_time, NeXus_version */
  nxprintattr(f, "creator",   "%s generated with " MCCODE_STRING, instrument_name);

  /* count the number of existing NXentry and create the next one */
  NXgetgroupinfo(f, &count, name, class);
  sprintf(entry0, "entry%i", count+1);
  strcpy(mcnxentry, entry0);

  /* create the main NXentry (mandatory in NeXus) */
  if (NXmakegroup(f, entry0, "NXentry") == NX_OK)
  if (NXopengroup(f, entry0, "NXentry") == NX_OK) {
    nxprintf(f, "program_name", MCCODE_STRING);
    nxprintf(f, "start_time", "%s", ctime(&t));
    nxprintf(f, "title", "%s%s%s simulation generated by instrument %s",
      dirname && strlen(dirname) ? dirname : ".", MC_PATHSEP_S, siminfo_name,
      instrument_name);
    nxprintattr(f, "program_name", MCCODE_STRING);
    nxprintattr(f, "instrument", "%s",   instrument_name);
    nxprintattr(f, "simulation",   "%s%s%s",
        dirname && strlen(dirname) ? dirname : ".", MC_PATHSEP_S, siminfo_name);

    /* write NeXus instrument group */
    if (NXmakegroup(f, "instrument", "NXinstrument") == NX_OK)
    if (NXopengroup(f, "instrument", "NXinstrument") == NX_OK) {
      int   i;
      char *string=NULL;

      /* write NeXus parameters(types) data =================================== */
      string = (char*)malloc(CHAR_BUF_LENGTH);
      if (string) {
        strcpy(string, "");
        for(i = 0; i < numipar; i++)
        {
          char ThisParam[CHAR_BUF_LENGTH];
          snprintf(ThisParam, CHAR_BUF_LENGTH, " %s(%s)", mcinputtable[i].name,
                  (*mcinputtypes[mcinputtable[i].type].parminfo)
                      (mcinputtable[i].name));
          if (strlen(string) + strlen(ThisParam) < CHAR_BUF_LENGTH)
            strcat(string, ThisParam);
        }
        nxprintattr(f, "Parameters", "%s",    string);
        free(string);
      }

      nxprintattr(f, "name", "%s",          instrument_name);
      nxprintf   (f, "name", "%s",          instrument_name);
      nxprintattr(f, "Source", "%s",        instrument_source);

      nxprintattr(f, "Trace_enabled", "%s", traceenabled ? "yes" : "no");
      nxprintattr(f, "Default_main", "%s",  defaultmain ?  "yes" : "no");
#ifdef MC_EMBEDDED_RUNTIME
      nxprintattr(f, "Embedded_runtime", "yes");
#else
      nxprintattr(f, "Embedded_runtime", "no");
#endif

      /* add instrument source code when available */
      buffer = mcinfo_readfile(instrument_source);
      if (buffer && strlen(buffer)) {
        long length=strlen(buffer);
        nxprintf (f, "description", "%s", buffer);
        NXopendata(f,"description");
        nxprintattr(f, "file_name", "%s", instrument_source);
        nxprintattr(f, "file_size", "%li", length);
        nxprintattr(f, "MCCODE_STRING", MCCODE_STRING);
        NXclosedata(f);
        nxprintf (f,"instrument_source", "%s " MCCODE_NAME " " MCCODE_PARTICLE " Monte Carlo simulation", instrument_name);
        free(buffer);
      } else
        nxprintf (f, "description", "File %s not found (instrument description %s is missing)",
          instrument_source, instrument_name);

      if (mcnexus_embed_idf) {
        /* add Mantid/IDF.xml when available */
        char *IDFfile=NULL;
        IDFfile = (char*)malloc(CHAR_BUF_LENGTH);
        sprintf(IDFfile,"%s%s",instrument_source,".xml");
        buffer = mcinfo_readfile(IDFfile);
        if (buffer && strlen(buffer)) {
          NXmakegroup (f, "instrument_xml", "NXnote");
          if (NXopengroup(f, "instrument_xml", "NXnote") == NX_OK) {
            nxprintf(f, "data", "%s", buffer);
            nxprintf(f, "description", "IDF.xml file found with instrument %s", instrument_source);
            nxprintf(f, "type", "text/xml");
            NXclosegroup(f); /* instrument_xml */
          }
        }
        free(buffer);
        free(IDFfile);
      }

      /* Add "components" entry */
      if (NXmakegroup(f, "components", "NXdata") == NX_OK) {
        NXopengroup(f, "components", "NXdata");
        nxprintattr(f, "description", "Component list for instrument %s",  instrument_name);
	NXclosegroup(f); /* components */
      } else {
	printf("Failed to create NeXus component hierarchy\n");
      }
      NXclosegroup(f); /* instrument */
    } /* NXinstrument */

    /* write NeXus simulation group */
    if (NXmakegroup(f, "simulation", "NXnote") == NX_OK)
    if (NXopengroup(f, "simulation", "NXnote") == NX_OK) {

      nxprintattr(f, "name",   "%s%s%s",
        dirname && strlen(dirname) ? dirname : ".", MC_PATHSEP_S, siminfo_name);

      nxprintf   (f, "name",      "%s",     siminfo_name);
      nxprintattr(f, "Format", "%s",    mcformat && strlen(mcformat) ? mcformat : MCCODE_NAME);
      nxprintattr(f, "URL",       "http://www.mccode.org");
      nxprintattr(f, "program",   MCCODE_STRING);
      nxprintattr(f, "Instrument", "%s",instrument_source);
      nxprintattr(f, "Trace", "%s",     mcdotrace ?     "yes" : "no");
      nxprintattr(f, "Gravitation", "%s",mcgravitation ? "yes" : "no");
      nxprintattr(f, "Seed",      "%li", mcseed);
      /* written before mccode_main splits the rays over MPI nodes */
      nxprintattr(f, "Ncount_requested", "%llu", mcget_ncount());
      nxprintattr(f, "Directory", "%s", dirname ? dirname : "");
    #ifdef USE_MPI
      if (mpi_node_count > 1)
        nxprintf(f, "Nodes", "%i",        mpi_node_count);
    #endif

      /* output parameter string ================================================ */
      if (NXmakegroup(f, "Param", "NXparameters") == NX_OK) {
	NXopengroup(f,"Param", "NXparameters");
        int i;
        char string[CHAR_BUF_LENGTH];
        for(i = 0; i < numipar; i++) {
          if (mcget_run_num() || (mcinputtable[i].val && strlen(mcinputtable[i].val))) {
            if (mcinputtable[i].par == NULL)
              strncpy(string, (mcinputtable[i].val ? mcinputtable[i].val : ""), CHAR_BUF_LENGTH);
            else
              (*mcinputtypes[mcinputtable[i].type].printer)(string, mcinputtable[i].par);

            nxprintf(f,  mcinputtable[i].name, "%s", string);
            nxprintattr(f, mcinputtable[i].name, "%s", string);
          }
        }
        NXclosegroup(f); /* Param */
      } /* NXparameters */
      NXclosegroup(f); /* simulation */
    } /* NXsimulation */

    /* create a group to hold all links for all monitors */
    NXmakegroup(f, "data", "NXdetector");

    /* leave the NXentry opened (closed at exit) */
  } /* NXentry */
} /* mcinfo_out_nexus */

/*******************************************************************************
* Runtime capture of component SETTING parameter values (NeXus only)
*
* mccomp_param_nexus() only receives the literal parameter expressions from the
* instrument file. To also store the numerical value present at the end of
* INITIALIZE, the runtime keeps a small registry, filled from the existing
* (generated) calls in _<comp>_setpos():
*
*   mccomp_placement_type_nexus() -> mcrt_register_comp()  (instance + type)
*   mccomp_param_nexus()          -> mcrt_register_param() (one per SETTING par)
*
* The parameter struct base comes from the generated _getvar_parameters(name).
* Member offsets are reconstructed from the order of the calls and the type
* strings, following the struct layout written by cogen_comp_declare():
*   - SETTING parameters come first, in set_par order (= order of the calls)
*   - int -> int, char* -> char[16384], char -> char, double -> double (symbol),
*     MCNUM -> double, MCNUM* (vector) or MCNUM[n] (static {..} vector, sized
*     from the FIRST instance of the component type)
*   - mccode-antlr writes the same layout with other type strings: "char *",
*     "double" for MCNUM and "double*" for vectors, where a literal vector
*     "a,b,c" is a calloc'ed double* holding those elements
*     Type strings are compared with whitespace removed.
* The layout is validated at setpos time (strings by content, numbers when the
* literal is a plain number); mismatching instances are not reported.
*
* mccomp_param_runtime_nexus_all(), called from mccode_main() after init(),
* adds 'runtime_value' and 'runtime_value_status' attributes to
*   entry<N>/instrument/components/NNNN_<comp>/parameters/<par>
*******************************************************************************/

/* MUST match the char[16384] declaration of string parameters in
   cogen_comp_declare() (mccode/src/cogen.c.in) */
#ifndef MCCODE_COMP_STRING_PAR_LEN
#define MCCODE_COMP_STRING_PAR_LEN 16384
#endif

enum mcrtpar_kind {
  MCRTPAR_INT, MCRTPAR_STRING, MCRTPAR_CHAR, MCRTPAR_DOUBLE,
  MCRTPAR_VECTOR_PTR, MCRTPAR_VECTOR_ARR, MCRTPAR_UNKNOWN
};

struct mcrtcomp_struct {
  char  *nexuscomp;     /* e.g. 0003_Mon      */
  char  *name;          /* e.g. Mon           */
  char  *comptype;      /* e.g. PSD_monitor   */
  void  *base;          /* &_Mon_var._parameters */
  size_t next_offset;   /* running offset while registering pars */
  long   first_of_type; /* registry index of first instance of comptype */
  int    n_checked;     /* number of successful layout checks */
  int    n_failed;      /* number of failed layout checks */
  int    unknown_type;  /* a parameter type could not be mapped */
};

struct mcrtpar_struct {
  long   comp;          /* index in mcrtcomp_list */
  char  *parameter;
  char  *value;         /* literal (or string value) from setpos */
  int    kind;
  size_t offset;
  long   nelem;         /* for MCRTPAR_VECTOR_ARR, and MCRTPAR_VECTOR_PTR from a literal */
};

static struct mcrtcomp_struct *mcrtcomp_list  = NULL;
static long                    mcrtcomp_num   = 0;
static long                    mcrtcomp_alloc = 0;
static struct mcrtpar_struct  *mcrtpar_list   = NULL;
static long                    mcrtpar_num    = 0;
static long                    mcrtpar_alloc  = 0;

/* portable alignment probes */
struct mcrt_align_int { char c; int     t; };
struct mcrt_align_dbl { char c; double  t; };
struct mcrt_align_ptr { char c; double *t; };
#define MCRT_ALIGN_INT offsetof(struct mcrt_align_int, t)
#define MCRT_ALIGN_DBL offsetof(struct mcrt_align_dbl, t)
#define MCRT_ALIGN_PTR offsetof(struct mcrt_align_ptr, t)

static char *mcrt_strdup(const char *s)
{
  char  *d;
  size_t n;
  if (!s) s = "";
  n = strlen(s) + 1;
  d = (char *)malloc(n);
  if (d) memcpy(d, s, n);
  return d;
}

/* mirrors parse_curlybrackets_vector() in cogen.c.in, which sizes MCNUM[n] */
static long mcrt_parse_curly(const char *string, double *values, long maxn)
{
  const char *s = string;
  char *r;
  long vidx = 0;
  if (!s) return 0;
  while (*s != '\0') {
    double val;
    if (*s == ' ' || *s == ',' || *s == '{') { ++s; continue; }
    if (*s == '}') return vidx;
    val = strtod(s, &r);
    if (values && vidx < maxn) values[vidx] = val;
    ++vidx;
    if (*r == '\0') return vidx;
    s = r + 1;
  }
  return vidx;
}

/* plain numeric literal check: only digits/sign/dot start, no identifiers */
static int mcrt_numeric_start(const char *s)
{
  while (*s && isspace((unsigned char)*s)) s++;
  if (*s == '+' || *s == '-') s++;
  return (isdigit((unsigned char)*s) || (*s == '.' && isdigit((unsigned char)s[1])));
}

static int mcrt_literal_double(const char *s, double *v)
{
  char *end;
  if (!s || !mcrt_numeric_start(s)) return 0;
  errno = 0;
  *v = strtod(s, &end);
  while (*end && isspace((unsigned char)*end)) end++;
  return (*end == '\0' && errno == 0);
}

static int mcrt_literal_long(const char *s, long *v)
{
  char *end;
  if (!s || !mcrt_numeric_start(s)) return 0;
  errno = 0;
  *v = strtol(s, &end, 0); /* base 0: C literal semantics (0x.., 0..) */
  while (*end && isspace((unsigned char)*end)) end++;
  return (*end == '\0' && errno == 0);
}

/* shortest of %.15g/%.17g that reads back to exactly the same double */
static void mcrt_format_double(char *buf, size_t n, double v)
{
  snprintf(buf, n, "%.15g", v);
  if (strtod(buf, NULL) != v) snprintf(buf, n, "%.17g", v);
}

/* non-zero subnormal: what a heap/static pointer typically looks like as a double */
static int mcrt_looks_like_pointer(double v)
{
  uint64_t bits;
  memcpy(&bits, &v, sizeof(bits));
  return (((bits >> 52) & 0x7ff) == 0) && ((bits & 0xfffffffffffffULL) != 0);
}

static void mcrt_register_comp(char *nexuscomp, char *comptype)
{
  struct mcrtcomp_struct *c;
  long i;
  char *n;

  if (!nexuscomp || !comptype) return;
  if (mcrtcomp_num >= mcrtcomp_alloc) {
    long na = mcrtcomp_alloc ? 2*mcrtcomp_alloc : 64;
    struct mcrtcomp_struct *tmp = realloc(mcrtcomp_list, na*sizeof(*tmp));
    if (!tmp) return;
    mcrtcomp_list = tmp; mcrtcomp_alloc = na;
  }
  c = &mcrtcomp_list[mcrtcomp_num];
  memset(c, 0, sizeof(*c));
  c->nexuscomp = mcrt_strdup(nexuscomp);
  c->comptype  = mcrt_strdup(comptype);
  /* strip the 4-digit 'NNNN_' prefix written by cogen_comp_setpos() */
  n = nexuscomp;
  if (strlen(n) > 5 && isdigit((unsigned char)n[0]) && isdigit((unsigned char)n[1])
      && isdigit((unsigned char)n[2]) && isdigit((unsigned char)n[3]) && n[4] == '_')
    n += 5;
  c->name = mcrt_strdup(n);
  c->base = c->name ? _getvar_parameters(c->name) : NULL;
  c->first_of_type = mcrtcomp_num;
  for (i = 0; i < mcrtcomp_num; i++)
    if (!strcmp(mcrtcomp_list[i].comptype, c->comptype)) {
      c->first_of_type = mcrtcomp_list[i].first_of_type;
      break;
    }
  mcrtcomp_num++;
}

/* literal of the same parameter for the first instance of this comp type */
static const char *mcrt_first_instance_literal(long compidx, const char *parameter, const char *own)
{
  long i, first = mcrtcomp_list[compidx].first_of_type;
  if (first == compidx) return own;
  for (i = 0; i < mcrtpar_num; i++)
    if (mcrtpar_list[i].comp == first && !strcmp(mcrtpar_list[i].parameter, parameter))
      return mcrtpar_list[i].value;
  return own;
}

static void mcrt_register_param(char *nexuscomp, char *parameter, char *defval,
                                char *value, char *type)
{
  struct mcrtcomp_struct *c = NULL;
  struct mcrtpar_struct  *p;
  long   ci;
  size_t size = 0, align = 1, i, j = 0;
  char   t[32];

  if (!nexuscomp || !parameter || !type) return;
  for (ci = mcrtcomp_num-1; ci >= 0; ci--)
    if (!strcmp(mcrtcomp_list[ci].nexuscomp, nexuscomp)) { c = &mcrtcomp_list[ci]; break; }
  if (!c) return;

  if (mcrtpar_num >= mcrtpar_alloc) {
    long na = mcrtpar_alloc ? 2*mcrtpar_alloc : 256;
    struct mcrtpar_struct *tmp = realloc(mcrtpar_list, na*sizeof(*tmp));
    if (!tmp) return;
    mcrtpar_list = tmp; mcrtpar_alloc = na;
  }
  p = &mcrtpar_list[mcrtpar_num];
  memset(p, 0, sizeof(*p));
  p->comp      = ci;
  p->parameter = mcrt_strdup(parameter);
  p->value     = mcrt_strdup(value);

  /* type string without whitespace: mccode-antlr writes e.g. "char *" */
  for (i = 0; type[i] && j < sizeof(t)-1; i++)
    if (!isspace((unsigned char)type[i])) t[j++] = type[i];
  t[j] = '\0';

  /* map type string (instr_formal_type_names_real in cogen.c.in) to kind/size */
  if (!strcmp(t, "int")) {
    p->kind = MCRTPAR_INT;    size = sizeof(int);    align = MCRT_ALIGN_INT;
  } else if (!strcmp(t, "char*")) {
    p->kind = MCRTPAR_STRING; size = MCCODE_COMP_STRING_PAR_LEN; align = 1;
  } else if (!strcmp(t, "char")) {
    p->kind = MCRTPAR_CHAR;   size = 1;              align = 1;
  } else if (!strcmp(t, "double")) {
    p->kind = MCRTPAR_DOUBLE; size = sizeof(double); align = MCRT_ALIGN_DBL;
  } else if (!strcmp(t, "double*")) {
    /* mccode-antlr vector: a literal "a,b,c" was calloc'ed with that many elements */
    p->kind = MCRTPAR_VECTOR_PTR; size = sizeof(double*); align = MCRT_ALIGN_PTR;
    if (p->value && mcrt_numeric_start(p->value))
      p->nelem = mcrt_parse_curly(p->value, NULL, 0);
  } else if (!strcmp(t, "MCNUM")) {
    /* double, vector pointer or static vector: all share this type string */
    const char *first = mcrt_first_instance_literal(ci, parameter, p->value);
    if (first && first[0] == '{') {
      p->kind  = MCRTPAR_VECTOR_ARR;
      p->nelem = mcrt_parse_curly(first, NULL, 0);
      size = p->nelem*sizeof(double); align = MCRT_ALIGN_DBL;
    } else if ((defval && !strcmp(defval, "NULL"))
            || (p->value && (!strcmp(p->value, "NULL") || p->value[0] == '&'))) {
      p->kind = MCRTPAR_VECTOR_PTR; size = sizeof(double*); align = MCRT_ALIGN_PTR;
    } else {
      p->kind = MCRTPAR_DOUBLE; size = sizeof(double); align = MCRT_ALIGN_DBL;
    }
  } else {
    p->kind = MCRTPAR_UNKNOWN;
    c->unknown_type = 1;
  }

  p->offset = (c->next_offset + align - 1) / align * align;
  c->next_offset = p->offset + size;
  mcrtpar_num++;

  /* validate reconstructed layout against the values just assigned in setpos */
  if (!c->base || c->unknown_type) return;
  {
    char *addr = (char *)c->base + p->offset;
    switch (p->kind) {
      case MCRTPAR_STRING: {
        const char *expect = value ? value : "";
        if (strncmp(addr, expect, MCCODE_COMP_STRING_PAR_LEN-1)) c->n_failed++;
        else c->n_checked++;
        break;
      }
      case MCRTPAR_INT: {
        long l; int iv;
        memcpy(&iv, addr, sizeof(int));
        if (mcrt_literal_long(p->value, &l)) {
          if ((long)iv == l) c->n_checked++; else c->n_failed++;
        }
        break;
      }
      case MCRTPAR_DOUBLE: {
        double d, v;
        memcpy(&v, addr, sizeof(double));
        if (mcrt_literal_double(p->value, &d)) {
          if (v == d) c->n_checked++; else c->n_failed++;
        } else if (p->value && !strcmp(p->value, "UNSET")) {
          /* UNSET is a NaN with a specific payload: a strong layout check */
          if (is_unset(v)) c->n_checked++; else c->n_failed++;
        } else if (mcrt_looks_like_pointer(v)) {
          p->kind = MCRTPAR_VECTOR_PTR; /* same size and alignment on LP64/LLP64 */
        }
        break;
      }
      case MCRTPAR_VECTOR_ARR:
      case MCRTPAR_VECTOR_PTR: {
        char *data = addr;
        if (p->kind == MCRTPAR_VECTOR_PTR) {
          double *ptr;
          memcpy(&ptr, addr, sizeof(ptr));
          data = (char *)ptr;
        }
        if (data && p->value && (p->value[0] == '{' || mcrt_numeric_start(p->value)) && p->nelem > 0) {
          long k, n;
          double *vals = calloc(p->nelem, sizeof(double));
          if (vals) {
            int ok = 1;
            n = mcrt_parse_curly(p->value, vals, p->nelem);
            if (n > p->nelem) n = p->nelem;
            for (k = 0; k < n; k++) {
              double v;
              memcpy(&v, data + k*sizeof(double), sizeof(double));
              if (v != vals[k]) ok = 0;
            }
            if (ok) c->n_checked++; else c->n_failed++;
            free(vals);
          }
        }
        break;
      }
      default: break; /* CHAR: not checkable */
    }
  }
}

/* write runtime_value/runtime_value_status into an existing parameter NXnote */
static void mcrt_write_attrs(NXhandle f, char *nexuscomp, char *parameter,
                             const char *value, const char *status)
{
  NXMDisableErrorReporting();
  if (NXopengroup(f, "instrument", "NXinstrument") == NX_OK) {
    if (NXopengroup(f, "components", "NXdata") == NX_OK) {
      if (NXopengroup(f, nexuscomp, "NXdata") == NX_OK) {
        if (NXopengroup(f, "parameters", "NXdata") == NX_OK) {
          if (NXopengroup(f, parameter, "NXnote") == NX_OK) {
            /* zero-length attributes are not supported: omit empty values */
            if (value && strlen(value))
              NXputattr(f, "runtime_value", (void *)value, strlen(value), NX_CHAR);
            NXputattr(f, "runtime_value_status", (void *)status, strlen(status), NX_CHAR);
            NXclosegroup(f); /* parameter */
          }
          NXclosegroup(f);   /* parameters */
        }
        NXclosegroup(f);     /* component */
      }
      NXclosegroup(f);       /* components */
    }
    NXclosegroup(f);         /* instrument */
  }
  NXMEnableErrorReporting();
}

static void mcrt_free_registry(void)
{
  long i;
  for (i = 0; i < mcrtpar_num; i++) {
    free(mcrtpar_list[i].parameter); free(mcrtpar_list[i].value);
  }
  for (i = 0; i < mcrtcomp_num; i++) {
    free(mcrtcomp_list[i].nexuscomp); free(mcrtcomp_list[i].name);
    free(mcrtcomp_list[i].comptype);
  }
  free(mcrtpar_list);  mcrtpar_list  = NULL; mcrtpar_num  = mcrtpar_alloc  = 0;
  free(mcrtcomp_list); mcrtcomp_list = NULL; mcrtcomp_num = mcrtcomp_alloc = 0;
}

/*******************************************************************************
* mccomp_param_runtime_nexus_all: write post-INIT values of all registered
*   component SETTING parameters. Called from mccode_main() after init().
*   requires: NXentry to be opened
*******************************************************************************/
void mccomp_param_runtime_nexus_all(NXhandle f)
{
  long i;

  if (!f || mcdisable_output_files) { mcrt_free_registry(); return; }

  for (i = 0; i < mcrtcomp_num; i++)
    if (mcrtcomp_list[i].n_failed) {
      fprintf(stderr, "Warning: NeXus runtime parameter values not stored for component %s=%s() "
              "(parameter layout check failed %i times) (mccomp_param_runtime_nexus_all)\n",
              mcrtcomp_list[i].name, mcrtcomp_list[i].comptype, mcrtcomp_list[i].n_failed);
    }

  for (i = 0; i < mcrtpar_num; i++) {
    struct mcrtpar_struct  *p = &mcrtpar_list[i];
    struct mcrtcomp_struct *c = &mcrtcomp_list[p->comp];
    const char *status = NULL;
    char  num[64];
    char *buffer = NULL;
    const char *strval = NULL;

    if (!c->base)              status = "unsupported:no-instance";
    else if (c->unknown_type)  status = "unsupported:unknown-type";
    else if (c->n_failed)      status = "layout-mismatch";
    else {
      char *addr = (char *)c->base + p->offset;
      switch (p->kind) {
        case MCRTPAR_INT: {
          int iv; memcpy(&iv, addr, sizeof(int));
          snprintf(num, sizeof(num), "%d", iv); strval = num;
          break;
        }
        case MCRTPAR_CHAR:
          snprintf(num, sizeof(num), "%d", (int)*addr); strval = num;
          break;
        case MCRTPAR_STRING: {
          size_t len = 0;
          while (len < MCCODE_COMP_STRING_PAR_LEN-1 && addr[len]) len++;
          buffer = malloc(len+1);
          if (buffer) { memcpy(buffer, addr, len); buffer[len] = '\0'; strval = buffer; }
          break;
        }
        case MCRTPAR_DOUBLE: {
          double v; memcpy(&v, addr, sizeof(double));
          if (mcrt_looks_like_pointer(v))
            status = "unsupported:pointer";
          else {
            if (is_unset(v)) strcpy(num, "UNSET");
            else mcrt_format_double(num, sizeof(num), v);
            strval = num;
          }
          break;
        }
        case MCRTPAR_VECTOR_ARR:
        case MCRTPAR_VECTOR_PTR: {
          long k;
          size_t blen = (size_t)p->nelem*32 + 4;
          if (p->kind == MCRTPAR_VECTOR_PTR) {
            /* only mccode-antlr literal vectors have a known length */
            double *ptr;
            memcpy(&ptr, addr, sizeof(ptr));
            addr = (char *)ptr;
            if (!addr || p->nelem <= 0) { status = "unsupported:pointer"; break; }
          }
          buffer = malloc(blen);
          if (buffer) {
            size_t pos = 0;
            pos += snprintf(buffer+pos, blen-pos, "{");
            for (k = 0; k < p->nelem; k++) {
              double v; char elem[32];
              memcpy(&v, addr + k*sizeof(double), sizeof(double));
              mcrt_format_double(elem, sizeof(elem), v);
              pos += snprintf(buffer+pos, blen-pos, "%s%s", k ? ", " : "", elem);
            }
            snprintf(buffer+pos, blen-pos, "}");
            strval = buffer;
          }
          break;
        }
        default:
          status = "unsupported:unknown-type";
      }
      if (!status) status = c->n_checked ? "ok" : "unverified";
    }
    mcrt_write_attrs(f, c->nexuscomp, p->parameter, strval, status);
    free(buffer);
  }
  mcrt_free_registry();
} /* mccomp_param_runtime_nexus_all */

/*******************************************************************************
* mccomp_placement_type_nexus:
*   Places
*    - absolute (3x1) position
*    - absolute (3x3) rotation
*    - type / class of component instance into attributes under
*     entry<N>/instrument/compname
*   requires: NXentry to be opened
*******************************************************************************/
static void mccomp_placement_type_nexus(NXhandle nxhandle, char* component, Coords position, Rotation rotation, char* comptype)
{
  /* open NeXus instrument group */

  #ifdef USE_NEXUS
  if(nxhandle) {
    mcrt_register_comp(component, comptype); /* for post-INIT runtime values */
    if (NXopengroup(nxhandle, "instrument", "NXinstrument") == NX_OK) {
      if (NXopengroup(nxhandle, "components", "NXdata") == NX_OK) {
	if (NXmakegroup(nxhandle, component, "NXdata") == NX_OK) {
	  if (NXopengroup(nxhandle, component, "NXdata") == NX_OK) {
	    int64_t pdims[3]; pdims[0]=3; pdims[1]=0; pdims[2]=0;
	    if (NXcompmakedata64(nxhandle, "Position", NX_FLOAT64, 1, pdims, NX_COMPRESSION, pdims) == NX_OK) {
	      if (NXopendata(nxhandle, "Position") == NX_OK) {
		double pos[3]; coords_get(position, &pos[0], &pos[1], &pos[2]);
		if (NXputdata (nxhandle, pos) == NX_OK) {
		  NXclosedata(nxhandle);
		} else {
		  fprintf(stderr, "COULD NOT PUT Position field for component %s\n",component);
		}
	      } else {
		fprintf(stderr, "Warning: could not open Position field for component %s\n",component);
	      }
	    }
	    int64_t rdims[3]; rdims[0]=3; rdims[1]=3; rdims[2]=0;
	    if (NXcompmakedata64(nxhandle, "Rotation", NX_FLOAT64, 2, rdims, NX_COMPRESSION, rdims) == NX_OK) {
	      if (NXopendata(nxhandle, "Rotation") == NX_OK) {
		if (NXputdata (nxhandle, rotation) == NX_OK) {
		  NXclosedata(nxhandle);
		} else {
		  fprintf(stderr, "COULD NOT PUT Rotation field for component %s\n",component);
		}
	      } else {
		fprintf(stderr, "Warning: could not open Rotation field for component %s\n",component);
	      }
	    }
	    nxprintf(nxhandle, "Component_type", "%s", comptype ? comptype : "");
	    NXclosegroup(nxhandle); // component
	  } else {
	    printf("FAILED to open comp data group %s\n",component);
	  }
	} else {
	  printf("FAILED to create comp data group %s\n",component);
	}
	NXclosegroup(nxhandle); // components
      } else {
	printf("Failed to open NeXus component hierarchy\n");
      }
      NXclosegroup(nxhandle); // instrument
    } else {
      printf("Failed to open NeXus instrument hierarchy\n");
    }
  } else {
    fprintf(stderr,"NO NEXUS FILE\n");
  }
  #endif
} /* mccomp_placement_nexus */

/*******************************************************************************
* mccomp_param_nexus:
*   Output parameter/value pair for component instance into
*   the attribute
*     entry<N>/instrument/compname/parameter
*   requires: NXentry to be opened
*******************************************************************************/
static void mccomp_param_nexus(NXhandle nxhandle, char* component, char* parameter, char* defval, char* value, char* type)
{
  /* open NeXus instrument group */

  #ifdef USE_NEXUS
  if(nxhandle) {
    mcrt_register_param(component, parameter, defval, value, type); /* for post-INIT runtime values */
    if (NXopengroup(nxhandle, "instrument", "NXinstrument") == NX_OK) {
      if (NXopengroup(nxhandle, "components", "NXdata") == NX_OK) {
	if (NXopengroup(nxhandle, component, "NXdata") == NX_OK) {
	  NXMDisableErrorReporting(); /* inactivate NeXus error messages, as creation may fail */
	  NXmakegroup(nxhandle, "parameters", "NXdata");
	  NXMEnableErrorReporting();  /* re-enable NeXus error messages */
	  if (NXopengroup(nxhandle, "parameters", "NXdata") == NX_OK) {
	    NXmakegroup(nxhandle, parameter, "NXnote");
	    if (NXopengroup(nxhandle, parameter, "NXnote") == NX_OK) {
	      nxprintattr(nxhandle, "type", "%s", type ? type : "");
	      nxprintattr(nxhandle, "default", "%s",  defval ? defval : "");
	      nxprintattr(nxhandle, "value", "%s",  value ? value : "");
	      NXclosegroup(nxhandle); // parameter
	    } else {
	      printf("FAILED to open parameters %s data group \n",parameter);
	    }
	    NXclosegroup(nxhandle); // "parameters"
	  } else {
	    printf("FAILED to open comp/parameters data group \n");
	  }
	  NXclosegroup(nxhandle); // component
	  } else {
	  printf("FAILED to open comp data group %s\n",component);
	}
	NXclosegroup(nxhandle); // components
      } else {
	printf("Failed to open NeXus component hierarchy\n");
      }
      NXclosegroup(nxhandle); // instrument
    } else {
      printf("Failed to open NeXus instrument hierarchy\n");
    }
  } else {
    fprintf(stderr,"NO NEXUS FILE\n");
  }
#endif
} /* mccomp_param_nexus */

/*******************************************************************************
* mcdatainfo_out_nexus: output detector header
*   mcdatainfo_out_nexus(detector) create group and write info to NeXus data file
*   open data:NXdetector then filename:NXdata and write headers/attributes
*   requires: NXentry to be opened
*******************************************************************************/
/* napi5 assembles group paths in char[1024] buffers without bounds checks:
   a longer path overflows them (crash or corrupt file), so it is not written */
static int mcnexus_path_ok(MCDETECTOR *detector, char *data_name, int warn)
{
  size_t len = strlen(mcnxentry) + strlen("/instrument/components/")
             + strlen(detector->nexuscomp) + strlen("/output/") + strlen(data_name);
  if (len < 1000) return(1);
  if (warn)
    fprintf(stderr, "Warning: %s: NeXus path of '%.40s...' has %lu characters, more than the NeXus API handles. "
      "Not written to the NeXus file (mcdatainfo_out_nexus)\n", detector->component, data_name, (unsigned long)len);
  return(0);
}

static void
mcdatainfo_out_nexus(NXhandle f, MCDETECTOR detector)
{
  char data_name[CHAR_BUF_LENGTH];
  if (!f || !detector.m || mcdisable_output_files) return;

  strcpy_valid(data_name,
    strlen(detector.filename) ?
      detector.filename : detector.component);
  if (!mcnexus_path_ok(&detector, data_name, 1)) return;

  /* the NXdetector group has been created in mcinfo_out_nexus (siminfo_init) */
  if (NXopengroup(f, "instrument", "NXinstrument") == NX_OK) {
    if (NXopengroup(f, "components", "NXdata") == NX_OK) {
      NXMDisableErrorReporting(); /* inactivate NeXus error messages, as creation may fail */
      NXmakegroup(f, detector.nexuscomp, "NXdata");
      if (NXopengroup(f, detector.nexuscomp, "NXdata") == NX_OK) {
	NXmakegroup(f, "output", "NXdetector");
	if (NXopengroup(f, "output", "NXdetector") == NX_OK) {
	  if (NXmakegroup(f, data_name, "NXdata") == NX_OK) {
	    if (NXopengroup(f, data_name, "NXdata") == NX_OK) {
	      /* output metadata (as attributes) ======================================== */
	      nxprintattr(f, "Date", "%s",       detector.date);
	      nxprintattr(f, "type", "%s",       detector.type);
	      nxprintattr(f, "Source", "%s",     detector.instrument);
	      nxprintattr(f, "component", "%s",  detector.component);
	      nxprintattr(f, "position", "%s",   detector.position);

	      nxprintattr(f, "title", "%s",      detector.title);
	      nxprintattr(f, !mcget_run_num() || mcget_run_num() >= mcget_ncount() ?
			  "Ncount" :
			  "ratio", "%s",  detector.ncount);

	      if (strlen(detector.filename)) {
		nxprintattr(f, "filename", "%s", detector.filename);
	      }

	      nxprintattr(f, "statistics", "%s", detector.statistics);
	      nxprintattr(f, "signal", "%s",     detector.signal);
	      nxprintattr(f, "values", "%s",     detector.values);

	      if (detector.rank >= 1)
		{
		  nxprintattr(f, "xvar", "%s",     detector.xvar);
		  nxprintattr(f, "yvar", "%s",     detector.yvar);
		  nxprintattr(f, "xlabel", "%s",   detector.xlabel);
		  nxprintattr(f, "ylabel", "%s",   detector.ylabel);
		  if (detector.rank > 1) {
		    nxprintattr(f, "zvar", "%s",   detector.zvar);
		    nxprintattr(f, "zlabel", "%s", detector.zlabel);
		  }
		}

	      nxprintattr(f, abs(detector.rank)==1 ?
			  "xlimits" :
			  "xylimits", "%s", detector.limits);
	      nxprintattr(f, "variables", "%s",
			  strcasestr(detector.format, "list") ? detector.ylabel : detector.variables);

	      NXclosegroup(f); // data_name
	    }
	  }
	  NXclosegroup(f); // output
	}
	NXclosegroup(f); // detector.nexuscomp
      }
      NXclosegroup(f); // components
    }
    NXMEnableErrorReporting();  /* re-enable NeXus error messages */
    NXclosegroup(f); // instrument
  } /* NXdetector (instrument) */ 
} /* mcdatainfo_out_nexus */

/*******************************************************************************
* mcdetector_out_axis_nexus: write detector axis into current NXdata
*   requires: NXdata to be opened
*******************************************************************************/
int mcdetector_out_axis_nexus(NXhandle f, char *label, char *var, int rank, long length, double min, double max)
{
  if (!f || length <= 1 || mcdisable_output_files || max == min) return(NX_OK);
  else {
    double *axis;
    axis=malloc(sizeof(double)*length);
    if (!axis ) {
      printf("Fatal memory error allocating NeXus axis of length %li, exiting!\n", length);
      return(NX_ERROR);
    }
    char *valid;
    valid=malloc(sizeof(char)*CHAR_BUF_LENGTH);
    if (!valid ) {
      printf("Fatal memory error allocating label axis of length %i, exiting!\n", CHAR_BUF_LENGTH);
      free(axis);
      return(NX_ERROR);
    }
    int dim=(int)length;
    int i;
    int nprimary=1;
    /* create an axis from [min:max] */
    for(i = 0; i < length; i++)
      axis[i] = min+(max-min)*(i+0.5)/length;
    /* create the data set */
    strcpy_valid(valid, label);
    NXcompmakedata(f, valid, NX_FLOAT64, 1, &dim, NX_COMPRESSION, &dim);
    /* open it */
    if (NXopendata(f, valid) != NX_OK) {
      fprintf(stderr, "Warning: could not open axis rank %i '%s' (NeXus)\n",
        rank, valid);
      free(axis);
      free(valid);
      return(NX_ERROR);
    }
    /* put the axis and its attributes */
    NXputdata  (f, axis);
    nxprintattr(f, "long_name", "%s",  label);
    nxprintattr(f, "short_name", "%s", var);
    NXputattr  (f, "axis",       &rank,     1, NX_INT32);
    nxprintattr(f, "units", "%s",      var);
    NXputattr  (f, "primary",    &nprimary, 1, NX_INT32);
    NXclosedata(f);
    free(axis);
    free(valid);
    return(NX_OK);
  }
} /* mcdetector_out_axis_nexus */

/*******************************************************************************
* mcdetector_out_array_nexus: write detector array into current NXdata (1D,2D)
*   requires: NXdata to be opened
*******************************************************************************/
int mcdetector_out_array_nexus(NXhandle f, char *part, double *data, MCDETECTOR detector)
{

  int64_t dims[3]={detector.m,detector.n,detector.p};  /* number of elements to write */
  int64_t fulldims[3]={detector.m,detector.n,detector.p};
  int signal=1;
  int exists=0;
  int64_t current_dims[3]={0,0,0};
  int ret=NX_OK;

  if (!f || !data || !detector.m || mcdisable_output_files) return(NX_OK);

  /* when this is a list, we set 1st dimension to NX_UNLIMITED for creation */
  if (strcasestr(detector.format, "list")) fulldims[0] = NX_UNLIMITED;

  /* HDF5 refuses chunks of 4 GiB or more (napi5 uses the whole block as chunk):
     the data set would not be created at all */
  int64_t chunk[3]={dims[0],dims[1],dims[2]};
  double  bytes=8.0*dims[0]*(detector.rank > 1 ? dims[1] : 1)*(detector.rank > 2 ? dims[2] : 1);
  if (bytes >= 4294967295.0) chunk[0] = chunk[0]/(int64_t)(bytes/4294967295.0 + 1) + 1;

  /* create the data set in NXdata group */
  NXMDisableErrorReporting(); /* inactivate NeXus error messages, as creation may fail */
  ret = NXcompmakedata64(f, part, NX_FLOAT64, detector.rank, fulldims, NX_COMPRESSION, chunk);
  if (ret != NX_OK) {
    /* failed: data set already exists */
    int datatype=0;
    int rank=0;
    exists=1;
    /* inquire current size of data set (nb of events stored) */
    NXopendata(f, part);
    NXgetinfo64(f, &rank, current_dims, &datatype);
    NXclosedata(f);
  }
  NXMEnableErrorReporting();  /* re-enable NeXus error messages */

  /* open the data set */
  if (NXopendata(f, part) == NX_ERROR) {
    fprintf(stderr, "Warning: could not open DataSet %s '%s' (NeXus)\n",
      part, detector.title);
    return(NX_ERROR);
  }
  if (strcasestr(detector.format, "list")) {
    current_dims[1] = current_dims[2] = 0; /* set starting location for writing slab */
    NXputslab64(f, data, current_dims, dims);
    if (!exists)
      printf("Events:   \"%s\"\n",
        strlen(detector.filename) ? detector.filename : detector.component);
    else
      printf("Append:   \"%s\"\n",
	     strlen(detector.filename) ? detector.filename : detector.component);
  } else {
    NXputdata (f, data);
  }

  if (strstr(part,"data") || strstr(part, "events")) {
    NXputattr(f, "signal", &signal, 1, NX_INT32);
    nxprintattr(f, "short_name", "%s", strlen(detector.filename) ?
      detector.filename : detector.component);
  }
  nxprintattr(f, "long_name", "%s '%s'", part, detector.title);
  NXclosedata(f);

  return(NX_OK);
} /* mcdetector_out_array_nexus */

/*******************************************************************************
* mcdetector_out_data_nexus: write detector axes+data into current NXdata
*   The data:NXdetector is opened, then filename:NXdata
*   requires: NXentry to be opened
*******************************************************************************/
int mcdetector_out_data_nexus(NXhandle f, MCDETECTOR detector)
{
  char data_name[CHAR_BUF_LENGTH];

  if (!f || !detector.m || mcdisable_output_files) return(NX_OK);

  strcpy_valid(data_name,
    strlen(detector.filename) ?
      detector.filename : detector.component);
  if (!mcnexus_path_ok(&detector, data_name, 0)) return(NX_ERROR);
  NXlink pLink;
  int    linked = 0;
  /* the NXdetector group has been created in mcinfo_out_nexus (siminfo_init) */
  if (NXopengroup(f, "instrument", "NXinstrument") == NX_OK) {
    if (NXopengroup(f, "components", "NXdata") == NX_OK) {
      if (NXopengroup(f, detector.nexuscomp, "NXdata") == NX_OK) {
	if (NXopengroup(f, "output", "NXdetector") == NX_OK) {

	  /* the NXdata group has been created in mcdatainfo_out_nexus */
	  if (NXopengroup(f, data_name, "NXdata") == NX_OK) {
	    
	    MPI_MASTER(
		       nxprintattr(f, "options", "%s",
				   strlen(detector.options) ? detector.options : "None");
		       );
	    /* write axes, for histogram data sets, not for lists */
	    if (!strcasestr(detector.format, "list")) {
	      mcdetector_out_axis_nexus(f, detector.xlabel, detector.xvar,
					1, detector.m, detector.xmin, detector.xmax);
	      mcdetector_out_axis_nexus(f, detector.ylabel, detector.yvar,
					2, detector.n, detector.ymin, detector.ymax);
	      mcdetector_out_axis_nexus(f, detector.zlabel, detector.zvar,
					3, detector.p, detector.zmin, detector.zmax); 
	    } else {
	      	    MPI_MASTER(
			       nxprintattr(f, "dataset columns", "%s",
					   strlen(detector.ylabel) ? detector.ylabel : "None");
		    );
	    }

	    /* write the actual data (appended if already exists) */
	    if (!strcasestr(detector.format, "list") && !strcasestr(detector.format, "pixels")) {
	      mcdetector_out_array_nexus(f, "data", detector.p1, detector);
	      mcdetector_out_array_nexus(f, "errors", detector.p2, detector);
	      mcdetector_out_array_nexus(f, "ncount", detector.p0, detector);
	    } else if (strcasestr(detector.format, "pixels")) {
	      mcdetector_out_array_nexus(  f, "pixels", detector.p1, detector);
	    } else {
	      mcdetector_out_array_nexus(  f, "events", detector.p1, detector);
	    }
	    linked = NXgetgroupID(f, &pLink) == NX_OK;
	    NXclosegroup(f);
	  } /* NXdata data_name*/
	  NXclosegroup(f);
	} /* NXdetector output */
	NXclosegroup(f);
      } /* NXdata detector.nexuscomp */
      NXclosegroup(f);
    } /* NXdata components */
    NXclosegroup(f);
  } /* NXdata instrument */
  
  if (linked && !strcasestr(detector.format, "pixels")) {
    if (NXopengroup(f, "data", "NXdetector") == NX_OK) {
      NXmakelink(f, &pLink);
      NXclosegroup(f);
    }
  }
  return(NX_OK);
} /* mcdetector_out_array_nexus */


MCDETECTOR mcdetector_out_0D_nexus(MCDETECTOR detector)
{
  /* Write data set information to NeXus file. */
  MPI_MASTER(
    mcdatainfo_out_nexus(nxhandle, detector);
  );

  return(detector);
} /* mcdetector_out_0D_ascii */

MCDETECTOR mcdetector_out_1D_nexus(MCDETECTOR detector)
{
  MPI_MASTER(
  mcdatainfo_out_nexus(nxhandle, detector);
  mcdetector_out_data_nexus(nxhandle, detector);
  );
  return(detector);
} /* mcdetector_out_1D_ascii */

MCDETECTOR mcdetector_out_2D_nexus(MCDETECTOR detector)
{
  MPI_MASTER(
  mcdatainfo_out_nexus(nxhandle, detector);
  mcdetector_out_data_nexus(nxhandle, detector);
  );


  return(detector);
} /* mcdetector_out_2D_nexus */

MCDETECTOR mcdetector_out_3D_nexus(MCDETECTOR detector)
{
  MPI_MASTER(
  mcdatainfo_out_nexus(nxhandle, detector);
  mcdetector_out_data_nexus(nxhandle, detector);
  );
  return(detector);
} /* mcdetector_out_3D_nexus */


#endif /* USE_NEXUS*/








/* ========================================================================== */

/*                            Main input functions                            */
/*            DETECTOR_OUT_xD function calls -> ascii or NeXus                */

/* ========================================================================== */

/*******************************************************************************
* siminfo_init:   open SIM and write header
*******************************************************************************/
FILE *siminfo_init(FILE *f)
{
  int exists=0;

  /* check format */
  if (!mcformat || !strlen(mcformat)
   || !strcasecmp(mcformat, "MCSTAS") || !strcasecmp(mcformat, "MCXTRACE")
   || !strcasecmp(mcformat, "PGPLOT") || !strcasecmp(mcformat, "GNUPLOT") || !strcasecmp(mcformat, "MCCODE")
   || !strcasecmp(mcformat, "MATLAB")) {
    mcformat="McCode";
#ifdef USE_NEXUS
  } else if (strcasestr(mcformat, "NeXus")) {
    /* Do nothing */
#endif
  } else {
    fprintf(stderr,
	    "Warning: You have requested the output format %s which is unsupported by this binary. Resetting to standard %s format.\n",mcformat ,"McCode");
    mcformat="McCode";
  }

  /* open the SIM file if not defined yet */
  if (siminfo_file || mcdisable_output_files)
    return (siminfo_file);

#ifdef USE_NEXUS
  /* only master writes NeXus header: calls NXopen(nxhandle) */
  if (mcformat && strcasestr(mcformat, "NeXus")) {
	  MPI_MASTER(
	  siminfo_file = mcnew_file(siminfo_name, "h5", &exists);
    if(!siminfo_file)
      fprintf(stderr,
	      "Warning: could not open simulation description file '%s'\n",
	      siminfo_name);
	  else
	    mcinfo_out_nexus(nxhandle);
	  );
#ifdef USE_MPI
    { /* once per node, at the first call (from mccode_main, on every node): the
         per-node event list files name their data sets after the master's
         NXentry (mclist_node_dset), which a NeXus scan step increments */
      static int sent = 0;
      if (!sent++) MPI_Bcast(mcnxentry, CHAR_BUF_LENGTH, MPI_CHAR, mpi_node_root, MPI_COMM_WORLD);
    }
#endif
    return(siminfo_file); /* points to nxhandle */
  }
#endif

  /* write main description file (only MASTER) */
  MPI_MASTER(

  siminfo_file = mcnew_file(siminfo_name, "sim", &exists);
  if(!siminfo_file)
    fprintf(stderr,
	    "Warning: could not open simulation description file '%s'\n",
	    siminfo_name);
  else
  {
    /* write SIM header */
    time_t t=time(NULL);
    siminfo_out("%s simulation description file for %s.\n",
      MCCODE_NAME, instrument_name);
    siminfo_out("Date:    %s", ctime(&t)); /* includes \n */
    siminfo_out("Program: %s\n\n", MCCODE_STRING);

    siminfo_out("begin instrument: %s\n", instrument_name);
    mcinfo_out(   "  ", siminfo_file);
    siminfo_out("end instrument\n");

    siminfo_out("\nbegin simulation: %s\n", dirname);
    mcruninfo_out("  ", siminfo_file);
    siminfo_out("end simulation\n");

  }
  ); /* MPI_MASTER */
  return (siminfo_file);

} /* siminfo_init */

#if defined(USE_MPI) && defined(USE_NEXUS)
static void mclist_vds_write(void);
#endif

/*******************************************************************************
*   siminfo_close:  close SIM
*******************************************************************************/
void siminfo_close()
{
#ifdef USE_MPI
  if(mpi_node_rank == mpi_node_root) {
#endif
  if(siminfo_file && !mcdisable_output_files) {
#ifdef USE_NEXUS
    if (mcformat && strcasestr(mcformat, "NeXus")) {
      time_t t=time(NULL);
      nxprintf(nxhandle, "end_time", "%s", ctime(&t));
      nxprintf(nxhandle, "duration", "%li", (long)t-mcstartdate);
      NXclosegroup(nxhandle); /* NXentry */
      NXclose(&nxhandle);
#ifdef USE_MPI
      mclist_vds_write(); /* event lists from all nodes, needs NXclose */
#endif
    } else {
#endif
      fclose(siminfo_file);
#ifdef USE_NEXUS
    }
#endif
#ifdef USE_MPI
  }
#endif
    siminfo_file = NULL;
  }
} /* siminfo_close */

/*******************************************************************************
* mcdetector_out_0D: wrapper for 0D (single value).
*   Output single detector/monitor data (p0, p1, p2).
*   Title is t, component name is c.
*******************************************************************************/
MCDETECTOR mcdetector_out_0D(char *t, double p0, double p1, double p2,
			     char *c, Coords posa, Rotation rota, int index)
{
  /* import and perform basic detector analysis (and handle MPI reduce) */
  MCDETECTOR detector = detector_import(mcformat,
    c, (t ? t : MCCODE_STRING " data"),
    1, 1, 1,
    "I", "", "",
    "I", "", "",
    0, 0, 0, 0, 0, 0, c,
    &p0, &p1, &p2, posa, rota, index); /* write Detector: line */

#ifdef USE_NEXUS
  if (strcasestr(detector.format, "NeXus"))
    return(mcdetector_out_0D_nexus(detector));
  else
#endif
    return(mcdetector_out_0D_ascii(detector));

} /* mcdetector_out_0D */



/*******************************************************************************
* mcdetector_out_1D: wrapper for 1D.
*   Output 1d detector data (p0, p1, p2) for n bins linearly
*   distributed across the range x1..x2 (x1 is lower limit of first
*   bin, x2 is upper limit of last bin). Title is t, axis labels are xl
*   and yl. File name is f, component name is c.
*
*   t:    title
*   xl:   x-label
*   yl:   y-label
*   xvar: measured variable length
*   x1:   x axus min
*   x2:   x axis max
*   n:    1d data vector lenght
*   p0:   pntr to start of data block#0
*   p1:   pntr to start of data block#1
*   p2:   pntr to start of data block#2
*   f:    filename
*
*   Not included in the macro, and here forwarded to detector_import:
*   c:    ?
*   posa: ?
*******************************************************************************/
MCDETECTOR mcdetector_out_1D(char *t, char *xl, char *yl,
        char *xvar, double x1, double x2,
        long n,
        double *p0, double *p1, double *p2, char *f,
        char *c, Coords posa, Rotation rota, int index)
{
  /* import and perform basic detector analysis (and handle MPI_Reduce) */
  // detector_import calls mcdetector_statistics, which will return different
  // MCDETECTOR versions for 1-D data based on the value of mcformat.
  //
  MCDETECTOR detector = detector_import(mcformat,
    c, (t ? t : MCCODE_STRING " 1D data"),
    n, 1, 1,
    xl, yl, (n > 1 ? "Signal per bin" : " Signal"),
    xvar, "(I,I_err)", "I",
    x1, x2, 0, 0, 0, 0, f,
    p0, p1, p2, posa, rota, index); /* write Detector: line */
  if (!detector.p1 || !detector.m) return(detector);

#ifdef USE_NEXUS
  if (strcasestr(detector.format, "NeXus"))
    detector = mcdetector_out_1D_nexus(detector);
  else
#endif
    detector = mcdetector_out_1D_ascii(detector);
  if (detector.p1 != p1 && detector.p1) {
    // mcdetector_statistics allocated memory but it hasn't been freed.
    free(detector.p1);
    // plus undo the other damage done there:
    detector.p0 = p0; // was set to NULL
    detector.p1 = p1; // was set to this_p1
    detector.p2 = p2; // was set to NULL
    detector.m = detector.n; // (e.g., labs(n))
    detector.n = 1;  // not (n x n)
    detector.istransposed = n < 0 ? 1 : 0;
  }
  return detector;

} /* mcdetector_out_1D */

/*******************************************************************************
* mcdetector_out_2D: wrapper for 2D.
*   Special case for list: master creates file first, then slaves append their
*   blocks without header-
*
*   t:    title
*   xl:   x-label
*   yl:   y-label
*   x1:   x axus min
*   x2:   x axis max
*   y1:   y axis min
*   y2:   y axis max
*   m:    dim 1 (x) size
*   n:    dim 2 (y) size
*   p0:   pntr to start of data block#0
*   p1:   pntr to start of data block#1
*   p2:   pntr to start of data block#2
*   f:    filename
*
*   Not included in the macro, and here forwarded to detector_import:
*   c:    ?
*   posa: ?
*   rota: ?
*******************************************************************************/
MCDETECTOR mcdetector_out_2D(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2,
                  long m, long n,
                  double *p0, double *p1, double *p2, char *f,
		  char *c, Coords posa, Rotation rota, int index)
{
  char xvar[CHAR_BUF_LENGTH];
  char yvar[CHAR_BUF_LENGTH];

  /* create short axes labels */
  if (xl && strlen(xl)) { strncpy(xvar, xl, CHAR_BUF_LENGTH); xvar[2]='\0'; }
  else strcpy(xvar, "x");
  if (yl && strlen(yl)) { strncpy(yvar, yl, CHAR_BUF_LENGTH); yvar[2]='\0'; }
  else strcpy(yvar, "y");

  MCDETECTOR detector;

  /* import and perform basic detector analysis (and handle MPI_Reduce) */
  if (labs(m) == 1) {/* n>1 on Y, m==1 on X: 1D, no X axis*/
    detector = detector_import(mcformat,
      c, (t ? t : MCCODE_STRING " 1D data"),
      n, 1, 1,
      yl, "", "Signal per bin",
      yvar, "(I,Ierr)", "I",
      y1, y2, x1, x2, 0, 0, f,
      p0, p1, p2, posa, rota, index); /* write Detector: line */
  } else if (labs(n)==1) {/* m>1 on X, n==1 on Y: 1D, no Y axis*/
    detector = detector_import(mcformat,
      c, (t ? t : MCCODE_STRING " 1D data"),
      m, 1, 1,
      xl, "", "Signal per bin",
      xvar, "(I,Ierr)", "I",
      x1, x2, y1, y2, 0, 0, f,
      p0, p1, p2, posa, rota, index); /* write Detector: line */
  }else {
    detector = detector_import(mcformat,
      c, (t ? t : MCCODE_STRING " 2D data"),
      m, n, 1,
      xl, yl, "Signal per bin",
      xvar, yvar, "I",
      x1, x2, y1, y2, 0, 0, f,
      p0, p1, p2, posa, rota, index); /* write Detector: line */
  }

  if (!detector.p1 || !detector.m) return(detector);

#ifdef USE_NEXUS
  if (strcasestr(detector.format, "NeXus"))
    return(mcdetector_out_2D_nexus(detector));
  else
#endif
    return(mcdetector_out_2D_ascii(detector));

} /* mcdetector_out_2D */

/*******************************************************************************
* mcdetector_list_import: build the MCDETECTOR structure for a 2D_list call
*   (no MPI communication for event lists, histograms are MPI_Reduce'd as usual)
*******************************************************************************/
static MCDETECTOR mcdetector_list_import(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2,
                  long m, long n,
                  double *p0, double *p1, double *p2, char *f,
                  char *c, Coords posa, Rotation rota, char* options, int index)
{
  char xvar[CHAR_BUF_LENGTH];
  char yvar[CHAR_BUF_LENGTH];
  int  islist = (mcformat && strcasestr(mcformat, "list") != NULL);

  /* create short axes labels */
  if (xl && strlen(xl)) { strncpy(xvar, xl, CHAR_BUF_LENGTH); xvar[2]='\0'; }
  else strcpy(xvar, "x");
  if (yl && strlen(yl)) { strncpy(yvar, yl, CHAR_BUF_LENGTH); yvar[2]='\0'; }
  else strcpy(yvar, "y");

  MCDETECTOR detector;

  /* import and perform basic detector analysis (and handle MPI_Reduce) */
  if (!islist && labs(m) == 1) {/* n>1 on Y, m==1 on X: 1D, no X axis*/
    detector = detector_import(mcformat,
      c, (t ? t : MCCODE_STRING " 1D data"),
      n, 1, 1,
      yl, "", "Signal per bin",
      yvar, "(I,Ierr)", "I",
      y1, y2, x1, x2, 0, 0, f,
      p0, p1, p2, posa, rota, index); /* write Detector: line */
  } else if (!islist && labs(n)==1) {/* m>1 on X, n==1 on Y: 1D, no Y axis*/
    detector = detector_import(mcformat,
      c, (t ? t : MCCODE_STRING " 1D data"),
      m, 1, 1,
      xl, "", "Signal per bin",
      xvar, "(I,Ierr)", "I",
      x1, x2, y1, y2, 0, 0, f,
      p0, p1, p2, posa, rota, index); /* write Detector: line */
  }else {
    detector = detector_import(mcformat,
      c, (t ? t : MCCODE_STRING " 2D data"),
      m, n, 1,
      xl, yl, "Signal per bin",
      xvar, yvar, "I",
      x1, x2, y1, y2, 0, 0, f,
     p0, p1, p2, posa, rota, index); /* write Detector: line */
  }

  if (options && strlen(options)) {
    strncpy(detector.options, options, CHAR_BUF_LENGTH-1);
    detector.options[CHAR_BUF_LENGTH-1] = '\0';
  } else {
    strcpy(detector.options,"None");
  }


  return(detector);
} /* mcdetector_list_import */

/*******************************************************************************
* mcdetector_list_write: write one imported block (local, no MPI communication).
*   append_raw=0: full write (NeXus data info + data, or ASCII header/# Data + rows)
*   append_raw=1: continuation block, rows are appended to the existing data set
*******************************************************************************/
static void mcdetector_list_write(MCDETECTOR detector, int append_raw)
{
  if (!detector.p1 || !detector.m || mcdisable_output_files) return;

#ifdef USE_NEXUS
  if (strcasestr(detector.format, "NeXus")) {
    if (!append_raw) mcdatainfo_out_nexus(nxhandle, detector);
    mcdetector_out_data_nexus(nxhandle, detector);
    return;
  }
#endif
  if (!append_raw) {
    mcdetector_out_2D_ascii(detector);
  } else {
    int   exists  = 0;
    FILE *outfile = mcnew_file(detector.filename, "dat", &exists);
    if (outfile) {
      mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p1,
        outfile, detector.istransposed);
      fclose(outfile);
    }
  }
} /* mcdetector_list_write */

#ifdef USE_MPI
/*******************************************************************************
* MPI event-list output
*
*   Event lists are concatenated on the master node, which is the only writer.
*
*   During the final save (mcsave_final=1, set by mccode_main before finally())
*   every node executes the same SAVE sequence, so the exchange is collective:
*   the number of blocks per node is gathered first, hence nodes without any
*   event still take part, and the master receives exactly what is announced.
*
*   Any other call (a list buffer flushed during TRACE, e.g. Monitor_nD
*   'list all', or a signal-triggered save) happens at a different time on each
*   node and must not communicate: the master writes its block directly, the
*   other nodes append theirs to a local spool file which is sent to the master
*   during the final save and then removed.
*
*   NeXus is different: event lists are neither sent nor copied. Every node,
*   the master included, appends its blocks to its own HDF5 file
*   dirname/mccode_node<rank>.h5 (compressed as set by NX_COMPRESSION). The final save only
*   gathers the row counts, and the master writes the 'events' data set of
*   mccode.h5 as an HDF5 virtual data set (VDS) concatenating the nodes in rank
*   order (see mclist_vds_write). The mccode_node*.h5 files are part of the
*   result; 'h5repack -l CONTI' makes a self-contained copy.
*******************************************************************************/
#ifdef USE_NEXUS
#include <hdf5.h>

/* one VDS to create in mccode.h5 after NXclose (master only) */
struct mclist_vds {
  char       path[4*CHAR_BUF_LENGTH]; /* /entry/.../events in mccode.h5 */
  char       dset[2*CHAR_BUF_LENGTH]; /* data set in the mccode_node*.h5 files */
  char       short_name[CHAR_BUF_LENGTH];
  char       long_name[2*CHAR_BUF_LENGTH];
  long long  cols;
  long long *rows;                    /* per node */
  struct mclist_vds *next;
};
static struct mclist_vds *mclist_vds_list = NULL;
static int mclist_node_file_created = 0;

/* name of the event data set of a list monitor in the per-node files */
static void mclist_node_dset(char *dset, char *f, char *c, int index)
{
  char valid[CHAR_BUF_LENGTH+1];
  if (!strcpy_valid(valid, (f && strlen(f)) ? f : c)) strcpy(valid, "list");
  /* prefixed by the NXentry: the steps of a NeXus scan share the per-node files */
  snprintf(dset, 2*CHAR_BUF_LENGTH, "%s_list%d_%s", mcnxentry, index, valid);
}

/* string attribute on an HDF5 object */
static void mclist_vds_attr(hid_t obj, char *name, char *value)
{
  hid_t type  = H5Tcopy(H5T_C_S1);
  hid_t space = H5Screate(H5S_SCALAR);
  hid_t attr;
  H5Tset_size(type, strlen(value) ? strlen(value) : 1);
  attr = H5Acreate2(obj, name, type, space, H5P_DEFAULT, H5P_DEFAULT);
  if (attr >= 0) { H5Awrite(attr, type, value); H5Aclose(attr); }
  H5Sclose(space);
  H5Tclose(type);
}

/* append rows*cols values to data set dset of this node's file (created,
   truncated, on the first append of a run writing entry1; reopened by the
   later steps of a NeXus scan). nxpath is where the events go in mccode.h5,
   below the NXentry (stored with the entry as attributes 'mccode_path' and
   'mccode_entry', for nexus_vds.py). Returns the number of rows now in the
   data set (0 if none), or -1 on error. No MPI communication. */
static long long mclist_node_append(char *dset, char *nxpath, long long rows, long long cols, double *data)
{
  char      name[CHAR_BUF_LENGTH];
  char     *file;
  hid_t     fid, did = -1, space;
  hsize_t   dims[2] = {0, 0};
  long long total = -1;
  /* a new mccode.h5 starts afresh; a later NXentry is a NeXus scan step whose
     predecessors' events are in the same per-node file */
  int       fresh = !strcmp(mcnxentry, "entry1");

  snprintf(name, sizeof(name), "mccode_node%d", mpi_node_rank);
  if (!rows && !mclist_node_file_created) {
    /* nothing yet: only make sure no file of an earlier run is left over */
    static int checked = 0;
    if (!checked && fresh) { file = mcfull_file(name, "h5"); remove(file); free(file); }
    checked = 1;
    return(0);
  }

  file = mcfull_file(name, "h5");
  if (!mclist_node_file_created) {
    FILE *prev = fresh ? NULL : fopen(file, "rb");
    if (prev) { fclose(prev); fid = H5Fopen(file, H5F_ACC_RDWR, H5P_DEFAULT); }
    else        fid = H5Fcreate(file, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    if (fid >= 0) mclist_node_file_created = 1;
  } else
    fid = H5Fopen(file, H5F_ACC_RDWR, H5P_DEFAULT);
  if (fid < 0) {
    fprintf(stderr, "Error: [MPI node %i] could not open '%s' to store %lli events (mclist_node_append)\n",
      mpi_node_rank, file, rows);
    free(file);
    return(-1);
  }

  if (H5Lexists(fid, dset, H5P_DEFAULT) > 0) {
    did = H5Dopen2(fid, dset, H5P_DEFAULT);
    if (did >= 0) {
      space = H5Dget_space(did);
      H5Sget_simple_extent_dims(space, dims, NULL);
      H5Sclose(space);
    }
  } else if (rows && cols) {
    /* 2D, chunked (~1 MB), unlimited along events, deflate as NX_COMPRESSION */
    hsize_t maxdims[2] = {H5S_UNLIMITED, cols};
    hsize_t chunk[2]   = {cols < 131072 ? 131072/cols : 1, cols};
    hid_t   plist      = H5Pcreate(H5P_DATASET_CREATE);
    dims[1] = cols;
    space   = H5Screate_simple(2, dims, maxdims);
    H5Pset_chunk(plist, 2, chunk);
    int     level      = NX_COMPRESSION == NX_COMP_LZW ? 6 /* NAPI default */
                       : NX_COMPRESSION/100 == NX_COMP_LZW ? NX_COMPRESSION%100 : -1;
    if (level >= 0 && H5Zfilter_avail(H5Z_FILTER_DEFLATE) > 0) {
      H5Pset_shuffle(plist);
      H5Pset_deflate(plist, level);
    }
    did = H5Dcreate2(fid, dset, H5T_NATIVE_DOUBLE, space, H5P_DEFAULT, plist, H5P_DEFAULT);
    if (did >= 0) {
      mclist_vds_attr(did, "mccode_path",  nxpath);
      mclist_vds_attr(did, "mccode_entry", mcnxentry);
    }
    H5Sclose(space);
    H5Pclose(plist);
  } else { /* no data set and nothing to add */
    H5Fclose(fid);
    free(file);
    return(0);
  }

  if (did >= 0) {
    total = (long long)dims[0];
    if (rows && dims[1] != (hsize_t)cols)
      fprintf(stderr, "Error: [MPI node %i] %lli events of %lli columns can not be appended to %llu columns in '%s' (mclist_node_append)\n",
        mpi_node_rank, rows, cols, (unsigned long long)dims[1], file);
    else if (rows) {
      hsize_t start[2] = {dims[0], 0}, count[2] = {rows, cols};
      hid_t   mspace   = H5Screate_simple(2, count, NULL);
      dims[0] += rows;
      if (H5Dset_extent(did, dims) >= 0
       && (space = H5Dget_space(did)) >= 0) {
        H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, NULL);
        if (H5Dwrite(did, H5T_NATIVE_DOUBLE, mspace, space, H5P_DEFAULT, data) >= 0)
          total = (long long)dims[0];
        H5Sclose(space);
      }
      H5Sclose(mspace);
      if (total != (long long)dims[0])
        fprintf(stderr, "Error: [MPI node %i] could not write %lli events to '%s' (mclist_node_append)\n",
          mpi_node_rank, rows, file);
    }
    H5Dclose(did);
  }
  H5Fflush(fid, H5F_SCOPE_LOCAL);
  H5Fclose(fid);
  free(file);
  return(total);
} /* mclist_node_append */

/* master, on a terminating signal: an interrupted run makes no collective call,
   so event lists stay in the per-node files without VDS in mccode.h5 */
static void mclist_interrupt_note(void)
{
  char *dir = dirname && strlen(dirname) ? dirname : ".";
  if (mpi_node_count < 2 || mpi_node_rank != mpi_node_root
   || !mcformat || !strcasestr(mcformat, "NeXus") || mcdisable_output_files) return;
  fprintf(stderr, "Warning: interrupted MPI run: event lists (if any) stay in %s%smccode_node*.h5, not linked from mccode.h5. "
    "Link them with: python3 \"$(%s --showcfg=tooldir)/Python/mccodelib/nexus_vds.py\" %s\n",
    dir, MC_PATHSEP_S, strcmp(MCCODE_NAME, "mcxtrace") ? "mcrun" : "mxrun", dir);
}

/* master, after NXclose: create the VDS registered by mcdetector_out_list_nexus_mpi */
static void mclist_vds_write(void)
{
  char  *file;
  hid_t  fid;
  if (!mclist_vds_list) return;

  file = mcfull_file(siminfo_name, "h5");
  fid  = H5Fopen(file, H5F_ACC_RDWR, H5P_DEFAULT);
  if (fid < 0)
    fprintf(stderr, "Error: could not reopen '%s' to add event lists (mclist_vds_write)\n", file);

  while (mclist_vds_list) {
    struct mclist_vds *v = mclist_vds_list;
    if (fid >= 0) {
      long long total = 0;
      hsize_t   off = 0, vdims[2];
      hid_t     vspace, plist, did;
      int       node_i, signal = 1;
      for (node_i = 0; node_i < mpi_node_count; node_i++) total += v->rows[node_i];
      vdims[0] = total; vdims[1] = v->cols;
      vspace = H5Screate_simple(2, vdims, NULL);
      plist  = H5Pcreate(H5P_DATASET_CREATE);
      /* nodes in rank order, empty nodes left out. Relative source file names:
         resolved from the directory of mccode.h5 */
      for (node_i = 0; node_i < mpi_node_count; node_i++) {
        char    src[CHAR_BUF_LENGTH];
        hsize_t start[2] = {off, 0}, count[2] = {v->rows[node_i], v->cols};
        hid_t   sspace;
        if (!v->rows[node_i]) continue;
        sspace = H5Screate_simple(2, count, NULL);
        H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, NULL, count, NULL);
        snprintf(src, sizeof(src), "mccode_node%d.h5", node_i);
        H5Pset_virtual(plist, vspace, src, v->dset, sspace);
        H5Sclose(sspace);
        off += v->rows[node_i];
      }
      H5Sselect_all(vspace);
      did = H5Dcreate2(fid, v->path, H5T_NATIVE_DOUBLE, vspace, H5P_DEFAULT, plist, H5P_DEFAULT);
      if (did >= 0) {
        hid_t ascalar = H5Screate(H5S_SCALAR);
        hid_t attr    = H5Acreate2(did, "signal", H5T_NATIVE_INT, ascalar, H5P_DEFAULT, H5P_DEFAULT);
        if (attr >= 0) { H5Awrite(attr, H5T_NATIVE_INT, &signal); H5Aclose(attr); }
        H5Sclose(ascalar);
        mclist_vds_attr(did, "short_name", v->short_name);
        mclist_vds_attr(did, "long_name",  v->long_name);
        H5Dclose(did);
        printf("Events:   \"%s\" (%lli events from %i nodes, in mccode_node*.h5)\n",
          v->short_name, total, mpi_node_count);
      } else
        fprintf(stderr, "Error: could not create event list '%s' in '%s' (mclist_vds_write)\n", v->path, file);
      H5Pclose(plist);
      H5Sclose(vspace);
    }
    mclist_vds_list = v->next;
    free(v->rows);
    free(v);
  }
  if (fid >= 0) H5Fclose(fid);
  free(file);
} /* mclist_vds_write */

static MCDETECTOR mcdetector_out_list_nexus_mpi(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2,
                  long m, long n,
                  double *p0, double *p1, double *p2, char *f,
                  char *c, Coords posa, Rotation rota, char* options, int index,
                  MCDETECTOR detector)
{
  long long rows = p1 ? labs(m) : 0;
  long long cols = labs(n);
  long long total, mine[2];
  long long *counts = NULL;
  char      dset[2*CHAR_BUF_LENGTH];
  char      nxpath[4*CHAR_BUF_LENGTH] = "";

  mclist_node_dset(dset, f, c, index);
  if (rows && cols) { /* detector is valid: where the events go in mccode.h5 */
    char data_name[CHAR_BUF_LENGTH];
    strcpy_valid(data_name, strlen(detector.filename) ? detector.filename : detector.component);
    snprintf(nxpath, sizeof(nxpath), "instrument/components/%s/output/%s/events",
      detector.nexuscomp, data_name);
  }
  total = mclist_node_append(dset, nxpath, rows && cols ? rows : 0, cols, p1);
  if (!mcsave_final) return(detector);

  /* final save: collective, only the row counts are sent */
  mine[0] = total > 0 ? total : 0;
  mine[1] = total > 0 ? cols  : 0;
  if (mpi_node_rank == mpi_node_root)
    counts = (long long *)calloc(2*mpi_node_count, sizeof(long long));
  MPI_Gather(mine, 2, MPI_LONG_LONG, counts, 2, MPI_LONG_LONG,
    mpi_node_root, MPI_COMM_WORLD);

  if (mpi_node_rank == mpi_node_root) {
    long long all = 0, allcols = 0;
    int node_i;
    for (node_i = 0; node_i < mpi_node_count; node_i++) {
      if (!counts[2*node_i]) continue;
      if (!allcols) allcols = counts[2*node_i+1];
      if (counts[2*node_i+1] != allcols) {
        fprintf(stderr, "Warning: MPI node %i has %lli columns for %s, expected %lli. Its %lli events are left out.\n",
          node_i, counts[2*node_i+1], c, allcols, counts[2*node_i]);
        counts[2*node_i] = 0;
      }
      all += counts[2*node_i];
    }
    if (all) {
      /* data set info (attributes) for all events; the data set itself is
         a VDS written by mclist_vds_write after NXclose */
      double dummy = 0;
      char   data_name[CHAR_BUF_LENGTH];
      struct mclist_vds *v = (struct mclist_vds *)calloc(1, sizeof(struct mclist_vds));
      MCDETECTOR info = mcdetector_list_import(t, xl, yl, x1, x2, y1, y2, (long)all, (long)allcols,
        NULL, &dummy, NULL, f, c, posa, rota, options, index);
      info.p1 = NULL; /* attributes and links only */
      mcdatainfo_out_nexus(nxhandle, info);
      mcdetector_out_data_nexus(nxhandle, info);
      if (!v || !(v->rows = (long long *)calloc(mpi_node_count, sizeof(long long))))
        exit(-fprintf(stderr, "Error: Out of memory (mcdetector_out_list_nexus_mpi)\n"));
      strcpy_valid(data_name, strlen(info.filename) ? info.filename : info.component);
      snprintf(v->path, sizeof(v->path), "/%s/instrument/components/%s/output/%s/events",
        mcnxentry, info.nexuscomp, data_name);
      strcpy(v->dset, dset);
      snprintf(v->short_name, sizeof(v->short_name), "%s",
        strlen(info.filename) ? info.filename : info.component);
      snprintf(v->long_name, sizeof(v->long_name), "events '%s'", info.title);
      v->cols = allcols;
      for (node_i = 0; node_i < mpi_node_count; node_i++) v->rows[node_i] = counts[2*node_i];
      v->next = mclist_vds_list;
      mclist_vds_list = v;
    }
    free(counts);
  }
  return(detector);
} /* mcdetector_out_list_nexus_mpi */
#endif /* USE_NEXUS */

static char *mclist_spool_name(char *f, char *c, int index, int node)
{
  char valid[CHAR_BUF_LENGTH+1];
  char name[2*CHAR_BUF_LENGTH];

  if (!strcpy_valid(valid, (f && strlen(f)) ? f : c)) strcpy(valid, "list");
  snprintf(name, sizeof(name), "mcspool_%d_%s_node%d", index, valid, node);
  return(mcfull_file(name, "tmp")); /* dirname/name.tmp, to be freed */
}

/* number of complete blocks in a spool file; the file is rewound.
   Sequential reads only (no fseek/ftell), so spool files may exceed 2 GB. */
static long long mclist_spool_blocks(FILE *sp)
{
  long long blocks = 0, hdr[2];
  double    scratch[4096];
  if (!sp) return(0);
  rewind(sp);
  while (fread(hdr, sizeof(hdr), 1, sp) == 1) {
    long long count = llabs(hdr[0])*llabs(hdr[1]);
    while (count > 0) {
      size_t chunk = count > 4096 ? 4096 : (size_t)count;
      if (fread(scratch, sizeof(double), chunk, sp) != chunk) break;
      count -= chunk;
    }
    if (count) break; /* incomplete last block: ignored */
    blocks++;
  }
  rewind(sp);
  return(blocks);
}

static MCDETECTOR mcdetector_out_list_mpi(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2,
                  long m, long n,
                  double *p0, double *p1, double *p2, char *f,
                  char *c, Coords posa, Rotation rota, char* options, int index)
{
  long long rows = p1 ? labs(m) : 0;
  long long cols = labs(n);
  MCDETECTOR detector;

  /* local block: no MPI communication is done for lists in detector_import */
  detector = mcdetector_list_import(t, xl, yl, x1, x2, y1, y2, m, n,
    p0, p1, p2, f, c, posa, rota, options, index);

  if (mcdisable_output_files) return(detector);

#ifdef USE_NEXUS
  if (mcformat && strcasestr(mcformat, "NeXus"))
    return(mcdetector_out_list_nexus_mpi(t, xl, yl, x1, x2, y1, y2, m, n,
      p0, p1, p2, f, c, posa, rota, options, index, detector));
#endif

  if (!mcsave_final) {
    /* nodes are not synchronised: write (master) or spool (others) locally */
    if (mpi_node_rank == mpi_node_root)
      mcdetector_list_write(detector, 0);
    else if (rows && cols) {
      char *spool = mclist_spool_name(f, c, index, mpi_node_rank);
      FILE *sp    = spool ? fopen(spool, "ab") : NULL;
      long long hdr[2] = { m, n };
      if (!sp
       || fwrite(hdr, sizeof(hdr), 1, sp) != 1
       || fwrite(p1, sizeof(double), rows*cols, sp) != (size_t)(rows*cols))
        fprintf(stderr, "Warning: [MPI node %i] could not spool %lli events of %s to '%s' (mcdetector_out_list_mpi)\n",
          mpi_node_rank, rows, c, spool ? spool : "(null)");
      if (sp) fclose(sp);
      free(spool);
    }
    return(detector);
  }

  /* final save: collective, every node takes part whatever its number of events */
  long long  nblocks = 0, spooled = 0;
  long long *blocks  = NULL;
  char      *spool   = NULL;
  FILE      *sp      = NULL;

  if (mpi_node_rank != mpi_node_root) {
    spool = mclist_spool_name(f, c, index, mpi_node_rank);
    if (spool) sp = fopen(spool, "rb");
    spooled = mclist_spool_blocks(sp);
    nblocks = spooled + (rows && cols ? 1 : 0);
  } else
    blocks = (long long *)calloc(mpi_node_count, sizeof(long long));

  MPI_Gather(&nblocks, 1, MPI_LONG_LONG, blocks, 1, MPI_LONG_LONG,
    mpi_node_root, MPI_COMM_WORLD);

  if (mpi_node_rank != mpi_node_root) {
    /* send spooled blocks, then the current one */
    long long hdr[2], sent = 0;
    while (sent < nblocks) {
      double *buf = NULL;
      long long count;
      if (sent < spooled) {
        count = 0;
        buf   = NULL;
        if (fread(hdr, sizeof(hdr), 1, sp) == 1) {
          count = llabs(hdr[0])*llabs(hdr[1]);
          buf   = (double *)malloc(count*sizeof(double));
        }
        if (!buf || fread(buf, sizeof(double), count, sp) != (size_t)count) {
          fprintf(stderr, "Error: [MPI node %i] could not read spooled events from '%s' (mcdetector_out_list_mpi)\n",
            mpi_node_rank, spool);
          MPI_Abort(MPI_COMM_WORLD, 1);
        }
      } else { /* spool exhausted: current block */
        hdr[0] = m; hdr[1] = n; count = rows*cols;
        buf = p1;
      }
      mc_MPI_Send(hdr, 2, MPI_LONG_LONG, mpi_node_root);
      mc_MPI_Send(buf, count, MPI_DOUBLE, mpi_node_root);
      if (buf != p1) free(buf);
      sent++;
    }
    if (sp) fclose(sp);
    if (spool) { remove(spool); free(spool); }
  } else {
    /* master: own block first, then the other nodes in rank order */
    int written = 0;
    int node_i;
    if (rows && cols && detector.m) { mcdetector_list_write(detector, 0); written = 1; }
    for (node_i = 0; node_i < mpi_node_count; node_i++) {
      long long k;
      if (node_i == mpi_node_root) continue;
      for (k = 0; k < blocks[node_i]; k++) {
        long long hdr[2] = {0, 0};
        long long count;
        double   *buf;
        MCDETECTOR block;
        if (mc_MPI_Recv(hdr, 2, MPI_LONG_LONG, node_i) != MPI_SUCCESS) {
          fprintf(stderr, "Error: MPI master could not receive event list header from node %i (mcdetector_out_list_mpi)\n", node_i);
          MPI_Abort(MPI_COMM_WORLD, 1);
        }
        count = llabs(hdr[0])*llabs(hdr[1]);
        buf   = (double *)malloc((count ? count : 1)*sizeof(double));
        if (!buf || mc_MPI_Recv(buf, count, MPI_DOUBLE, node_i) != MPI_SUCCESS) {
          fprintf(stderr, "Error: MPI master could not receive %lli event list values from node %i (mcdetector_out_list_mpi)\n", count, node_i);
          MPI_Abort(MPI_COMM_WORLD, 1);
        }
        if (llabs(hdr[1]) != cols)
          fprintf(stderr, "Warning: MPI node %i sent %lli columns for %s, master has %lli. Appending anyway.\n",
            node_i, llabs(hdr[1]), c, cols);
        if (count) {
          block = mcdetector_list_import(t, xl, yl, x1, x2, y1, y2, (long)hdr[0], (long)hdr[1],
            NULL, buf, NULL, f, c, posa, rota, options, index);
          mcdetector_list_write(block, written);
          written = 1;
        }
        free(buf);
      }
    }
    free(blocks);
  }
  return(detector);
} /* mcdetector_out_list_mpi */
#endif /* USE_MPI */

/*******************************************************************************
* mcdetector_out_2D_list: List mode 2D including forwarding "options" from
* Monitor_nD
*
*   With MPI, event lists from all nodes are written by the master, see
*   mcdetector_out_list_mpi.
*
*   t:    title
*   xl:   x-label
*   yl:   y-label
*   x1:   x axus min
*   x2:   x axis max
*   y1:   y axis min
*   y2:   y axis max
*   m:    dim 1 (x) size
*   n:    dim 2 (y) size
*   p0:   pntr to start of data block#0
*   p1:   pntr to start of data block#1
*   p2:   pntr to start of data block#2
*   f:    filename
*
*   Not included in the macro, and here forwarded to detector_import:
*   c:    ?
*   posa: ?
*   rota: ?
*******************************************************************************/
static MCDETECTOR mcdetector_out_2D_list_write(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2,
                  long m, long n,
                  double *p0, double *p1, double *p2, char *f,
		  char *c, Coords posa, Rotation rota, char* options, int index)
{
  MCDETECTOR detector;

#ifdef USE_MPI
  /* event lists: all nodes must take part, also those without events */
  if (mpi_node_count > 1 && mcformat && strcasestr(mcformat, "list"))
    return(mcdetector_out_list_mpi(t, xl, yl, x1, x2, y1, y2, m, n,
      p0, p1, p2, f, c, posa, rota, options, index));
#endif

  detector = mcdetector_list_import(t, xl, yl, x1, x2, y1, y2, m, n,
    p0, p1, p2, f, c, posa, rota, options, index);

  if (!detector.p1 || !detector.m) return(detector);

#ifdef USE_NEXUS
  if (strcasestr(detector.format, "NeXus"))
    return(mcdetector_out_2D_nexus(detector));
  else
#endif
    return(mcdetector_out_2D_ascii(detector));

} /* mcdetector_out_2D_list_write */

#ifndef NOSIGNALS
/* end of an event list write: handle a signal that came during it. Called
   with the global mcformat as the caller found it (see mcdetector_out_list):
   the replayed save must not see a temporary list format, or it would skip
   the MPI reductions of all histograms while other nodes do them (hang). */
static void mcsig_end_write(double *p1)
{
  mcsig_busy--;
  if (!mcsig_busy && mcsig_pending) {
    int sig = mcsig_pending;
    mcsig_pending = 0;
    mcsig_skip_p1 = p1; /* the block just written */
    mcsig_replay  = 1;
    sighandler(sig);    /* returns only for save/status signals */
    mcsig_replay  = 0;
    mcsig_skip_p1 = NULL;
  }
}
#endif

MCDETECTOR mcdetector_out_2D_list(char *t, char *xl, char *yl,
                  double x1, double x2, double y1, double y2,
                  long m, long n,
                  double *p0, double *p1, double *p2, char *f,
		  char *c, Coords posa, Rotation rota, char* options, int index)
{
  MCDETECTOR detector;
#ifndef NOSIGNALS
  /* the replayed save must not write the block of the interrupted flush again
     (the component resets its buffer only after this call returns) */
  if (mcsig_skip_p1 && p1 == mcsig_skip_p1)
    return(mcdetector_list_import(t, xl, yl, x1, x2, y1, y2, m, n,
      p0, p1, p2, f, c, posa, rota, options, index));
  mcsig_busy++;
#endif
  detector = mcdetector_out_2D_list_write(t, xl, yl, x1, x2, y1, y2, m, n,
    p0, p1, p2, f, c, posa, rota, options, index);
#ifndef NOSIGNALS
  mcsig_end_write(p1);
#endif
  return(detector);
} /* mcdetector_out_2D_list */

/*******************************************************************************
* mcdetector_out_list: wrapper for list output (calls out_2D with mcformat+"list").
*   m=number of events, n=size of each event
*******************************************************************************/
MCDETECTOR mcdetector_out_list(char *t, char *xl, char *yl,
                  long m, long n,
                  double *p1, char *f,
			       char *c, Coords posa, Rotation rota, char* options, int index)
{
  char       format_new[CHAR_BUF_LENGTH];
  char      *format_org;
  MCDETECTOR detector;

#ifndef NOSIGNALS
  mcsig_busy++; /* a signal during the write is handled once mcformat is restored */
#endif
  format_org = mcformat;
  strcpy(format_new, mcformat);
  strcat(format_new, " list");
  mcformat = format_new;
  detector = mcdetector_out_2D_list(t, xl, yl,
                  1,labs(m),1,labs(n),
                  m,n,
                  NULL, p1, NULL, f,
		  c, posa,rota,options, index);

  mcformat = format_org;
#ifndef NOSIGNALS
  mcsig_end_write(p1);
#endif
  return(detector);
}

/*******************************************************************************
 * mcuse_dir: set data/sim storage directory and create it,
 * or exit with error if exists
 ******************************************************************************/
static void
mcuse_dir(char *dir)
{
  if (!dir || !strlen(dir)) return;
#ifdef MC_PORTABLE
  fprintf(stderr, "Error: "
          "Directory output cannot be used with portable simulation (mcuse_dir)\n");
  exit(1);
#else  /* !MC_PORTABLE */
  /* handle file://directory URL type */
  if (strncmp(dir, "file://", strlen("file://")))
    dirname = dir;
  else
    dirname = dir+strlen("file://");


#ifdef USE_MPI
  if(mpi_node_rank == mpi_node_root) {
#endif
    int exists=0;
    DIR* handle = opendir(dirname);
    if (handle) {
      /* Directory exists. */
      closedir(handle);
      exists=1;
    }
    if(mkdir(dirname, 0777)) {
#ifndef DANSE
      if(!mcappend) {
	fprintf(stderr, "Error: unable to create directory '%s' (mcuse_dir)\n", dir);
	fprintf(stderr, "(Maybe the directory already exists?)\n");
#endif
#ifdef USE_MPI
	MPI_Abort(MPI_COMM_WORLD, -1);
#endif
	exit(-1);
      }
    }
#ifdef USE_MPI
    }
#endif

  /* remove trailing PATHSEP (if any) */
  while (strlen(dirname) && dirname[strlen(dirname) - 1] == MC_PATHSEP_C)
    dirname[strlen(dirname) - 1]='\0';
#endif /* !MC_PORTABLE */
} /* mcuse_dir */

/*******************************************************************************
* mcinfo: display instrument simulation info to stdout and exit
*******************************************************************************/
static void
mcinfo(void)
{
  fprintf(stdout, "begin instrument: %s\n", instrument_name);
  mcinfo_out("  ", stdout);
  fprintf(stdout, "end instrument\n");
  fprintf(stdout, "begin simulation: %s\n", dirname ? dirname : ".");
  mcruninfo_out("  ", stdout);
  fprintf(stdout, "end simulation\n");
  exit(0); /* includes MPI_Finalize in MPI mode */
} /* mcinfo */

/*******************************************************************************
* mcparameterinfo: display instrument parameter info to stdout and exit
*******************************************************************************/
static void
mcparameterinfo(void)
{
  mcparameterinfo_out("  ", stdout);
  exit(0); /* includes MPI_Finalize in MPI mode */
} /* mcparameterinfo */



#endif /* ndef MCCODE_R_IO_C */

/* end of the I/O section =================================================== */







/*******************************************************************************
* mcset_ncount: set total number of rays to generate
*******************************************************************************/
void mcset_ncount(unsigned long long int count)
{
  mcncount = count;
}

/* mcget_ncount: get total number of rays to generate */
unsigned long long int mcget_ncount(void)
{
  return mcncount;
}

/* mcget_run_num: get curent number of rays */
/* Within the TRACE scope we are now using _particle->uid directly */
unsigned long long int mcget_run_num() // shuld be (_class_particle* _particle) somehow
{
  /* This function only remains for the few cases outside TRACE where we need to know
     the number of simulated particles */
  return mcrun_num;
}

/* mcsetn_arg: get ncount from a string argument */
static void
mcsetn_arg(char *arg)
{
  mcset_ncount((long long int) strtod(arg, NULL));
}

/* mcsetseed: set the random generator seed from a string argument */
static void
mcsetseed(char *arg)
{
  mcseed = atol(arg);
  if(!mcseed) {
  //  srandom(mcseed);
  //} else {
    fprintf(stderr, "Error: seed must not be zero (mcsetseed)\n");
    exit(1);
  }
}

/* Following part is only embedded when not redundent with mccode-r.h ========= */

#ifndef MCCODE_H

/* SECTION: MCDISPLAY support. =============================================== */

/*******************************************************************************
* Just output MCDISPLAY keywords to be caught by an external plotter client.
*******************************************************************************/

void mcdis_magnify(char *what){
  // Do nothing here, better use interactive zoom from the tools
}

void mcdis_line(double x1, double y1, double z1,
                double x2, double y2, double z2){
  printf("MCDISPLAY: multiline(2,%g,%g,%g,%g,%g,%g)\n",
         x1,y1,z1,x2,y2,z2);
}

void mcdis_dashed_line(double x1, double y1, double z1,
		       double x2, double y2, double z2, int n){
  int i;
  const double dx = (x2-x1)/(2*n+1);
  const double dy = (y2-y1)/(2*n+1);
  const double dz = (z2-z1)/(2*n+1);

  for(i = 0; i < n+1; i++)
    mcdis_line(x1 + 2*i*dx,     y1 + 2*i*dy,     z1 + 2*i*dz,
	       x1 + (2*i+1)*dx, y1 + (2*i+1)*dy, z1 + (2*i+1)*dz);
}

void mcdis_multiline(int count, ...){
  va_list ap;
  double x,y,z;

  printf("MCDISPLAY: multiline(%d", count);
  va_start(ap, count);
  while(count--)
    {
    x = va_arg(ap, double);
    y = va_arg(ap, double);
    z = va_arg(ap, double);
    printf(",%g,%g,%g", x, y, z);
    }
  va_end(ap);
  printf(")\n");
}

void mcdis_rectangle(char* plane, double x, double y, double z,
		     double width, double height){
  /* draws a rectangle in the plane           */
  /* x is ALWAYS width and y is ALWAYS height */
  if (strcmp("xy", plane)==0) {
    mcdis_multiline(5,
		    x - width/2, y - height/2, z,
		    x + width/2, y - height/2, z,
		    x + width/2, y + height/2, z,
		    x - width/2, y + height/2, z,
		    x - width/2, y - height/2, z);
  } else if (strcmp("xz", plane)==0) {
    mcdis_multiline(5,
		    x - width/2, y, z - height/2,
		    x + width/2, y, z - height/2,
		    x + width/2, y, z + height/2,
		    x - width/2, y, z + height/2,
		    x - width/2, y, z - height/2);
  } else if (strcmp("yz", plane)==0) {
    mcdis_multiline(5,
		    x, y - height/2, z - width/2,
		    x, y - height/2, z + width/2,
		    x, y + height/2, z + width/2,
		    x, y + height/2, z - width/2,
		    x, y - height/2, z - width/2);
  } else {

    fprintf(stderr, "Error: Definition of plane %s unknown\n", plane);
    exit(1);
  }
}

void mcdis_circle(char *plane, double x, double y, double z, double r){
  printf("MCDISPLAY: mcdiscircle('%s',%g,%g,%g,%g)\n", plane, x, y, z, r);
}

/* A zero axis n=(0,0,0) has no direction: draw along +y, the identity orientation
 * of the --trace=2 primitives, and warn once (to stderr, outside the MCDISPLAY stream) */
static void mcdis_check_axis(const char *what, double *nx, double *ny, double *nz){
  static int warned = 0;
  if (*nx == 0 && *ny == 0 && *nz == 0) {
    if (!warned++)
      fprintf(stderr, "Warning: mcdisplay %s() called with axis n=(0,0,0), using (0,1,0) "
              "(further occurrences not reported)\n", what);
    *ny = 1;
  }
}

void mcdis_new_circle(double x, double y, double z, double r, double nx, double ny, double nz){
  mcdis_check_axis("new_circle", &nx, &ny, &nz);
  printf("MCDISPLAY: mcdisnew_circle(%g,%g,%g,%g,%g,%g,%g)\n", x, y, z, r, nx, ny, nz);
}


/* Draws a circle with center (x,y,z), radius (r), and in the plane
 * with normal (nx,ny,nz)*/
void mcdis_Circle(double x, double y, double z, double r, double nx, double ny, double nz){
    int i;
    mcdis_check_axis("Circle", &nx, &ny, &nz);
    if(nx==0 && ny && nz==0){
        for (i=0;i<24; i++){
            mcdis_line(x+r*sin(i*2*PI/24),y,z+r*cos(i*2*PI/24),
                    x+r*sin((i+1)*2*PI/24),y,z+r*cos((i+1)*2*PI/24));
        }
    }else{
        double mx,my,mz;
        /*generate perpendicular vector using (nx,ny,nz) and (0,1,0)*/
        vec_prod(mx,my,mz, 0,1,0, nx,ny,nz);
        NORM(mx,my,mz);
        /*draw circle*/
        for (i=0;i<24; i++){
            double ux,uy,uz;
            double wx,wy,wz;
            rotate(ux,uy,uz, mx,my,mz, i*2*PI/24, nx,ny,nz);
            rotate(wx,wy,wz, mx,my,mz, (i+1)*2*PI/24, nx,ny,nz);
            mcdis_line(x+ux*r,y+uy*r,z+uz*r,
                    x+wx*r,y+wy*r,z+wz*r);
        }
    }
}


/*  OLD IMPLEMENTATION
    draws a box with center at (x, y, z) and
    width (deltax), height (deltay), length (deltaz) */
void mcdis_legacy_box(double x, double y, double z,
	       double width, double height, double length){

  mcdis_rectangle("xy", x, y, z-length/2, width, height);
  mcdis_rectangle("xy", x, y, z+length/2, width, height);
  mcdis_line(x-width/2, y-height/2, z-length/2,
	     x-width/2, y-height/2, z+length/2);
  mcdis_line(x-width/2, y+height/2, z-length/2,
	     x-width/2, y+height/2, z+length/2);
  mcdis_line(x+width/2, y-height/2, z-length/2,
	     x+width/2, y-height/2, z+length/2);
  mcdis_line(x+width/2, y+height/2, z-length/2,
	     x+width/2, y+height/2, z+length/2);
}

/* --trace=1 box: the legacy box with its local y axis rotated onto (nx,ny,nz),
 * as drawn at --trace=2 */
static void mcdis_rotated_box(double x, double y, double z,
	       double width, double height, double length, double nx, double ny, double nz){
  double c[8][3], ax, ay, az;
  int i, j;
  NORM(nx,ny,nz);
  if (nx == 0 && ny > 0 && nz == 0) {
    mcdis_legacy_box(x, y, z, width, height, length);
    return;
  }
  vec_prod(ax,ay,az, 0,1,0, nx,ny,nz);
  if (ax == 0 && az == 0) az = 1; /* n = -y: half turn around z */
  for (i = 0; i < 8; i++) {
    double px = (i & 1 ? 0.5 : -0.5)*width;
    double py = (i & 2 ? 0.5 : -0.5)*height;
    double pz = (i & 4 ? 0.5 : -0.5)*length;
    rotate(c[i][0],c[i][1],c[i][2], px,py,pz, acos(ny < -1 ? -1 : ny), ax,ay,az);
  }
  /* 12 edges: corners differing in one bit */
  for (i = 0; i < 8; i++)
    for (j = 1; j < 8; j <<= 1)
      if (!(i & j))
        mcdis_line(x+c[i][0], y+c[i][1], z+c[i][2],
                   x+c[i|j][0], y+c[i|j][1], z+c[i|j][2]);
}

/*  NEW 3D IMPLEMENTATION OF BOX SUPPORTS HOLLOW ALSO
    draws a box with center at (x, y, z) and
    width (deltax), height (deltay), length (deltaz) */
void mcdis_box(double x, double y, double z,
	       double width, double height, double length, double thickness, double nx, double ny, double nz){
  mcdis_check_axis("box", &nx, &ny, &nz);
  if (mcdotrace==2) {
    printf("MCDISPLAY: mcdisbox(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)\n", x, y, z, width, height, length, thickness, nx, ny, nz);
  } else {
    mcdis_rotated_box(x, y, z, width, height, length, nx, ny, nz);
    /* hollow: closed inner cavity, as in e.g. Incoherent */
    if (thickness > 0 && width-2*thickness > 0 && height-2*thickness > 0 && length-2*thickness > 0)
      mcdis_rotated_box(x, y, z, width-2*thickness, height-2*thickness, length-2*thickness, nx, ny, nz);
  }
}


/* OLD IMPLEMENTATION
Draws a cylinder with center at (x,y,z) with extent (r,height).
 * The cylinder axis is along the vector nx,ny,nz. */
void mcdis_legacy_cylinder( double x, double y, double z,
        double r, double height, int N, double nx, double ny, double nz){
    int i;
    /*no lines make little sense - so trigger the default*/
    if(N<=0) N=5;

    NORM(nx,ny,nz);
    double h_2=height/2.0;
    mcdis_Circle(x+nx*h_2,y+ny*h_2,z+nz*h_2,r,nx,ny,nz);
    mcdis_Circle(x-nx*h_2,y-ny*h_2,z-nz*h_2,r,nx,ny,nz);

    double mx,my,mz;
    /*generate perpendicular vector using (nx,ny,nz) and (0,1,0)*/
    if(nx==0 && ny && nz==0){
        mx=my=0;mz=1;
    }else{
        vec_prod(mx,my,mz, 0,1,0, nx,ny,nz);
        NORM(mx,my,mz);
    }
    /*draw circle*/
    for (i=0; i<24; i++){
        double ux,uy,uz;
        rotate(ux,uy,uz, mx,my,mz, i*2*PI/24, nx,ny,nz);
        mcdis_line(x+nx*h_2+ux*r, y+ny*h_2+uy*r, z+nz*h_2+uz*r,
                 x-nx*h_2+ux*r, y-ny*h_2+uy*r, z-nz*h_2+uz*r);
    }
}

/* NEW 3D IMPLEMENTATION ALSO SUPPORTING HOLLOW
Draws a cylinder with center at (x,y,z) with extent (r,height).
 * The cylinder axis is along the vector nx,ny,nz.*/
void mcdis_cylinder( double x, double y, double z,
        double r, double height, double thickness, double nx, double ny, double nz){
  mcdis_check_axis("cylinder", &nx, &ny, &nz);
  if (mcdotrace==2) {
      printf("MCDISPLAY: mcdiscylinder(%g, %g, %g, %g, %g, %g, %g, %g, %g)\n",
         x, y, z, r, height, thickness, nx, ny, nz);
  } else {
    mcdis_legacy_cylinder(x, y, z,
			  r, height, 12, nx, ny, nz);
    /* hollow: closed inner cavity, as in e.g. Incoherent */
    if (thickness > 0 && r-thickness > 0 && height-2*thickness > 0)
      mcdis_legacy_cylinder(x, y, z,
			    r-thickness, height-2*thickness, 12, nx, ny, nz);
  }
}

/* Draws a cone with center at (x,y,z) with extent (r,height).
 * The cone axis is along the vector nx,ny,nz.*/
void mcdis_cone( double x, double y, double z,
        double r, double height, double nx, double ny, double nz){
  mcdis_check_axis("cone", &nx, &ny, &nz);
  if (mcdotrace==2) {
    printf("MCDISPLAY: mcdiscone(%g, %g, %g, %g, %g, %g, %g, %g)\n",
       x, y, z, r, height, nx, ny, nz);
  } else {
    /* (x,y,z) is the cone centre, as drawn at --trace=2 */
    NORM(nx,ny,nz);
    x -= 0.5*height*nx; y -= 0.5*height*ny; z -= 0.5*height*nz;
    mcdis_Circle(x, y, z, r, nx, ny, nz);
    mcdis_Circle(x+0.25*height*nx, y+0.25*height*ny, z+0.25*height*nz, 0.75*r, nx, ny, nz);
    mcdis_Circle(x+0.5*height*nx, y+0.5*height*ny, z+0.5*height*nz, 0.5*r, nx, ny, nz);
    mcdis_Circle(x+0.75*height*nx, y+0.75*height*ny, z+0.75*height*nz, 0.25*r, nx, ny, nz);
    mcdis_line(x, y, z, x+height*nx, y+height*ny, z+height*nz);
  }
}

/* Draws a disc with center at (x,y,z) with extent (r).
 * The disc axis is along the vector nx,ny,nz.*/
void mcdis_disc( double x, double y, double z,
        double r, double nx, double ny, double nz){
  mcdis_check_axis("disc", &nx, &ny, &nz);
  printf("MCDISPLAY: mcdisdisc(%g, %g, %g, %g, %g, %g, %g)\n",
     x, y, z, r, nx, ny, nz);
}

/* Draws a annulus with center at (x,y,z) with extent (outer radius) and remove inner thickness.
 * The annulus axis is along the vector nx,ny,nz.*/
void mcdis_annulus( double x, double y, double z,
        double outer_radius, double thickness, double nx, double ny, double nz){
  mcdis_check_axis("annulus", &nx, &ny, &nz);
  printf("MCDISPLAY: mcdisannulus(%g, %g, %g, %g, %g, %g, %g, %g)\n",
     x, y, z, outer_radius, thickness, nx, ny, nz);
}

/* draws a sphere with center at (x,y,z) with extent (r)*/
void mcdis_sphere(double x, double y, double z, double r){
  if (mcdotrace==2) {
    printf("MCDISPLAY: mcdissphere(%g,%g,%g,%g)\n", x, y, z, r);
  } else {
    double nx,ny,nz;
    int i;
    int N=12;

    nx=0;ny=0;nz=1;
    mcdis_Circle(x,y,z,r,nx,ny,nz);
    for (i=1;i<N;i++){
        rotate(nx,ny,nz, nx,ny,nz, PI/N, 0,1,0);
        mcdis_Circle(x,y,z,r,nx,ny,nz);
    }
    /*lastly draw a great circle perpendicular to all N circles*/
    //mcdis_Circle(x,y,z,radius,1,0,0);

    for (i=1;i<=N;i++){
        double yy=-r+ 2*r*((double)i/(N+1));
        mcdis_Circle(x,y+yy ,z,  sqrt(r*r-yy*yy) ,0,1,0);
    }
  }
}
/* POLYHEDRON IMPLEMENTATION*/

void mcdis_polyhedron(char *vertices_faces){
  printf("MCDISPLAY: polyhedron %s\n", vertices_faces);
}

/* POLYGON IMPLEMENTATION */
void mcdis_polygon(int count, ...){
  va_list ap;
  double *x,*y,*z;

  double x0=0,y0=0,z0=0; /* Used for centre-of-mass in trace==2 */

  x=malloc(count*sizeof(double));
  y=malloc(count*sizeof(double));
  z=malloc(count*sizeof(double));
  if (!x || !y || !z) {
    fprintf(stderr,"Error initializing polygon set size %i\n",count);
    exit(-1);
  }
  va_start(ap, count);
  // Fallback for trace==1 is multiline, one rank higher
  if (mcdotrace==1) {
    printf("MCDISPLAY: multiline(%i,",count+1);
  }
  
  int j;
  for (j=0; j<count; j++) {
    x[j] = va_arg(ap, double);
    y[j] = va_arg(ap, double);
    z[j] = va_arg(ap, double);
    if (mcdotrace==1) {
      printf("%g,%g,%g,",x[j],y[j],z[j]);
    } else {
      // Calculation of polygon centre of mass
      x0 += x[j]; y0 += y[j]; z0 += z[j];
    }
  }
  va_end(ap);

  /* Patch data for multiline(count+1, ... use 0th point*/
  if (mcdotrace==1) {
    printf("%g,%g,%g)\n",x[0],y[0],z[0]);
  } else {
    x0 /= count; y0 /= count; z0 /= count;
    /* Build up a json string for a "polyhedron" */
    int faceSize;
    int vtxSize;
    if (count > 3) {
      /* Split in triangles - as many as polygon rank */
      faceSize=count;
      vtxSize=count+1;
    } else {
      faceSize=1;
      vtxSize=count;
    }
    
    /* Upper bound: a vertex "[%g, %g, %g], " is at most 3*13+8 chars, a face
       "{ \"face\": [%d, %d, %d]}, " at most 3*11+17 */
    size_t estimated_size = 64 + (size_t)vtxSize*48 + (size_t)faceSize*64;

    char *json_string = malloc(estimated_size);
    if (json_string == NULL) {
        fprintf(stderr, "Memory allocation failed.\n");
        return;
    }

    char *ptr = json_string;
    ptr += sprintf(ptr, "{ \"vertices\": [");

    if (count==3) { // Single, basic triangle
      ptr += sprintf(ptr, "[%g, %g, %g], [%g, %g, %g], [%g, %g, %g]", x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2]);
    } else {
      for (int i = 0; i < vtxSize-1; i++) {
        ptr += sprintf(ptr, "[%g, %g, %g]", x[i], y[i], z[i]);
        if (i < vtxSize - 2) {
	  ptr += sprintf(ptr, ", ");
        } else {
	  ptr += sprintf(ptr, ", [%g, %g, %g]", x0, y0, z0);
	}
      }
    }
    ptr += sprintf(ptr, "], \"faces\": [");
    if (count==3) { // Single, basic triangle, 1 face...
      ptr += sprintf(ptr, "{ \"face\": [");
      ptr += sprintf(ptr, "0, 1, 2");
      ptr += sprintf(ptr, "]}");
    } else {
      /* Fan of triangles (i, i+1, centre), all with the polygon's own winding */
      for (int i = 0; i < faceSize; i++) {
        ptr += sprintf(ptr, "{ \"face\": [");
	ptr += sprintf(ptr, "%d, %d, %d", i, (i+1) % count, count);
	ptr += sprintf(ptr, "]}");
	if (i < faceSize-1) {
	  ptr += sprintf(ptr, ", ");
	}
      }
    }
    ptr += sprintf(ptr, "]}");
    mcdis_polyhedron(json_string);

    free(json_string);
  }
  free(x);free(y);free(z);
}
/* END NEW POLYGON IMPLEMENTATION*/

/*
void polygon(double x1, double y1, double z1,
                double x2, double y2, double z2){
  printf("MCDISPLAY: polygon(2,%g,%g,%g,%g,%g,%g)\n",
         x1,y1,z1,x2,y2,z2);
}
*/

/* SECTION: coordinates handling ============================================ */

/*******************************************************************************
* Since we use a lot of geometric calculations using Cartesian coordinates,
* we collect some useful routines here. However, it is also permissible to
* work directly on the underlying struct coords whenever that is most
* convenient (that is, the type Coords is not abstract).
*
* Coordinates are also used to store rotation angles around x/y/z axis.
*
* Since coordinates are used much like a basic type (such as double), the
* structure itself is passed and returned, rather than a pointer.
*
* At compile-time, the values of the coordinates may be unknown (for example
* a motor position). Hence coordinates are general expressions and not simple
* numbers. For this we used the type Coords_exp which has three CExp
* fields. For runtime (or calculations possible at compile time), we use
* Coords which contains three double fields.
*******************************************************************************/

/* coords_set: Assign coordinates. */
Coords coords_set(MCNUM x, MCNUM y, MCNUM z)
{
  Coords a;

  a.x = x;
  a.y = y;
  a.z = z;
  return a;
}

/* coords_get: get coordinates. Required when 'x','y','z' are #defined as ray pars */
Coords coords_get(Coords a, MCNUM *x, MCNUM *y, MCNUM *z)
{
  *x = a.x;
  *y = a.y;
  *z = a.z;
  return a;
}

/* coords_add: Add two coordinates. */
Coords coords_add(Coords a, Coords b)
{
  Coords c;

  c.x = a.x + b.x;
  c.y = a.y + b.y;
  c.z = a.z + b.z;
  if (fabs(c.z) < 1e-14) c.z=0.0;
  return c;
}

/* coords_sub: Subtract two coordinates. */
Coords coords_sub(Coords a, Coords b)
{
  Coords c;

  c.x = a.x - b.x;
  c.y = a.y - b.y;
  c.z = a.z - b.z;
  if (fabs(c.z) < 1e-14) c.z=0.0;
  return c;
}

/* coords_neg: Negate coordinates. */
Coords coords_neg(Coords a)
{
  Coords b;

  b.x = -a.x;
  b.y = -a.y;
  b.z = -a.z;
  return b;
}

/* coords_scale: Scale a vector. */
Coords coords_scale(Coords b, double scale) {
  Coords a;

  a.x = b.x*scale;
  a.y = b.y*scale;
  a.z = b.z*scale;
  return a;
}

/* coords_sp: Scalar product: a . b */
double coords_sp(Coords a, Coords b) {
  double value;

  value = a.x*b.x + a.y*b.y + a.z*b.z;
  return value;
}

/* coords_xp: Cross product: a = b x c. */
Coords coords_xp(Coords b, Coords c) {
  Coords a;

  a.x = b.y*c.z - c.y*b.z;
  a.y = b.z*c.x - c.z*b.x;
  a.z = b.x*c.y - c.x*b.y;
  return a;
}

/* coords_len: Gives length of coords set. */
double coords_len(Coords a) {
  return sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
}

/* coords_mirror: Mirror a in plane (through the origin) defined by normal n*/
Coords coords_mirror(Coords a, Coords n) {
  double t = scalar_prod(n.x, n.y, n.z, n.x, n.y, n.z);
  Coords b;
  if (t!=1) {
    t = sqrt(t);
    n.x /= t;
    n.y /= t;
    n.z /= t;
  }
  t=scalar_prod(a.x, a.y, a.z, n.x, n.y, n.z);
  b.x = a.x-2*t*n.x;
  b.y = a.y-2*t*n.y;
  b.z = a.z-2*t*n.z;
  return b;
}

/* coords_print: Print out vector values. */
void coords_print(Coords a) {
  #ifndef OPENACC
  fprintf(stdout, "(%f, %f, %f)\n", a.x, a.y, a.z);
  #endif
  return;
}

mcstatic void coords_norm(Coords* c) {
	double temp = coords_sp(*c,*c);

	// Skip if we will end dividing by zero
	if (temp == 0) return;

	temp = sqrt(temp);

	c->x /= temp;
	c->y /= temp;
	c->z /= temp;
}

/* coords_test_zero: check if zero vector*/
int coords_test_zero(Coords a){
  return ( a.x==0 && a.y==0 && a.z==0 );
}

/*******************************************************************************
* The Rotation type implements a rotation transformation of a coordinate
* system in the form of a double[3][3] matrix.
*
* Contrary to the Coords type in coords.c, rotations are passed by
* reference. Functions that yield new rotations do so by writing to an
* explicit result parameter; rotations are not returned from functions. The
* reason for this is that arrays cannot by returned from functions (though
* structures can; thus an alternative would have been to wrap the
* double[3][3] array up in a struct). Such are the ways of C programming.
*
* A rotation represents the tranformation of the coordinates of a vector when
* changing between coordinate systems that are rotated with respect to each
* other. For example, suppose that coordinate system Q is rotated 45 degrees
* around the Z axis with respect to coordinate system P. Let T be the
* rotation transformation representing a 45 degree rotation around Z. Then to
* get the coordinates of a vector r in system Q, apply T to the coordinates
* of r in P. If r=(1,0,0) in P, it will be (sqrt(1/2),-sqrt(1/2),0) in
* Q. Thus we should be careful when interpreting the sign of rotation angles:
* they represent the rotation of the coordinate systems, not of the
* coordinates (which has opposite sign).
*******************************************************************************/

/*******************************************************************************
* rot_set_rotation: Get transformation for rotation first phx around x axis,
* then phy around y, then phz around z.
*******************************************************************************/
void rot_set_rotation(Rotation t, double phx, double phy, double phz)
{
  if ((phx == 0) && (phy == 0) && (phz == 0)) {
    t[0][0] = 1.0;
    t[0][1] = 0.0;
    t[0][2] = 0.0;
    t[1][0] = 0.0;
    t[1][1] = 1.0;
    t[1][2] = 0.0;
    t[2][0] = 0.0;
    t[2][1] = 0.0;
    t[2][2] = 1.0;
  } else {
    double cx = cos(phx);
    double sx = sin(phx);
    double cy = cos(phy);
    double sy = sin(phy);
    double cz = cos(phz);
    double sz = sin(phz);

    t[0][0] = cy*cz;
    t[0][1] = sx*sy*cz + cx*sz;
    t[0][2] = sx*sz - cx*sy*cz;
    t[1][0] = -cy*sz;
    t[1][1] = cx*cz - sx*sy*sz;
    t[1][2] = sx*cz + cx*sy*sz;
    t[2][0] = sy;
    t[2][1] = -sx*cy;
    t[2][2] = cx*cy;
  }
}

/*******************************************************************************
* rot_test_identity: Test if rotation is identity
*******************************************************************************/
int rot_test_identity(Rotation t)
{
  return (t[0][0] + t[1][1] + t[2][2] == 3);
}

/*******************************************************************************
* rot_mul: Matrix multiplication of transformations (this corresponds to
* combining transformations). After rot_mul(T1, T2, T3), doing T3 is
* equal to doing first T2, then T1.
* Note that T3 must not alias (use the same array as) T1 or T2.
*******************************************************************************/
void rot_mul(Rotation t1, Rotation t2, Rotation t3)
{
  if (rot_test_identity(t1)) {
    rot_copy(t3, t2);
  } else if (rot_test_identity(t2)) {
    rot_copy(t3, t1);
  } else {
    int i,j;
    for(i = 0; i < 3; i++)
      for(j = 0; j < 3; j++)
	t3[i][j] = t1[i][0]*t2[0][j] + t1[i][1]*t2[1][j] + t1[i][2]*t2[2][j];
  }
}

/*******************************************************************************
* rot_copy: Copy a rotation transformation (arrays cannot be assigned in C).
*******************************************************************************/
void rot_copy(Rotation dest, Rotation src)
{
  int i,j;
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++)
      dest[i][j] = src[i][j];
}

/*******************************************************************************
* rot_transpose: Matrix transposition, which is inversion for Rotation matrices
*******************************************************************************/
void rot_transpose(Rotation src, Rotation dst)
{
  dst[0][0] = src[0][0];
  dst[0][1] = src[1][0];
  dst[0][2] = src[2][0];
  dst[1][0] = src[0][1];
  dst[1][1] = src[1][1];
  dst[1][2] = src[2][1];
  dst[2][0] = src[0][2];
  dst[2][1] = src[1][2];
  dst[2][2] = src[2][2];
}

/*******************************************************************************
* rot_apply: returns t*a
*******************************************************************************/
Coords rot_apply(Rotation t, Coords a)
{
  Coords b;
  if (rot_test_identity(t)) {
    return a;
  } else {
    b.x = t[0][0]*a.x + t[0][1]*a.y + t[0][2]*a.z;
    b.y = t[1][0]*a.x + t[1][1]*a.y + t[1][2]*a.z;
    b.z = t[2][0]*a.x + t[2][1]*a.y + t[2][2]*a.z;
    return b;
  }
}

/**
 * Pretty-printing of rotation matrices.
 */
void rot_print(Rotation rot) {
	printf("[ %4.2f %4.2f %4.2f ]\n",
			rot[0][0], rot[0][1], rot[0][2]);
	printf("[ %4.2f %4.2f %4.2f ]\n",
			rot[1][0], rot[1][1], rot[1][2]);
	printf("[ %4.2f %4.2f %4.2f ]\n\n",
			rot[2][0], rot[2][1], rot[2][2]);
}

/**
 * Vector product: used by vec_prod (mccode-r.h). Use coords_xp for Coords.
 */
void vec_prod_func(double *x, double *y, double *z,
		double x1, double y1, double z1,
		double x2, double y2, double z2) {
    *x = (y1)*(z2) - (y2)*(z1);
    *y = (z1)*(x2) - (z2)*(x1);
    *z = (x1)*(y2) - (x2)*(y1);
}

/**
 * Scalar product: use coords_sp for Coords.
 */
double scalar_prod(
		double x1, double y1, double z1,
		double x2, double y2, double z2) {
	return ((x1 * x2) + (y1 * y2) + (z1 * z2));
}

mcstatic void norm_func(double *x, double *y, double *z) {
	double temp = (*x * *x) + (*y * *y) + (*z * *z);
	if (temp != 0) {
		temp = sqrt(temp);
		*x /= temp;
		*y /= temp;
		*z /= temp;
	}
}


/* SECTION: GPU algorithms ================================================== */


/*
*  Divide-and-conquer strategy for parallelizing this task: Sort absorbed
*  particles last.
*
*   particles:  the particle array, required to checking _absorbed
*   pbuffer:    same-size particle buffer array required for parallel sort
*   len:        sorting area-of-interest size (e.g. from previous calls)
*   buffer_len: total array size
*   flag_split: if set, multiply live particles into absorbed slots, up to buffer_len
*   multiplier: output arg, becomes the  SPLIT multiplier if flag_split is set
*/
#ifdef FUNNEL
long sort_absorb_last(_class_particle* particles, _class_particle* pbuffer, long len, long buffer_len, long flag_split, long* multiplier) {
  #define SAL_THREADS 1024 // num parallel sections
  if (multiplier != NULL) *multiplier = -1; // set default out value for multiplier
  if (len<SAL_THREADS) return sort_absorb_last_serial(particles, len);
  long newlen = 0;
  long los[SAL_THREADS]; // target array startidxs
  long lens[SAL_THREADS]; // target array sublens
  long l = floor(len/(SAL_THREADS-1)); // subproblem_len
  long ll = len - l*(SAL_THREADS-1); // last_subproblem_len

  // TODO: The l vs ll is too simplistic, since ll can become much larger
  // than l, resulting in idling. We should distribute lengths more evenly.

  // step 1: sort sub-arrays
  #pragma acc parallel loop present(particles[0:buffer_len], pbuffer[0:buffer_len])
  for (unsigned long tidx=0; tidx<SAL_THREADS; tidx++) {
    long lo = l*tidx;
    long loclen = l;
    if (tidx==(SAL_THREADS-1)) loclen = ll; // last sub-problem special case
    long i = lo;
    long j = lo + loclen - 1;

    // write into pbuffer at i and j
    #pragma acc loop seq
    while (i < j) {
      #pragma acc loop seq
      while (!particles[i]._absorbed && i<j) {
        pbuffer[i] = particles[i];
        i++;
      }
      #pragma acc loop seq
      while (particles[j]._absorbed && i<j) {
        pbuffer[j] = particles[j];
        j--;
      }
      if (i < j) {
        pbuffer[j] = particles[i];
        pbuffer[i] = particles[j];
        i++;
        j--;
      }
    }
    // transfer edge case
    if (i==j)
      pbuffer[i] = particles[i];

    lens[tidx] = i - lo;
    if (i==j && !particles[i]._absorbed) lens[tidx]++;
  }

  // determine lo's
  long accumlen = 0;
  #pragma acc loop seq
  for (long idx=0; idx<SAL_THREADS; idx++) {
    los[idx] = accumlen;
    accumlen = accumlen + lens[idx];
  }

  // step 2: write non-absorbed sub-arrays to psorted/output from the left
  #pragma acc parallel loop present(pbuffer[0:buffer_len])
  for (unsigned long tidx=0; tidx<SAL_THREADS; tidx++) {
    long j, k;
    #pragma acc loop seq
    for (long i=0; i<lens[tidx]; i++) {
      j = i + l*tidx;
      k = i + los[tidx];
      particles[k] = pbuffer[j];
    }
  }
  //for (int ii=0;ii<accumlen;ii++) printf("%ld ", (psorted[ii]->_absorbed));

  // return (no SPLIT, or nothing left to split)
  if (flag_split != 1 || accumlen == 0)
    return accumlen;

  // SPLIT - repeat the non-absorbed block N-1 times, where len % accumlen = N + R
  int mult = buffer_len / accumlen; // TODO: possibly use a new arg, bufferlen, rather than len

  // not enough space for full-block split, return
  if (mult <= 1)
    return accumlen;

  // copy non-absorbed block
  #pragma acc parallel loop present(particles[0:buffer_len])
  for (long tidx = 0; tidx < accumlen; tidx++) { // tidx: thread index
    _class_particle sourcebuffer;
    _class_particle targetbuffer;
    // assign reduced weight to all particles
    particles[tidx].p=particles[tidx].p/mult;
    #pragma acc loop seq
    for (long bidx = 1; bidx < mult; bidx++) { // bidx: block index
      // preserve absorbed particle (for randstate)
      sourcebuffer = particles[bidx*accumlen + tidx];
      // buffer full particle struct
      targetbuffer = particles[tidx];
      // reassign previous randstate
      for (int ridx = 0; ridx < RANDSTATE_LEN; ridx++)
        targetbuffer.randstate[ridx] = sourcebuffer.randstate[ridx];
      // apply
      particles[bidx*accumlen + tidx] = targetbuffer;
    }
  }

  // set out split multiplier value
  *multiplier = mult;

  // return expanded array size
  return accumlen * mult;
}

#endif

/*
*  Fallback serial version of the one above.
*/
long sort_absorb_last_serial(_class_particle* particles, long len) {
  long i = 0;
  long j = len - 1;
  _class_particle pbuffer;

  // bubble
  while (i < j) {
    while (!particles[i]._absorbed && i<j) i++;
    while (particles[j]._absorbed && i<j) j--;
    if (i < j) {
      pbuffer = particles[j];
      particles[j] = particles[i];
      particles[i] = pbuffer;
      i++;
      j--;
    }
  }

  // return new length
  if (i==j && !particles[i]._absorbed)
    return i + 1;
  else
    return i;
}

/*******************************************************************************
* mccoordschange: applies rotation to (x y z) and (vx vy vz) and Spin (sx,sy,sz)
*******************************************************************************/
void mccoordschange(Coords a, Rotation t, _class_particle *particle)
{
  Coords b, c;

  b.x = particle->x;
  b.y = particle->y;
  b.z = particle->z;
  c = rot_apply(t, b);
  b = coords_add(c, a);
  particle->x = b.x;
  particle->y = b.y;
  particle->z = b.z;

#if MCCODE_PARTICLE_CODE == 2112
    if (particle->vz != 0.0 || particle->vx != 0.0 || particle->vy != 0.0)
      mccoordschange_polarisation(t, &(particle->vx), &(particle->vy), &(particle->vz));

    if (particle->sz != 0.0 || particle->sx != 0.0 || particle->sy != 0.0)
      mccoordschange_polarisation(t, &(particle->sx), &(particle->sy), &(particle->sz));
#elif MCCODE_PARTICLE_CODE == 22
    if (particle->kz != 0.0 || particle->kx != 0.0 || particle->ky != 0.0)
      mccoordschange_polarisation(t, &(particle->kx), &(particle->ky), &(particle->kz));

    if (particle->Ez != 0.0 || particle->Ex != 0.0 || particle->Ey != 0.0)
      mccoordschange_polarisation(t, &(particle->Ex), &(particle->Ey), &(particle->Ez));
#endif
}

/*******************************************************************************
* mccoordschange_polarisation: applies rotation to vector (sx sy sz)
*******************************************************************************/
void mccoordschange_polarisation(Rotation t, double *sx, double *sy, double *sz)
{
  Coords b, c;

  b.x = *sx;
  b.y = *sy;
  b.z = *sz;
  c = rot_apply(t, b);
  *sx = c.x;
  *sy = c.y;
  *sz = c.z;
}

/* SECTION: vector math  ==================================================== */

/* normal_vec_func: Compute normal vector to (x,y,z). */
void normal_vec(double *nx, double *ny, double *nz,
                double x, double y, double z)
{
  double ax = fabs(x);
  double ay = fabs(y);
  double az = fabs(z);
  double l;
  if(x == 0 && y == 0 && z == 0)
  {
    *nx = 0;
    *ny = 0;
    *nz = 0;
    return;
  }
  if(ax < ay)
  {
    if(ax < az)
    {                           /* Use X axis */
      l = sqrt(z*z + y*y);
      *nx = 0;
      *ny = z/l;
      *nz = -y/l;
      return;
    }
  }
  else
  {
    if(ay < az)
    {                           /* Use Y axis */
      l = sqrt(z*z + x*x);
      *nx = z/l;
      *ny = 0;
      *nz = -x/l;
      return;
    }
  }
  /* Use Z axis */
  l = sqrt(y*y + x*x);
  *nx = y/l;
  *ny = -x/l;
  *nz = 0;
} /* normal_vec */

/*******************************************************************************
 * solve_2nd_order: second order equation solve: A*t^2 + B*t + C = 0
 * solve_2nd_order(&t1, NULL, A,B,C)
 *   returns 0 if no solution was found, or set 't1' to the smallest positive
 *   solution.
 * solve_2nd_order(&t1, &t2, A,B,C)
 *   same as with &t2=NULL, but also returns the second solution.
 * EXAMPLE usage for intersection of a trajectory with a plane in gravitation
 * field (gx,gy,gz):
 * The neutron starts at point r=(x,y,z) with velocityv=(vx vy vz). The plane
 * has a normal vector n=(nx,ny,nz) and contains the point W=(wx,wy,wz).
 * The problem consists in solving the 2nd order equation:
 *      1/2.n.g.t^2 + n.v.t + n.(r-W) = 0
 * so that A = 0.5 n.g; B = n.v; C = n.(r-W);
 * Without acceleration, t=-n.(r-W)/n.v
 ******************************************************************************/
int solve_2nd_order_old(double *t1, double *t2,
                  double A,  double B,  double C)
{
  int ret=0;

  if (!t1) return 0;
  *t1 = 0;
  if (t2) *t2=0;

  if (fabs(A) < 1E-10) /* approximate to linear equation: A ~ 0 */
  {
    if (B) {  *t1 = -C/B; ret=1; if (t2) *t2=*t1; }
    /* else no intersection: A=B=0 ret=0 */
  }
  else
  {
    double D;
    D = B*B - 4*A*C;
    if (D >= 0) /* Delta > 0: two solutions */
    {
      double sD, dt1, dt2;
      sD = sqrt(D);
      dt1 = (-B + sD)/2/A;
      dt2 = (-B - sD)/2/A;
      /* we identify very small values with zero */
      if (fabs(dt1) < 1e-10) dt1=0.0;
      if (fabs(dt2) < 1e-10) dt2=0.0;

      /* now we choose the smallest positive solution */
      if      (dt1<=0.0 && dt2>0.0) ret=2; /* dt2 positive */
      else if (dt2<=0.0 && dt1>0.0) ret=1; /* dt1 positive */
      else if (dt1> 0.0 && dt2>0.0)
      {  if (dt1 < dt2) ret=1; else ret=2; } /* all positive: min(dt1,dt2) */
      /* else two solutions are negative. ret=-1 */
      if (ret==1) { *t1 = dt1;  if (t2) *t2=dt2; }
      else        { *t1 = dt2;  if (t2) *t2=dt1; }
      ret=2;  /* found 2 solutions and t1 is the positive one */
    } /* else Delta <0: no intersection. ret=0 */
  }
  return(ret);
} /* solve_2nd_order */

int solve_2nd_order(double *t0, double *t1, double A, double B, double C){
  int retval=0;
  double sign=copysign(1.0,B);
  double dt0,dt1;

  dt0=0;
  dt1=0;
  if(t1){ *t1=0;}

  /*protect against rounding errors by locally equating DBL_EPSILON with 0*/
  if (fabs(A)<DBL_EPSILON){
    A=0;
  }
  if (fabs(B)<DBL_EPSILON){
    B=0;
  }
  if (fabs(C)<DBL_EPSILON){
    C=0;
  }

  /*check if coefficient are sane*/
  if( A==0  && B==0){
    retval=0;
  }else{
    if(A==0){
      /*equation is linear*/
      dt0=-C/B;
      retval=1;
    }else if (C==0){
      /*one root is 0*/
      if(sign<0){
        dt0=0;dt1=-B/A;
      }else{
        dt0=-B/A;dt1=0;
      }
      retval=2;
    }else{
      /*a regular 2nd order eq. Also works out fine for B==0.*/
      double D;
      D=B*B-4*A*C;
      if (D>=0){
        dt0=(-B - sign*sqrt(B*B-4*A*C))/(2*A);
        dt1=C/(A*dt0);
        retval=2;
      }else{
        /*no real roots*/
        retval=0;
      }
    }
    /*sort the solutions*/
    if (retval==1){
      /*put both solutions in t0 and t1*/
      *t0=dt0;
      if(t1) *t1=dt1;
    }else{
      /*we have two solutions*/
      /*swap if both are positive and t1 smaller than t0 or t1 the only positive*/
      int swap=0;
      if(dt1>0 && ( dt1<dt0 || dt0<=0) ){
        swap=1;
      }
      if (swap){
        *t0=dt1;
        if(t1) *t1=dt0;
      }else{
        *t0=dt0;
        if(t1) *t1=dt1;
      }
    }

  }
  return retval;

} /*solve_2nd_order_improved*/


/*******************************************************************************
 * randvec_target_circle: Choose random direction towards target at (x,y,z)
 * with given radius.
 * If radius is zero, choose random direction in full 4PI, no target.
 ******************************************************************************/
void _randvec_target_circle(double *xo, double *yo, double *zo, double *solid_angle,
        double xi, double yi, double zi, double radius,
        _class_particle* _particle)
{
  double l2, phi, theta, nx, ny, nz, xt, yt, zt, xu, yu, zu;

  if(radius == 0.0)
  {
    /* No target, choose uniformly a direction in full 4PI solid angle. */
    theta = acos(1 - rand0max(2));
    phi = rand0max(2 * PI);
    if(solid_angle)
      *solid_angle = 4*PI;
    nx = 1;
    ny = 0;
    nz = 0;
    yi = sqrt(xi*xi+yi*yi+zi*zi);
    zi = 0;
    xi = 0;
  }
  else
  {
    double costheta0;
    l2 = xi*xi + yi*yi + zi*zi; /* sqr Distance to target. */
    costheta0 = sqrt(l2/(radius*radius+l2));
    if (radius < 0) costheta0 *= -1;
    if(solid_angle)
    {
      /* Compute solid angle of target as seen from origin. */
        *solid_angle = 2*PI*(1 - costheta0);
    }

    /* Now choose point uniformly on circle surface within angle theta0 */
    theta = acos (1 - rand0max(1 - costheta0)); /* radius on circle */
    phi = rand0max(2 * PI); /* rotation on circle at given radius */
    /* Now, to obtain the desired vector rotate (xi,yi,zi) angle theta around a
       perpendicular axis u=i x n and then angle phi around i. */
    if(xi == 0 && zi == 0)
    {
      nx = 1;
      ny = 0;
      nz = 0;
    }
    else
    {
      nx = -zi;
      nz = xi;
      ny = 0;
    }
  }

  /* [xyz]u = [xyz]i x n[xyz] (usually vertical) */
  vec_prod(xu,  yu,  zu, xi, yi, zi,        nx, ny, nz);
  /* [xyz]t = [xyz]i rotated theta around [xyz]u */
  rotate  (xt,  yt,  zt, xi, yi, zi, theta, xu, yu, zu);
  /* [xyz]o = [xyz]t rotated phi around n[xyz] */
  rotate (*xo, *yo, *zo, xt, yt, zt, phi, xi, yi, zi);
}
/* randvec_target_circle */

/*******************************************************************************
 * randvec_target_rect_angular: Choose random direction towards target at
 * (xi,yi,zi) with given ANGULAR dimension height x width. height=phi_x=[0,PI],
 * width=phi_y=[0,2*PI] (radians)
 * If height or width is zero, choose random direction in full 4PI, no target.
 *******************************************************************************/
void _randvec_target_rect_angular(double *xo, double *yo, double *zo, double *solid_angle,
        double xi, double yi, double zi, double width, double height, Rotation A,
        _class_particle* _particle)
{
  double theta, phi, nx, ny, nz, xt, yt, zt, xu, yu, zu;
  Coords tmp;
  Rotation Ainverse;

  rot_transpose(A, Ainverse);

  if(height == 0.0 || width == 0.0)
  {
    randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, 0);
    return;
  }
  else
  {
    if(solid_angle)
    {
      /* Compute solid angle of target as seen from origin. */
      *solid_angle = 2*fabs(width*sin(height/2));
    }

    /* Go to global coordinate system */

    tmp = coords_set(xi, yi, zi);
    tmp = rot_apply(Ainverse, tmp);
    coords_get(tmp, &xi, &yi, &zi);

    /* Now choose point uniformly on the unit sphere segment with angle theta/phi */
    phi   = width*randpm1()/2.0;
    theta = asin(randpm1()*sin(height/2.0));
    /* Now, to obtain the desired vector rotate (xi,yi,zi) angle theta around
       n, and then phi around u. */
    if(xi == 0 && zi == 0)
    {
      nx = 1;
      ny = 0;
      nz = 0;
    }
    else
    {
      nx = -zi;
      nz = xi;
      ny = 0;
    }
  }

  /* [xyz]u = [xyz]i x n[xyz] (usually vertical) */
  vec_prod(xu,  yu,  zu, xi, yi, zi,        nx, ny, nz);
  /* [xyz]t = [xyz]i rotated theta around [xyz]u */
  rotate  (xt,  yt,  zt, xi, yi, zi, theta, nx, ny, nz);
  /* [xyz]o = [xyz]t rotated phi around n[xyz] */
  rotate (*xo, *yo, *zo, xt, yt, zt, phi, xu,  yu,  zu);

  /* Go back to local coordinate system */
  tmp = coords_set(*xo, *yo, *zo);
  tmp = rot_apply(A, tmp);
  coords_get(tmp, &*xo, &*yo, &*zo);
}
/* randvec_target_rect_angular */

/*******************************************************************************
 * randvec_target_rect_real: Choose random direction towards target at (xi,yi,zi)
 * with given dimension height x width (in meters !).
 *
 * Local emission coordinate is taken into account and corrected for 'order' times.
 * (See remarks posted to mcstas-users by George Apostolopoulus <gapost@ipta.demokritos.gr>)
 *
 * If height or width is zero, choose random direction in full 4PI, no target.
 *
 * Traditionally, this routine had the name randvec_target_rect - this is now a
 * a define (see mcstas-r.h) pointing here. If you use the old rouine, you are NOT
 * taking the local emmission coordinate into account.
*******************************************************************************/
void _randvec_target_rect_real(double *xo, double *yo, double *zo, double *solid_angle,
        double xi, double yi, double zi,
        double width, double height, Rotation A,
        double lx, double ly, double lz, int order,
        _class_particle* _particle)
{
  double dx, dy, dist, dist_p, nx, ny, nz, mx, my, mz, n_norm, m_norm;
  double cos_theta;
  Coords tmp;
  Rotation Ainverse;

  rot_transpose(A, Ainverse);

  if(height == 0.0 || width == 0.0)
  {
    randvec_target_circle(xo, yo, zo, solid_angle,
               xi, yi, zi, 0);
    return;
  }
  else
  {
    /* Now choose point uniformly on rectangle within width x height */
    dx = width*randpm1()/2.0;
    dy = height*randpm1()/2.0;

    /* Determine distance to target plane*/
    dist = sqrt(xi*xi + yi*yi + zi*zi);
    /* Go to global coordinate system */

    tmp = coords_set(xi, yi, zi);
    tmp = rot_apply(Ainverse, tmp);
    coords_get(tmp, &xi, &yi, &zi);

    /* Determine vector normal to trajectory axis (z) and gravity [0 1 0] */
    vec_prod(nx, ny, nz, xi, yi, zi, 0, 1, 0);

    /* This now defines the x-axis, normalize: */
    n_norm=sqrt(nx*nx + ny*ny + nz*nz);
    nx = nx/n_norm;
    ny = ny/n_norm;
    nz = nz/n_norm;

    /* Now, determine our y-axis (vertical in many cases...) */
    vec_prod(mx, my, mz, xi, yi, zi, nx, ny, nz);
    m_norm=sqrt(mx*mx + my*my + mz*mz);
    mx = mx/m_norm;
    my = my/m_norm;
    mz = mz/m_norm;

    /* Our output, random vector can now be defined by linear combination: */

    *xo = xi + dx * nx + dy * mx;
    *yo = yi + dx * ny + dy * my;
    *zo = zi + dx * nz + dy * mz;

    /* Go back to local coordinate system */
    tmp = coords_set(*xo, *yo, *zo);
    tmp = rot_apply(A, tmp);
    coords_get(tmp, &*xo, &*yo, &*zo);

    /* Go back to local coordinate system */
    tmp = coords_set(xi, yi, zi);
    tmp = rot_apply(A, tmp);
    coords_get(tmp, &xi, &yi, &zi);

    if (solid_angle) {
      /* Calculate vector from local point to remote random point */
      lx = *xo - lx;
      ly = *yo - ly;
      lz = *zo - lz;
      dist_p = sqrt(lx*lx + ly*ly + lz*lz);

      /* Adjust the 'solid angle' */
      /* 1/r^2 to the chosen point times cos(\theta) between the normal */
      /* vector of the target rectangle and direction vector of the chosen point. */
      cos_theta = (xi * lx + yi * ly + zi * lz) / (dist * dist_p);
      *solid_angle = width * height / (dist_p * dist_p);
      int counter;
      for (counter = 0; counter < order; counter++) {
        *solid_angle = *solid_angle * cos_theta;
      }
    }
  }
}
/* randvec_target_rect_real */


/* SECTION: random numbers ==================================================

  How to add a new RNG:

  - Use an rng with a manegable state vector, e.g. of lengt 4 or 7. The state
  will sit on the particle struct as a "randstate_t state[RANDSTATE_LEN]"
  - If the rng has a long state (as MT), set an empty "srandom" and initialize
  it explicitly using the appropriate define (RNG_ALG)
  - Add a seed and a random function (the transforms will be reused)
  - Write the proper defines in mccode-r.h, e.g. randstate_t and RANDSTATE_LEN,
  srandom and random.
  - Compile using -DRNG_ALG=<selector int value>

============================================================================= */


/* "Mersenne Twister", by Makoto Matsumoto and Takuji Nishimura. */
/* See http://www.math.keio.ac.jp/~matumoto/emt.html for original source. */
/*
   A C-program for MT19937, with initialization improved 2002/1/26.
   Coded by Takuji Nishimura and Makoto Matsumoto.

   Before using, initialize the state by using mt_srandom(seed)
   or init_by_array(init_key, key_length).

   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

     1. Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

     2. Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.

     3. The names of its contributors may not be used to endorse or promote
        products derived from this software without specific prior written
        permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


   Any feedback is very welcome.
   http://www.math.keio.ac.jp/matumoto/emt.html
   email: matumoto@math.keio.ac.jp
*/
#include <stdio.h>
#include <stdint.h>   // for uint32_t
#include <stddef.h>   // for size_t

/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfU   /* constant vector a */
#define UPPER_MASK 0x80000000U /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffU /* least significant r bits */

static uint32_t mt[N]; /* the array for the state vector  */
static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */

// Required for compatibility with common RNG interface (e.g., kiss/mt polymorphism)
void mt_srandom_empty(void) {}

// Initializes mt[N] with a seed
void mt_srandom(uint32_t seed) {
    mt[0] = seed;
    for (mti = 1; mti < N; mti++) {
        mt[mti] = 1812433253U * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti;
        /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
        /* In the previous versions, MSBs of the seed affect   */
        /* only MSBs of the array mt[].                        */
        /* 2002/01/09 modified by Makoto Matsumoto             */
        mt[mti] &= 0xffffffffU;
        /* for >32 bit machines */
    }
}
/* Initialize by an array with array-length.
   Init_key is the array for initializing keys.
   key_length is its length. */
void init_by_array(uint32_t init_key[], size_t key_length) {
    size_t i = 1, j = 0, k;
    mt_srandom(19650218U);
    k = (N > key_length ? N : key_length);
    for (; k; k--) {
        mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U))
              + init_key[j] + (uint32_t)j;
        mt[i] &= 0xffffffffU;
        i++; j++;
        if (i >= N) { mt[0] = mt[N - 1]; i = 1; }
        if (j >= key_length) j = 0;
    }
    for (k = N - 1; k; k--) {
        mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U))
              - (uint32_t)i;
        mt[i] &= 0xffffffffU;
        i++;
        if (i >= N) { mt[0] = mt[N - 1]; i = 1; }
    }
    mt[0] = 0x80000000U; /* MSB is 1; ensuring non-zero initial array */
}

// Generates a random number on [0, 0xffffffff]-interval
uint32_t mt_random(void) {
    uint32_t y;
    static const uint32_t mag01[2] = { 0x0U, MATRIX_A };
    /* mag01[x] = x * MATRIX_A  for x=0,1 */

    if (mti >= N) { /* generate N words at one time */
        int kk;

        if (mti == N + 1)   /* if mt_srandom() has not been called, */ 
            mt_srandom(5489U);  /* a default initial seed is used */

        for (kk = 0; kk < N - M; kk++) {
            y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
            mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1U];
        }
        for (; kk < N - 1; kk++) {
            y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
            mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1U];
        }
        y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
        mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1U];

        mti = 0;
    }

    y = mt[mti++];

    /* Tempering */
    y ^= (y >> 11);
    y ^= (y << 7) & 0x9d2c5680U;
    y ^= (y << 15) & 0xefc60000U;
    y ^= (y >> 18);

    return y;
}
#undef N
#undef M
#undef MATRIX_A
#undef UPPER_MASK
#undef LOWER_MASK
/* End of "Mersenne Twister". */


/*
KISS

 From: http://www.helsbreth.org/random/rng_kiss.html
 Scott Nelson 1999

 Based on Marsaglia's KISS or (KISS+SWB) <http://www.cs.yorku.ca/~oz/marsaglia-
rng.html>

 KISS - Keep it Simple Stupid PRNG

 the idea is to use simple, fast, individually promising
 generators to get a composite that will be fast, easy to code
 have a very long period and pass all the tests put to it.
 The three components of KISS are
        x(n)=a*x(n-1)+1 mod 2^32
        y(n)=y(n-1)(I+L^13)(I+R^17)(I+L^5),
        z(n)=2*z(n-1)+z(n-2) +carry mod 2^32
 The y's are a shift register sequence on 32bit binary vectors
 period 2^32-1;
 The z's are a simple multiply-with-carry sequence with period
 2^63+2^32-1.  The period of KISS is thus
      2^32*(2^32-1)*(2^63+2^32-1) > 2^127

 In 2025 adapted for consistent 64-bit behavior across platforms.
*/

/* the KISS state is stored as a vector of 7 uint64_t        */
/*   0  1  2  3  4      5  6   */
/* [ x, y, z, w, carry, k, m ] */

uint64_t *kiss_srandom(uint64_t state[7], uint64_t seed) {
    if (seed == 0) seed = 1ull;
    state[0] = seed | 1ull; // x
    state[1] = seed | 2ull; // y
    state[2] = seed | 4ull; // z
    state[3] = seed | 8ull; // w
    state[4] = 0ull;        // carry
    state[5] = 0ull;        // k
    state[6] = 0ull;        // m
    return state;
}

uint64_t kiss_random(uint64_t state[7]) {
    // Linear congruential generator
    state[0] = state[0] * 69069ull + 1ull;

    // Xorshift
    state[1] ^= state[1] << 13ull;
    state[1] ^= state[1] >> 17ull;
    state[1] ^= state[1] << 5ull;

    // Multiply-with-carry
    state[5] = (state[2] >> 2ull) + (state[3] >> 3ull) + (state[4] >> 2ull);
    state[6] = state[3] + state[3] + state[2] + state[4];
    state[2] = state[3];
    state[3] = state[6];
    state[4] = state[5] >> 62ull;  // Top bit of carry (adjusted for 64-bit)

    return state[0] + state[1] + state[3];
}
/* end of "KISS" rng */


/* FAST KISS in another implementation (Hundt) */

//////////////////////////////////////////////////////////////////////////////
// fast keep it simple stupid generator
//////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Thomas Mueller hash for initialization of rngs
// http://stackoverflow.com/questions/664014/
//        what-integer-hash-function-are-good-that-accepts-an-integer-hash-key
//////////////////////////////////////////////////////////////////////////////
randstate_t _hash(randstate_t x) {
  x = ((x >> 16) ^ x) * (randstate_t)0x45d9f3b;
  x = ((x >> 16) ^ x) * (randstate_t)0x45d9f3b;
  x = ((x >> 16) ^ x);
  return x;
}


// SECTION: random number transforms ==========================================



// generate a random number from normal law
double _randnorm(randstate_t* state)
{
  static double v1, v2, s; /* removing static breaks comparison with McStas <= 2.5 */
  static int phase = 0;
  double X, u1, u2;

  if(phase == 0)
  {
    do
    {
      u1 = _rand01(state);
      u2 = _rand01(state);
      v1 = 2*u1 - 1;
      v2 = 2*u2 - 1;
      s = v1*v1 + v2*v2;
    } while(s >= 1 || s == 0);

    X = v1*sqrt(-2*log(s)/s);
  }
  else
  {
    X = v2*sqrt(-2*log(s)/s);
  }

  phase = 1 - phase;
  return X;
}
// another one
double _randnorm2(randstate_t* state) {
  double x, y, r;
  do {
      x = 2.0 * _rand01(state) - 1.0;
      y = 2.0 * _rand01(state) - 1.0;
      r = x*x + y*y;
  } while (r == 0.0 || r >= 1.0);
  return x * sqrt((-2.0 * log(r)) / r);
}

// Generate a random number from -1 to 1 with triangle distribution
double _randtriangle(randstate_t* state) {
	double randnum = _rand01(state);
	if (randnum>0.5) return(1-sqrt(2*(randnum-0.5)));
	else return(sqrt(2*randnum)-1);
}
double _rand01(randstate_t* state) {
	double randnum;
	randnum = (double) _random();
  // TODO: can we mult instead of div?
	randnum /= (double) MC_RAND_MAX + 1;
	return randnum;
}
double _rand01_opague(void* opague_state) {
	randstate_t* state = (randstate_t*)opague_state;
	// Following lines exactly like in _rand01 just above (repeated to
	// avoid another layer of indirection):
	double randnum;
	randnum = (double) _random();
	// TODO: can we mult instead of div?
	randnum /= (double) MC_RAND_MAX + 1;
	return randnum;
}
// Return a random number between 1 and -1
double _randpm1(randstate_t* state) {
	double randnum;
	randnum = (double) _random();
	randnum /= ((double) MC_RAND_MAX + 1) / 2;
	randnum -= 1;
	return randnum;
}
// Return a random number between 0 and max.
double _rand0max(double max, randstate_t* state) {
	double randnum;
	randnum = (double) _random();
	randnum /= ((double) MC_RAND_MAX + 1) / max;
	return randnum;
}
// Return a random number between min and max.
double _randminmax(double min, double max, randstate_t* state) {
	return _rand0max(max - min, state) + max;
}


/* SECTION: main and signal handlers ======================================== */

/*******************************************************************************
* mchelp: displays instrument executable help with possible options
*******************************************************************************/
static void
mchelp(char *pgmname)
{
  int i;

  fprintf(stderr, "%s (%s) instrument simulation, generated with " MCCODE_STRING " (" MCCODE_DATE ")\n", instrument_name, instrument_source);
  fprintf(stderr, "Usage: %s [options] [parm=value ...]\n", pgmname);
  fprintf(stderr,
"Options are:\n"
"  -s SEED   --seed=SEED      Set random seed (must be != 0)\n"
"  -n COUNT  --ncount=COUNT   Set number of particles to simulate.\n"
"  -d DIR    --dir=DIR        Put all data files in directory DIR.\n"
"  -a        --append         Append data files to those in directory DIR.\n"	  
"  -t        --trace          Enable trace of " MCCODE_PARTICLE "s through instrument.\n"
"                             (Use -t=2 or --trace=2 for modernised mcdisplay rendering)\n"
"  -g        --gravitation    Enable gravitation for all trajectories.\n"
"  --no-output-files          Do not write any data files.\n"
"  -h        --help           Show this help message.\n"
"  -i        --info           Detailed instrument information.\n"
"  --list-parameters          Print the instrument parameters to standard out\n"
"  -y        --yes            Assume default values for parameters not given\n"
"  --meta-list                Print names of components which defined metadata\n"
"  --meta-defined COMP[:NAME] Print component defined metadata names, or (0,1) if NAME provided\n"
"  --meta-type COMP:NAME      Print metadata format type specified in definition\n"
"  --meta-data COMP:NAME      Print the metadata text\n"
"  --source                   Show the instrument code which was compiled.\n"
#ifdef OPENACC
"\n"
"  --vecsize                  OpenACC vector-size (default: 128)\n"
"  --numgangs                 Number of OpenACC gangs (default: 7813)\n"
"  --gpu_innerloop            Maximum rays to process pr. OpenACC \n"
"                             kernel run (default: 2147483647)\n"
"\n"
#endif
"\n"
"  --bufsiz                   Monitor_nD list/buffer-size (default: 1000000)\n"
"  --format=FORMAT            Output data files using FORMAT="
   FLAVOR_UPPER
#ifdef USE_NEXUS
   " NEXUS\n"
"  --IDF                      Embed an xml-formatted IDF instrument definition\n"
"                             in the NeXus file (if existent in .)\n\n"
#else
"\n\n"
#endif
);
#ifdef USE_MPI
  fprintf(stderr,
  "This instrument has been compiled with MPI support.\n  Use 'mpirun %s [options] [parm=value ...]'.\n", pgmname);
#endif
#ifdef OPENACC
  fprintf(stderr,
  "This instrument has been compiled with NVIDIA GPU support through OpenACC.\n  Running on systems without such devices will lead to segfaults.\nFurter, fprintf, sprintf and printf have been removed from any component TRACE.\n");
#endif

  if(numipar > 0)
  {
    fprintf(stderr, "Instrument parameters are:\n");
    for(i = 0; i < numipar; i++)
      if (mcinputtable[i].val && strlen(mcinputtable[i].val))
        fprintf(stderr, "  %-16s(%s) [default='%s']\n", mcinputtable[i].name,
        (*mcinputtypes[mcinputtable[i].type].parminfo)(mcinputtable[i].name),
        mcinputtable[i].val);
      else
        fprintf(stderr, "  %-16s(%s)\n", mcinputtable[i].name,
        (*mcinputtypes[mcinputtable[i].type].parminfo)(mcinputtable[i].name));
  }

#ifndef NOSIGNALS
  fprintf(stderr, "Known signals are: "
#ifdef SIGUSR1
  "USR1 (status) "
#endif
#ifdef SIGUSR2
  "USR2 (save) "
#endif
#ifdef SIGBREAK
  "BREAK (save) "
#endif
#ifdef SIGTERM
  "TERM (save and exit)"
#endif
  "\n");
#endif /* !NOSIGNALS */
} /* mchelp */


/* mcshowhelp: show help and exit with 0 */
static void
mcshowhelp(char *pgmname)
{
  mchelp(pgmname);
  exit(0);
}

/* mcusage: display usage when error in input arguments and exit with 1 */
static void
mcusage(char *pgmname)
{
  fprintf(stderr, "Error: incorrect command line arguments\n");
  mchelp(pgmname);
  exit(1);
}

/* mcenabletrace: enable trace/mcdisplay or error if requires recompile */
static void
mcenabletrace(int mode)
{
 if(traceenabled) {
  mcdotrace = mode;
  #pragma acc update device ( mcdotrace )
 } else {
   if (mode>0) {
     fprintf(stderr,
	     "Error: trace not enabled (mcenabletrace)\n"
	     "Please re-run the " MCCODE_NAME " compiler "
	     "with the --trace option, or rerun the\n"
	     "C compiler with the MC_TRACE_ENABLED macro defined.\n");
     exit(1);
   }
 }
}

/*******************************************************************************
* mcreadparams: request parameters from the prompt (or use default)
*******************************************************************************/
void
mcreadparams(void)
{
  int i,j,status;
  static char buf[CHAR_BUF_LENGTH];
  char *p;
  int len;

  MPI_MASTER(printf("Instrument parameters for %s (%s)\n",
                    instrument_name, instrument_source));

  for(i = 0; mcinputtable[i].name != 0; i++)
  {
    do
    {
      MPI_MASTER(
                 if (mcinputtable[i].val && strlen(mcinputtable[i].val))
                   printf("Set value of instrument parameter %s (%s) [default='%s']:\n",
                          mcinputtable[i].name,
                          (*mcinputtypes[mcinputtable[i].type].parminfo)
                          (mcinputtable[i].name), mcinputtable[i].val);
                 else
                   printf("Set value of instrument parameter %s (%s):\n",
                          mcinputtable[i].name,
                          (*mcinputtypes[mcinputtable[i].type].parminfo)
                          (mcinputtable[i].name));
                 fflush(stdout);
                 );
#ifdef USE_MPI
      if(mpi_node_rank == mpi_node_root)
        {
          p = fgets(buf, CHAR_BUF_LENGTH, stdin);
          if(p == NULL)
            {
              fprintf(stderr, "Error: empty input for paramater %s (mcreadparams)\n", mcinputtable[i].name);
              exit(1);
            }
        }
      else
        p = buf;
      MPI_Bcast(buf, CHAR_BUF_LENGTH, MPI_CHAR, mpi_node_root, MPI_COMM_WORLD);
#else /* !USE_MPI */
      p = fgets(buf, CHAR_BUF_LENGTH, stdin);
      if(p == NULL)
        {
          fprintf(stderr, "Error: empty input for paramater %s (mcreadparams)\n", mcinputtable[i].name);
          exit(1);
        }
#endif /* USE_MPI */
      len = strlen(buf);
      if (!len || (len == 1 && (buf[0] == '\n' || buf[0] == '\r')))
      {
        if (mcinputtable[i].val && strlen(mcinputtable[i].val)) {
          strncpy(buf, mcinputtable[i].val, CHAR_BUF_LENGTH);  /* use default value */
          len = strlen(buf);
        }
      }
      for(j = 0; j < 2; j++)
      {
        if(len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
        {
          len--;
          buf[len] = '\0';
        }
      }

      status = (*mcinputtypes[mcinputtable[i].type].getparm)
                   (buf, mcinputtable[i].par);
      if(!status)
      {
        (*mcinputtypes[mcinputtable[i].type].error)(mcinputtable[i].name, buf);
        if (!mcinputtable[i].val || strlen(mcinputtable[i].val)) {
          fprintf(stderr, "       Change %s default value in instrument definition.\n", mcinputtable[i].name);
          exit(1);
        }
      }
    } while(!status);
  }
} /* mcreadparams */

/*******************************************************************************
* mcparseoptions: parse command line arguments (options, parameters)
*******************************************************************************/
void
mcparseoptions(int argc, char *argv[])
{
  int i, j;
  char *p;
  int paramset = 0, *paramsetarray;
  char *usedir=NULL;

  /* Add one to numipar to avoid allocating zero size memory block. */
  paramsetarray = (int*)malloc((numipar + 1)*sizeof(*paramsetarray));
  if(paramsetarray == NULL)
  {
    fprintf(stderr, "Error: insufficient memory (mcparseoptions)\n");
    exit(1);
  }
  for(j = 0; j < numipar; j++)
    {
      paramsetarray[j] = 0;
      if (mcinputtable[j].val != NULL && strlen(mcinputtable[j].val))
      {
        int  status;
        char buf[CHAR_BUF_LENGTH];
        strncpy(buf, mcinputtable[j].val, CHAR_BUF_LENGTH);
        status = (*mcinputtypes[mcinputtable[j].type].getparm)
                   (buf, mcinputtable[j].par);
        if(!status) fprintf(stderr, "Invalid '%s' default value %s in instrument definition (mcparseoptions)\n", mcinputtable[j].name, buf);
        else paramsetarray[j] = 1;
      } else {
        (*mcinputtypes[mcinputtable[j].type].getparm)
          (NULL, mcinputtable[j].par);
        paramsetarray[j] = 0;
      }
    }
  for(i = 1; i < argc; i++)
  {
    if(!strcmp("-s", argv[i]) && (i + 1) < argc)
      mcsetseed(argv[++i]);
    else if(!strncmp("-s", argv[i], 2))
      mcsetseed(&argv[i][2]);
    else if(!strcmp("--seed", argv[i]) && (i + 1) < argc)
      mcsetseed(argv[++i]);
    else if(!strncmp("--seed=", argv[i], 7))
      mcsetseed(&argv[i][7]);
    else if(!strcmp("-n", argv[i]) && (i + 1) < argc)
      mcsetn_arg(argv[++i]);
    else if(!strncmp("-n", argv[i], 2))
      mcsetn_arg(&argv[i][2]);
    else if(!strcmp("--ncount", argv[i]) && (i + 1) < argc)
      mcsetn_arg(argv[++i]);
    else if(!strncmp("--ncount=", argv[i], 9))
      mcsetn_arg(&argv[i][9]);
    else if(!strcmp("-d", argv[i]) && (i + 1) < argc)
      usedir=argv[++i];  /* will create directory after parsing all arguments (end of this function) */
    else if(!strncmp("-d", argv[i], 2))
      usedir=&argv[i][2];
    else if(!strcmp("--dir", argv[i]) && (i + 1) < argc)
      usedir=argv[++i];
    else if(!strncmp("-a", argv[i], 2))
      mcappend = 1;
    else if(!strcmp("--append", argv[i]))
      mcappend = 1;
    else if(!strncmp("--dir=", argv[i], 6))
      usedir=&argv[i][6];
    else if(!strcmp("-h", argv[i]))
      mcshowhelp(argv[0]);
    else if(!strcmp("--help", argv[i]) || !strcmp("--version", argv[i]))
      mcshowhelp(argv[0]);
    else if(!strcmp("-i", argv[i])) {
      mcformat=FLAVOR_UPPER;
      mcinfo();
    }
    else if(!strcmp("--info", argv[i]))
      mcinfo();
    else if (!strcmp("--list-parameters", argv[i]))
      mcparameterinfo();
    else if (!strcmp("--meta-list", argv[i]) && ((i+1) >= argc || argv[i+1][0] == '-')){
      //printf("Components with metadata defined:\n");
      exit(metadata_table_print_all_components(num_metadata, metadata_table) == 0);
    }
    else if (!strcmp("--meta-defined", argv[i]) && (i+1) < argc){
      exit(metadata_table_print_component_keys(num_metadata, metadata_table, argv[i+1]) == 0);
    }
    else if (!strcmp("--meta-type", argv[i]) && (i+1) < argc){
      char * literal_type = metadata_table_type(num_metadata, metadata_table, argv[i+1]);
      if (literal_type == NULL) exit(1);
      printf("%s\n", literal_type);
      exit(0);
    }
    else if (!strcmp("--meta-data", argv[i]) && (i+1) < argc){
      char * literal = metadata_table_literal(num_metadata, metadata_table, argv[i+1]);
      if (literal == NULL) exit(1);
      printf("%s\n", literal);
      exit(0);
    }
    else if(!strncmp("--trace=", argv[i], 8)) {
      mcenabletrace(atoi(&argv[i][8]));
    } else if(!strncmp("-t=", argv[i], 3) || !strcmp("--verbose", argv[i])) {
      mcenabletrace(atoi(&argv[i][3]));
    } else if(!strcmp("-t", argv[i]))
      mcenabletrace(1);
    else if(!strcmp("--trace", argv[i]) || !strcmp("--verbose", argv[i]))
      mcenabletrace(1);
    else if(!strcmp("--gravitation", argv[i]))
      mcgravitation = 1;
    else if(!strcmp("-g", argv[i]))
      mcgravitation = 1;
    else if(!strcmp("--yes", argv[i]))
      mcusedefaults = 1;
    else if(!strcmp("-y", argv[i]))
      mcusedefaults = 1;
    else if(!strncmp("--format=", argv[i], 9)) {
      mcformat=&argv[i][9];
    }
    else if(!strcmp("--format", argv[i]) && (i + 1) < argc) {
      mcformat=argv[++i];
    }
#ifdef USE_NEXUS
    else if(!strcmp("--IDF", argv[i])) {
      mcnexus_embed_idf = 1;
    }
#endif
    else if(!strncmp("--vecsize=", argv[i], 10)) {
      vecsize=atoi(&argv[i][10]);
    }    
    else if(!strcmp("--vecsize", argv[i]) && (i + 1) < argc) {
      vecsize=atoi(argv[++i]);
    }
    else if(!strncmp("--bufsiz=", argv[i], 9)) {
      MONND_BUFSIZ=atoi(&argv[i][9]);
    }
    else if(!strcmp("--bufsiz", argv[i]) && (i + 1) < argc) {
      MONND_BUFSIZ=atoi(argv[++i]);
    }
    else if(!strncmp("--numgangs=", argv[i], 11)) {
      numgangs=atoi(&argv[i][11]);
    }
    else if(!strcmp("--numgangs", argv[i]) && (i + 1) < argc) {
      numgangs=atoi(argv[++i]);
    }
    else if(!strncmp("--gpu_innerloop=", argv[i], 16)) {
      gpu_innerloop=(long)strtod(&argv[i][16], NULL);
    }
    else if(!strcmp("--gpu_innerloop", argv[i]) && (i + 1) < argc) {
      gpu_innerloop=(long)strtod(argv[++i], NULL);
    }

    else if(!strcmp("--no-output-files", argv[i]))
      mcdisable_output_files = 1;
    else if(!strcmp("--source", argv[i])) {
      printf("/* Source code %s from %s: */\n"
        "/******************************************************************************/\n"
        "%s\n"
        "/******************************************************************************/\n"
        "/* End of source code %s from %s */\n",
        instrument_name, instrument_source, instrument_code,
        instrument_name, instrument_source);
      exit(1);
    }
    else if(argv[i][0] != '-' && (p = strchr(argv[i], '=')) != NULL)
    {
      *p++ = '\0';

      for(j = 0; j < numipar; j++)
        if(!strcmp(mcinputtable[j].name, argv[i]))
        {
          int status;
          status = (*mcinputtypes[mcinputtable[j].type].getparm)(p,
                        mcinputtable[j].par);
          if(!status || !strlen(p))
          {
            (*mcinputtypes[mcinputtable[j].type].error)
              (mcinputtable[j].name, p);
            exit(1);
          }
          paramsetarray[j] = 1;
          paramset = 1;
          break;
        }
      if(j == numipar)
      {                                /* Unrecognized parameter name */
        fprintf(stderr, "Error: unrecognized parameter %s (mcparseoptions)\n", argv[i]);
        exit(1);
      }
    }
    else if(argv[i][0] == '-') {
      fprintf(stderr, "Error: unrecognized option argument %s (mcparseoptions). Ignored.\n", argv[i++]);
    }
    else {
      fprintf(stderr, "Error: unrecognized argument %s (mcparseoptions). Aborting.\n", argv[i]);
      mcusage(argv[0]);
    }
  }
  if (mcusedefaults) {
    MPI_MASTER(
     printf("Using default values for parameters not given\n");
    );
    paramset = 1; /* defaults were already set above */
  }
  if(!paramset)
    mcreadparams();                /* Prompt for parameters if not specified. */
  else
  {
    for(j = 0; j < numipar; j++)
      if(!paramsetarray[j])
      {
        fprintf(stderr, "Error: Instrument parameter %s left unset (mcparseoptions)\n",
                mcinputtable[j].name);
        exit(1);
      }
  }
  free(paramsetarray);
#ifdef USE_MPI
  if (mcdotrace) mpi_node_count=1; /* disable threading when in trace mode */
#endif
  if (usedir && strlen(usedir) && !mcdisable_output_files) mcuse_dir(usedir);
} /* mcparseoptions */

#ifndef NOSIGNALS
/*******************************************************************************
* sighandler: signal handler that makes simulation stop, and save results
*******************************************************************************/
void sighandler(int sig)
{
  /* MOD: E. Farhi, Sep 20th 2001: give more info */
  time_t t1, t0;
#define SIG_SAVE 0
#define SIG_TERM 1
#define SIG_STAT 2
#define SIG_ABRT 3

  /* one final save only: a further terminate/save signal while the final save
     runs is ignored. mpirun forwards signals, so a rank may get SIGTERM twice,
     the second one possibly in another thread while the first is saving.
     The flag is set right away to keep that window small. */
  {
    static volatile int terminating = 0;
    int term = 0, save = 0, replay = mcsig_replay;
    mcsig_replay = 0; /* only this call is the replay */
#ifdef SIGINT
    if (sig == SIGINT)   term = 1;
#endif
#ifdef SIGTERM
    if (sig == SIGTERM)  term = 1;
#endif
#ifdef SIGQUIT
    if (sig == SIGQUIT)  term = 1;
#endif
#ifdef SIGUSR2
    if (sig == SIGUSR2)  save = 1;
#endif
#ifdef SIGHUP
    if (sig == SIGHUP)   save = 1;
#endif
#ifdef SIGBREAK
    if (sig == SIGBREAK) save = 1;
#endif
    if (!replay && (term || save) && (terminating || mcsave_final)) {
      printf("\n# " MCCODE_STRING ": [pid %i] Signal %i ignored: final save in progress\n", getpid(), sig);
      return;
    }
    if (term) terminating = 1;
    if ((term || save) && mcsig_busy && !replay) { /* inside an event list write: finish it first */
      mcsig_pending = sig;
      return;
    }
  }

  printf("\n# " MCCODE_STRING ": [pid %i] Signal %i detected", getpid(), sig);
#ifdef USE_MPI
  printf(" [proc %i]", mpi_node_rank);
#endif
#if defined(SIGUSR1) && defined(SIGUSR2) && defined(SIGKILL)
  if (!strcmp(mcsig_message, "sighandler") && (sig != SIGUSR1) && (sig != SIGUSR2))
  {
    printf("\n# Fatal : unrecoverable loop ! Suicide (naughty boy).\n");
    kill(0, SIGKILL); /* kill myself if error occurs within sighandler: loops */
  }
#endif
  switch (sig) {
#ifdef SIGINT
    case SIGINT : printf(" SIGINT (interrupt from terminal, Ctrl-C)"); sig = SIG_TERM; break;
#endif
#ifdef SIGILL
    case SIGILL  : printf(" SIGILL (Illegal instruction)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGFPE
    case SIGFPE  : printf(" SIGFPE (Math Error)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGSEGV
    case SIGSEGV : printf(" SIGSEGV (Mem Error)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGTERM
    case SIGTERM : printf(" SIGTERM (Termination)"); sig = SIG_TERM; break;
#endif
#ifdef SIGABRT
    case SIGABRT : printf(" SIGABRT (Abort)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGQUIT
    case SIGQUIT : printf(" SIGQUIT (Quit from terminal)"); sig = SIG_TERM; break;
#endif
#ifdef SIGTRAP
    case SIGTRAP : printf(" SIGTRAP (Trace trap)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGPIPE
    case SIGPIPE : printf(" SIGPIPE (Broken pipe)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGUSR1
    case SIGUSR1 : printf(" SIGUSR1 (Display info)"); sig = SIG_STAT; break;
#endif
#ifdef SIGUSR2
    case SIGUSR2 : printf(" SIGUSR2 (Save simulation)"); sig = SIG_SAVE; break;
#endif
#ifdef SIGHUP
    case SIGHUP  : printf(" SIGHUP (Hangup/update)"); sig = SIG_SAVE; break;
#endif
#ifdef SIGBUS
    case SIGBUS  : printf(" SIGBUS (Bus error)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGURG
    case SIGURG  : printf(" SIGURG (Urgent socket condition)"); sig = SIG_ABRT; break;
#endif
#ifdef SIGBREAK
    case SIGBREAK: printf(" SIGBREAK (Break signal, Ctrl-Break)"); sig = SIG_SAVE; break;
#endif
    default : printf(" (look at signal list for signification)"); sig = SIG_ABRT; break;
  }
  printf("\n");
  printf("# Simulation: %s (%s) \n", instrument_name, instrument_source);
  printf("# Breakpoint: %s ", mcsig_message);
  if (strstr(mcsig_message, "Save") && (sig == SIG_SAVE))
    sig = SIG_STAT;
  SIG_MESSAGE("sighandler");
  if (mcget_ncount() == 0)
    printf("(0 %%)\n" );
  else
  {
    printf("%.2f %% (%10.1f/%10.1f)\n", 100.0*mcget_run_num()/mcget_ncount(), 1.0*mcget_run_num(), 1.0*mcget_ncount());
  }
  t0 = (time_t)mcstartdate;
  t1 = time(NULL);
  printf("# Date:      %s", ctime(&t1));
  printf("# Started:   %s", ctime(&t0));

  if (sig == SIG_STAT)
  {
    printf("# " MCCODE_STRING ": Resuming simulation (continue)\n");
    fflush(stdout);
    return;
  }
  else
  if (sig == SIG_SAVE)
  {
    printf("# " MCCODE_STRING ": Saving data and resume simulation (continue)\n");
    save(NULL);
    fflush(stdout);
    return;
  }
  else
  if (sig == SIG_TERM)
  {
    printf("# " MCCODE_STRING ": Finishing simulation (save results and exit)\n");
#if defined(USE_MPI) && defined(USE_NEXUS)
    mclist_interrupt_note();
#endif
    finally();
    exit(0);
  }
  else
  {
    fflush(stdout);
    perror("# Last I/O Error");
    printf("# " MCCODE_STRING ": Simulation stop (abort).\n");
// This portion of the signal handling only works on UNIX
#if defined(__unix__) || defined(__APPLE__)
    signal(sig, SIG_DFL); /* force to use default sighandler now */
    kill(getpid(), sig);  /* and trigger it with the current signal */
#endif
    exit(-1);
  }
#undef SIG_SAVE
#undef SIG_TERM
#undef SIG_STAT
#undef SIG_ABRT

} /* sighandler */
#endif /* !NOSIGNALS */

#ifdef NEUTRONICS
/*Main neutronics function steers the McStas calls, initializes parameters etc */
/* Only called in case NEUTRONICS = TRUE */
void neutronics_main_(float *inx, float *iny, float *inz, float *invx, float *invy, float *invz, float *intime, float *insx, float *insy, float *insz, float *inw, float *outx, float *outy, float *outz, float *outvx, float *outvy, float *outvz, float *outtime, float *outsx, float *outsy, float *outsz, float *outwgt)
{

  extern double mcnx, mcny, mcnz, mcnvx, mcnvy, mcnvz;
  extern double mcnt, mcnsx, mcnsy, mcnsz, mcnp;

  /* External code governs iteration - McStas is iterated once per call to neutronics_main. I.e. below counter must be initiancated for each call to neutronics_main*/
  mcrun_num=0;

  time_t t;
  t = (time_t)mcstartdate;
  mcstartdate = t;  /* set start date before parsing options and creating sim file */
  init();

  /* *** parse options *** */
  SIG_MESSAGE("[" __FILE__ "] main START");
  mcformat=getenv(FLAVOR_UPPER "_FORMAT") ?
           getenv(FLAVOR_UPPER "_FORMAT") : FLAVOR_UPPER;

  /* Set neutron state based on input from neutronics code */
  mcsetstate(*inx,*iny,*inz,*invx,*invy,*invz,*intime,*insx,*insy,*insz,*inw);

  /* main neutron event loop - runs only one iteration */

  //mcstas_raytrace(&mcncount); /* prior to McStas 1.12 */

  mcallowbackprop = 1; //avoid absorbtion from negative dt
  int argc=1;
  char *argv[0];
  int dummy = mccode_main(argc, argv);

  *outx =  mcnx;
  *outy =  mcny;
  *outz =  mcnz;
  *outvx =  mcnvx;
  *outvy =  mcnvy;
  *outvz =  mcnvz;
  *outtime =  mcnt;
  *outsx =  mcnsx;
  *outsy =  mcnsy;
  *outsz =  mcnsz;
  *outwgt =  mcnp;

  return;
} /* neutronics_main */

#endif /*NEUTRONICS*/

#endif /* !MCCODE_H */
/* End of file "mccode-r.c". */
/* End of file "mccode-r.c". */

/* embedding file "mcxtrace-r.c" */

/*******************************************************************************
*
* McXtrace, X-ray tracing package
*           Copyright (C) 1997-2009, All rights reserved
*           DTU Physics , Kgs. Lyngby, Denmark
*
* Runtime: share/mcxtrace-r.c
*
* %Identification
* Edited by: EK
* Date:    May 29, 2009
* Release: McXtrace X.Y
* Version: $Revision$
*
* Runtime system for McXtrace.
* Embedded within instrument in runtime mode.
*
* Usage: Automatically embedded in the c code whenever required.
*
*******************************************************************************/

#ifndef MCXTRACE_R_H
#include "mcxtrace-r.h"
#endif

/*******************************************************************************
* The I/O format definitions and functions
*******************************************************************************/

#ifndef MCXTRACE_H


/*******************************************************************************
* mcsetstate: transfer parameters into global McXtrace variables
*******************************************************************************/
_class_particle mcsetstate(double x, double y, double z, double kx, double ky, double kz,
			   double phi, double t, double Ex, double Ey, double Ez, double p, int mcgravitation, void *mcMagnet, int mcallowbackprop)
{
  _class_particle mcphoton;

  mcphoton.x  = x;
  mcphoton.y  = y;
  mcphoton.z  = z;
  mcphoton.kx = kx;
  mcphoton.ky = ky;
  mcphoton.kz = kz;
  mcphoton.phi  = phi;
  mcphoton.t  = t;
  mcphoton.Ex = Ex;
  mcphoton.Ey = Ey;
  mcphoton.Ez = Ez;
  mcphoton.p  = p;
  /*mcphoton.mcgravitation = mcgravitation;
    mcphoton.mcMagnet = mcMagnet;*/
  mcphoton.allow_backprop = mcallowbackprop;
  mcphoton._uid       = 0;
  mcphoton._index     = 1;
  mcphoton._absorbed  = 0;
  mcphoton._restore   = 0;
  mcphoton._scattered = 0;

  // init uservars via cogen'd-function
  particle_uservar_init(&mcphoton);

  return(mcphoton);
} /* mcsetstate */

/*******************************************************************************
* mcgetstate: get photon parameters from particle structure
*******************************************************************************/
_class_particle mcgetstate(_class_particle mcphoton, double *x, double *y, double *z,
               double *kx, double *ky, double *kz, double *phi, double *t,
               double *Ex, double *Ey, double *Ez, double *p)
{
  *x  =  mcphoton.x;
  *y  =  mcphoton.y;
  *z  =  mcphoton.z;
  *kx =  mcphoton.kx;
  *ky =  mcphoton.ky;
  *kz =  mcphoton.kz;
  *phi  =  mcphoton.phi;
  *t  =  mcphoton.t;
  *Ex =  mcphoton.Ex;
  *Ey =  mcphoton.Ey;
  *Ez =  mcphoton.Ez;
  *p  =  mcphoton.p;

  return(mcphoton);
} /* mcgetstate */

/*******************************************************************************
* SCATTER_func: provides function to SCATTER from within libaries
*******************************************************************************/
void SCATTER_func(_class_particle *_particle) {
  if(mcdotrace) {
	  printf("SCATTER: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n",
	         _particle->x,_particle->y,_particle->z,
	         _particle->kx,_particle->ky,_particle->kz,
			 _particle->phi,_particle->t,
			 _particle->Ex,_particle->Ey,_particle->Ez,
			 _particle->p);
  }
  if (!_particle->_absorbed) _particle->_scattered++;
}  /* SCATTER_func */

/*******************************************************************************
* mcgenstate: set default photon parameters 
*******************************************************************************/
/*moved to generated code*/
/*#pragma acc routine seq*/
/*_class_particle mcgenstate(void)*/
/*{*/
/*  return(mcsetstate(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, mcgravitation, mcMagnet, mcallowbackprop));*/
/*}*/

/*******************************************************************************
* mccoordschanges: old style rotation routine rot -> (x y z) ,(vx vy vz),(sx,sy,sz)
*******************************************************************************/
void
mccoordschanges(Coords a, Rotation t, double *x, double *y, double *z,
               double *kx, double *ky, double *kz, double *Ex, double *Ey, double *Ez)
{
  Coords b, c;

  b.x = *x;
  b.y = *y;
  b.z = *z;
  c = rot_apply(t, b);
  b = coords_add(c, a);
  *x = b.x;
  *y = b.y;
  *z = b.z;

  if ( (kz && ky  && kx) && (*kz != 0.0 || *kx != 0.0 || *ky != 0.0) )
    mccoordschange_polarisation(t, kx, ky, kz);

  if ( (Ez && Ey  && Ex) && (*Ez != 0.0 || *Ex != 0.0 || *Ey != 0.0) )
    mccoordschange_polarisation(t, Ex, Ey, Ez);

}

/* intersection routines ==================================================== */

/*******************************************************************************
* inside_rectangle: Check if (x,y) is inside rectangle (xwidth, yheight)
* return 0 if outside and 1 if inside
*******************************************************************************/
int inside_rectangle(double x, double y, double xwidth, double yheight)
{
  if (x>-xwidth/2 && x<xwidth/2 && y>-yheight/2 && y<yheight/2)
    return 1;
  else
    return 0;
}

/*******************************************************************************
 * box_intersect: compute length intersection with a box
 * returns 0 when no intersection is found
 *      or 1 in case of intersection with resulting lengths dl_in and dl_out
*******************************************************************************/
int box_intersect(double *dl_in, double *dl_out,
                  double x, double y, double z,
                  double kx, double ky, double kz,
                  double dx, double dy, double dz)
{

  double k, l,xf,yf,zf, l_[6],dx_2,dy_2,dz_2;
  double ab[2];
  unsigned int count=0;
  k=sqrt(scalar_prod(kx,ky,kz,kx,ky,kz));
  dx_2=dx/2.0;dy_2=dy/2.0;dz_2=dz/2.0; 
  /*we really don't need to store the 6 intersects as only two are possible. i.e. should remove that.*/
  if (kx) {
    l=(-dx_2-x)/kx*k;
    yf=l*ky/k+y;zf=l*kz/k+z;
    if(yf > -dy_2 && yf<dy_2 && zf > -dz_2 && zf<dz_2){
      l_[0]=l;
      ab[count++]=l_[0];
    }else{
      l_[0]=0;
    }
    l=(dx_2-x)/kx*k;
    yf=l*ky/k+y;zf=l*kz/k+z;
    if(yf > -dy_2 && yf<dy_2 && zf > -dz_2 && zf<dz_2){
      l_[1]=l;
      ab[count++]=l_[1];
    }else{
      l_[1]=0;
    }
  }
  if (ky) {
    l=(-dy_2-y)/ky*k;
    xf=l*kx/k+x;zf=l*kz/k+z;
    if(xf > -dx_2 && xf<dx_2 && zf > -dz_2 && zf<dz_2){
      l_[2]=l;
      ab[count++]=l_[2];
    }else{
      l_[2]=0;
    } 
    l=(dy_2-y)/ky*k;
    xf=l*kx/k+x;zf=l*kz/k+z;
    if(xf > -dx_2 && xf<dx_2 && zf > -dz_2 && zf<dz_2){
      l_[3]=l;
      ab[count++]=l_[3];
    }else{
      l_[3]=0;
    }
  }
  if (kz) {
    l=(-dz_2-z)/kz*k;
    xf=l*kx/k+x; yf=l*ky/k+y;
    if(xf > -dx_2 && xf<dx_2 && yf > -dy_2 && yf<dy_2){
      l_[4]=l;
      ab[count++]=l_[4];
    }else{
      l_[4]=0;
    }
    l=(dz_2-z)/kz*k;
    xf=l*kx/k+x; yf=l*ky/k+y;
    if(xf > -dx_2 && xf<dx_2 && yf > -dy_2 && yf<dy_2){
      l_[5]=l;
      ab[count++]=l_[5];
    }else{
      l_[5]=0;
    }
  }
  if (!count){
    *dl_in=0;*dl_out=0;
    return 0;
  }

  if (ab[0]<ab[1]){
    *dl_in=ab[0];*dl_out=ab[1];
    return 1;
  }else{
    *dl_in=ab[1];*dl_out=ab[0];
    return 1;
  }

} /* box_intersect */

/*******************************************************************************
 * cylinder_intersect: compute intersection with a cylinder
 * returns 0 when no intersection is found
 *      or 1/2/4/8/16 bits depending on intersection,
 *     and resulting times l0 and l1
 * Written by: EK 11.6.09 
 *******************************************************************************/
int cylinder_intersect(double *l0, double *l1, double x, double y, double z,
                   double kx, double ky, double kz, double r, double h)
{
  double A,B,C,D,k2,k;
  double dl1p=0,dl0p=0,dl1c=0,dl0c=0,y0,y1;
  int ret=1,stat=0,plane_stat=0;
  enum {HIT_CYL=01,ENTER_TOP=02,ENTER_BOT=04,EXIT_TOP=010,EXIT_BOT=020,ENTER_MASK=06,EXIT_MASK=030};
  k2=(kx*kx + ky*ky + kz*kz);
  k=sqrt(k2);

  /*check for prop. vector 0*/
  if(!k2) return 0;

  A= (k2 - ky*ky);
  B= 2*(x*kx + z*kz);
  C=(x*x + z*z - r*r);
  D=B*B-4*A*C;
  if(D>=0){
    if (kx || kz){
      stat|=HIT_CYL;
    /*propagation not parallel to y-axis*/
    /*hit infinitely high cylinder?*/
      D=sqrt(D);
      dl0c=k*(-B-D)/(2*A);
      dl1c=k*(-B+D)/(2*A);
      y0=dl0c*ky/k+y;
      y1=dl1c*ky/k+y;
      if ( (y0<-h/2 && y1<-h/2) || (y0>h/2 && y1>h/2) ){
        /*ray passes above or below cylinder*/
        return 0;
      }
    }
    /*now check top and bottom planes*/
    if (ky){
      dl0p = k*(-h/2-y)/ky;
      dl1p = k*(h/2-y)/ky;
      /*switch solutions?*/
      if (dl0p<dl1p){
        plane_stat|=(ENTER_BOT|EXIT_TOP);
      }else{
        double tmp=dl1p;
        dl1p=dl0p;dl0p=tmp;
        plane_stat|=(ENTER_TOP|EXIT_BOT);
      }
    }
  }
  if (stat & HIT_CYL){
    if (ky && dl0p>dl0c){
      *l0=dl0p;/*1st top/bottom plane intersection happens after 1st cylinder intersect*/
      stat|= plane_stat & ENTER_MASK;
    } else
      *l0=dl0c;
    if(ky && dl1p<dl1c){
      *l1=dl1p;/*2nd top/bottom plane intersection happens before 2nd cylinder intersect*/
      stat|= plane_stat & EXIT_MASK;
    }else
      *l1=dl1c;
  }
  return stat;
} /* cylinder_intersect */


/*******************************************************************************
 * sphere_intersect: Calculate intersection between a line and a sphere.
 * returns 0 when no intersection is found
 *      or 1 in case of intersection with resulting lengths l0 and l1 
 *******************************************************************************/
#pragma acc routine seq
int sphere_intersect(double *l0, double *l1, double x, double y, double z,
                 double kx, double ky, double kz, double r)
{
  double B, C, D, k;

  k = kx*kx + ky*ky + kz*kz;
  B = (x*kx + y*ky + z*kz);
  C = x*x + y*y + z*z - r*r;
  D = B*B - k*C;
  if(D < 0)
    return 0;
  D = sqrt(D);
  *l0 = (-B - D) / sqrt(k);
  *l1 = (-B + D) / sqrt(k);
  return 1;
} /* sphere_intersect */

/******************************************************************************
 * ellipsoid_intersect: Calculate intersection between a line and an ellipsoid.
 * They ellisoid is fixed by a set of half-axis (a,b,c) and a matrix Q, with the
 * columns of Q being the (orthogonal) vectors along which the half-axis lie.
 * This allows for complete freedom in orienting the ellipsoid.
 * returns 0 when no intersection is found
 *      or 1 when they _are_ found with resulting lengths l0 and l1.
 *****************************************************************************/
int ellipsoid_intersect(double *l0, double *l1, double x, double y, double z,
    double kx, double ky, double kz, double a, double b, double c,
    Rotation Q)
{
  Rotation A,Gamma,Q_t,Tmp;
  double u,v,w;

  Gamma[0][0]=Gamma[0][1]=Gamma[0][2]=0;
  Gamma[1][1]=Gamma[1][0]=Gamma[1][2]=0;
  Gamma[2][2]=Gamma[2][0]=Gamma[2][1]=0;
  /* now set diagonal to ellipsoid half axis if non-zero.
   * This way a zero value means the ellipsoid extends infinitely along that axis,
   * which is useful for objects only curved in one direction*/ 
  if (a!=0){
    Gamma[0][0]=1/(a*a);
  }
  if (b!=0){
    Gamma[1][1]=1/(b*b);
  }
  if (c!=0){
    Gamma[2][2]=1/(c*c);
  }

  if (Q!=NULL){
    rot_transpose(Q,Q_t);
    rot_mul(Gamma,Q_t,Tmp);
    rot_mul(Q,Tmp,A);
  }else{
    rot_copy(A,Gamma);
  }

  /*to get the solutions as lengths in m use unit vector along k*/
  double ex,ey,ez,k;
  k=sqrt(kx*kx+ky*ky+kz*kz);
  ex=kx/k;
  ey=ky/k;
  ez=kz/k;

  u=ex*(A[0][0]*ex + A[1][0]*ey + A[2][0]*ez) + ey*( A[0][1]*ex + A[1][1]*ey + A[2][1]*ez) + ez*(A[0][2]*ex + A[1][2]*ey + A[2][2]*ez);
  v=x *(A[0][0]*ex + A[1][0]*ey + A[2][0]*ez) + ex*(A[0][0]*x + A[1][0]*y + A[2][0]*z) +
    y *(A[0][1]*ex + A[1][1]*ey + A[2][1]*ez) + ey*(A[0][1]*x + A[1][1]*y + A[2][1]*z) +
    z *(A[0][2]*ex + A[1][2]*ey + A[2][2]*ez) + ez*(A[0][2]*x + A[1][2]*y + A[2][2]*z);
  w=x*(A[0][0]*x + A[1][0]*y + A[2][0]*z) + y*(A[0][1]*x + A[1][1]*y + A[2][1]*z) + z*(A[0][2]*x + A[1][2]*y + A[2][2]*z);

  double D=v*v-4*u*w+4*u;
  if (D<0) return 0;

  D=sqrt(D);

  *l0=(-v-D) / (2*u);
  *l1=(-v+D) / (2*u);
  return 1;
}


/*******************************************************************************
 * plane_intersect: Calculate intersection between a plane (with normal n including the point w)
 * and a line through x along the direction k.
 * returns 0 when no intersection is found (i.e. line is parallel to the plane)
 * returns 1 or -1 when intersection length is positive and negative, respectively
 *******************************************************************************/
int plane_intersect(double *l, double x, double y, double z,
                 double kx, double ky, double kz, double nx, double ny, double nz, double wx, double wy, double wz)
{
  double s,k2;
  k2=scalar_prod(kx,ky,kz,kx,ky,kz);
  s=scalar_prod(kx,ky,kz,nx,ny,nz);
  if (k2<FLT_EPSILON || fabs(s)<FLT_EPSILON) return 0;
  *l = - sqrt(k2)*scalar_prod(nx,ny,nz,x-wx,y-wy,z-wz)/s;
  if (*l<0) return -1;
  else return 1;
} /* plane_intersect */

/*******************************************************************************
 * paraboloid_intersect: Calculate intersection between a rotational paraboloid
 * and a line with direction k through the point x,y,z.
 * The paraboloid is oriented such that it opens towards positive y,with the scaling
 * prms  a and b for x and y resp.. The paex is on the z=0-axis. I.e. the equation for the paraboloid is:
 * z=(x/a)^2 + (y/b)^2
 * If the other direction (opening towards z<0) is wanted simply set the sign parameter to -1
 *******************************************************************************/
int
paraboloid_intersect(double *l0, double *l1, double x, double y, double z,
    double kx, double ky, double kz, double a, double b, int sign)
{
  double A,B,C,D,k;
  double a2i=0,b2i=0;
  int retval=0;
  if(a!=0 && b!=0){
    a2i=1.0/(a*a);b2i=1.0/(b*b);
  }else if (a!=0){
    /*paraboloid is infinite/invariant along y, must check if k||y */
    if (kx==0 && kz==0){
      *l0=*l1=0;return 0;
    }
    a2i=1.0/(a*a);b2i=0;
  }else if (b!=0){
    /*paraboloid is infinite/invariant along x, must check if k||x */
    if (ky==0 && kz==0){
      *l0=*l1=0;return 0;
    }
    a2i=0;b2i=1.0/(b*b);
  }
  k=sqrt(kx*kx + ky*ky + kz*kz);

  A=sign*(kx*kx*a2i + ky*ky*b2i);
  B=sign*2*kx*x*a2i + sign*ky*y*b2i - kz;
  C=sign*x*x*a2i + sign*y*y*b2i - z;

  retval=solve_2nd_order(l0,l1,A,B,C);
  /*convert to solution in m*/
  *l0 *= k; *l1 *=k;
  return retval;
}

/******************************************************************************
 * paraboloid_normal: Calucate the normal vector to the given paraboloid at the
 * point (x,y,z) and put the result i nx,ny,nz. No check is performed if the
 * the point is on th surface. In that case the result is undefined.
 *****************************************************************************/
int paraboloid_normal(double *nx, double *ny, double *nz, double x,double y, double z, double a, double b, int sign){
  double a2i,b2i;
  double tx,ty,tz;
  if(a!=0 && b!=0){
    a2i=1.0/(a*a);b2i=1.0/(b*b);
  }else if (a!=0){
    a2i=1.0/(a*a);b2i=0;
  }else if (b!=0){
    a2i=0;b2i=1.0/(b*b);
  }else{
    *nx=0; *ny=0; *nz=1;
    return 1;
  }
  tx=-sign*2*x*a2i;
  ty=-sign*2*y*b2i;
  tz=1;
  NORM(tx,ty,tz);
  *nx=tx; *ny=ty; *nz=tz;
  return 1;
}



#endif /* !MCXTRACE_H */
/* End of file "mcxtrace-r.c". */


/* *****************************************************************************
* Start of instrument 'SOLEIL' generated code
***************************************************************************** */

#ifdef MC_TRACE_ENABLED
int traceenabled = 1;
#else
int traceenabled = 0;
#endif
#define MCXTRACE "/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/"
int   defaultmain         = 1;
char  instrument_name[]   = "SOLEIL";
char  instrument_source[] = "SOLEIL.instr";
char *instrument_exe      = NULL; /* will be set to argv[0] in main */
char  instrument_code[]   = "Instrument SOLEIL source code SOLEIL.instr is not embedded in this executable.\n  Use --source option when running mcxtrace.\n";

int main(int argc, char *argv[]){return mccode_main(argc, argv);}

/* *****************************************************************************
* instrument 'SOLEIL' and components DECLARE
***************************************************************************** */

/* Instrument parameters: structure and a table for the initialisation
   (Used in e.g. inputparse and I/O function (e.g. detector_out) */

struct _struct_instrument_parameters {
  MCNUM splits;
  MCNUM MARS_E0;
  char* MARS_reflec_material_M12;
  char* MARS_reflections;
  MCNUM MARS_dEr;
  MCNUM MARS_alpha;
  MCNUM PSICHE_E0;
  MCNUM PSICHE_dE;
  MCNUM PSICHE_DCM_present;
  MCNUM PSICHE_sample_theta;
  char* PSICHE_sample_material;
  char* PSICHE_sample_geometry;
  MCNUM PSICHE_dcm_theta;
  MCNUM DISCO_grazing_angle_one;
  MCNUM DISCO_HFP_shift;
  MCNUM DISCO_VFP_shift;
  MCNUM DISCO_second_HFP_shift;
  MCNUM DISCO_x_screw;
  MCNUM DISCO_scan;
  MCNUM PUMA_E0;
  MCNUM PUMA_dE;
  MCNUM PUMA_DCM_theta;
  MCNUM PUMA_HFM_angle;
  MCNUM PUMA_HFM_focal;
  MCNUM PUMA_KB_angle;
  char* PUMA_KB_coating;
  int PUMA_h;
  int PUMA_k;
  int PUMA_l;
  MCNUM CRISTAL_E0;
  MCNUM CRISTAL_dE;
  MCNUM CRISTAL_M1_angle;
  MCNUM CRISTAL_M2_angle;
  MCNUM CRISTAL_M1_radius;
  MCNUM CRISTAL_M2_radius;
  char* CRISTAL_M_coating;
  char* CRISTAL_reflections;
  MCNUM GALAXIES_E0;
  MCNUM GALAXIES_dE;
  MCNUM GALAXIES_hrm;
  char* GALAXIES_hrm_ref;
  MCNUM GALAXIES_sec_slits;
  MCNUM GALAXIES_ana_R;
  MCNUM GALAXIES_ana_deg;
  char* GALAXIES_sample;
  MCNUM SAMBA_E0;
  MCNUM SAMBA_dE;
  MCNUM SAMBA_M1_angle;
  MCNUM SAMBA_M2_angle;
  char* SAMBA_sample;
  MCNUM PX1_E0;
  MCNUM PX1_dE;
  MCNUM PX1_K;
  MCNUM PX1_vfm_radius;
  MCNUM PX1_hfm_radius;
  MCNUM PX1_mirror_grazing_angle;
  MCNUM PX1_det_dist;
  char* PX1_sample;
  MCNUM PX1_rotX;
  MCNUM PX1_rotY;
  MCNUM PX1_rotZ;
  MCNUM PX2a_E0;
  MCNUM PX2a_hfm_radius;
  MCNUM PX2a_vfm_radius;
  MCNUM PX2a_mirror_grazing_angle;
  char* PX2a_sample;
  MCNUM PX2a_rotX;
  MCNUM PX2a_rotY;
  MCNUM PX2a_rotZ;
  MCNUM SWING_E0;
  MCNUM SWING_dE;
  MCNUM SWING_dcm_theta;
  MCNUM SWING_hfm_radius;
  MCNUM SWING_vfm_radius;
  MCNUM SWING_mirror_grazing_angle;
  char* SWING_sample;
  MCNUM SWING_sample_det;
  MCNUM ROCK_E0;
  MCNUM ROCK_dE;
  MCNUM ROCK_scan;
  MCNUM ROCK_angle_m2a_m2b;
  MCNUM ROCK_angle_m1;
  char* ROCK_sample_file;
  char* ROCK_reflec_material_M1;
  char* ROCK_reflec_material_M2A_M2B;
  int ROCK_cc;
  MCNUM ANATOMIX_E0;
  MCNUM ANATOMIX_Emono;
  MCNUM ANATOMIX_dE;
  MCNUM ANATOMIX_ANGLE;
  char* ANATOMIX_sample;
  MCNUM NANO_E0;
  MCNUM NANO_dE;
  MCNUM NANO_Emono;
  int NANO_coating_m2;
  MCNUM NANO_angle_m1_m2;
  MCNUM NANO_angle_kb1;
  MCNUM NANO_angle_kb2;
  MCNUM DIFFABS_E0;
  MCNUM DIFFABS_dE;
  MCNUM DIFFABS_M1_angle;
  MCNUM DIFFABS_M1_radius;
  MCNUM DIFFABS_M2_radius;
  MCNUM DIFFABS_DCM_theta;
  char* DIFFABS_sample;
  MCNUM SIXS_E0;
  MCNUM SIXS_dE;
  MCNUM SIXS_dcm_theta;
  MCNUM SIXS_M1_angle;
  MCNUM SIXS_M1_radius;
  MCNUM SIXS_M2_radius;
  char* SIXS_sample_coating;
  char* SIXS_sample_bulk;
  MCNUM SIXS_sample_thickness;
  MCNUM SIXS_sample_angle;
  char* CASSIOPEE_mirror_material;
  int CASSIOPEE_undulator_index;
  MCNUM CASSIOPEE_M1_angle;
  MCNUM CASSIOPEE_PG_angle;
  MCNUM CASSIOPEE_PM_angle;
  MCNUM CASSIOPEE_E0;
  MCNUM CASSIOPEE_dE;
  MCNUM CASSIOPEE_lambda;
  MCNUM CASSIOPEE_beta_mono;
  MCNUM CASSIOPEE_r_rho;
  MCNUM SIRIUS_E0;
  MCNUM SIRIUS_dE;
  MCNUM SIRIUS_M1_angle;
  MCNUM SIRIUS_M2_angle;
  MCNUM SIRIUS_def_angle;
  MCNUM SIRIUS_sample_pos;
  char* SIRIUS_sample;
  MCNUM LUCIA_E0;
  MCNUM LUCIA_dE;
  MCNUM LUCIA_dcm_theta;
  char* LUCIA_sample_material;
  char* LUCIA_sample_geometry;
};
typedef struct _struct_instrument_parameters _class_instrument_parameters;

/* instrument SPLIT and GROUP control logic */
struct instrument_logic_struct {
  long Split_MARS_Sample; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_MARS_Sample_particle; /* this is the particle to duplicate */
  long Split_DISCO_reflective_grating; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_DISCO_reflective_grating_particle; /* this is the particle to duplicate */
  long Split_CRISTAL_fluo; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_CRISTAL_fluo_particle; /* this is the particle to duplicate */
  long Split_GALAXIES_sample; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_GALAXIES_sample_particle; /* this is the particle to duplicate */
  long Split_SAMBA_fluo; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_SAMBA_fluo_particle; /* this is the particle to duplicate */
  long Split_PX1_sample; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_PX1_sample_particle; /* this is the particle to duplicate */
  long Split_PX2a_sample; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_PX2a_sample_particle; /* this is the particle to duplicate */
  long Split_SWING_sample_stage; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_SWING_sample_stage_particle; /* this is the particle to duplicate */
  long Split_ROCK_absorption_sample; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_ROCK_absorption_sample_particle; /* this is the particle to duplicate */
  long Split_DIFFABS_fluo; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_DIFFABS_fluo_particle; /* this is the particle to duplicate */
  long Split_SIXS_sample_stage; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_SIXS_sample_stage_particle; /* this is the particle to duplicate */
  long Split_SIRIUS_fluo; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_SIRIUS_fluo_particle; /* this is the particle to duplicate */
  long Split_LUCIA_sample; /* this is the SPLIT counter decremented down to 0 */
  _class_particle Split_LUCIA_sample_particle; /* this is the particle to duplicate */
};

struct _instrument_struct {
  char   _name[256]; /* the name of this instrument e.g. 'SOLEIL' */
/* Counters per component instance */
  double counter_AbsorbProp[579]; /* absorbed events in PROP routines */
  double counter_N[579], counter_P[579], counter_P2[579]; /* event counters after each component instance */
  _class_particle _trajectory[579]; /* current trajectory for STORE/RESTORE */
/* Components position table (absolute and relative coords) */
  Coords _position_relative[579]; /* positions of all components */
  Coords _position_absolute[579];
  _class_instrument_parameters _parameters; /* instrument parameters */
  struct instrument_logic_struct logic; /* instrument logic */
} _instrument_var;
struct _instrument_struct *instrument = & _instrument_var;
#pragma acc declare create ( _instrument_var )
#pragma acc declare create ( instrument )

int numipar = 137;
struct mcinputtable_struct mcinputtable[] = {
  "splits", &(_instrument_var._parameters.splits), instr_type_double, "1", "",
  "MARS_E0", &(_instrument_var._parameters.MARS_E0), instr_type_double, "16.99", "",
  "MARS_reflec_material_M12", &(_instrument_var._parameters.MARS_reflec_material_M12), instr_type_string, "Pt.dat", "",
  "MARS_reflections", &(_instrument_var._parameters.MARS_reflections), instr_type_string, "LaB6_660b_AVID2.hkl", "",
  "MARS_dEr", &(_instrument_var._parameters.MARS_dEr), instr_type_double, "1e-4", "",
  "MARS_alpha", &(_instrument_var._parameters.MARS_alpha), instr_type_double, "0", "",
  "PSICHE_E0", &(_instrument_var._parameters.PSICHE_E0), instr_type_double, "31", "",
  "PSICHE_dE", &(_instrument_var._parameters.PSICHE_dE), instr_type_double, "1", "",
  "PSICHE_DCM_present", &(_instrument_var._parameters.PSICHE_DCM_present), instr_type_double, "0", "",
  "PSICHE_sample_theta", &(_instrument_var._parameters.PSICHE_sample_theta), instr_type_double, "0", "",
  "PSICHE_sample_material", &(_instrument_var._parameters.PSICHE_sample_material), instr_type_string, "Ag", "",
  "PSICHE_sample_geometry", &(_instrument_var._parameters.PSICHE_sample_geometry), instr_type_string, "wire.ply", "",
  "PSICHE_dcm_theta", &(_instrument_var._parameters.PSICHE_dcm_theta), instr_type_double, "0", "",
  "DISCO_grazing_angle_one", &(_instrument_var._parameters.DISCO_grazing_angle_one), instr_type_double, "22.5", "",
  "DISCO_HFP_shift", &(_instrument_var._parameters.DISCO_HFP_shift), instr_type_double, "0", "",
  "DISCO_VFP_shift", &(_instrument_var._parameters.DISCO_VFP_shift), instr_type_double, "0", "",
  "DISCO_second_HFP_shift", &(_instrument_var._parameters.DISCO_second_HFP_shift), instr_type_double, "0", "",
  "DISCO_x_screw", &(_instrument_var._parameters.DISCO_x_screw), instr_type_double, "50", "",
  "DISCO_scan", &(_instrument_var._parameters.DISCO_scan), instr_type_double, "0", "",
  "PUMA_E0", &(_instrument_var._parameters.PUMA_E0), instr_type_double, "10", "",
  "PUMA_dE", &(_instrument_var._parameters.PUMA_dE), instr_type_double, "0.1", "",
  "PUMA_DCM_theta", &(_instrument_var._parameters.PUMA_DCM_theta), instr_type_double, "0", "",
  "PUMA_HFM_angle", &(_instrument_var._parameters.PUMA_HFM_angle), instr_type_double, "1.3", "",
  "PUMA_HFM_focal", &(_instrument_var._parameters.PUMA_HFM_focal), instr_type_double, "40", "",
  "PUMA_KB_angle", &(_instrument_var._parameters.PUMA_KB_angle), instr_type_double, "2.9", "",
  "PUMA_KB_coating", &(_instrument_var._parameters.PUMA_KB_coating), instr_type_string, "Rh.txt", "",
  "PUMA_h", &(_instrument_var._parameters.PUMA_h), instr_type_int, "1", "",
  "PUMA_k", &(_instrument_var._parameters.PUMA_k), instr_type_int, "1", "",
  "PUMA_l", &(_instrument_var._parameters.PUMA_l), instr_type_int, "1", "",
  "CRISTAL_E0", &(_instrument_var._parameters.CRISTAL_E0), instr_type_double, "12", "",
  "CRISTAL_dE", &(_instrument_var._parameters.CRISTAL_dE), instr_type_double, "1e-4", "",
  "CRISTAL_M1_angle", &(_instrument_var._parameters.CRISTAL_M1_angle), instr_type_double, "3", "",
  "CRISTAL_M2_angle", &(_instrument_var._parameters.CRISTAL_M2_angle), instr_type_double, "3", "",
  "CRISTAL_M1_radius", &(_instrument_var._parameters.CRISTAL_M1_radius), instr_type_double, "0", "",
  "CRISTAL_M2_radius", &(_instrument_var._parameters.CRISTAL_M2_radius), instr_type_double, "0", "",
  "CRISTAL_M_coating", &(_instrument_var._parameters.CRISTAL_M_coating), instr_type_string, "Rh.txt", "",
  "CRISTAL_reflections", &(_instrument_var._parameters.CRISTAL_reflections), instr_type_string, "LaB6_660b_AVID2.hkl", "",
  "GALAXIES_E0", &(_instrument_var._parameters.GALAXIES_E0), instr_type_double, "10", "",
  "GALAXIES_dE", &(_instrument_var._parameters.GALAXIES_dE), instr_type_double, "0.1", "",
  "GALAXIES_hrm", &(_instrument_var._parameters.GALAXIES_hrm), instr_type_double, "0", "",
  "GALAXIES_hrm_ref", &(_instrument_var._parameters.GALAXIES_hrm_ref), instr_type_string, "Si311", "",
  "GALAXIES_sec_slits", &(_instrument_var._parameters.GALAXIES_sec_slits), instr_type_double, "0.1", "",
  "GALAXIES_ana_R", &(_instrument_var._parameters.GALAXIES_ana_R), instr_type_double, "1.0", "",
  "GALAXIES_ana_deg", &(_instrument_var._parameters.GALAXIES_ana_deg), instr_type_double, "10", "",
  "GALAXIES_sample", &(_instrument_var._parameters.GALAXIES_sample), instr_type_string, "Si.lau", "",
  "SAMBA_E0", &(_instrument_var._parameters.SAMBA_E0), instr_type_double, "15", "",
  "SAMBA_dE", &(_instrument_var._parameters.SAMBA_dE), instr_type_double, "0.1", "",
  "SAMBA_M1_angle", &(_instrument_var._parameters.SAMBA_M1_angle), instr_type_double, "3", "",
  "SAMBA_M2_angle", &(_instrument_var._parameters.SAMBA_M2_angle), instr_type_double, "3", "",
  "SAMBA_sample", &(_instrument_var._parameters.SAMBA_sample), instr_type_string, "LaB6.cif", "",
  "PX1_E0", &(_instrument_var._parameters.PX1_E0), instr_type_double, "12.67", "",
  "PX1_dE", &(_instrument_var._parameters.PX1_dE), instr_type_double, "0.1", "",
  "PX1_K", &(_instrument_var._parameters.PX1_K), instr_type_double, "1.4028", "",
  "PX1_vfm_radius", &(_instrument_var._parameters.PX1_vfm_radius), instr_type_double, "1051", "",
  "PX1_hfm_radius", &(_instrument_var._parameters.PX1_hfm_radius), instr_type_double, "872", "",
  "PX1_mirror_grazing_angle", &(_instrument_var._parameters.PX1_mirror_grazing_angle), instr_type_double, "4.1e-3", "",
  "PX1_det_dist", &(_instrument_var._parameters.PX1_det_dist), instr_type_double, "0.2", "",
  "PX1_sample", &(_instrument_var._parameters.PX1_sample), instr_type_string, "adrenaline.lau", "",
  "PX1_rotX", &(_instrument_var._parameters.PX1_rotX), instr_type_double, "0", "",
  "PX1_rotY", &(_instrument_var._parameters.PX1_rotY), instr_type_double, "0", "",
  "PX1_rotZ", &(_instrument_var._parameters.PX1_rotZ), instr_type_double, "0", "",
  "PX2a_E0", &(_instrument_var._parameters.PX2a_E0), instr_type_double, "12.65", "",
  "PX2a_hfm_radius", &(_instrument_var._parameters.PX2a_hfm_radius), instr_type_double, "495", "",
  "PX2a_vfm_radius", &(_instrument_var._parameters.PX2a_vfm_radius), instr_type_double, "859", "",
  "PX2a_mirror_grazing_angle", &(_instrument_var._parameters.PX2a_mirror_grazing_angle), instr_type_double, "4e-3", "",
  "PX2a_sample", &(_instrument_var._parameters.PX2a_sample), instr_type_string, "adrenaline.lau", "",
  "PX2a_rotX", &(_instrument_var._parameters.PX2a_rotX), instr_type_double, "0", "",
  "PX2a_rotY", &(_instrument_var._parameters.PX2a_rotY), instr_type_double, "0", "",
  "PX2a_rotZ", &(_instrument_var._parameters.PX2a_rotZ), instr_type_double, "0", "",
  "SWING_E0", &(_instrument_var._parameters.SWING_E0), instr_type_double, "13", "",
  "SWING_dE", &(_instrument_var._parameters.SWING_dE), instr_type_double, "0.1", "",
  "SWING_dcm_theta", &(_instrument_var._parameters.SWING_dcm_theta), instr_type_double, "0", "",
  "SWING_hfm_radius", &(_instrument_var._parameters.SWING_hfm_radius), instr_type_double, "495", "",
  "SWING_vfm_radius", &(_instrument_var._parameters.SWING_vfm_radius), instr_type_double, "859", "",
  "SWING_mirror_grazing_angle", &(_instrument_var._parameters.SWING_mirror_grazing_angle), instr_type_double, "4e-3", "",
  "SWING_sample", &(_instrument_var._parameters.SWING_sample), instr_type_string, "6lyz.pdb", "",
  "SWING_sample_det", &(_instrument_var._parameters.SWING_sample_det), instr_type_double, "2", "",
  "ROCK_E0", &(_instrument_var._parameters.ROCK_E0), instr_type_double, "15.918", "",
  "ROCK_dE", &(_instrument_var._parameters.ROCK_dE), instr_type_double, "1", "",
  "ROCK_scan", &(_instrument_var._parameters.ROCK_scan), instr_type_double, "0", "",
  "ROCK_angle_m2a_m2b", &(_instrument_var._parameters.ROCK_angle_m2a_m2b), instr_type_double, "0.008", "",
  "ROCK_angle_m1", &(_instrument_var._parameters.ROCK_angle_m1), instr_type_double, "0.0045", "",
  "ROCK_sample_file", &(_instrument_var._parameters.ROCK_sample_file), instr_type_string, "CuMo", "",
  "ROCK_reflec_material_M1", &(_instrument_var._parameters.ROCK_reflec_material_M1), instr_type_string, "Ir.dat", "",
  "ROCK_reflec_material_M2A_M2B", &(_instrument_var._parameters.ROCK_reflec_material_M2A_M2B), instr_type_string, "NULL", "",
  "ROCK_cc", &(_instrument_var._parameters.ROCK_cc), instr_type_int, "0", "",
  "ANATOMIX_E0", &(_instrument_var._parameters.ANATOMIX_E0), instr_type_double, "11", "",
  "ANATOMIX_Emono", &(_instrument_var._parameters.ANATOMIX_Emono), instr_type_double, "0", "",
  "ANATOMIX_dE", &(_instrument_var._parameters.ANATOMIX_dE), instr_type_double, "1", "",
  "ANATOMIX_ANGLE", &(_instrument_var._parameters.ANATOMIX_ANGLE), instr_type_double, "0", "",
  "ANATOMIX_sample", &(_instrument_var._parameters.ANATOMIX_sample), instr_type_string, "wire.ply", "",
  "NANO_E0", &(_instrument_var._parameters.NANO_E0), instr_type_double, "11", "",
  "NANO_dE", &(_instrument_var._parameters.NANO_dE), instr_type_double, "1", "",
  "NANO_Emono", &(_instrument_var._parameters.NANO_Emono), instr_type_double, "0", "",
  "NANO_coating_m2", &(_instrument_var._parameters.NANO_coating_m2), instr_type_int, "1", "",
  "NANO_angle_m1_m2", &(_instrument_var._parameters.NANO_angle_m1_m2), instr_type_double, "2.5e-3", "",
  "NANO_angle_kb1", &(_instrument_var._parameters.NANO_angle_kb1), instr_type_double, "3e-3", "",
  "NANO_angle_kb2", &(_instrument_var._parameters.NANO_angle_kb2), instr_type_double, "2.5e-3", "",
  "DIFFABS_E0", &(_instrument_var._parameters.DIFFABS_E0), instr_type_double, "13", "",
  "DIFFABS_dE", &(_instrument_var._parameters.DIFFABS_dE), instr_type_double, "1", "",
  "DIFFABS_M1_angle", &(_instrument_var._parameters.DIFFABS_M1_angle), instr_type_double, "0", "",
  "DIFFABS_M1_radius", &(_instrument_var._parameters.DIFFABS_M1_radius), instr_type_double, "1400", "",
  "DIFFABS_M2_radius", &(_instrument_var._parameters.DIFFABS_M2_radius), instr_type_double, "1400", "",
  "DIFFABS_DCM_theta", &(_instrument_var._parameters.DIFFABS_DCM_theta), instr_type_double, "0", "",
  "DIFFABS_sample", &(_instrument_var._parameters.DIFFABS_sample), instr_type_string, "LaB6_660b_AVID2.hkl", "",
  "SIXS_E0", &(_instrument_var._parameters.SIXS_E0), instr_type_double, "13", "",
  "SIXS_dE", &(_instrument_var._parameters.SIXS_dE), instr_type_double, "0.1", "",
  "SIXS_dcm_theta", &(_instrument_var._parameters.SIXS_dcm_theta), instr_type_double, "0", "",
  "SIXS_M1_angle", &(_instrument_var._parameters.SIXS_M1_angle), instr_type_double, "3", "",
  "SIXS_M1_radius", &(_instrument_var._parameters.SIXS_M1_radius), instr_type_double, "1400", "",
  "SIXS_M2_radius", &(_instrument_var._parameters.SIXS_M2_radius), instr_type_double, "1400", "",
  "SIXS_sample_coating", &(_instrument_var._parameters.SIXS_sample_coating), instr_type_string, "Mo.lau", "",
  "SIXS_sample_bulk", &(_instrument_var._parameters.SIXS_sample_bulk), instr_type_string, "Si.lau", "",
  "SIXS_sample_thickness", &(_instrument_var._parameters.SIXS_sample_thickness), instr_type_double, "50e-10", "",
  "SIXS_sample_angle", &(_instrument_var._parameters.SIXS_sample_angle), instr_type_double, "0.175", "",
  "CASSIOPEE_mirror_material", &(_instrument_var._parameters.CASSIOPEE_mirror_material), instr_type_string, "Pt.dat", "",
  "CASSIOPEE_undulator_index", &(_instrument_var._parameters.CASSIOPEE_undulator_index), instr_type_int, "1", "",
  "CASSIOPEE_M1_angle", &(_instrument_var._parameters.CASSIOPEE_M1_angle), instr_type_double, "0", "",
  "CASSIOPEE_PG_angle", &(_instrument_var._parameters.CASSIOPEE_PG_angle), instr_type_double, "0", "",
  "CASSIOPEE_PM_angle", &(_instrument_var._parameters.CASSIOPEE_PM_angle), instr_type_double, "0", "",
  "CASSIOPEE_E0", &(_instrument_var._parameters.CASSIOPEE_E0), instr_type_double, "0", "",
  "CASSIOPEE_dE", &(_instrument_var._parameters.CASSIOPEE_dE), instr_type_double, "1e-3", "",
  "CASSIOPEE_lambda", &(_instrument_var._parameters.CASSIOPEE_lambda), instr_type_double, "0", "",
  "CASSIOPEE_beta_mono", &(_instrument_var._parameters.CASSIOPEE_beta_mono), instr_type_double, "0", "",
  "CASSIOPEE_r_rho", &(_instrument_var._parameters.CASSIOPEE_r_rho), instr_type_double, "0", "",
  "SIRIUS_E0", &(_instrument_var._parameters.SIRIUS_E0), instr_type_double, "8", "",
  "SIRIUS_dE", &(_instrument_var._parameters.SIRIUS_dE), instr_type_double, "0.1", "",
  "SIRIUS_M1_angle", &(_instrument_var._parameters.SIRIUS_M1_angle), instr_type_double, "3", "",
  "SIRIUS_M2_angle", &(_instrument_var._parameters.SIRIUS_M2_angle), instr_type_double, "3", "",
  "SIRIUS_def_angle", &(_instrument_var._parameters.SIRIUS_def_angle), instr_type_double, "2.0", "",
  "SIRIUS_sample_pos", &(_instrument_var._parameters.SIRIUS_sample_pos), instr_type_double, "30", "",
  "SIRIUS_sample", &(_instrument_var._parameters.SIRIUS_sample), instr_type_string, "LaB6.cif", "",
  "LUCIA_E0", &(_instrument_var._parameters.LUCIA_E0), instr_type_double, "3.09", "",
  "LUCIA_dE", &(_instrument_var._parameters.LUCIA_dE), instr_type_double, "0.02", "",
  "LUCIA_dcm_theta", &(_instrument_var._parameters.LUCIA_dcm_theta), instr_type_double, "38.9", "",
  "LUCIA_sample_material", &(_instrument_var._parameters.LUCIA_sample_material), instr_type_string, "CaCO3AlP", "",
  "LUCIA_sample_geometry", &(_instrument_var._parameters.LUCIA_sample_geometry), instr_type_string, "plant_cell.ply", "",
  NULL, NULL, instr_type_double, ""
};

struct metadata_table_struct metadata_table[] = {
  "", "", "", ""
};
int num_metadata = 0;

/* ************************************************************************** */
/*             SHARE user declarations for all components                     */
/* ************************************************************************** */

/* Shared user declarations for all components types 'Text'. */

  /* ------------------------------------------------------------------ */
  /* Stroke font (4 wide x 6 tall grid). NULL = blank (space).          */
  /* Extend it by adding entries here.                                  */
  /* ------------------------------------------------------------------ */
  static const char *glyph[128] = {
      ['A'] = "0,0 2,6 4,0|1,2 3,2",
      ['B'] = "0,6 0,0 3,0 4,1 4,2 3,3 0,3|3,3 4,4 4,5 3,6 0,6",
      ['C'] = "4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1",
      ['D'] = "0,6 0,0 2,0 4,2 4,4 2,6 0,6",
      ['E'] = "4,6 0,6 0,0 4,0|0,3 3,3",
      ['F'] = "4,6 0,6 0,0|0,3 3,3",
      ['G'] = "4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,3 2,3",
      ['H'] = "0,6 0,0|4,6 4,0|0,3 4,3",
      ['I'] = "1,6 3,6|2,6 2,0|1,0 3,0",
      ['J'] = "3,6 3,1 2,0 1,0 0,1",
      ['K'] = "0,6 0,0|0,2 4,6|1,3 4,0",
      ['L'] = "0,6 0,0 4,0",
      ['M'] = "0,0 0,6 2,3 4,6 4,0",
      ['N'] = "0,0 0,6 4,0 4,6",
      ['O'] = "1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,1 1,0",
      ['P'] = "0,0 0,6 3,6 4,5 4,4 3,3 0,3",
      ['Q'] = "1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,1 1,0|2,2 4,0",
      ['R'] = "0,0 0,6 3,6 4,5 4,4 3,3 0,3|2,3 4,0",
      ['S'] = "4,5 3,6 1,6 0,5 0,4 1,3 3,3 4,2 4,1 3,0 1,0 0,1",
      ['T'] = "0,6 4,6|2,6 2,0",
      ['U'] = "0,6 0,1 1,0 3,0 4,1 4,6",
      ['V'] = "0,6 2,0 4,6",
      ['W'] = "0,6 1,0 2,4 3,0 4,6",
      ['X'] = "0,0 4,6|0,6 4,0",
      ['Y'] = "0,6 2,3 4,6|2,3 2,0",
      ['Z'] = "0,6 4,6 0,0 4,0",
      ['0'] = "1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,1 1,0|0,1 4,5",
      ['1'] = "1,5 2,6 2,0|0,0 4,0",
      ['2'] = "0,5 1,6 3,6 4,5 4,4 0,0 4,0",
      ['3'] = "0,6 4,6 2,3 4,0 0,0",
      ['4'] = "3,6 3,0|4,2 0,2 3,6",
      ['5'] = "4,6 0,6 0,3 3,3 4,2 4,1 3,0 0,0",
      ['6'] = "4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,2 3,3 0,3",
      ['7'] = "0,6 4,6 1,0",
      ['8'] = "1,0 3,0 4,1 4,2 3,3 1,3 0,2 0,1 1,0"
              "|1,3 0,4 0,5 1,6 3,6 4,5 4,4 3,3 1,3",
      ['9'] = "0,1 1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,4 1,3 4,3",
      ['-'] = "0,3 4,3",
      ['+'] = "0,3 4,3|2,1 2,5",
      ['.'] = "1,0 1,1",
      [','] = "1,1 2,0",
      [':'] = "1,1 2,1|1,4 2,4",
      ['/'] = "0,0 4,6",
      ['('] = "3,6 2,5 2,1 3,0",
      [')'] = "1,6 2,5 2,1 1,0",
      ['!'] = "2,6 2,1|1,0 3,0",
      ['?'] = "0,5 1,6 3,6 4,5 4,4 2,2 2,0",
      ['_'] = "0,0 4,0",
      ['='] = "0,2 4,2|0,4 4,4",
      ['*'] = "2,2 2,6|0,3 4,5|0,5 4,3",
      [' '] = NULL,
  };

  /* ------------------------------------------------------------------ */
  /* Core: draw one glyph at pen position (u0,0), scaled.                */
  /* plane: 0 = XY, 1 = YZ, 2 = ZX. Text runs along the first axis,       */
  /* letter height grows along the second axis.                          */
  /* ------------------------------------------------------------------ */
  

/* Shared user declarations for all components types 'Bending_magnet'. */
  //  %include "read_table-lib"

  #ifndef MCCODE_BESSELKNU
  #define MCCODE_BESSELKNU 1

  #pragma acc routine seq
  double
  besselKnu (double nu, double x) {
    const double h = 0.5;
    double KK = 0, dK;
    int r = 0;
    const int maxiter = 1000;
    KK = exp (-x) / 2.0;
    dK = 1;
    while (dK > DBL_EPSILON && r < maxiter) {
      r++;
      dK = exp (-x * cosh (r * h)) * cosh (nu * r * h);
      KK += dK;
    }
    #ifndef OPENACC
    if (r >= maxiter) {
      fprintf (stderr, "Warning: Maximum number of iterations exceeded in besselKnu(%g,%g).\n", nu, x);
    }
    #endif
    KK *= h;
    return KK;
  }
  #endif /*MCCODE_BESSELKNU*/

  #ifndef M_SQRT1_2
  #define M_SQRT1_2 0.70710678118654752440
  #endif

/* Shared user declarations for all components types 'Monitor_nD'. */
/*******************************************************************************
*
* McXtrace, x-ray-tracing package
*         Copyright 1997-2013, All rights reserved
*         DTU Physics, Kgs. Lyngby, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Library: share/monitor_nd-lib.h
*
* %Identification
* Written by: EF
* Date: Aug 28, 2002
* Origin: ILL
* Release: McXtrace 0.9
* Version: $Revision$
*
* This file is to be imported by the monitor_nd related components
* It handles some shared functions.
*
* Usage: within SHARE
* %include "monitor_nd-lib"
*
*******************************************************************************/

#ifndef MONITOR_ND_LIB_H

#define MONITOR_ND_LIB_H "$Revision$"
#define MONnD_COORD_NMAX  30  /* max number of variables to record */

  typedef struct MonitornD_Defines
  {
    int COORD_NONE  ;
    int COORD_X     ;
    int COORD_Y     ;
    int COORD_Z     ;
    int COORD_RADIUS; 
    int COORD_VX    ;
    int COORD_VY    ;
    int COORD_VZ    ;
    int COORD_V     ;
    int COORD_T     ;
    int COORD_P     ;
    int COORD_EX    ;
    int COORD_EY    ;
    int COORD_EZ    ;
    int COORD_KX    ;
    int COORD_KY    ;
    int COORD_KZ    ;
    int COORD_K     ;
    int COORD_ENERGY;
    int COORD_LAMBDA;
    int COORD_KXY   ;
    int COORD_KYZ   ;
    int COORD_KXZ   ;
    int COORD_VXY   ;
    int COORD_VYZ   ;
    int COORD_VXZ   ;
    int COORD_HDIV  ;
    int COORD_VDIV  ;
    int COORD_ANGLE ;
    int COORD_NCOUNT;
    int COORD_THETA ;
    int COORD_PHI   ;
    int COORD_USER0 ;
    int COORD_USER1 ;
    int COORD_USER2 ;
    int COORD_USER3 ;
    int COORD_USER4 ;
    int COORD_USER5 ;
    int COORD_USER6 ;
    int COORD_USER7 ;
    int COORD_USER8 ;
    int COORD_USER9 ;
    int COORD_USERDOUBLE0 ;
    int COORD_USERDOUBLE1 ;
    int COORD_USERDOUBLE2 ;
    int COORD_USERDOUBLE3 ;
    int COORD_USERDOUBLE4 ;
    int COORD_USERDOUBLE5 ;
    int COORD_USERDOUBLE6 ;
    int COORD_USERDOUBLE7 ;
    int COORD_USERDOUBLE8 ;
    int COORD_USERDOUBLE9 ;
    int COORD_USERDOUBLE10 ;
    int COORD_USERDOUBLE11 ;
    int COORD_USERDOUBLE12 ;
    int COORD_USERDOUBLE13 ;
    int COORD_USERDOUBLE14 ;
    int COORD_USERDOUBLE15 ;
    int COORD_XY    ;
    int COORD_XZ    ;
    int COORD_YZ    ;
    int COORD_PHASE ;
    int COORD_PIXELID;

    /* token modifiers */
    int COORD_VAR   ; /* next token should be a variable or normal option */
    int COORD_MIN   ; /* next token is a min value */
    int COORD_MAX   ; /* next token is a max value */
    int COORD_DIM   ; /* next token is a bin value */
    int COORD_FIL   ; /* next token is a filename */
    int COORD_EVNT  ; /* next token is a buffer size value */
    //int COORD_3HE   ; /* next token is a 3He pressure value */
    int COORD_LOG   ; /* next variable will be in log scale */
    int COORD_ABS   ; /* next variable will be in abs scale */
    int COORD_SIGNAL; /* next variable will be the signal var */
    int COORD_AUTO  ; /* set auto limits */

    char TOKEN_DEL[32]; /* token separators */

    char SHAPE_SQUARE; /* shape of the monitor */
    char SHAPE_DISK  ;
    char SHAPE_SPHERE;
    char SHAPE_CYLIND;
    char SHAPE_BANANA; /* cylinder without top/bottom, on restricted angular area */
    char SHAPE_BOX   ;
    char SHAPE_PREVIOUS;
    char SHAPE_OFF;

  } MonitornD_Defines_type;

  typedef struct MonitornD_Variables
  {
    double area;
    double Sphere_Radius     ;
    double Cylinder_Height   ;
    char   Flag_With_Borders ;   /* 2 means xy borders too */
    char   Flag_List         ;   /* 1 store 1 buffer, 2 is list all, 3 list all+append */
    char   Flag_Multiple     ;   /* 1 when n1D, 0 for 2D */
    char   Flag_Verbose      ;
    int    Flag_Shape        ;
    char   Flag_Auto_Limits  ;   /* get limits from first Buffer */
    char   Flag_Absorb       ;   /* monitor is also a slit */
    char   Flag_per_cm2      ;   /* flux is per cm2 */
    char   Flag_log          ;   /* log10 of the flux */
    char   Flag_parallel     ;   /* set photon state back after detection (parallel components) */
    char   Flag_Binary_List  ;
    char   Flag_capture      ;   /* lambda monitor with lambda/lambda(2200m/s = 1.7985 Angs) weightening */
    int    Flag_signal       ;   /* 0:monitor p, else monitor a mean value */
    int    Flag_OFF          ;   /* Flag to indicate external geometry from OFF file */
    unsigned long OFF_polyidx;   /* When intersection is done externally by off_intersect, this gives the 
				    polygon number, i.e. pixel index */

    unsigned long Coord_Number      ;   /* total number of variables to monitor, plus intensity (0) */
    unsigned long Coord_NumberNoPixel;  /* same but without counting PixelID */
    unsigned long Buffer_Block      ;   /* Buffer size for list or auto limits */
    unsigned long Photon_Counter    ;   /* event counter, simulation total counts is mcget_ncount() */
    unsigned long Buffer_Counter    ;   /* index in Buffer size (for realloc) */
    unsigned long Buffer_Size       ;
    int    Coord_Type[MONnD_COORD_NMAX];      /* type of variable */
    char   Coord_Label[MONnD_COORD_NMAX][30]; /* label of variable */
    char   Coord_Var[MONnD_COORD_NMAX][30];   /* short id of variable */
    long   Coord_Bin[MONnD_COORD_NMAX];       /* bins of variable array */
    long   Coord_BinProd[MONnD_COORD_NMAX];   /* product of bins of variable array */
    double Coord_Min[MONnD_COORD_NMAX];
    double Coord_Max[MONnD_COORD_NMAX];
    char   Monitor_Label[MONnD_COORD_NMAX*30];/* Label for monitor */
    char   Mon_File[128];                     /* output file name */

    /* these don't seem to be used anymore as they are superseded by _particle
    double cx, cy, cz;
    double cvx, cvy, cvz;
    double ckx, cky, ckz;
    double cEx, cEy, cEz;
    double ct, cphi, cp;*/
    double He3_pressure;
    char   Flag_UsePreMonitor    ;   /* use a previously stored photon parameter set */
    char   UserName0[128];
    char   UserName1[128];
    char   UserName2[128];
    char   UserName3[128];
    char   UserName4[128];
    char   UserName5[128];
    char   UserName6[128];
    char   UserName7[128];
    char   UserName8[128];
    char   UserName9[128];
    char   UserVariable0[128];
    char   UserVariable1[128];
    char   UserVariable2[128];
    char   UserVariable3[128];
    char   UserVariable4[128];
    char   UserVariable5[128];
    char   UserVariable6[128];
    char   UserVariable7[128];
    char   UserVariable8[128];
    char   UserVariable9[128];
    char   option[CHAR_BUF_LENGTH];

    long long int Nsum;
    double psum, p2sum;
    double **Mon2D_N;
    double **Mon2D_p;
    double **Mon2D_p2;
    double *Mon2D_Buffer;
    unsigned long PixelID;

    double mxmin,mxmax,mymin,mymax,mzmin,mzmax;
    double mean_dx, mean_dy, min_x, min_y, max_x, max_y, mean_p;

    char   compcurname[128];
    Coords compcurpos;
    Rotation compcurrot;
    int compcurindex;
  } MonitornD_Variables_type;

/* monitor_nd-lib function prototypes */
/* ========================================================================= */

void Monitor_nD_Init(MonitornD_Defines_type *, MonitornD_Variables_type *, MCNUM, MCNUM, MCNUM, MCNUM, MCNUM, MCNUM, MCNUM, MCNUM, MCNUM, int);
#pragma acc routine
int Monitor_nD_Trace(MonitornD_Defines_type *, MonitornD_Variables_type *, _class_particle* _particle);
MCDETECTOR Monitor_nD_Save(MonitornD_Defines_type *, MonitornD_Variables_type *);
void Monitor_nD_Finally(MonitornD_Defines_type *, MonitornD_Variables_type *);
void Monitor_nD_McDisplay(MonitornD_Defines_type *, MonitornD_Variables_type *);

#endif

/* end of monitor_nd-lib.h */
/*******************************************************************************
*
* McXtrace, x-ray-tracing package
*         Copyright 1997-2013, All rights reserved
*         DTU Physics, Kgs. Lyngby, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Library: share/monitor_nd-lib.c
*
* %Identification
* Written by: EF
* Date: Aug 28, 2002
* Origin: ILL
* Release: McXtrace 0.9
* Version: $Revision$
*
* This file is to be imported by the monitor_nd related components
* It handles some shared functions. Embedded within instrument in runtime mode.
*
* Usage: within SHARE
* %include "monitor_nd-lib"
*
*******************************************************************************/

#ifndef MONITOR_ND_LIB_H
#error McXtrace : please import this library with %include "monitor_nd-lib"
#endif

/* ========================================================================= */
/* Monitor_nD_Init: this routine is used to parse options                    */
/* ========================================================================= */

void Monitor_nD_Init(MonitornD_Defines_type *DEFS,
  MonitornD_Variables_type *Vars,
  MCNUM xwidth,
  MCNUM yheight,
  MCNUM zdepth,
  MCNUM xmin,
  MCNUM xmax,
  MCNUM ymin,
  MCNUM ymax,
  MCNUM zmin,
  MCNUM zmax,
  int offflag)
  {
    long carg = 1;
    char *option_copy, *token;
    char Flag_New_token = 1;
    char Flag_End       = 1;
    char Flag_All       = 0;
    char Flag_No        = 0;
    char Flag_abs       = 0;
    int  Flag_auto      = 0;  /* -1: all, 1: the current variable */
    int  Set_Vars_Coord_Type;
    char Set_Vars_Coord_Label[64];
    char Set_Vars_Coord_Var[64];
    char Short_Label[MONnD_COORD_NMAX][64];
    int  Set_Coord_Mode;
    long i=0, j=0;
    double lmin, lmax, XY=0;
    long t;


    t = (long)time(NULL);

/* initialize DEFS */
/* Variables to monitor */
    DEFS->COORD_NONE   =0;
    DEFS->COORD_X      =1;
    DEFS->COORD_Y      =2;
    DEFS->COORD_Z      =3;
    DEFS->COORD_RADIUS =19;
    DEFS->COORD_VX     =4;
    DEFS->COORD_VY     =5;
    DEFS->COORD_VZ     =6;
    DEFS->COORD_V      =16;
    DEFS->COORD_PHASE  =39;
    DEFS->COORD_T      =7;
    DEFS->COORD_P      =8;
    DEFS->COORD_EX     =9;
    DEFS->COORD_EY     =10;
    DEFS->COORD_EZ     =11;
    DEFS->COORD_KX     =12;
    DEFS->COORD_KY     =13;
    DEFS->COORD_KZ     =14;
    DEFS->COORD_K      =15;
    DEFS->COORD_ENERGY =17;
    DEFS->COORD_LAMBDA =18;
    DEFS->COORD_HDIV   =20;
    DEFS->COORD_VDIV   =21;
    DEFS->COORD_ANGLE  =22;
    DEFS->COORD_NCOUNT =23;
    DEFS->COORD_THETA  =24;
    DEFS->COORD_PHI    =25;
    DEFS->COORD_USER0  =55;
    DEFS->COORD_USER1  =26;
    DEFS->COORD_USER2  =27;
    DEFS->COORD_USER3  =28;
    DEFS->COORD_USER4  =56;
    DEFS->COORD_USER5  =57;
    DEFS->COORD_USER6  =58;
    DEFS->COORD_USER7  =59;
    DEFS->COORD_USER8  =60;
    DEFS->COORD_USER9  =61;
    DEFS->COORD_XY     =37;
    DEFS->COORD_YZ     =31;
    DEFS->COORD_XZ     =32;
    DEFS->COORD_VXY    =30;
    DEFS->COORD_VYZ    =34;
    DEFS->COORD_VXZ    =36;
    DEFS->COORD_KXY    =29;
    DEFS->COORD_KYZ    =33;
    DEFS->COORD_KXZ    =35;
    DEFS->COORD_PIXELID=38;

/* token modifiers */
    DEFS->COORD_VAR    =0;    /* next token should be a variable or normal option */
    DEFS->COORD_MIN    =1;    /* next token is a min value */
    DEFS->COORD_MAX    =2;    /* next token is a max value */
    DEFS->COORD_DIM    =3;    /* next token is a bin value */
    DEFS->COORD_FIL    =4;    /* next token is a filename */
    DEFS->COORD_EVNT   =5;    /* next token is a buffer size value */
    //DEFS->COORD_3HE    =6;    /* next token is a 3He pressure value */
    DEFS->COORD_LOG    =64;   /* next variable will be in log scale */
    DEFS->COORD_ABS    =128;  /* next variable will be in abs scale */
    DEFS->COORD_SIGNAL =256;  /* next variable will be the signal var */
    DEFS->COORD_AUTO   =512;  /* set auto limits */

    strcpy(DEFS->TOKEN_DEL, " =,;[](){}:");  /* token separators */

    DEFS->SHAPE_SQUARE =0;    /* shape of the monitor */
    DEFS->SHAPE_DISK   =1;
    DEFS->SHAPE_SPHERE =2;
    DEFS->SHAPE_CYLIND =3;
    DEFS->SHAPE_BANANA =4;
    DEFS->SHAPE_BOX    =5;
    DEFS->SHAPE_PREVIOUS=6;
    DEFS->SHAPE_OFF=7;

    Vars->Sphere_Radius     = 0;
    Vars->Cylinder_Height   = 0;
    Vars->Flag_With_Borders = 0;   /* 2 means xy borders too */
    Vars->Flag_List         = 0;   /* 1=store 1 buffer, 2=list all, 3=re-use buffer */
    Vars->Flag_Multiple     = 0;   /* 1 when n1D, 0 for 2D */
    Vars->Flag_Verbose      = 0;
    Vars->Flag_Shape        = DEFS->SHAPE_SQUARE;
    Vars->Flag_Auto_Limits  = 0;   /* get limits from first Buffer */
    Vars->Flag_Absorb       = 0;   /* monitor is also a slit */
    Vars->Flag_per_cm2      = 0;   /* flux is per cm2 */
    Vars->Flag_log          = 0;   /* log10 of the flux */
    Vars->Flag_parallel     = 0;   /* set photon state back after detection (parallel components) */
    Vars->Flag_Binary_List  = 0;   /* save list as a binary file (smaller) */
    Vars->Coord_Number      = 0;   /* total number of variables to monitor, plus intensity (0) */
    Vars->Coord_NumberNoPixel=0;   /* same but without counting PixelID */

	Vars->Buffer_Block      = MONND_BUFSIZ;     /* Buffer size for list or auto limits */	
    Vars->Photon_Counter   = 0;   /* event counter, simulation total counts is mcget_ncount() */
    Vars->Buffer_Counter    = 0;   /* index in Buffer size (for realloc) */
    Vars->Buffer_Size       = 0;
    Vars->He3_pressure      = 0;
    Vars->Flag_capture      = 0;
    Vars->Flag_signal       = DEFS->COORD_P;
    Vars->Flag_OFF          = offflag;
    Vars->OFF_polyidx       = -1;
    Vars->mean_dx=Vars->mean_dy=0;
    Vars->min_x = Vars->max_x  =0;
    Vars->min_y = Vars->max_y  =0;

    Set_Vars_Coord_Type = DEFS->COORD_NONE;
    Set_Coord_Mode = DEFS->COORD_VAR;

    /* handle size parameters */
    /* normal use is with xwidth, yheight, zdepth */
    /* if xmin,xmax,ymin,ymax,zmin,zmax are non 0, use them */
    if (fabs(xmin-xmax) == 0)
      { Vars->mxmin = -fabs(xwidth)/2; Vars->mxmax = fabs(xwidth)/2; }
    else
      { if (xmin < xmax) {Vars->mxmin = xmin; Vars->mxmax = xmax;}
        else {Vars->mxmin = xmax; Vars->mxmax = xmin;}
      }
    if (fabs(ymin-ymax) == 0)
      { Vars->mymin = -fabs(yheight)/2; Vars->mymax = fabs(yheight)/2; }
    else
      { if (ymin < ymax) {Vars->mymin = ymin; Vars->mymax = ymax;}
        else {Vars->mymin = ymax; Vars->mymax = ymin;}
      }
    if (fabs(zmin-zmax) == 0)
      { Vars->mzmin = -fabs(zdepth)/2; Vars->mzmax = fabs(zdepth)/2; }
    else
      { if (zmin < zmax) {Vars->mzmin = zmin; Vars->mzmax = zmax; }
        else {Vars->mzmin = zmax; Vars->mzmax = zmin; }
      }

    if (fabs(Vars->mzmax-Vars->mzmin) == 0)
      Vars->Flag_Shape        = DEFS->SHAPE_SQUARE;
    else
      Vars->Flag_Shape        = DEFS->SHAPE_BOX;

    if (Vars->Flag_OFF) {
      Vars->Flag_Shape        = DEFS->SHAPE_OFF;
    }
    
    /* parse option string */

    option_copy = (char*)malloc(strlen(Vars->option)+1);
    if (option_copy == NULL)
    {
      fprintf(stderr,"Monitor_nD: %s cannot allocate 'options' copy (%li). Fatal.\n", Vars->compcurname, (long)strlen(Vars->option));
      exit(-1);
    }

    if (strlen(Vars->option))
    {
      Flag_End = 0;
      strcpy(option_copy, Vars->option);
    }

    if (strstr(Vars->option, "cm2") || strstr(Vars->option, "cm^2")) Vars->Flag_per_cm2 = 1;

    if (strstr(Vars->option, "binary") || strstr(Vars->option, "float"))
      Vars->Flag_Binary_List  = 1;
    if (strstr(Vars->option, "double"))
      Vars->Flag_Binary_List  = 2;

    strcpy(Vars->Coord_Label[0], "Intensity");
    strncpy(Vars->Coord_Var[0], "p", 30);
    Vars->Coord_Type[0] = DEFS->COORD_P;
    Vars->Coord_Bin[0] = 1;
    Vars->Coord_Min[0] = 0;
    Vars->Coord_Max[0] = FLT_MAX;

    /* default file name is comp_name+dateID */
    sprintf(Vars->Mon_File, "%s_%li", Vars->compcurname, t);

    carg = 1;
    while((Flag_End == 0) && (carg < 128))
    {
      if (Flag_New_token) /* retain previous token or get a new one */
      {
        if (carg == 1) token=(char *)strtok(option_copy,DEFS->TOKEN_DEL);
        else token=(char *)strtok(NULL,DEFS->TOKEN_DEL);
        if (token == NULL) Flag_End=1;
      }
      Flag_New_token = 1;
      if ((token != NULL) && (strlen(token) != 0))
      {
        char iskeyword=0; /* left at 0 when variables are processed, 1 for modifiers */
        int  old_Mode;
        /* change token to lower case */
        for (i=0; i<strlen(token); i++) token[i]=tolower(token[i]);
        /* first handle option values from preceeding keyword token detected */
        old_Mode = Set_Coord_Mode;
        if (Set_Coord_Mode == DEFS->COORD_MAX)  /* max=%i */
        {
          if (!Flag_All)
            Vars->Coord_Max[Vars->Coord_Number] = atof(token);
          else
            for (i = 0; i <= Vars->Coord_Number; Vars->Coord_Max[i++] = atof(token));
          Set_Coord_Mode = DEFS->COORD_VAR; Flag_All = 0;
        }
        if (Set_Coord_Mode == DEFS->COORD_MIN)  /* min=%i */
        {
          if (!Flag_All)
            Vars->Coord_Min[Vars->Coord_Number] = atof(token);
          else
            for (i = 0; i <= Vars->Coord_Number; Vars->Coord_Min[i++] = atof(token));
          Set_Coord_Mode = DEFS->COORD_MAX;
        }
        if (Set_Coord_Mode == DEFS->COORD_DIM)  /* bins=%i */
        {
          if (!Flag_All)
            Vars->Coord_Bin[Vars->Coord_Number] = atoi(token);
          else
            for (i = 0; i <= Vars->Coord_Number; Vars->Coord_Bin[i++] = atoi(token));
          Set_Coord_Mode = DEFS->COORD_VAR; Flag_All = 0;
        }
        if (Set_Coord_Mode == DEFS->COORD_FIL)  /* file=%s */
        {
          if (!Flag_No) strncpy(Vars->Mon_File,token,128);
          else { strcpy(Vars->Mon_File,""); Vars->Coord_Number = 0; Flag_End = 1;}
          Set_Coord_Mode = DEFS->COORD_VAR;
        }
        if (Set_Coord_Mode == DEFS->COORD_EVNT) /* list=%i */
        {
          if (!strcmp(token, "all") || Flag_All) Vars->Flag_List = 2;
          else { i = (long)ceil(atof(token)); if (i) Vars->Buffer_Block = i;
            Vars->Flag_List = 1; }
          Set_Coord_Mode = DEFS->COORD_VAR; Flag_All = 0;
        }
        /*if (Set_Coord_Mode == DEFS->COORD_3HE)*/  /* pressure=%g */
        /*{*/
        /*    Vars->He3_pressure = atof(token);*/
        /*    Set_Coord_Mode = DEFS->COORD_VAR; Flag_All = 0;*/
        /*}*/

        /* now look for general option keywords */
        if (!strcmp(token, "borders"))  {Vars->Flag_With_Borders = 1; iskeyword=1; }
        if (!strcmp(token, "verbose"))  {Vars->Flag_Verbose      = 1; iskeyword=1; }
        if (!strcmp(token, "log"))      {Vars->Flag_log          = 1; iskeyword=1; }
        if (!strcmp(token, "abs"))      {Flag_abs                = 1; iskeyword=1; }
        if (!strcmp(token, "multiple")) {Vars->Flag_Multiple     = 1; iskeyword=1; }
        if (!strcmp(token, "list") || !strcmp(token, "events")) {
          Vars->Flag_List = 1; Set_Coord_Mode = DEFS->COORD_EVNT;  }
        if (!strcmp(token, "limits") || !strcmp(token, "min"))
          Set_Coord_Mode = DEFS->COORD_MIN;
        if (!strcmp(token, "slit") || !strcmp(token, "absorb")) {
          Vars->Flag_Absorb = 1;  iskeyword=1; }
        if (!strcmp(token, "max"))  Set_Coord_Mode = DEFS->COORD_MAX;
        if (!strcmp(token, "bins") || !strcmp(token, "dim")) Set_Coord_Mode = DEFS->COORD_DIM;
        if (!strcmp(token, "file") || !strcmp(token, "filename")) {
          Set_Coord_Mode = DEFS->COORD_FIL;
          if (Flag_No) { strcpy(Vars->Mon_File,""); Vars->Coord_Number = 0; Flag_End = 1; }
        }
        if (!strcmp(token, "inactivate")) {
          Flag_End = 1; Vars->Coord_Number = 0; iskeyword=1; }
        if (!strcmp(token, "all"))    { Flag_All = 1;  iskeyword=1; }
        if (!strcmp(token, "sphere")) { Vars->Flag_Shape = DEFS->SHAPE_SPHERE; iskeyword=1; }
        if (!strcmp(token, "cylinder")) { Vars->Flag_Shape = DEFS->SHAPE_CYLIND; iskeyword=1; }
        if (!strcmp(token, "banana")) { Vars->Flag_Shape = DEFS->SHAPE_BANANA; iskeyword=1; }
        if (!strcmp(token, "square")) { Vars->Flag_Shape = DEFS->SHAPE_SQUARE; iskeyword=1; }
        if (!strcmp(token, "disk"))   { Vars->Flag_Shape = DEFS->SHAPE_DISK; iskeyword=1; }
        if (!strcmp(token, "box"))     { Vars->Flag_Shape = DEFS->SHAPE_BOX; iskeyword=1; }
        if (!strcmp(token, "previous")) { Vars->Flag_Shape = DEFS->SHAPE_PREVIOUS; iskeyword=1; }
        if (!strcmp(token, "parallel")){ Vars->Flag_parallel = 1; iskeyword=1; }
        if (!strcmp(token, "capture")) { Vars->Flag_capture = 1; iskeyword=1; }
        if (!strcmp(token, "auto")) { 
        #ifndef OPENACC
          if (Flag_auto != -1) {
	    Vars->Flag_Auto_Limits = 1;
	    if (Flag_All) Flag_auto = -1;
	    else          Flag_auto = 1;
	    iskeyword=1; Flag_All=0;
	  }
	#endif
	}
        if (!strcmp(token, "premonitor")) {
          Vars->Flag_UsePreMonitor = 1; iskeyword=1; }
        if (!strcmp(token, "3He_pressure") || !strcmp(token, "pressure")) {
          Vars->He3_pressure = 3; iskeyword=1; }
        if (!strcmp(token, "no") || !strcmp(token, "not")) { Flag_No = 1;  iskeyword=1; }
        if (!strcmp(token, "signal")) Set_Coord_Mode = DEFS->COORD_SIGNAL;

        /* Mode has changed: this was a keyword or value  ? */
        if (Set_Coord_Mode != old_Mode) iskeyword=1;

        /* now look for variable names to monitor */
        Set_Vars_Coord_Type = DEFS->COORD_NONE; lmin = 0; lmax = 0;

        if (!strcmp(token, "x"))
          { Set_Vars_Coord_Type = DEFS->COORD_X; strcpy(Set_Vars_Coord_Label,"x [m]"); strcpy(Set_Vars_Coord_Var,"x");
          lmin = Vars->mxmin; lmax = Vars->mxmax;
          Vars->Coord_Min[Vars->Coord_Number+1] = Vars->mxmin;
          Vars->Coord_Max[Vars->Coord_Number+1] = Vars->mxmax;}
        if (!strcmp(token, "y"))
          { Set_Vars_Coord_Type = DEFS->COORD_Y; strcpy(Set_Vars_Coord_Label,"y [m]"); strcpy(Set_Vars_Coord_Var,"y");
          lmin = Vars->mymin; lmax = Vars->mymax;
          Vars->Coord_Min[Vars->Coord_Number+1] = Vars->mymin;
          Vars->Coord_Max[Vars->Coord_Number+1] = Vars->mymax;}
        if (!strcmp(token, "z"))
          { Set_Vars_Coord_Type = DEFS->COORD_Z; strcpy(Set_Vars_Coord_Label,"z [m]"); strcpy(Set_Vars_Coord_Var,"z"); lmin = Vars->mzmin; lmax = Vars->mzmax; }
        if (!strcmp(token, "k") || !strcmp(token, "wavevector"))
          { Set_Vars_Coord_Type = DEFS->COORD_K; strcpy(Set_Vars_Coord_Label,"|k| [Angs-1]"); strcpy(Set_Vars_Coord_Var,"k"); lmin = 0; lmax = 10; }
        if (!strcmp(token, "v"))
          { Set_Vars_Coord_Type = DEFS->COORD_V; strcpy(Set_Vars_Coord_Label,"Velocity [m/s]"); strcpy(Set_Vars_Coord_Var,"v"); lmin = 0; lmax = 10000; }
        if (!strcmp(token, "t") || !strcmp(token, "time") || !strcmp(token, "tof"))
          { Set_Vars_Coord_Type = DEFS->COORD_T; strcpy(Set_Vars_Coord_Label,"TOF [s]"); strcpy(Set_Vars_Coord_Var,"t"); lmin = 0; lmax = .1; }
        if (!strcmp(token, "phase"))
        { Set_Vars_Coord_Type = DEFS->COORD_PHASE; strcpy(Set_Vars_Coord_Label,"phase [rad]"); strcpy(Set_Vars_Coord_Var,"pha"); lmin = 0; lmax = 2*M_PI; }
        /* "intensity"/"flux" only name the default signal: a variable after "signal=", else a no-op word (#2445) */
        if (!strcmp(token, "p") || !strcmp(token, "i")
         || ((!strcmp(token, "intensity") || !strcmp(token, "flux")) && Set_Coord_Mode == DEFS->COORD_SIGNAL))
          { Set_Vars_Coord_Type = DEFS->COORD_P;
            strcpy(Set_Vars_Coord_Label,"Intensity");
            strncat(Set_Vars_Coord_Label, " [p/s", 30);
            if (Vars->Flag_per_cm2) strncat(Set_Vars_Coord_Label, "/cm2", 30);
            if (XY > 1 && Vars->Coord_Number)
              strncat(Set_Vars_Coord_Label, "/bin", 30);
            strncat(Set_Vars_Coord_Label, "]", 30);
            strcpy(Set_Vars_Coord_Var,"I");
            lmin = 0; lmax = FLT_MAX;
            if (Flag_auto>0) Flag_auto=0;
          }
        else if (!strcmp(token, "intensity") || !strcmp(token, "flux")) iskeyword=1;

        if (!strcmp(token, "vx"))
          { Set_Vars_Coord_Type = DEFS->COORD_VX; strcpy(Set_Vars_Coord_Label,"vx [m/s]"); strcpy(Set_Vars_Coord_Var,"vx"); lmin = -1000; lmax = 1000; }
        if (!strcmp(token, "vy"))
          { Set_Vars_Coord_Type = DEFS->COORD_VY; strcpy(Set_Vars_Coord_Label,"vy [m/s]"); strcpy(Set_Vars_Coord_Var,"vy"); lmin = -1000; lmax = 1000; }
        if (!strcmp(token, "vz"))
          { Set_Vars_Coord_Type = DEFS->COORD_VZ; strcpy(Set_Vars_Coord_Label,"vz [m/s]"); strcpy(Set_Vars_Coord_Var,"vz"); lmin = -10000; lmax = 10000; }
        if (!strcmp(token, "kx"))
          { Set_Vars_Coord_Type = DEFS->COORD_KX; strcpy(Set_Vars_Coord_Label,"kx [Angs-1]"); strcpy(Set_Vars_Coord_Var,"kx"); lmin = -1; lmax = 1; }
        if (!strcmp(token, "ky"))
          { Set_Vars_Coord_Type = DEFS->COORD_KY; strcpy(Set_Vars_Coord_Label,"ky [Angs-1]"); strcpy(Set_Vars_Coord_Var,"ky"); lmin = -1; lmax = 1; }
        if (!strcmp(token, "kz"))
          { Set_Vars_Coord_Type = DEFS->COORD_KZ; strcpy(Set_Vars_Coord_Label,"kz [Angs-1]"); strcpy(Set_Vars_Coord_Var,"kz"); lmin = -10; lmax = 10; }
        if (!strcmp(token, "Ex"))
          { Set_Vars_Coord_Type = DEFS->COORD_EX; strcpy(Set_Vars_Coord_Label,"Ex [1]"); strcpy(Set_Vars_Coord_Var,"Ex"); lmin = -1; lmax = 1; }
        if (!strcmp(token, "Ey"))
          { Set_Vars_Coord_Type = DEFS->COORD_EY; strcpy(Set_Vars_Coord_Label,"Ey [1]"); strcpy(Set_Vars_Coord_Var,"Ey"); lmin = -1; lmax = 1; }
        if (!strcmp(token, "Ez"))
          { Set_Vars_Coord_Type = DEFS->COORD_EZ; strcpy(Set_Vars_Coord_Label,"Ez [1]"); strcpy(Set_Vars_Coord_Var,"Ez"); lmin = -1; lmax = 1; }

        if (!strcmp(token, "energy") || !strcmp(token, "omega") || !strcmp(token, "e"))
          { Set_Vars_Coord_Type = DEFS->COORD_ENERGY; strcpy(Set_Vars_Coord_Label,"Energy [keV]"); strcpy(Set_Vars_Coord_Var,"E"); lmin = 0; lmax = 100; }
        if (!strcmp(token, "lambda") || !strcmp(token, "wavelength") || !strcmp(token, "l"))
          { Set_Vars_Coord_Type = DEFS->COORD_LAMBDA; strcpy(Set_Vars_Coord_Label,"Wavelength [Angs]"); strcpy(Set_Vars_Coord_Var,"L"); lmin = 0; lmax = 100; }
        if (!strcmp(token, "radius") || !strcmp(token, "r"))
          { Set_Vars_Coord_Type = DEFS->COORD_RADIUS; strcpy(Set_Vars_Coord_Label,"Radius [m]"); strcpy(Set_Vars_Coord_Var,"xy"); lmin = 0; lmax = xmax; }
        if (!strcmp(token, "xy"))
          { Set_Vars_Coord_Type = DEFS->COORD_XY; strcpy(Set_Vars_Coord_Label,"Radius (xy) [m]"); strcpy(Set_Vars_Coord_Var,"xy"); lmin = 0; lmax = xmax; }
        if (!strcmp(token, "yz"))
          { Set_Vars_Coord_Type = DEFS->COORD_YZ; strcpy(Set_Vars_Coord_Label,"Radius (yz) [m]"); strcpy(Set_Vars_Coord_Var,"yz"); lmin = 0; lmax = xmax; }
        if (!strcmp(token, "xz"))
          { Set_Vars_Coord_Type = DEFS->COORD_XZ; strcpy(Set_Vars_Coord_Label,"Radius (xz) [m]"); strcpy(Set_Vars_Coord_Var,"xz"); lmin = 0; lmax = xmax; }
        if (!strcmp(token, "vxy"))
          { Set_Vars_Coord_Type = DEFS->COORD_VXY; strcpy(Set_Vars_Coord_Label,"Radial Velocity (xy) [m]"); strcpy(Set_Vars_Coord_Var,"Vxy"); lmin = 0; lmax = 2000; }
        if (!strcmp(token, "kxy"))
          { Set_Vars_Coord_Type = DEFS->COORD_KXY; strcpy(Set_Vars_Coord_Label,"Radial Wavevector (xy) [Angs-1]"); strcpy(Set_Vars_Coord_Var,"Kxy"); lmin = 0; lmax = 2; }
        if (!strcmp(token, "vyz"))
          { Set_Vars_Coord_Type = DEFS->COORD_VYZ; strcpy(Set_Vars_Coord_Label,"Radial Velocity (yz) [m]"); strcpy(Set_Vars_Coord_Var,"Vyz"); lmin = 0; lmax = 2000; }
        if (!strcmp(token, "kyz"))
          { Set_Vars_Coord_Type = DEFS->COORD_KYZ; strcpy(Set_Vars_Coord_Label,"Radial Wavevector (yz) [Angs-1]"); strcpy(Set_Vars_Coord_Var,"Kyz"); lmin = 0; lmax = 2; }
        if (!strcmp(token, "vxz"))
          { Set_Vars_Coord_Type = DEFS->COORD_VXZ; strcpy(Set_Vars_Coord_Label,"Radial Velocity (xz) [m]"); strcpy(Set_Vars_Coord_Var,"Vxz"); lmin = 0; lmax = 2000; }
        if (!strcmp(token, "kxz"))
          { Set_Vars_Coord_Type = DEFS->COORD_KXZ; strcpy(Set_Vars_Coord_Label,"Radial Wavevector (xz) [Angs-1]"); strcpy(Set_Vars_Coord_Var,"Kxz"); lmin = 0; lmax = 2; }
        if (!strcmp(token, "angle") || !strcmp(token, "a"))
          { Set_Vars_Coord_Type = DEFS->COORD_ANGLE; strcpy(Set_Vars_Coord_Label,"Angle [deg]"); strcpy(Set_Vars_Coord_Var,"A"); lmin = -50; lmax = 50; }
        if (!strcmp(token, "hdiv")|| !strcmp(token, "divergence") || !strcmp(token, "xdiv") || !strcmp(token, "hd") || !strcmp(token, "dx"))
          { Set_Vars_Coord_Type = DEFS->COORD_HDIV; strcpy(Set_Vars_Coord_Label,"Hor. Divergence [deg]"); strcpy(Set_Vars_Coord_Var,"hd"); lmin = -5; lmax = 5; }
        if (!strcmp(token, "vdiv") || !strcmp(token, "ydiv") || !strcmp(token, "vd") || !strcmp(token, "dy"))
          { Set_Vars_Coord_Type = DEFS->COORD_VDIV; strcpy(Set_Vars_Coord_Label,"Vert. Divergence [deg]"); strcpy(Set_Vars_Coord_Var,"vd"); lmin = -5; lmax = 5; }
        if (!strcmp(token, "theta") || !strcmp(token, "longitude") || !strcmp(token, "th"))
          { Set_Vars_Coord_Type = DEFS->COORD_THETA; strcpy(Set_Vars_Coord_Label,"Longitude [deg]"); strcpy(Set_Vars_Coord_Var,"th"); lmin = -180; lmax = 180; }
        if (!strcmp(token, "phi") || !strcmp(token, "latitude") || !strcmp(token, "ph"))
          { Set_Vars_Coord_Type = DEFS->COORD_PHI; strcpy(Set_Vars_Coord_Label,"Latitude [deg]"); strcpy(Set_Vars_Coord_Var,"ph"); lmin = -90; lmax = 90; }
        if (!strcmp(token, "ncounts") || !strcmp(token, "n") || !strcmp(token, "photon"))
          { Set_Vars_Coord_Type = DEFS->COORD_NCOUNT; strcpy(Set_Vars_Coord_Label,"Photon ID [1]"); strcpy(Set_Vars_Coord_Var,"n"); lmin = 0; lmax = mcget_ncount(); if (Flag_auto>0) Flag_auto=0; }
        if (!strcmp(token, "id") || !strcmp(token, "pixel"))
          { Set_Vars_Coord_Type = DEFS->COORD_PIXELID; 
            strcpy(Set_Vars_Coord_Label,"Pixel ID [1]"); 
            strcpy(Set_Vars_Coord_Var,"id"); lmin = 0; lmax = FLT_MAX; 
            if (Flag_auto>0) Flag_auto=0;
            Vars->Flag_List = 1; }
	if (!strcmp(token, "user0") || !strcmp(token, "u0"))
          { Set_Vars_Coord_Type = DEFS->COORD_USER0; strncpy(Set_Vars_Coord_Label,Vars->UserName0,30); strcpy(Set_Vars_Coord_Var,"U0"); lmin = -1e10; lmax = 1e10; }
        if (!strcmp(token, "user") || !strcmp(token, "user1") || !strcmp(token, "u1"))
          { Set_Vars_Coord_Type = DEFS->COORD_USER1; strncpy(Set_Vars_Coord_Label,Vars->UserName1,30); strcpy(Set_Vars_Coord_Var,"U1"); lmin = -1e10; lmax = 1e10; }
        if (!strcmp(token, "user2") || !strcmp(token, "u2"))
          { Set_Vars_Coord_Type = DEFS->COORD_USER2; strncpy(Set_Vars_Coord_Label,Vars->UserName2,30); strcpy(Set_Vars_Coord_Var,"U2"); lmin = -1e10; lmax = 1e10; }
        if (!strcmp(token, "user3") || !strcmp(token, "u3"))
          { Set_Vars_Coord_Type = DEFS->COORD_USER3; strncpy(Set_Vars_Coord_Label,Vars->UserName3,30); strcpy(Set_Vars_Coord_Var,"U3"); lmin = -1e10; lmax = 1e10; }
        if (!strcmp(token, "user4") || !strcmp(token, "u4"))
          { Set_Vars_Coord_Type = DEFS->COORD_USER4; strncpy(Set_Vars_Coord_Label,Vars->UserName4,30); strcpy(Set_Vars_Coord_Var,"U4"); lmin = -1e10; lmax = 1e10; }
	if (!strcmp(token, "user5") || !strcmp(token, "u5"))
	  { Set_Vars_Coord_Type = DEFS->COORD_USER5; strncpy(Set_Vars_Coord_Label,Vars->UserName5,30); strcpy(Set_Vars_Coord_Var,"U5"); lmin = -1e10; lmax = 1e10; }
	if (!strcmp(token, "user6") || !strcmp(token, "u6"))
	  { Set_Vars_Coord_Type = DEFS->COORD_USER6; strncpy(Set_Vars_Coord_Label,Vars->UserName6,30); strcpy(Set_Vars_Coord_Var,"U6"); lmin = -1e10; lmax = 1e10; }
	if (!strcmp(token, "user7") || !strcmp(token, "u7"))
	  { Set_Vars_Coord_Type = DEFS->COORD_USER7; strncpy(Set_Vars_Coord_Label,Vars->UserName7,30); strcpy(Set_Vars_Coord_Var,"U7"); lmin = -1e10; lmax = 1e10; }
	if (!strcmp(token, "user8") || !strcmp(token, "u8"))
	  { Set_Vars_Coord_Type = DEFS->COORD_USER8; strncpy(Set_Vars_Coord_Label,Vars->UserName8,30); strcpy(Set_Vars_Coord_Var,"U8"); lmin = -1e10; lmax = 1e10; }
	if (!strcmp(token, "user9") || !strcmp(token, "u9"))
	  { Set_Vars_Coord_Type = DEFS->COORD_USER9; strncpy(Set_Vars_Coord_Label,Vars->UserName9,30); strcpy(Set_Vars_Coord_Var,"U9"); lmin = -1e10; lmax = 1e10; }

        /* now stores variable keywords detected, if any */
        if (Set_Vars_Coord_Type != DEFS->COORD_NONE)
        {
          int Coord_Number = Vars->Coord_Number;
          if (Vars->Flag_log) { Set_Vars_Coord_Type |= DEFS->COORD_LOG; Vars->Flag_log = 0; }
          if (Flag_abs) { Set_Vars_Coord_Type |= DEFS->COORD_ABS; Flag_abs = 0; }
          if (Flag_auto != 0) { Set_Vars_Coord_Type |= DEFS->COORD_AUTO; 
            if (Flag_auto > 0) Flag_auto = 0; }
          if (Set_Coord_Mode == DEFS->COORD_SIGNAL)
          {
            Coord_Number = 0;
            Vars->Flag_signal = Set_Vars_Coord_Type;
          }
          else
          {
            if (Coord_Number < MONnD_COORD_NMAX)
            { Coord_Number++;
              Vars->Coord_Number = Coord_Number; 
              if (Set_Vars_Coord_Type != DEFS->COORD_PIXELID)
                Vars->Coord_NumberNoPixel++;
            }
            else if (Vars->Flag_Verbose) printf("Monitor_nD: %s reached max number of variables (%i).\n", Vars->compcurname, MONnD_COORD_NMAX);
          }
          Vars->Coord_Type[Coord_Number] = Set_Vars_Coord_Type;
          strncpy(Vars->Coord_Label[Coord_Number], Set_Vars_Coord_Label,30);
          strncpy(Vars->Coord_Var[Coord_Number], Set_Vars_Coord_Var,30);
          if (lmin > lmax) { XY = lmin; lmin=lmax; lmax = XY; }
          Vars->Coord_Min[Coord_Number] = lmin;
          Vars->Coord_Max[Coord_Number] = lmax;
          if (Set_Vars_Coord_Type == DEFS->COORD_NCOUNT || Set_Vars_Coord_Type == DEFS->COORD_PIXELID || Set_Vars_Coord_Type == DEFS->COORD_SIGNAL)
            Vars->Coord_Bin[Coord_Number] = 1;
          else
            Vars->Coord_Bin[Coord_Number] = 20;
          Set_Coord_Mode = DEFS->COORD_VAR;
          Flag_All = 0;
          Flag_No  = 0;
        } else {
          /* no variable name could be read from options */
          if (!iskeyword) {
            if (strcmp(token, "cm2") && strcmp(token, "incoming")
             && strcmp(token, "outgoing") && strcmp(token, "cm2")
             && strcmp(token, "cm^2") && strcmp(token, "float")
             && strcmp(token, "double") && strcmp(token, "binary")
             && strcmp(token, "steradian") && Vars->Flag_Verbose)
              printf("Monitor_nD: %s: unknown '%s' keyword in 'options'. Ignoring.\n", Vars->compcurname, token);
          }
        }
      carg++;
      } /* end if token */
    } /* end while carg */
    free(option_copy);
    if (carg == 128) printf("Monitor_nD: %s reached max number of tokens (%i). Skipping.\n", Vars->compcurname, 128);

    if ((Vars->Flag_Shape == DEFS->SHAPE_BOX) && (fabs(Vars->mzmax - Vars->mzmin) == 0)) Vars->Flag_Shape = DEFS->SHAPE_SQUARE;

    if (Vars->Flag_log == 1) Vars->Coord_Type[0] |= DEFS->COORD_LOG;
    if (Vars->Coord_Number == 0)
    { Vars->Flag_Auto_Limits=0; Vars->Flag_Multiple=0; Vars->Flag_List=0; }

    /* now setting Monitor Name from variable labels */
    strcpy(Vars->Monitor_Label,"");
    XY = 1; /* will contain total bin number */
    for (i = 0; i <= Vars->Coord_Number; i++)
    {
      if (Flag_auto != 0) Vars->Coord_Type[i] |= DEFS->COORD_AUTO;
      Set_Vars_Coord_Type = (Vars->Coord_Type[i] & (DEFS->COORD_LOG-1));
      if ((Set_Vars_Coord_Type == DEFS->COORD_X)
       || (Set_Vars_Coord_Type == DEFS->COORD_Y)
       || (Set_Vars_Coord_Type == DEFS->COORD_Z))
       strcpy(Short_Label[i],"Position");
      else
      if ((Set_Vars_Coord_Type == DEFS->COORD_THETA)
       || (Set_Vars_Coord_Type == DEFS->COORD_PHI)
       || (Set_Vars_Coord_Type == DEFS->COORD_ANGLE))
       strcpy(Short_Label[i],"Angle");
      else
      if ((Set_Vars_Coord_Type == DEFS->COORD_XY)
       || (Set_Vars_Coord_Type == DEFS->COORD_XZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_YZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_RADIUS))
       strcpy(Short_Label[i],"Radius");
      else
      if ((Set_Vars_Coord_Type == DEFS->COORD_VX)
       || (Set_Vars_Coord_Type == DEFS->COORD_VY)
       || (Set_Vars_Coord_Type == DEFS->COORD_VZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_V)
       || (Set_Vars_Coord_Type == DEFS->COORD_VXY)
       || (Set_Vars_Coord_Type == DEFS->COORD_VYZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_VXZ))
       strcpy(Short_Label[i],"Velocity");
      else
      if ((Set_Vars_Coord_Type == DEFS->COORD_KX)
       || (Set_Vars_Coord_Type == DEFS->COORD_KY)
       || (Set_Vars_Coord_Type == DEFS->COORD_KZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_KXY)
       || (Set_Vars_Coord_Type == DEFS->COORD_KYZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_KXZ)
       || (Set_Vars_Coord_Type == DEFS->COORD_K))
       strcpy(Short_Label[i],"Wavevector");
      else
      if ((Set_Vars_Coord_Type == DEFS->COORD_EX)
       || (Set_Vars_Coord_Type == DEFS->COORD_EY)
       || (Set_Vars_Coord_Type == DEFS->COORD_EZ))
       strcpy(Short_Label[i],"Polarisation");
      else
      if ((Set_Vars_Coord_Type == DEFS->COORD_HDIV)
       || (Set_Vars_Coord_Type == DEFS->COORD_VDIV))
       strcpy(Short_Label[i],"Divergence");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_ENERGY)
       strcpy(Short_Label[i],"Energy");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_LAMBDA)
       strcpy(Short_Label[i],"Wavelength");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_NCOUNT)
       strcpy(Short_Label[i],"Photon_ID");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_PIXELID)
       strcpy(Short_Label[i],"Pixel_ID");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_T)
          strcpy(Short_Label[i],"Time_Of_Flight");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_PHASE)
          strcpy(Short_Label[i],"Phase");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_P)
          strcpy(Short_Label[i],"Intensity");
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER0)
	  strncpy(Short_Label[i],Vars->UserName0,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER1)
          strncpy(Short_Label[i],Vars->UserName1,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER2)
          strncpy(Short_Label[i],Vars->UserName2,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER3)
          strncpy(Short_Label[i],Vars->UserName3,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER4)
          strncpy(Short_Label[i],Vars->UserName4,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER5)
          strncpy(Short_Label[i],Vars->UserName5,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER6)
          strncpy(Short_Label[i],Vars->UserName6,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER7)
          strncpy(Short_Label[i],Vars->UserName7,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER8)
          strncpy(Short_Label[i],Vars->UserName8,30);
      else
      if (Set_Vars_Coord_Type == DEFS->COORD_USER9)
          strncpy(Short_Label[i],Vars->UserName9,30);
      else
          strcpy(Short_Label[i],"Unknown");

      if (Vars->Coord_Type[i] & DEFS->COORD_ABS)
      { strcat(Vars->Coord_Label[i]," (abs)"); }

      if (Vars->Coord_Type[i] & DEFS->COORD_LOG)
      { strcat(Vars->Coord_Label[i]," (log)"); }

      strcat(Vars->Monitor_Label, " ");
      strcat(Vars->Monitor_Label, Short_Label[i]);
      XY *= Vars->Coord_Bin[i];

    } /* end for Short_Label */

    if ((Vars->Coord_Type[0] & (DEFS->COORD_LOG-1)) == DEFS->COORD_P) {
      strncat(Vars->Coord_Label[0], " [p/s", 30);
      if (Vars->Flag_per_cm2) strncat(Vars->Coord_Label[0], "/cm2", 30);

      if (XY > 1 && Vars->Coord_Number)
        strncat(Vars->Coord_Label[0], "/bin", 30);
      strncat(Vars->Coord_Label[0], "]", 30);
    }

    /* update label 'signal per bin' if more than 1 bin */
    if (XY > 1 && Vars->Coord_Number) {
      if (Vars->Flag_capture)
        printf("Monitor_nD: %s: Using capture flux weightening on %ld bins.\n"
               "WARNING     Use binned data with caution, and prefer monitor integral value (I,Ierr).\n", Vars->compcurname, (long)XY);
    }

    strcat(Vars->Monitor_Label, " Monitor");
    if (Vars->Flag_Shape == DEFS->SHAPE_SQUARE) strcat(Vars->Monitor_Label, " (Square)");
    if (Vars->Flag_Shape == DEFS->SHAPE_DISK)   strcat(Vars->Monitor_Label, " (Disk)");
    if (Vars->Flag_Shape == DEFS->SHAPE_SPHERE) strcat(Vars->Monitor_Label, " (Sphere)");
    if (Vars->Flag_Shape == DEFS->SHAPE_CYLIND) strcat(Vars->Monitor_Label, " (Cylinder)");
    if (Vars->Flag_Shape == DEFS->SHAPE_BANANA) strcat(Vars->Monitor_Label, " (Banana)");
    if (Vars->Flag_Shape == DEFS->SHAPE_BOX)    strcat(Vars->Monitor_Label, " (Box)");
    if (Vars->Flag_Shape == DEFS->SHAPE_PREVIOUS) strcat(Vars->Monitor_Label, " (on PREVIOUS)");
    if (Vars->Flag_Shape == DEFS->SHAPE_OFF) strcat(Vars->Monitor_Label, " (OFF geometry)");
    if ((Vars->Flag_Shape == DEFS->SHAPE_CYLIND) || (Vars->Flag_Shape == DEFS->SHAPE_BANANA) || (Vars->Flag_Shape == DEFS->SHAPE_SPHERE) || (Vars->Flag_Shape == DEFS->SHAPE_BOX))
    {
      if (strstr(Vars->option, "incoming"))
      {
        Vars->Flag_Shape = abs(Vars->Flag_Shape);
        strcat(Vars->Monitor_Label, " [in]");
      }
      else /* if strstr(Vars->option, "outgoing")) */
      {
        Vars->Flag_Shape = -abs(Vars->Flag_Shape);
        strcat(Vars->Monitor_Label, " [out]");
      }
    }
    if (Vars->Flag_UsePreMonitor == 1)
    {
        strcat(Vars->Monitor_Label, " at ");
        strncat(Vars->Monitor_Label, Vars->UserName1,30);
    }
    if (Vars->Flag_log == 1) strcat(Vars->Monitor_Label, " [log] ");

    /* now allocate memory to store variables in TRACE */

    /* Vars->Coord_Number  0   : intensity or signal
     * Vars->Coord_Number  1:n : detector variables */

    if ((Vars->Coord_NumberNoPixel != 2) && !Vars->Flag_Multiple && !Vars->Flag_List)
    { Vars->Flag_Multiple = 1; /* default is n1D */
      if (Vars->Coord_Number != Vars->Coord_NumberNoPixel) Vars->Flag_List = 1; }

    /* list and auto limits case : Vars->Flag_List or Vars->Flag_Auto_Limits
     * -> Buffer to flush and suppress after Vars->Flag_Auto_Limits
     */
    if ((Vars->Flag_Auto_Limits || Vars->Flag_List) && Vars->Coord_Number)
    { /* Dim : (Vars->Coord_Number+1)*Vars->Buffer_Block matrix (for p, dp) */
      Vars->Mon2D_Buffer = (double *)malloc((Vars->Coord_Number+1)*Vars->Buffer_Block*sizeof(double));
      if (Vars->Mon2D_Buffer == NULL)
      { printf("Monitor_nD: %s cannot allocate Vars->Mon2D_Buffer (%zi). No list and auto limits.\n", Vars->compcurname, Vars->Buffer_Block*(Vars->Coord_Number+1)*sizeof(double)); Vars->Flag_List = 0; Vars->Flag_Auto_Limits = 0; }
      else
      {
        for (i=0; i < (Vars->Coord_Number+1)*Vars->Buffer_Block; Vars->Mon2D_Buffer[i++] = (double)0);
      }
      Vars->Buffer_Size = Vars->Buffer_Block;
    }

    /* 1D and n1D case : Vars->Flag_Multiple */
    if (Vars->Flag_Multiple && Vars->Coord_NumberNoPixel)
    { /* Dim : Vars->Coord_Number*Vars->Coord_Bin[i] vectors */
      Vars->Mon2D_N  = (double **)malloc((Vars->Coord_Number)*sizeof(double *));
      Vars->Mon2D_p  = (double **)malloc((Vars->Coord_Number)*sizeof(double *));
      Vars->Mon2D_p2 = (double **)malloc((Vars->Coord_Number)*sizeof(double *));
      if ((Vars->Mon2D_N == NULL) || (Vars->Mon2D_p == NULL) || (Vars->Mon2D_p2 == NULL))
      { fprintf(stderr,"Monitor_nD: %s n1D cannot allocate Vars->Mon2D_N/p/p2 (%zi). Fatal.\n", Vars->compcurname, (Vars->Coord_Number)*sizeof(double *)); exit(-1); }
      for (i= 1; i <= Vars->Coord_Number; i++)
      {
        Vars->Mon2D_N[i-1]  = (double *)malloc(Vars->Coord_Bin[i]*sizeof(double));
        Vars->Mon2D_p[i-1]  = (double *)malloc(Vars->Coord_Bin[i]*sizeof(double));
        Vars->Mon2D_p2[i-1] = (double *)malloc(Vars->Coord_Bin[i]*sizeof(double));
        if ((Vars->Mon2D_N == NULL) || (Vars->Mon2D_p == NULL) || (Vars->Mon2D_p2 == NULL))
        { fprintf(stderr,"Monitor_nD: %s n1D cannot allocate %s Vars->Mon2D_N/p/p2[%li] (%zi). Fatal.\n", Vars->compcurname, Vars->Coord_Var[i], i, (Vars->Coord_Bin[i])*sizeof(double *)); exit(-1); }
        else
        {
          for (j=0; j < Vars->Coord_Bin[i]; j++ )
          { Vars->Mon2D_N[i-1][j] = (double)0; Vars->Mon2D_p[i-1][j] = (double)0; Vars->Mon2D_p2[i-1][j] = (double)0; }
        }
      }
    }
    else /* 2D case : Vars->Coord_Number==2 and !Vars->Flag_Multiple and !Vars->Flag_List */
    if ((Vars->Coord_NumberNoPixel == 2) && !Vars->Flag_Multiple)
    { /* Dim : Vars->Coord_Bin[1]*Vars->Coord_Bin[2] matrix */
      Vars->Mon2D_N  = (double **)malloc((Vars->Coord_Bin[1])*sizeof(double *));
      Vars->Mon2D_p  = (double **)malloc((Vars->Coord_Bin[1])*sizeof(double *));
      Vars->Mon2D_p2 = (double **)malloc((Vars->Coord_Bin[1])*sizeof(double *));
      if ((Vars->Mon2D_N == NULL) || (Vars->Mon2D_p == NULL) || (Vars->Mon2D_p2 == NULL))
      { fprintf(stderr,"Monitor_nD: %s 2D cannot allocate %s Vars->Mon2D_N/p/p2 (%zi). Fatal.\n", Vars->compcurname, Vars->Coord_Var[1], (Vars->Coord_Bin[1])*sizeof(double *)); exit(-1); }
      for (i= 0; i < Vars->Coord_Bin[1]; i++)
      {
        Vars->Mon2D_N[i]  = (double *)malloc(Vars->Coord_Bin[2]*sizeof(double));
        Vars->Mon2D_p[i]  = (double *)malloc(Vars->Coord_Bin[2]*sizeof(double));
        Vars->Mon2D_p2[i] = (double *)malloc(Vars->Coord_Bin[2]*sizeof(double));
        if ((Vars->Mon2D_N == NULL) || (Vars->Mon2D_p == NULL) || (Vars->Mon2D_p2 == NULL))
        { fprintf(stderr,"Monitor_nD: %s 2D cannot allocate %s Vars->Mon2D_N/p/p2[%li] (%zi). Fatal.\n", Vars->compcurname, Vars->Coord_Var[1], i, (Vars->Coord_Bin[2])*sizeof(double *)); exit(-1); }
        else
        {
          for (j=0; j < Vars->Coord_Bin[2]; j++ )
          { Vars->Mon2D_N[i][j] = (double)0; Vars->Mon2D_p[i][j] = (double)0; Vars->Mon2D_p2[i][j] = (double)0; }
        }
      }
    }
    else {
      Vars->Mon2D_N = Vars->Mon2D_p = Vars->Mon2D_p2 = NULL;
    }
      /* no Mon2D allocated for
       * (Vars->Coord_Number != 2) && !Vars->Flag_Multiple && Vars->Flag_List */

    Vars->psum  = 0;
    Vars->p2sum = 0;
    Vars->Nsum  = 0;

    Vars->area  = fabs(Vars->mxmax - Vars->mxmin)*fabs(Vars->mymax - Vars->mymin)*1E4; /* in cm**2 for square and box shapes */
    Vars->Sphere_Radius = fabs(Vars->mxmax - Vars->mxmin)/2;
    if ((abs(Vars->Flag_Shape) == DEFS->SHAPE_DISK) || (abs(Vars->Flag_Shape) == DEFS->SHAPE_SPHERE))
    {
      Vars->area = PI*Vars->Sphere_Radius*Vars->Sphere_Radius*1E4; /* disk shapes */
    }


    if (Vars->area == 0 && abs(Vars->Flag_Shape) != DEFS->SHAPE_PREVIOUS ) {
      if (abs(Vars->Flag_Shape) != DEFS->SHAPE_OFF) {  
	Vars->Coord_Number = 0;
      }
    }
    if (Vars->Coord_Number == 0 && Vars->Flag_Verbose)
      printf("Monitor_nD: %s is inactivated (0D)\n", Vars->compcurname);
    Vars->Cylinder_Height = fabs(Vars->mymax - Vars->mymin);

    if (Vars->Flag_Verbose)
    {
      printf("Monitor_nD: %s is a %s.\n", Vars->compcurname, Vars->Monitor_Label);
      printf("Monitor_nD: version %s with options=%s\n", MONITOR_ND_LIB_H, Vars->option);
    }
    
    /* compute the product of bin dimensions for PixelID */
    Vars->Coord_BinProd[0]=1;

    for (i = 1; i <= Vars->Coord_Number; i++) {
      Vars->Coord_BinProd[i]=Vars->Coord_Bin[i]*Vars->Coord_BinProd[i-1];
    }

    #ifdef USE_NEXUS

    #ifdef USE_MPI
    if(mpi_node_rank == mpi_node_root) {
    #endif
      if(nxhandle) {

	/* This section of code writes detector shape information to
	   entryN/instrument/components/'name'/geometry in the NeXus file */

	char nexuscomp[CHAR_BUF_LENGTH];
	char pref[5];
	if (Vars->compcurindex-1 < 10) {
	  sprintf(pref,"000");
	} else if (Vars->compcurindex-1 < 100) {
	  sprintf(pref,"00");
	} else if (Vars->compcurindex-1 < 1000) {
	  sprintf(pref,"0");
	} else if (Vars->compcurindex-1 < 10000) {
	  sprintf(pref,"");
	} else {
	  fprintf(stderr,"Error, no support for > 10000 comps at the moment!\n");
	  exit(-1);
	}
	sprintf(nexuscomp,"%s%d_%s",pref,Vars->compcurindex-1,Vars->compcurname);

	if (NXopengroup(nxhandle, "instrument", "NXinstrument") == NX_OK) {
	  if (NXopengroup(nxhandle, "components", "NXdata") == NX_OK) {
	    if (NXopengroup(nxhandle, nexuscomp, "NXdata") == NX_OK) {
	      if (NXmakegroup(nxhandle, "Geometry", "NXdata") == NX_OK) {
		if (NXopengroup(nxhandle, "Geometry", "NXdata") == NX_OK) {
		  char tmp[CHAR_BUF_LENGTH];
		  sprintf(tmp,"%g",Vars->Sphere_Radius);
		  nxprintattr(nxhandle, "radius", "%s", tmp);

		  sprintf(tmp,"%g",Vars->Cylinder_Height);
		  nxprintattr(nxhandle, "height", "%s", tmp);

		  sprintf(tmp,"%g",Vars->mxmin);
		  nxprintattr(nxhandle, "xmin", "%s",  tmp);
		  sprintf(tmp,"%g",Vars->mxmax);
		  nxprintattr(nxhandle, "xmax", "%s",  tmp);

		  sprintf(tmp,"%g",Vars->mymin);
		  nxprintattr(nxhandle, "ymin", "%s",  tmp);
		  sprintf(tmp,"%g",Vars->mymax);
		  nxprintattr(nxhandle, "ymax", "%s",  tmp);

		  sprintf(tmp,"%g",Vars->mzmin);
		  nxprintattr(nxhandle, "zmin", "%s",  tmp);
		  sprintf(tmp,"%g",Vars->mzmax);
		  nxprintattr(nxhandle, "zmax", "%s",  tmp);

		  sprintf(tmp,"%i",Vars->Flag_Shape);
		  nxprintattr(nxhandle, "Shape identifier", "%s",  tmp);
		  sprintf(tmp,"%s",Vars->Monitor_Label);
		  nxprintattr(nxhandle, "Shape string", "%s",  tmp);
		  sprintf(tmp,"%s",Vars->option);
		  nxprintattr(nxhandle, "Option string", "%s",  tmp);

		  NXclosegroup(nxhandle); // Geometry
		} else {
		  printf("Failed to open component NeXus component Geometry group\n");
		}
	      } else {
		printf("Failed to create component NeXus component Geometry group\n");
	      }
	      NXclosegroup(nxhandle); // component
	    }
	    NXclosegroup(nxhandle); // components
	  } else {
	    printf("Failed to open NeXus component hierarchy\n");
	  }
	  NXclosegroup(nxhandle); // instrument
	}
      } // nxhandle available
    #ifdef USE_MPI
      } // Master only
    #endif

    #endif // USE_NEXUS
    } /* end Monitor_nD_Init */

/* ========================================================================= */
/* Monitor_nD_Trace: this routine is used to monitor one propagating particle */
/* return values: 0=photon was absorbed, -1=photon was outside bounds, 1=photon was measured*/
/* ========================================================================= */

int Monitor_nD_Trace(MonitornD_Defines_type *DEFS, MonitornD_Variables_type *Vars, _class_particle* _particle)
{

  double  XY=0, pp=0;
  long    i =0, j =0;
  double  Coord[MONnD_COORD_NMAX];
  long    Coord_Index[MONnD_COORD_NMAX];
  char    While_End   =0;
  long    While_Buffer=0;
  char    Set_Vars_Coord_Type = DEFS->COORD_NONE;

  /* the logic below depends mainly on:
       Flag_List:        1=store 1 buffer, 2=list all, 3=re-use buffer 
       Flag_Auto_Limits: 0 (no auto limits/list), 1 (store events into Buffer), 2 (re-emit store events)
   */

  /* Vars->Flag_Auto_Limits=1: buffer full, we read the Buffer, and determine min and max bounds */
  if ((Vars->Buffer_Counter >= Vars->Buffer_Block) && (Vars->Flag_Auto_Limits == 1) && (Vars->Coord_Number > 0))
  {
    /* auto limits case : get limits in Buffer for each variable */
          /* Dim : (Vars->Coord_Number+1)*Vars->Buffer_Block matrix (for p, dp) */
    if (Vars->Flag_Verbose) printf("Monitor_nD: %s getting %li Auto Limits from List (%li events) in TRACE.\n", Vars->compcurname, Vars->Coord_Number, Vars->Buffer_Counter);
    for (i = 1; i <= Vars->Coord_Number; i++)
    {
      if (Vars->Coord_Type[i] & DEFS->COORD_AUTO)
      {
        Vars->Coord_Min[i] =  FLT_MAX;
        Vars->Coord_Max[i] = -FLT_MAX;
        for (j = 0; j < Vars->Buffer_Counter; j++)
        {
          XY = Vars->Mon2D_Buffer[i+j*(Vars->Coord_Number+1)];  /* scanning variables in Buffer */
          if (XY < Vars->Coord_Min[i]) Vars->Coord_Min[i] = XY;
          if (XY > Vars->Coord_Max[i]) Vars->Coord_Max[i] = XY;
        }
        if  (Vars->Flag_Verbose)  
          printf("  %s: min=%g max=%g\n", Vars->Coord_Var[i], Vars->Coord_Min[i], Vars->Coord_Max[i]);
      }
    }
    Vars->Flag_Auto_Limits = 2;  /* pass to 2nd auto limits step (read Buffer and generate new events to store in histograms) */
  } /* end if Flag_Auto_Limits == 1 */

#ifndef OPENACC
  /* manage realloc for 'list all' if Buffer size exceeded: flush Buffer to file */
  if ((Vars->Buffer_Counter >= Vars->Buffer_Block) && (Vars->Flag_List >= 2))
  {
    if (Vars->Buffer_Size >= 1000000 || Vars->Flag_List == 3)
    { /* save current (possibly append) and re-use Buffer */

      Monitor_nD_Save(DEFS, Vars);
      Vars->Flag_List = 3;
      Vars->Buffer_Block = Vars->Buffer_Size;
      Vars->Buffer_Counter  = 0;
      Vars->Photon_Counter = 0;
    }
    else
    {
      Vars->Mon2D_Buffer  = (double *)realloc(Vars->Mon2D_Buffer, (Vars->Coord_Number+1)*(2*Vars->Buffer_Block)*sizeof(double));
      if (Vars->Mon2D_Buffer == NULL)
            { printf("Monitor_nD: %s cannot reallocate Vars->Mon2D_Buffer[%li] (%zi). Skipping.\n", Vars->compcurname, i, (long int)(2*Vars->Buffer_Block)*sizeof(double)); Vars->Flag_List = 1; }
      else { 
		  Vars->Buffer_Block = 2*Vars->Buffer_Block;
		  Vars->Buffer_Size = Vars->Buffer_Block;
	  }
    }
  } /* end if Buffer realloc */
#endif

  char    outsidebounds=0;
  while (!While_End)
  { /* we generate Coord[] and Coord_index[] from Buffer (auto limits) or passing photon */
    if ((Vars->Flag_Auto_Limits == 2) && (Vars->Coord_Number > 0))
    { /* Vars->Flag_Auto_Limits == 2: read back from Buffer (Buffer is filled or auto limits have been computed) */
      if (While_Buffer < Vars->Buffer_Block)
      {
        /* first while loop (While_Buffer) */
        /* auto limits case : scan Buffer within limits and store in Mon2D */
        Coord[0] = pp = Vars->Mon2D_Buffer[While_Buffer*(Vars->Coord_Number+1)];

        for (i = 1; i <= Vars->Coord_Number; i++)
        {
          /* scanning variables in Buffer */
          if (Vars->Coord_Bin[i] <= 1) continue;
          XY = (Vars->Coord_Max[i]-Vars->Coord_Min[i]);

          Coord[i] = Vars->Mon2D_Buffer[i+While_Buffer*(Vars->Coord_Number+1)];
          if (XY > 0) Coord_Index[i] = floor((Coord[i]-Vars->Coord_Min[i])*Vars->Coord_Bin[i]/XY);
          else        Coord_Index[i] = 0;
          if (Vars->Flag_With_Borders)
          {
            if (Coord_Index[i] < 0)                   Coord_Index[i] = 0;
            if (Coord_Index[i] >= Vars->Coord_Bin[i]) Coord_Index[i] = Vars->Coord_Bin[i] - 1;
          }
        } /* end for */
        
        /* update the PixelID, we compute it from the previous variables index */
        if (Vars->Coord_NumberNoPixel < Vars->Coord_Number) /* there is a Pixel variable */
        for (i = 1; i <= Vars->Coord_Number; i++) {
          char Set_Vars_Coord_Type = (Vars->Coord_Type[i] & (DEFS->COORD_LOG-1));
          if (Set_Vars_Coord_Type == DEFS->COORD_PIXELID) {
            char flag_outside=0;
            Coord_Index[i] = Coord[i] = 0;
            for (j= 1; j < i; j++) {
              /* not for 1D variables with Bin=1 such as PixelID, NCOUNT, Intensity */
              if (Vars->Coord_Bin[j] == 1) continue; 
              if (0 > Coord_Index[j] || Coord_Index[j] >= Vars->Coord_Bin[j]) {
                flag_outside=1;
                Coord[i] = 0;
                break;
              }
              Coord[i] += Coord_Index[j]*Vars->Coord_BinProd[j-1];
            }
            if (!flag_outside) {
              Vars->Mon2D_Buffer[i+While_Buffer*(Vars->Coord_Number+1)] = Coord[i];
            }
          } /* end if PixelID */
        }
        While_Buffer++;
      } /* end if in Buffer */
      else /* (While_Buffer >= Vars->Buffer_Block) && (Vars->Flag_Auto_Limits == 2) */
      {
        Vars->Flag_Auto_Limits = 0;
        if (!Vars->Flag_List) /* free Buffer not needed anymore (no list to output) */
        { /* Dim : (Vars->Coord_Number+1)*Vars->Buffer_Block matrix (for p, p2) */
          free(Vars->Mon2D_Buffer); Vars->Mon2D_Buffer = NULL;
        }
        if (Vars->Flag_Verbose) printf("Monitor_nD: %s flushed %li Auto Limits from List (%li) in TRACE.\n", Vars->compcurname, Vars->Coord_Number, Vars->Buffer_Counter);
      }
    } /* if Vars->Flag_Auto_Limits == 2 */
    
    if (Vars->Flag_Auto_Limits != 2 || !Vars->Coord_Number) /* Vars->Flag_Auto_Limits == 0 (no auto limits/list) or 1 (store events into Buffer) */
    {
      /* automatically compute area and steradian solid angle when in AUTO mode */
      /* compute the steradian solid angle incoming on the monitor */
      double k;
      double tmp;
      k=sqrt(_particle->kx*_particle->kx + _particle->ky*_particle->ky + _particle->kz*_particle->kz);
      tmp=_particle->x;
      if (Vars->min_x > _particle->x){
        #pragma acc atomic write
        Vars->min_x = tmp;
      }
      if (Vars->max_x < _particle->x){
        #pragma acc atomic write
        Vars->max_x = tmp;
      }
      tmp=_particle->y;
      if (Vars->min_y > _particle->y){
        #pragma acc atomic write
        Vars->min_y = tmp;
      }
      if (Vars->max_y < _particle->y){
	tmp=_particle->y;
        #pragma acc atomic write
	Vars->max_y = tmp;
      }

      #pragma acc atomic
      Vars->mean_p = Vars->mean_p + _particle->p;
      if (k) {
        tmp=_particle->p*fabs(_particle->kx/k);
        #pragma acc atomic
        Vars->mean_dx = Vars->mean_dx + tmp; //_particle->p*fabs(_particle->kx/k);
        tmp=_particle->p*fabs(_particle->ky/k);
        #pragma acc atomic
        Vars->mean_dy = Vars->mean_dy + tmp; //_particle->p*fabs(_particle->ky/k);
      }

      for (i = 0; i <= Vars->Coord_Number; i++)
      { /* handle current photon : last while */
        XY = 0;
        Set_Vars_Coord_Type = (Vars->Coord_Type[i] & (DEFS->COORD_LOG-1));
        /* get values for variables to monitor */
        if (Set_Vars_Coord_Type == DEFS->COORD_X) XY = _particle->x;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_Y) XY = _particle->y;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_Z) XY = _particle->z;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VX) XY = _particle->kx/k*M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VY) XY = _particle->ky/k*M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VZ) XY = _particle->kz/k*M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_KX) XY = _particle->kx;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_KY) XY = _particle->ky;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_KZ) XY = _particle->kz;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_PHASE) XY = _particle->phi;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_T) XY = _particle->t;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_P) XY = _particle->p;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_HDIV) XY = RAD2DEG*atan2(_particle->kx,_particle->kz);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VDIV) XY = RAD2DEG*atan2(_particle->ky,_particle->kz);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_V) XY = M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_RADIUS)
          XY = sqrt(_particle->x*_particle->x+_particle->y*_particle->y+_particle->z*_particle->z);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_XY)
          XY = sqrt(_particle->x*_particle->x+_particle->y*_particle->y)*(_particle->x > 0 ? 1 : -1);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_YZ) XY = sqrt(_particle->y*_particle->y+_particle->z*_particle->z);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_XZ)
          XY = sqrt(_particle->x*_particle->x+_particle->z*_particle->z);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VXY) XY = sqrt(_particle->kx*_particle->kx+_particle->ky*_particle->ky)/k*M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VXZ) XY = sqrt(_particle->kx*_particle->kx+_particle->kz*_particle->kz)/k*M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_VYZ) XY = sqrt(_particle->ky*_particle->ky+_particle->kz*_particle->kz)/k*M_C;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_K) XY = k;//sqrt(_particle->kx*_particle->kx+_particle->ky*_particle->ky+_particle->kz*_particle->kz);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_KXY) XY = sqrt(_particle->kx*_particle->kx+_particle->ky*_particle->ky);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_KXZ) XY = sqrt(_particle->kx*_particle->kx+_particle->kz*_particle->kz);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_KYZ) XY = sqrt(_particle->ky*_particle->ky+_particle->kz*_particle->kz);
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_ENERGY) XY = k*K2E;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_LAMBDA) { if (k!=0) XY = 2*M_PI/k; }
        else
	  if (Set_Vars_Coord_Type == DEFS->COORD_NCOUNT) XY = _particle->_uid;
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_ANGLE)
        {  XY = sqrt(_particle->kx*_particle->kx+_particle->ky*_particle->ky);
           if (_particle->kz != 0)
                XY = RAD2DEG*atan2(XY,_particle->kz)*(_particle->x > 0 ? 1 : -1);
           else XY = 0;
        }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_THETA)  { if (_particle->z != 0) XY = RAD2DEG*atan2(_particle->x,_particle->z); }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_PHI) { double rr=sqrt(_particle->x*_particle->x+ _particle->y*_particle->y + _particle->z*_particle->z); if (rr != 0) XY = RAD2DEG*asin(_particle->y/rr); }
        else
	if (Set_Vars_Coord_Type == DEFS->COORD_USER0) {int fail; XY = particle_getvar(_particle,Vars->UserVariable0,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_USER1) {int fail; XY = particle_getvar(_particle,Vars->UserVariable1,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_USER2) {int fail; XY = particle_getvar(_particle,Vars->UserVariable2,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_USER3) {int fail; XY = particle_getvar(_particle,Vars->UserVariable3,&fail); if(fail) XY=0; }
        else
	if (Set_Vars_Coord_Type == DEFS->COORD_USER4) {int fail; XY = particle_getvar(_particle,Vars->UserVariable4,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_USER5) {int fail; XY = particle_getvar(_particle,Vars->UserVariable5,&fail); if(fail) XY=0; }
        else
	if (Set_Vars_Coord_Type == DEFS->COORD_USER6) {int fail; XY = particle_getvar(_particle,Vars->UserVariable6,&fail); if(fail) XY=0; }
        else
	if (Set_Vars_Coord_Type == DEFS->COORD_USER7) {int fail; XY = particle_getvar(_particle,Vars->UserVariable7,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_USER8) {int fail; XY = particle_getvar(_particle,Vars->UserVariable8,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_USER9) {int fail; XY = particle_getvar(_particle,Vars->UserVariable9,&fail); if(fail) XY=0; }
        else
        if (Set_Vars_Coord_Type == DEFS->COORD_PIXELID && !Vars->Flag_Auto_Limits) {
          /* compute the PixelID from previous coordinates 
             the PixelID is the product of Coord_Index[i] in the detector geometry 
             pixelID = sum( Coord_Index[j]*prod(Vars->Coord_Bin[1:(j-1)]) )
             
             this does not apply when we store events in the buffer as Coord_Index
             is not set. Then the pixelID will be re-computed during SAVE.
          */
          char flag_outside=0;
          for (j= 1; j < i; j++) {
            /* not for 1D variables with Bin=1 such as PixelID, NCOUNT, Intensity */
            if (Vars->Coord_Bin[j] <= 1) continue; 
            if (0 > Coord_Index[j] || Coord_Index[j] >= Vars->Coord_Bin[j]) { 
              flag_outside=1; XY=0; break;
            }
            XY += Coord_Index[j]*Vars->Coord_BinProd[j-1];
          }
	  //if (Vars->Flag_mantid && Vars->Flag_OFF && Vars->OFF_polyidx >=0) XY=Vars->OFF_polyidx;
          if (!flag_outside) XY += Vars->Coord_Min[i];
        }
        
        /* handle 'abs' and 'log' keywords */
        if (Vars->Coord_Type[i] & DEFS->COORD_ABS) XY=fabs(XY);

        if (Vars->Coord_Type[i] & DEFS->COORD_LOG) /* compute log of variable if requested */
        {  if (XY > 0) XY = log(XY)/log(10);
           else        XY = -100; }

        Coord[i] = XY; Coord_Index[i] = 0;
        if (i == 0) { pp = XY; Coord_Index[i] = 0; }
        else {
        /* check bounds for variables which have no automatic limits */
          if ((!Vars->Flag_Auto_Limits || !(Vars->Coord_Type[i] & DEFS->COORD_AUTO)) && Vars->Coord_Bin[i]>1)
          { /* compute index in histograms for each variable to monitor */
            XY = (Vars->Coord_Max[i]-Vars->Coord_Min[i]);
            if (XY > 0) Coord_Index[i] = floor((Coord[i]-Vars->Coord_Min[i])*Vars->Coord_Bin[i]/XY);
            if (Vars->Flag_With_Borders)
            {
              if (Coord_Index[i] >= Vars->Coord_Bin[i]) Coord_Index[i] = Vars->Coord_Bin[i] - 1;
              if (Coord_Index[i] < 0) Coord_Index[i] = 0;
            }
            //if (0 > Coord_Index[i] || Coord_Index[i] >= Vars->Coord_Bin[i])
            //  outsidebounds=1;
          } /* else will get Index later from Buffer when Flag_Auto_Limits == 2 */
        }
        
      } /* end for i */
      While_End = 1;
    }/* end else if Vars->Flag_Auto_Limits == 2 */
    
    /* ====================================================================== */
    /* store n1d/2d photon from Buffer (Auto_Limits == 2) or current photon in while */
    if (Vars->Flag_Auto_Limits != 1) /* not when storing auto limits Buffer */
    {
      /* apply per cm2 */
      if (Vars->Flag_per_cm2 && Vars->area != 0)
        pp /= Vars->area;

      /* 2D case : Vars->Coord_Number==2 and !Vars->Flag_Multiple and !Vars->Flag_List */
      if ( Vars->Coord_NumberNoPixel == 2 && !Vars->Flag_Multiple)
      { /* Dim : Vars->Coord_Bin[1]*Vars->Coord_Bin[2] matrix */
        
        i = Coord_Index[1];
        j = Coord_Index[2];
        if (i >= 0 && i < Vars->Coord_Bin[1] && j >= 0 && j < Vars->Coord_Bin[2])
        {
          if (Vars->Mon2D_N) {
	    /* Temporary workaround for the NVC OpenACC ICE (NVIDIA TPR#39009):
	       use local pointer aliases for atomic writes through struct members.
	       Once fixed upstream, remove these aliases and restore the original
	       Vars->... atomic expressions. */
	    double *Mon2D_N = Vars->Mon2D_N[i];
	    double *Mon2D_p = Vars->Mon2D_p[i];
	    double *Mon2D_p2 = Vars->Mon2D_p2[i];
	    double p2 = pp*pp;
            #pragma acc atomic
	    Mon2D_N[j] = Mon2D_N[j]+1;
            #pragma acc atomic
	    Mon2D_p[j] = Mon2D_p[j]+pp;
            #pragma acc atomic
	    Mon2D_p2[j] = Mon2D_p2[j] + p2;
	  }
        } else {
          outsidebounds=1; 
        }
      } else {
        /* 1D and n1D case : Vars->Flag_Multiple */
        /* Dim : Vars->Coord_Number*Vars->Coord_Bin[i] vectors (intensity is not included) */
          
        for (i= 1; i <= Vars->Coord_Number; i++) {
          j = Coord_Index[i];
          if (j >= 0 && j < Vars->Coord_Bin[i]) {
            if  (Vars->Flag_Multiple && Vars->Mon2D_N) {
	      if (Vars->Mon2D_N) {
		double *Mon2D_N = Vars->Mon2D_N[i-1];
		double *Mon2D_p = Vars->Mon2D_p[i-1];
		double *Mon2D_p2 = Vars->Mon2D_p2[i-1];
		double p2 = pp*pp;
                #pragma acc atomic
		Mon2D_N[j] = Mon2D_N[j]+1;
                #pragma acc atomic
		Mon2D_p[j] = Mon2D_p[j]+pp;
		#pragma acc atomic
		Mon2D_p2[j] = Mon2D_p2[j] + p2;
	      }
	    }
          } else { 
            outsidebounds=1;
            break;
          }
        }
      }
    } /* end (Vars->Flag_Auto_Limits != 1) */
    
    if (Vars->Flag_Auto_Limits != 2 && !outsidebounds) /* not when reading auto limits Buffer */
    { /* now store Coord into Buffer (no index needed) if necessary (list or auto limits) */
      if ((Vars->Flag_List) || (Vars->Flag_Auto_Limits == 1))
      {
        /* Reserve a unique row in the list buffer. The atomic capture makes
           the read-and-increment of Buffer_Counter indivisible, so concurrent
           GPU threads can never be handed the same row. The non-atomic
           pre-check only avoids growing the counter once the buffer is full;
           a few threads may still overshoot Buffer_Block, which is why the
           counter is clamped again in Monitor_nD_Save. */
        unsigned long buffer_slot = Vars->Buffer_Block;
        if (Vars->Buffer_Counter < Vars->Buffer_Block) {
          #pragma acc atomic capture
          buffer_slot = Vars->Buffer_Counter++;
        }
        if (buffer_slot < Vars->Buffer_Block)
        {
          /* The row is owned by this thread only: plain stores suffice */
          double *Mon2D_Buffer = Vars->Mon2D_Buffer + buffer_slot*(Vars->Coord_Number+1);
          for (i = 0; i <= Vars->Coord_Number; i++)
            Mon2D_Buffer[i] = Coord[i];
          if (Vars->Flag_Verbose && (buffer_slot + 1 == Vars->Buffer_Block) && (Vars->Flag_List == 1))
            printf("Monitor_nD: %s %li photons stored in List.\n", Vars->compcurname, (long)Vars->Buffer_Block);
        }
      }
    } /* end (Vars->Flag_Auto_Limits != 2) */
    
  } /* end while */
  #pragma acc atomic
  Vars->Nsum = Vars->Nsum + 1;
  #pragma acc atomic
  Vars->psum  = Vars->psum + pp;
  #pragma acc atomic
  Vars->p2sum = Vars->p2sum + pp*pp;

  /*determine return value: 1:photon was in bounds and measured, -1: outside bounds, 0: outside bounds, should be absorbed.*/
  if(outsidebounds){
      if(Vars->Flag_Absorb){
          return 0;
      }else{
          return -1;
      }
  } else {
   /* For the OPENACC list buffer an atomic capture/update of the
      updated Neutron_counter - updated below under list mode 
	  Only need to be updated when inside bounds. */
   #pragma acc atomic update
   Vars->Photon_Counter++;
  }
  return 1;
} /* end Monitor_nD_Trace */

/* ========================================================================= */
/* Monitor_nD_Save: this routine is used to save data files                  */
/* ========================================================================= */

MCDETECTOR Monitor_nD_Save(MonitornD_Defines_type *DEFS, MonitornD_Variables_type *Vars)
  {
    char   *fname;
    long    i,j;
    double *p0m = NULL;
    double *p1m = NULL;
    double *p2m = NULL;
    char    Coord_X_Label[CHAR_BUF_LENGTH];
    double  min1d, max1d;
    double  min2d, max2d;
    char    While_End = 0;
    long    While_Buffer = 0;
    double  XY=0, pp=0;
    double  Coord[MONnD_COORD_NMAX];
    long    Coord_Index[MONnD_COORD_NMAX];
    char    label[CHAR_BUF_LENGTH];
    double  ratio;

    MCDETECTOR detector;
    memset(&detector, 0, sizeof(detector));
    strcpy(detector.options,Vars->option);
    ratio = 100.0*mcget_run_num()/mcget_ncount();
    if (Vars->Flag_Verbose && Vars->Flag_per_cm2) {
      printf("Monitor_nD: %s: active flat detector area is %g [cm^2], total area is %g [cm^2]\n",
        Vars->compcurname, (Vars->max_x-Vars->min_x)
                          *(Vars->max_y-Vars->min_y)*1E4, Vars->area);
      printf("Monitor_nD: %s: beam solid angle is %g [st] (%g x %g [deg^2])\n",
        Vars->compcurname,
        2*fabs(2*atan2(Vars->mean_dx,Vars->mean_p)
         *sin(2*atan2(Vars->mean_dy,Vars->mean_p)/2)),
        atan2(Vars->mean_dx,Vars->mean_p)*RAD2DEG,
        atan2(Vars->mean_dy,Vars->mean_p)*RAD2DEG);
    }

    /* On GPU (OpenACC) several threads may have incremented Buffer_Counter
       past Buffer_Block while racing for the last free rows; only
       Buffer_Block rows hold data. No-op for serial CPU runs. */
    if (Vars->Buffer_Counter > Vars->Buffer_Block)
      Vars->Buffer_Counter = Vars->Buffer_Block;

    /* check Buffer flush when end of simulation reached */
    if ((Vars->Buffer_Counter <= Vars->Buffer_Block) && Vars->Flag_Auto_Limits && Vars->Mon2D_Buffer && Vars->Buffer_Counter)
    {
      /* Get Auto Limits */
      if (Vars->Flag_Verbose) printf("Monitor_nD: %s getting %li Auto Limits from List (%li events).\n", Vars->compcurname, Vars->Coord_Number, Vars->Buffer_Counter);

      for (i = 1; i <= Vars->Coord_Number; i++)
      {
        if ((Vars->Coord_Type[i] & DEFS->COORD_AUTO) && Vars->Coord_Bin[i] > 1)
        {
          Vars->Coord_Min[i] = FLT_MAX;
          Vars->Coord_Max[i] = -FLT_MAX;
          for (j = 0; j < Vars->Buffer_Counter; j++)
          {
            XY = Vars->Mon2D_Buffer[i+j*(Vars->Coord_Number+1)];  /* scanning variables in Buffer */
            if (XY < Vars->Coord_Min[i]) Vars->Coord_Min[i] = XY;
            if (XY > Vars->Coord_Max[i]) Vars->Coord_Max[i] = XY;
          }
          if  (Vars->Flag_Verbose)  
            printf("  %s: min=%g max=%g in %li bins\n", Vars->Coord_Var[i], Vars->Coord_Min[i], Vars->Coord_Max[i], Vars->Coord_Bin[i]);
        }
      }
      Vars->Flag_Auto_Limits = 2;  /* pass to 2nd auto limits step */
      Vars->Buffer_Block = Vars->Buffer_Counter;

      while (!While_End)
      { /* we generate Coord[] and Coord_index[] from Buffer (auto limits) */
        /* simulation ended before Buffer was filled. Limits have to be computed, and stored events must be sent into histograms */
        
        if (While_Buffer < Vars->Buffer_Block)
        {
          /* first while loops (While_Buffer) */
          Coord[0] = Vars->Mon2D_Buffer[While_Buffer*(Vars->Coord_Number+1)];

          /* auto limits case : scan Buffer within limits and store in Mon2D */
          for (i = 1; i <= Vars->Coord_Number; i++)
          {
            /* scanning variables in Buffer */
            if (Vars->Coord_Bin[i] <= 1) Coord_Index[i] = 0;
            else {
              XY = (Vars->Coord_Max[i]-Vars->Coord_Min[i]);
              Coord[i] = Vars->Mon2D_Buffer[i+While_Buffer*(Vars->Coord_Number+1)];
              if (XY > 0) Coord_Index[i] = floor((Coord[i]-Vars->Coord_Min[i])*Vars->Coord_Bin[i]/XY);
              else Coord_Index[i] = 0;
              if (Vars->Flag_With_Borders)
              {
                if (Coord_Index[i] < 0) Coord_Index[i] = 0;
                if (Coord_Index[i] >= Vars->Coord_Bin[i]) Coord_Index[i] = Vars->Coord_Bin[i] - 1;
              }
            }
          } /* end for */

          /* update the PixelID, we compute it from the previous variables index */
          for (i = 1; i <= Vars->Coord_Number; i++) {
            char Set_Vars_Coord_Type = (Vars->Coord_Type[i] & (DEFS->COORD_LOG-1));
            if (Set_Vars_Coord_Type == DEFS->COORD_PIXELID) {
              char outsidebounds=0;
              Coord_Index[i] = Coord[i] = 0;
              for (j= 1; j < i; j++) {
                /* not for 1D variables with Bin=1 such as PixelID, NCOUNT, Intensity */
                if (Vars->Coord_Bin[j] == 1) continue; 
                if (0 > Coord_Index[j] || Coord_Index[j] >= Vars->Coord_Bin[j]) {
                  outsidebounds=1;
                  Coord[i] = 0;
                  break;
                }
                Coord[i] += Coord_Index[j]*Vars->Coord_BinProd[j-1];
              }
              if (!outsidebounds) {
                Vars->Mon2D_Buffer[i+While_Buffer*(Vars->Coord_Number+1)] = Coord[i];
              }
            } /* end if PixelID */
          }
          While_Buffer++;
        } /* end if in Buffer */
        else /* (While_Buffer >= Vars->Buffer_Block) && (Vars->Flag_Auto_Limits == 2) */
        {
          Vars->Flag_Auto_Limits = 0;
          While_End = 1;
          if (Vars->Flag_Verbose) printf("Monitor_nD: %s flushed %li Auto Limits from List (%li).\n", Vars->compcurname, Vars->Coord_Number, Vars->Buffer_Counter);
        }

        /* store n1d/2d section from Buffer */

        pp = Coord[0];
        /* apply per cm2 or per st */
        if (Vars->Flag_per_cm2 && Vars->area      != 0)
          pp /= Vars->area;
        
        /* 2D case : Vars->Coord_Number==2 and !Vars->Flag_Multiple and !Vars->Flag_List */
        if (!Vars->Flag_Multiple && Vars->Coord_NumberNoPixel == 2)
        { /* Dim : Vars->Coord_Bin[1]*Vars->Coord_Bin[2] matrix */
          i = Coord_Index[1];
          j = Coord_Index[2];
          if (i >= 0 && i < Vars->Coord_Bin[1] && j >= 0 && j < Vars->Coord_Bin[2])
          {
            if (Vars->Mon2D_N) {
              Vars->Mon2D_N[i][j]++;
              Vars->Mon2D_p[i][j] += pp;
              Vars->Mon2D_p2[i][j] += pp*pp;
            }
          } else if (Vars->Flag_Absorb) pp=0;
        }
        else
        /* 1D and n1D case : Vars->Flag_Multiple */
        { /* Dim : Vars->Coord_Number*Vars->Coord_Bin[i] vectors (intensity is not included) */
          for (i= 1; i <= Vars->Coord_Number; i++)
          {
            j = Coord_Index[i];
            if (j >= 0 && j < Vars->Coord_Bin[i])
            {
              if (Vars->Flag_Multiple && Vars->Mon2D_N) {
                Vars->Mon2D_N[i-1][j]++;
                Vars->Mon2D_p[i-1][j] += pp;
                Vars->Mon2D_p2[i-1][j] += pp*pp;
              }
            } else if (Vars->Flag_Absorb) {
              pp=0; break;
            }
          }
        } /* end store 2D/1D */
        
      } /* end while */
    } /* end Force Get Limits */

    /* write output files (sent to file as p[i*n + j] vectors) */
    if (Vars->Coord_Number == 0)
    {
      double Nsum;
      double psum, p2sum;
      Nsum = Vars->Nsum;
      psum = Vars->psum;
      p2sum= Vars->p2sum;
      if (Vars->Flag_signal != DEFS->COORD_P && Nsum > 0)
      { psum /=Nsum; p2sum /= Nsum*Nsum; }
      /* DETECTOR_OUT_0D(Vars->Monitor_Label, Vars->Nsum, Vars->psum, Vars->p2sum); */
      detector = mcdetector_out_0D(Vars->Monitor_Label, Nsum, psum, p2sum, Vars->compcurname, Vars->compcurpos,Vars->compcurrot,Vars->compcurindex);
    }
    else
    if (strlen(Vars->Mon_File) > 0)
    {
      fname = (char*)malloc(strlen(Vars->Mon_File)+10*Vars->Coord_Number);
      if (Vars->Flag_List && Vars->Mon2D_Buffer) /* List: DETECTOR_OUT_2D */
      {
       
        if (Vars->Flag_List >= 2) Vars->Buffer_Size = Vars->Photon_Counter;
        if (Vars->Buffer_Size >= Vars->Photon_Counter)
          Vars->Buffer_Size = Vars->Photon_Counter;
#ifdef OPENACC
        /* On GPU the list buffer is never flushed during TRACE, so it holds
           at most Buffer_Counter rows even when more events were counted.
           Never write rows beyond what was actually stored. */
        if (Vars->Buffer_Size > Vars->Buffer_Counter) {
          printf("Monitor_nD: %s: WARNING list truncated to %lu of %lld events "
                 "(buffer full). Increase --bufsiz or use Monitor_nD_noacc.\n",
                 Vars->compcurname, Vars->Buffer_Counter, (long long)Vars->Photon_Counter);
          Vars->Buffer_Size = Vars->Buffer_Counter;
        }
#endif
        strcpy(fname,Vars->Mon_File);
        if (strchr(Vars->Mon_File,'.') == NULL) strcat(fname, "_list");

        strcpy(Coord_X_Label,"");
        for (i= 0; i <= Vars->Coord_Number; i++)
        {
          strcat(Coord_X_Label, Vars->Coord_Var[i]);
          strcat(Coord_X_Label, " ");
          if (strchr(Vars->Mon_File,'.') == NULL)
          { strcat(fname, "."); strcat(fname, Vars->Coord_Var[i]); }
        }
        if (Vars->Flag_Verbose) printf("Monitor_nD: %s write monitor file %s List (%lix%li).\n", Vars->compcurname, fname,(long int)Vars->Photon_Counter,Vars->Coord_Number);

        /* handle the type of list output */
        strcpy(label, Vars->Monitor_Label);
        
        detector = mcdetector_out_list(
              label, "List of photon events", Coord_X_Label,
              -Vars->Buffer_Size, Vars->Coord_Number+1,
              Vars->Mon2D_Buffer,
              fname, Vars->compcurname, Vars->compcurpos, Vars->compcurrot, Vars->option,Vars->compcurindex);
      }
      if (Vars->Flag_Multiple) /* n1D: DETECTOR_OUT_1D */
      {
        for (i= 0; i < Vars->Coord_Number; i++)
        {

          strcpy(fname,Vars->Mon_File);
          if (strchr(Vars->Mon_File,'.') == NULL)
          { strcat(fname, "."); strcat(fname, Vars->Coord_Var[i+1]); }
          sprintf(Coord_X_Label, "%s monitor", Vars->Coord_Label[i+1]);
          strcpy(label, Coord_X_Label);
          if (Vars->Coord_Bin[i+1] > 0) { /* 1D monitor */
            if (Vars->Flag_Verbose) printf("Monitor_nD: %s write monitor file %s 1D (%li).\n", Vars->compcurname, fname, Vars->Coord_Bin[i+1]);
            min1d = Vars->Coord_Min[i+1];
            max1d = Vars->Coord_Max[i+1];
            if (min1d == max1d) max1d = min1d+1e-6;
            p1m = (double *)malloc(Vars->Coord_Bin[i+1]*sizeof(double));
            p2m = (double *)malloc(Vars->Coord_Bin[i+1]*sizeof(double));
            if (p1m == NULL || p2m == NULL) /* use Raw Buffer line output */
            {
              if (Vars->Flag_Verbose) printf("Monitor_nD: %s cannot allocate memory for output. Using raw data.\n", Vars->compcurname);
              if (p1m != NULL) free(p1m);
              detector = mcdetector_out_1D(
              label,
              Vars->Coord_Label[i+1],
              Vars->Coord_Label[0],
              Vars->Coord_Var[i+1],
              min1d, max1d,
              Vars->Coord_Bin[i+1],
              Vars->Mon2D_N[i],Vars->Mon2D_p[i],Vars->Mon2D_p2[i],
              fname, Vars->compcurname, Vars->compcurpos, Vars->compcurrot,Vars->compcurindex);
            } /* if (p2m == NULL) */
            else
            {
              if (Vars->Flag_log != 0)
              {
                XY = FLT_MAX;
                for (j=0; j < Vars->Coord_Bin[i+1]; j++) /* search min of signal */
                  if ((XY > Vars->Mon2D_p[i][j]) && (Vars->Mon2D_p[i][j] > 0)) XY = Vars->Mon2D_p[i][j];
                if (XY <= 0) XY = -log(FLT_MAX)/log(10); else XY = log(XY)/log(10)-1;
              } /* if */

              for (j=0; j < Vars->Coord_Bin[i+1]; j++)
              {
                p1m[j] = Vars->Mon2D_p[i][j];
                p2m[j] = Vars->Mon2D_p2[i][j];
                if (Vars->Flag_signal != DEFS->COORD_P && Vars->Mon2D_N[i][j] > 0)
                { /* normalize mean signal to the number of events */
                  p1m[j] /= Vars->Mon2D_N[i][j];
                  p2m[j] /= Vars->Mon2D_N[i][j]*Vars->Mon2D_N[i][j];
                }
                if (Vars->Flag_log != 0)
                {
                  if ((p1m[j] > 0) && (p2m[j] > 0))
                  {
                    p2m[j] /= p1m[j]*p1m[j];
                    p1m[j] = log(p1m[j])/log(10);
                  }
                  else
                  {
                    p1m[j] = XY;
                    p2m[j] = 0;
                  }
                }
              } /* for */
              detector = mcdetector_out_1D(
                label,
                Vars->Coord_Label[i+1],
                Vars->Coord_Label[0],
                Vars->Coord_Var[i+1],
                min1d, max1d,
                Vars->Coord_Bin[i+1],
                Vars->Mon2D_N[i],p1m,p2m,
                fname, Vars->compcurname, Vars->compcurpos, Vars->compcurrot,Vars->compcurindex);

            } /* else */
            /* comment out 'free memory' lines to avoid loosing arrays if
               'detector' structure is used by other instrument parts
            if (p1m != NULL) free(p1m); p1m=NULL;
            if (p2m != NULL) free(p2m); p2m=NULL;
            */
          } else { /* 0d monitor */
            detector = mcdetector_out_0D(label, Vars->Mon2D_p[i][0], Vars->Mon2D_p2[i][0], Vars->Mon2D_N[i][0], Vars->compcurname, Vars->compcurpos, Vars->compcurrot,Vars->compcurindex);
          }


        } /* for */
      } /* if 1D */
      else
      if (Vars->Coord_NumberNoPixel == 2)  /* 2D: DETECTOR_OUT_2D */
      {
        strcpy(fname,Vars->Mon_File);

        p0m = (double *)malloc(Vars->Coord_Bin[1]*Vars->Coord_Bin[2]*sizeof(double));
        p1m = (double *)malloc(Vars->Coord_Bin[1]*Vars->Coord_Bin[2]*sizeof(double));
        p2m = (double *)malloc(Vars->Coord_Bin[1]*Vars->Coord_Bin[2]*sizeof(double));
        if (p0m == NULL || p1m == NULL || p2m == NULL)
        {
          if (Vars->Flag_Verbose) printf("Monitor_nD: %s cannot allocate memory for 2D array (%li). Skipping.\n", Vars->compcurname, 3*Vars->Coord_Bin[1]*Vars->Coord_Bin[2]*sizeof(double));
          if (p0m != NULL) free(p0m);
          if (p1m != NULL) free(p1m);
        }
        else
        {
          if (Vars->Flag_log != 0)
          {
            XY = FLT_MAX;
            for (i= 0; i < Vars->Coord_Bin[1]; i++)
              for (j= 0; j < Vars->Coord_Bin[2]; j++) /* search min of signal */
                if ((XY > Vars->Mon2D_p[i][j]) && (Vars->Mon2D_p[i][j]>0)) XY = Vars->Mon2D_p[i][j];
            if (XY <= 0) XY = -log(FLT_MAX)/log(10); else XY = log(XY)/log(10)-1;
          }
          for (i= 0; i < Vars->Coord_Bin[1]; i++)
          {
            for (j= 0; j < Vars->Coord_Bin[2]; j++)
            {
              long index;
              index = j + i*Vars->Coord_Bin[2];
              p0m[index] = Vars->Mon2D_N[i][j];
              p1m[index] = Vars->Mon2D_p[i][j];
              p2m[index] = Vars->Mon2D_p2[i][j];
              if (Vars->Flag_signal != DEFS->COORD_P && p0m[index] > 0)
              {
                  p1m[index] /= p0m[index];
                  p2m[index] /= p0m[index]*p0m[index];
              }

              if (Vars->Flag_log != 0)
              {
                if ((p1m[index] > 0) && (p2m[index] > 0))
                {
                  p2m[index] /= (p1m[index]*p1m[index]);
                  p1m[index] = log(p1m[index])/log(10);

                }
                else
                {
                  p1m[index] = XY;
                  p2m[index] = 0;
                }
              }
            }
          }
          if (strchr(Vars->Mon_File,'.') == NULL)
          { strcat(fname, "."); strcat(fname, Vars->Coord_Var[1]);
              strcat(fname, "_"); strcat(fname, Vars->Coord_Var[2]); }
          if (Vars->Flag_Verbose) printf("Monitor_nD: %s write monitor file %s 2D (%lix%li).\n", Vars->compcurname, fname, Vars->Coord_Bin[1], Vars->Coord_Bin[2]);

          min1d = Vars->Coord_Min[1];
          max1d = Vars->Coord_Max[1];
          if (min1d == max1d) max1d = min1d+1e-6;
          min2d = Vars->Coord_Min[2];
          max2d = Vars->Coord_Max[2];
          if (min2d == max2d) max2d = min2d+1e-6;
          strcpy(label, Vars->Monitor_Label);
          if (Vars->Coord_Bin[1]*Vars->Coord_Bin[2] > 1
           && Vars->Flag_signal == DEFS->COORD_P)
            strcat(label, " per bin");
	  if (Vars->Flag_List) {
            detector = mcdetector_out_2D_list(
              label,
              Vars->Coord_Label[1],
	      Vars->Coord_Label[2],
	      min1d, max1d,
	      min2d, max2d,
	      Vars->Coord_Bin[1],
	      Vars->Coord_Bin[2],
	      p0m,p1m,p2m,
	      fname, Vars->compcurname, Vars->compcurpos, Vars->compcurrot,Vars->option,Vars->compcurindex);
	  } else {
          detector = mcdetector_out_2D(
            label,
            Vars->Coord_Label[1],
            Vars->Coord_Label[2],
            min1d, max1d,
            min2d, max2d,
            Vars->Coord_Bin[1],
            Vars->Coord_Bin[2],
            p0m,p1m,p2m,
	      fname, Vars->compcurname, Vars->compcurpos, Vars->compcurrot,Vars->compcurindex);
	  }

          /* comment out 'free memory' lines to avoid loosing arrays if
               'detector' structure is used by other instrument parts
          if (p0m != NULL) free(p0m);
          if (p1m != NULL) free(p1m);
          if (p2m != NULL) free(p2m);
          */
        }
      }
      free(fname);
    }
      return(detector);
  } /* end Monitor_nD_Save */

/* ========================================================================= */
/* Monitor_nD_Finally: this routine is used to free memory                   */
/* ========================================================================= */

void Monitor_nD_Finally(MonitornD_Defines_type *DEFS,
  MonitornD_Variables_type *Vars)
  {
    int i;

    /* Now Free memory Mon2D.. */
    if ((Vars->Flag_Auto_Limits || Vars->Flag_List) && Vars->Coord_Number)
    { /* Dim : (Vars->Coord_Number+1)*Vars->Buffer_Block matrix (for p, dp) */
      if (Vars->Mon2D_Buffer != NULL) free(Vars->Mon2D_Buffer);
    }

    /* 1D and n1D case : Vars->Flag_Multiple */
    if (Vars->Flag_Multiple && Vars->Coord_Number)
    { /* Dim : Vars->Coord_Number*Vars->Coord_Bin[i] vectors */
      for (i= 0; i < Vars->Coord_Number; i++)
      {
        free(Vars->Mon2D_N[i]);
        free(Vars->Mon2D_p[i]);
        free(Vars->Mon2D_p2[i]);
      }
      free(Vars->Mon2D_N);
      free(Vars->Mon2D_p);
      free(Vars->Mon2D_p2);
    }


    /* 2D case : Vars->Coord_Number==2 and !Vars->Flag_Multiple and !Vars->Flag_List */
    if ((Vars->Coord_NumberNoPixel == 2) && !Vars->Flag_Multiple)
    { /* Dim : Vars->Coord_Bin[1]*Vars->Coord_Bin[2] matrix */
      for (i= 0; i < Vars->Coord_Bin[1]; i++)
      {
        free(Vars->Mon2D_N[i]);
        free(Vars->Mon2D_p[i]);
        free(Vars->Mon2D_p2[i]);
      }
      free(Vars->Mon2D_N);
      free(Vars->Mon2D_p);
      free(Vars->Mon2D_p2);
    }
  } /* end Monitor_nD_Finally */

/* ========================================================================= */
/* Monitor_nD_McDisplay: this routine is used to display component           */
/* ========================================================================= */

void Monitor_nD_McDisplay(MonitornD_Defines_type *DEFS,
  MonitornD_Variables_type *Vars)
  {
    double radius, h;
    double xmin;
    double xmax;
    double ymin;
    double ymax;
    double zmin;
    double zmax;
    int    i;
    double hdiv_min=-180, hdiv_max=180, vdiv_min=-90, vdiv_max=90;
    char   restricted = 0;

    radius = Vars->Sphere_Radius;
    h = Vars->Cylinder_Height;
    xmin = Vars->mxmin;
    xmax = Vars->mxmax;
    ymin = Vars->mymin;
    ymax = Vars->mymax;
    zmin = Vars->mzmin;
    zmax = Vars->mzmax;

    /* determine if there are angular limits set at start (no auto) in coord_types
     * cylinder/banana: look for hdiv
     * sphere: look for angle, radius (->atan2(val,radius)), hdiv, vdiv
     * this activates a 'restricted' flag, to draw a region as blades on cylinder/sphere
     */
    for (i= 0; i <= Vars->Coord_Number; i++)
    {
      int Set_Vars_Coord_Type;
      Set_Vars_Coord_Type = (Vars->Coord_Type[i] & (DEFS->COORD_LOG-1));
      if (Set_Vars_Coord_Type == DEFS->COORD_HDIV || Set_Vars_Coord_Type == DEFS->COORD_THETA)
      { hdiv_min = Vars->Coord_Min[i]; hdiv_max = Vars->Coord_Max[i]; restricted = 1; }
      else if (Set_Vars_Coord_Type == DEFS->COORD_VDIV || Set_Vars_Coord_Type == DEFS->COORD_PHI)
      { vdiv_min = Vars->Coord_Min[i]; vdiv_max = Vars->Coord_Max[i];restricted = 1;  }
      else if (Set_Vars_Coord_Type == DEFS->COORD_ANGLE)
      { hdiv_min = vdiv_min = Vars->Coord_Min[i];
        hdiv_max = vdiv_max = Vars->Coord_Max[i];
        restricted = 1; }
      else if (Set_Vars_Coord_Type == DEFS->COORD_RADIUS)
      { double angle;
        angle = RAD2DEG*atan2(Vars->Coord_Max[i], radius);
        hdiv_min = vdiv_min = angle;
        hdiv_max = vdiv_max = angle;
        restricted = 1; }
      else if (Set_Vars_Coord_Type == DEFS->COORD_Y && abs(Vars->Flag_Shape) == DEFS->SHAPE_SPHERE)
      {
        vdiv_min = atan2(ymin,radius)*RAD2DEG;
        vdiv_max = atan2(ymax,radius)*RAD2DEG;
        restricted = 1;
      }
    }
    /* full sphere */
    if ((!restricted && (abs(Vars->Flag_Shape) == DEFS->SHAPE_SPHERE))
    || abs(Vars->Flag_Shape) == DEFS->SHAPE_PREVIOUS)
    {
      mcdis_magnify("");
      mcdis_circle("xy",0,0,0,radius);
      mcdis_circle("xz",0,0,0,radius);
      mcdis_circle("yz",0,0,0,radius);
    }
    /* banana/cylinder/sphere portion */
    else
    if (restricted && ((abs(Vars->Flag_Shape) == DEFS->SHAPE_CYLIND)
                    || (abs(Vars->Flag_Shape) == DEFS->SHAPE_BANANA)
                    || (abs(Vars->Flag_Shape) == DEFS->SHAPE_SPHERE)))
    {
      int NH=24, NV=24;
      int ih, iv;
      double width, height;
      int issphere;
      issphere = (abs(Vars->Flag_Shape) == DEFS->SHAPE_SPHERE);
      width = (hdiv_max-hdiv_min)/NH;
      if (!issphere) {
	NV=1; /* cylinder has vertical axis */
      }
      height= (vdiv_max-vdiv_min)/NV;
      
      /* check width and height of elements (sphere) to make sure the nb
         of plates remains limited */
      if (width < 10  && NH > 1) { width = 10;  NH=(hdiv_max-hdiv_min)/width; width=(hdiv_max-hdiv_min)/NH; }
      if (height < 10 && NV > 1) { height = 10; NV=(vdiv_max-vdiv_min)/height; height= (vdiv_max-vdiv_min)/NV; }
      
      mcdis_magnify("xyz");
      for(ih = 0; ih < NH; ih++)
        for(iv = 0; iv < NV; iv++)
        {
          double theta0, phi0, theta1, phi1;          /* angles in spherical coordinates */
          double x0,y0=0,z0,x1,y1=0,z1,x2,y2,z2,x3,y3,z3; /* vertices at plate edges */
          phi0 = (hdiv_min+ width*ih-90)*DEG2RAD;        /* in xz plane */
          phi1 = (hdiv_min+ width*(ih+1)-90)*DEG2RAD;
          if (issphere)
          {
            theta0= (vdiv_min+height* iv + 90)   *DEG2RAD; /* in vertical plane */
            theta1= (vdiv_min+height*(iv+1) + 90)*DEG2RAD;
            if (y0 < ymin) y0=ymin; 
            if (y0 > ymax) y0=ymax;
            if (y1 < ymin) y1=ymin; 
            if (y1 > ymax) y1=ymax;
            
            y0 = -radius*cos(theta0);            /* z with Z vertical */
            y1 = -radius*cos(theta1);
            if (y0 < ymin) y0=ymin;
            if (y0 > ymax) y0=ymax;
            if (y1 < ymin) y1=ymin;
            if (y1 > ymax) y1=ymax;
          } else {
            y0 = ymin;
            y1 = ymax;
            theta0=theta1=90*DEG2RAD;
          }

          x0 = radius*sin(theta0)*cos(phi0); /* x with Z vertical */
          z0 =-radius*sin(theta0)*sin(phi0); /* y with Z vertical */
          x1 = radius*sin(theta1)*cos(phi0); 
          z1 =-radius*sin(theta1)*sin(phi0);
          x2 = radius*sin(theta1)*cos(phi1); 
          z2 =-radius*sin(theta1)*sin(phi1);
          x3 = radius*sin(theta0)*cos(phi1); 
          z3 =-radius*sin(theta0)*sin(phi1);
          y2 = y1; y3 = y0;

          mcdis_multiline(5,
            x0,y0,z0,
            x1,y1,z1,
            x2,y2,z2,
            x3,y3,z3,
            x0,y0,z0);
        }
    }
    /* disk (circle) */
    else
    if (abs(Vars->Flag_Shape) == DEFS->SHAPE_DISK)
    {
      mcdis_magnify("");
      mcdis_circle("xy",0,0,0,radius);
    }
    /* rectangle (square) */
    else
    if (abs(Vars->Flag_Shape) == DEFS->SHAPE_SQUARE)
    {
      mcdis_magnify("xy");
      mcdis_multiline(5, (double)xmin, (double)ymin, 0.0,
             (double)xmax, (double)ymin, 0.0,
             (double)xmax, (double)ymax, 0.0,
             (double)xmin, (double)ymax, 0.0,
             (double)xmin, (double)ymin, 0.0);
    }
    /* full cylinder/banana */
    else
    if (!restricted && ((abs(Vars->Flag_Shape) == DEFS->SHAPE_CYLIND) || (abs(Vars->Flag_Shape) == DEFS->SHAPE_BANANA)))
    {
      mcdis_magnify("xyz");
      mcdis_circle("xz", 0,  h/2.0, 0, radius);
      mcdis_circle("xz", 0, -h/2.0, 0, radius);
      mcdis_line(-radius, -h/2.0, 0, -radius, +h/2.0, 0);
      mcdis_line(+radius, -h/2.0, 0, +radius, +h/2.0, 0);
      mcdis_line(0, -h/2.0, -radius, 0, +h/2.0, -radius);
      mcdis_line(0, -h/2.0, +radius, 0, +h/2.0, +radius);
    }
    else
    /* box */
    if (abs(Vars->Flag_Shape) == DEFS->SHAPE_BOX)
    {
      mcdis_magnify("xyz");
      mcdis_multiline(5, xmin, ymin, zmin,
                   xmax, ymin, zmin,
                   xmax, ymax, zmin,
                   xmin, ymax, zmin,
                   xmin, ymin, zmin);
      mcdis_multiline(5, xmin, ymin, zmax,
                   xmax, ymin, zmax,
                   xmax, ymax, zmax,
                   xmin, ymax, zmax,
                   xmin, ymin, zmax);
      mcdis_line(xmin, ymin, zmin, xmin, ymin, zmax);
      mcdis_line(xmax, ymin, zmin, xmax, ymin, zmax);
      mcdis_line(xmin, ymax, zmin, xmin, ymax, zmax);
      mcdis_line(xmax, ymax, zmin, xmax, ymax, zmax);
    }
  } /* end Monitor_nD_McDisplay */

/* end of monitor_nd-lib.c */

/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright 1997-2002, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Library: share/read_table-lib.h
*
* %Identification
* Written by: EF
* Date: Aug 28, 2002
* Origin: ILL
* Release: McStas 1.6
* Version: $Revision$
*
* This file is to be imported by components that may read data from table files
* It handles some shared functions.
*
* This library may be used directly as an external library. It has no dependency
*
* Usage: within SHARE
* %include "read_table-lib"
*
*******************************************************************************/

#ifndef READ_TABLE_LIB_H
#define READ_TABLE_LIB_H "$Revision$"

#define READ_TABLE_STEPTOL  0.04 /* tolerancy for constant step approx */

#ifndef MC_PATHSEP_C
#ifdef WIN32
#define MC_PATHSEP_C '\\'
#define MC_PATHSEP_S "\\"
#else  /* !WIN32 */
#ifdef MAC
#define MC_PATHSEP_C ':'
#define MC_PATHSEP_S ":"
#else  /* !MAC */
#define MC_PATHSEP_C '/'
#define MC_PATHSEP_S "/"
#endif /* !MAC */
#endif /* !WIN32 */
#endif /* !MC_PATHSEP_C */

/* Compiled-in resource directory used by Open_File() when $MCSTAS/$MCXTRACE
   is not set. The code generator bakes the install location into a macro
   named after the flavour (MCSTAS or MCXTRACE, see MCCODE_LIBENV in cogen),
   so pick up MCXTRACE for McXtrace rather than the McStas default below.
   (issue #2759: direct runs of McXtrace binaries from mccode.org .deb
   packages, where $MCXTRACE is not set, could not find data/ files). */
#if !defined(MCSTAS) && defined(MCXTRACE)
#define MCSTAS MCXTRACE
#endif

#ifndef MCSTAS
#ifdef WIN32
#define MCSTAS "C:\\mcstas\\lib"
#else  /* !WIN32 */
#ifdef MAC
#define MCSTAS ":mcstas:lib" /* ToDo: What to put here? */
#else  /* !MAC */
#define MCSTAS "/usr/local/lib/mcstas"
#endif /* !MAC */
#endif /* !WIN32 */
#endif /* !MCSTAS */

#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>

#ifndef _MSC_EXTENSIONS
#include <strings.h>
#else
#  include <string.h>
#  define strcasecmp _stricmp
#  define strncasecmp _strnicmp
#endif

  typedef struct struct_table
  {
    char    filename[1024];
    long    filesize;
    char   *header;  /* text header, e.g. comments */
    double *data;    /* vector { x[0], y[0], ... x[n-1], y[n-1]... } */
    double  min_x;   /* min value of first column */
    double  max_x;   /* max value of first column */
    double  step_x;  /* minimal step value of first column */
    long    rows;    /* number of rows in matrix block */
    long    columns; /* number of columns in matrix block */

    long    begin;   /* start fseek index of block */
    long    end;     /* stop  fseek index of block */
    long    block_number;  /* block index. 0 is catenation of all */
    long    array_length;  /* number of elements in the t_Table array */
    char    monotonic;     /* true when 1st column/vector data is monotonic */
    char    constantstep;  /* true when 1st column/vector data has constant step */
    char    method[32];    /* interpolation method: nearest, linear */
    char    quiet;   /*output level for messages to the console 0: print all messages, 1:only print some/including errors, 2: never print anything.*/
  } t_Table;

/*maximum number of rows to rebin a table = 1M*/
enum { mcread_table_rebin_maxsize = 1000000 };

typedef struct t_Read_table_file_item {
    int ref_count;
    t_Table *table_ref;
} t_Read_table_file_item;

typedef enum enum_Read_table_file_actions {STORE,FIND,GC,REBIN}  t_Read_table_file_actions;

/* read_table-lib function prototypes */
/* ========================================================================= */

/* 'public' functions */
long     Table_Read              (t_Table *Table, char *File, long block_number);
long     Table_Read_Offset       (t_Table *Table, char *File, long block_number,
                                  long *offset, long max_lines);
long     Table_Read_Offset_Binary(t_Table *Table, char *File, char *Type,
                                  long *Offset, long Rows, long Columns);
long     Table_Rebin(t_Table *Table); /* rebin table with regular 1st column and interpolate all columns 2:end */
long     Table_Info (t_Table Table);
#pragma acc routine
double   Table_Index(t_Table Table,   long i, long j); /* get indexed value */
#pragma acc routine
double   Table_Value(t_Table Table, double X, long j); /* search X in 1st column and return interpolated value in j-column */
t_Table *Table_Read_Array(char *File, long *blocks);
void     Table_Free_Array(t_Table *Table);
long     Table_Info_Array(t_Table *Table);
int      Table_SetElement(t_Table *Table, long i, long j, double value);
long     Table_Init(t_Table *Table, long rows, long columns); /* create a Table */
#pragma acc routine
double   Table_Value2d(t_Table Table, double X, double Y);    /* same as Table_Index with non-integer indices and 2d interpolation */
MCDETECTOR Table_Write(t_Table Table, char*file, char*xl, char*yl, 
           double x1, double x2, double y1, double y2); /* write Table to disk */
void * Table_File_List_Handler(t_Read_table_file_actions action, void *item, void *item_modifier);
t_Table *Table_File_List_find(char *name, int block, int offset);
int Table_File_List_gc(t_Table *tab);
void *Table_File_List_store(t_Table *tab);

#define Table_ParseHeader(header, ...) \
  Table_ParseHeader_backend(header,__VA_ARGS__,NULL);

char **Table_ParseHeader_backend(char *header, ...);
FILE *Open_File(char *name, const char *Mode, char *path);


/* private functions */
void Table_Free(t_Table *Table);
long Table_Read_Handle(t_Table *Table, FILE *fid, long block_number, long max_lines, char *name);
static void Table_Stat(t_Table *Table);
#pragma acc routine
double Table_Interp1d(double x, double x1, double y1, double x2, double y2);
#pragma acc routine
double Table_Interp1d_nearest(double x, double x1, double y1, double x2, double y2);
#pragma acc routine
double Table_Interp2d(double x, double y, double x1, double y1, double x2, double y2,
double z11, double z12, double z21, double z22);


#endif

/* end of read_table-lib.h */
/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2009, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Library: share/read_table-lib.c
*
* %Identification
* Written by: EF
* Date: Aug 28, 2002
* Origin: ILL
* Release: McStas CVS_090504
* Version: $Revision$
*
* This file is to be imported by components that may read data from table files
* It handles some shared functions. Embedded within instrument in runtime mode.
*
* Usage: within SHARE
* %include "read_table-lib"
*
*******************************************************************************/

#ifndef READ_TABLE_LIB_H
#include "read_table-lib.h"
#endif

#ifndef READ_TABLE_LIB_C
#define READ_TABLE_LIB_C "$Revision$"


/*******************************************************************************
 * void *Table_File_List_Handler(action, item, item_modifier)
 *   ACTION: handle file entries in the read_table-lib file list. If a file is read - it is supposed to be
 *   stored in a list such that we can avoid reading the same file many times.
 *   input  action: FIND, STORE, GC. check if file exists in the list, store an item in the list, or check if it can be garbage collected.
 *   input item: depends on the action.
 *    FIND)  item is a filename, and item_modifier is the block number
 *    STORE) item is the Table to store - item_modifier is ignored
 *    GC)    item is the Table to check. If it has a ref_count >1 then this is simply decremented.
 *   return  depends on the action
 *    FIND)  return a reference to a table+ref_count item if found - NULL otherwise. I.e. NULL means the file has not been read before and must be read again.
 *    STORE) return NULL always
 *    GC)    return NULL if no garbage collection is needed, return an adress to the t_Table which should be garbage collected. 0x1 is returned if
 *           the item is not found in the list
*******************************************************************************/
void * Table_File_List_Handler(t_Read_table_file_actions action, void *item, void *item_modifier){

    /* logic here is Read_Table should include a call to FIND. If found the return value should just be used as
     * if the table had been read from disk. If not found then read the table and STORE.
     * Table_Free should include a call to GC. If this returns non-NULL then we should proceed with freeing the memory
     * associated with the table item - otherwise only decrement the reference counter since there are more references
     * that may need it.*/

    static t_Read_table_file_item read_table_file_list[1024];  
    static int read_table_file_count=0;

    t_Read_table_file_item *tr;
    switch(action){
        case FIND:
            /*interpret data item as a filename, if it is found return a pointer to the table and increment refcount.
             * if not found return the item itself*/
            tr=read_table_file_list;
            while ( tr->table_ref!=NULL ){
                int i=*((int*) item_modifier);
                int j=*( ((int*) item_modifier)+1);
                if ( !strcmp(tr->table_ref->filename,(char *) item) &&
                        tr->table_ref->block_number==i && tr->table_ref->begin==j ){
                    tr->ref_count++;
                    return (void *) tr;
                }
                tr++;
            }
            return NULL;
        case STORE:
            /* Store a private heap copy of the table header, never the caller's
             * pointer: callers usually pass a stack-local t_Table (PowderN's
             * read_line_data, Table_Read_Array's loop variable, ...). A borrowed
             * pointer outlives that stack frame, and FIND would later compare
             * against whatever happens to occupy that stack slot - a false
             * "Reusing input file" hit returning stale, already-freed data.
             * Empty tables are not cached, and the last slot stays NULL as the
             * list terminator. */
            if (!item || !((t_Table *) item)->data) return NULL;
            if (read_table_file_count >= 1023) return NULL;
            {
              t_Table *copy = (t_Table *) malloc(sizeof(t_Table));
              if (!copy) return NULL;
              *copy = *((t_Table *) item);
              tr=&(read_table_file_list[read_table_file_count++]);
              tr->table_ref = copy;
              tr->ref_count = 1;
            }
            return NULL;
        case GC:
            /* Should this item be garbage collected (freed) - if so scratch the entry and return the address of the item - 
             * else decrement ref_count and return NULL.
             * A non-NULL return expects the item to actually be freed afterwards.*/
            tr=read_table_file_list;
            while ( tr->table_ref!=NULL ){
                if ( ((t_Table *)item)->data != NULL &&
                        tr->table_ref->data ==((t_Table *)item)->data &&
                        tr->table_ref->block_number == ((t_Table *)item)->block_number){
                    /*matching item found*/
                    if (tr->ref_count>1){
                        /*the item is found and no garbage collection needed*/
                        tr->ref_count--;
                        return NULL;
                    }else{
                        /* The item is found and the reference counter is 1.
                         * This means we should garbage collect. Move remaining list items up one slot,
                         * and return the table for garbage collection by caller*/
                        free(tr->table_ref); /* our private copy; caller frees data/header */
                        while (tr->table_ref!=NULL){
                            *tr=*(tr+1);
                            tr++;
                        }
                        read_table_file_count--;
                        return (t_Table *) item;
                    }
                }
                tr++;
            }
            /* item not found, and so should be garbage collected. This could be the case if freeing a
             * Table that has been constructed from code - not read from file. Return 0x1 to flag it for
             * collection.*/
            return (void *) 0x1 ;
        case REBIN:
            /* item is a Table whose data block has just been replaced (Table_Rebin),
             * item_modifier is its old data pointer. The cache holds its own copy of
             * the Table, so it must be told:
             *  - sole user (ref_count 1): point the cache entry at the new data, so
             *    later readers of the same file get the rebinned table. Caller frees
             *    the old data. Returns NULL.
             *  - shared (ref_count > 1): others still use the old data. Detach the
             *    caller from the entry (it now owns its new data privately) and
             *    keep the old data alive. Returns 0x1: caller must NOT free it.
             *  - not cached: returns NULL, caller frees the old data. */
            tr=read_table_file_list;
            while ( tr->table_ref!=NULL ){
                if ( item_modifier != NULL && tr->table_ref->data == (double *) item_modifier &&
                        tr->table_ref->block_number == ((t_Table *)item)->block_number){
                    if (tr->ref_count>1){
                        /* the header is shared too: give the detached Table its own */
                        t_Table *tab = (t_Table *) item;
                        if (tab->header) {
                          char *h = (char *) malloc(strlen(tab->header) + 1);
                          if (h) strcpy(h, tab->header);
                          tab->header = h;
                        }
                        tr->ref_count--;
                        return (void *) 0x1;
                    }else{
                        t_Table *entry = tr->table_ref;
                        *entry = *((t_Table *) item);
                        return NULL;
                    }
                }
                tr++;
            }
            return NULL;
    }
    /* If we arrive here, nothing worked, return NULL */
    return NULL;
}

/* Access functions to the handler*/

/********************************************
 * t_Table *Table_File_List_find(char *name, int block, int offset)
 * input name: filename to search for in the file list
 * input block: data block in the file as each file may contain more than 1 data block.
 * return a ref. to a table if it is found (you may use this pointer and skip reading the file), NULL otherwise (i.e. go ahead and read the file)
*********************************************/
t_Table *Table_File_List_find(char *name, int block, int offset){
    int vars[2]={block,offset};
    t_Read_table_file_item *item = Table_File_List_Handler(FIND,name, vars);
    if (item == NULL){
        return NULL;
    }else{
        return item->table_ref;
    }
}
/********************************************
 * int Table_File_List_gc(t_Table *tab)
 * input tab: the table to check for references.
 * return 0: no garbage collection needed
 *        1: Table's data and header (at least) should be freed.
*********************************************/
int Table_File_List_gc(t_Table *tab){
    void *rval=Table_File_List_Handler(GC,tab,0);
    if (rval==NULL) return 0;
    else return 1;
}


/*****************************************************************************
 * void *Table_File_List_store(t_Table *tab)
 * input tab: pointer to table to store.
 * return None. 
*******************************************************************************/
void *Table_File_List_store(t_Table *tab){
    return Table_File_List_Handler(STORE,tab,0);
}


/*******************************************************************************
* FILE *Open_File(char *name, char *Mode, char *path)
*   ACTION: search for a file and open it. Optionally return the opened path.
*           Searched: as given, then in the directories of the instrument file
*           and executable, and in data/ and contrib/ of the McStas/McXtrace
*           installation. Keep in sync with mccode_setup_ncrystal_search_paths()
*           in mcstas-comps/share/mccode-ncrystal-lib.c.
*   input   name:  file name from which table should be extracted
*           mode: "r", "w", "a" or any valid fopen mode
*           path:  NULL or a pointer to at least 1024 allocated chars
*   return  initialized file handle or NULL in case of error
*******************************************************************************/

  FILE *Open_File(char *File, const char *Mode, char *Path)
  {
    char path[1024];
    FILE *hfile = NULL;
    
    if (!File || File[0]=='\0')                     return(NULL);
    if (!strcmp(File,"NULL") || !strcmp(File,"0"))  return(NULL);
    
    /* search in current or full path */
    strncpy(path, File, 1024);
    hfile = fopen(path, Mode);
    if(!hfile)
    {
      char dir[1024];

      if (!hfile && instrument_source[0] != '\0' && strlen(instrument_source)) /* search in instrument source location */
      {
        char *path_pos   = NULL;
        /* extract path: searches for last file separator */
        path_pos    = strrchr(instrument_source, MC_PATHSEP_C);  /* last PATHSEP */
        if (path_pos) {
          long path_length = path_pos +1 - instrument_source;  /* from start to path+sep */
          if (path_length) {
            strncpy(dir, instrument_source, path_length);
            dir[path_length] = '\0';
            snprintf(path, 1024, "%s%c%s", dir, MC_PATHSEP_C, File);
            hfile = fopen(path, Mode);
          }
        }
      }
      if (!hfile && instrument_exe[0] != '\0' && strlen(instrument_exe)) /* search in PWD instrument executable location */
      {
        char *path_pos   = NULL;
        /* extract path: searches for last file separator */
        path_pos    = strrchr(instrument_exe, MC_PATHSEP_C);  /* last PATHSEP */
        if (path_pos) {
          long path_length = path_pos +1 - instrument_exe;  /* from start to path+sep */
          if (path_length) {
            strncpy(dir, instrument_exe, path_length);
            dir[path_length] = '\0';
            snprintf(path, 1024, "%s%c%s", dir, MC_PATHSEP_C, File);
            hfile = fopen(path, Mode);
          }
        }
      }
      if (!hfile) /* search in MCSTAS/data */
      {
        strcpy(dir, getenv(FLAVOR_UPPER) ? getenv(FLAVOR_UPPER) : MCSTAS);
        snprintf(path, 1024, "%s%c%s%c%s", dir, MC_PATHSEP_C, "data", MC_PATHSEP_C, File);
        hfile = fopen(path, Mode);
      }
      if (!hfile) /* search in MVCSTAS/contrib */
      {
        strcpy(dir, getenv(FLAVOR_UPPER) ? getenv(FLAVOR_UPPER) : MCSTAS);
        snprintf(path, 1024, "%s%c%s%c%s", dir, MC_PATHSEP_C, "contrib", MC_PATHSEP_C, File);
        hfile = fopen(path, Mode);
      }
      if(!hfile)
      {
        // fprintf(stderr, "Warning: Could not open input file '%s' (Open_File)\n", File);
        return (NULL);
      }
    }
    if (Path) strncpy(Path, path, 1024);
    return(hfile);
  } /* end Open_File */

/*******************************************************************************
* long Read_Table(t_Table *Table, char *name, int block_number)
*   ACTION: read a single Table from a text file
*   input   Table: pointer to a t_Table structure
*           name:  file name from which table should be extracted
*           block_number: if the file does contain more than one
*                 data block, then indicates which one to get (from index 1)
*                 a 0 value means append/catenate all
*   return  initialized single Table t_Table structure containing data, header, ...
*           number of read elements (-1: error, 0:header only)
* The routine stores any line starting with '#', '%' and ';' into the header
* File is opened, read and closed
* Other lines are interpreted as numerical data, and stored.
* Data block should be a rectangular matrix or vector.
* Data block may be rebinned with Table_Rebin (also sort in ascending order)
*******************************************************************************/
  long Table_Read(t_Table *Table, char *File, long block_number)
  { /* reads all or a single data block from 'file' and returns a Table structure  */
    return(Table_Read_Offset(Table, File, block_number, NULL, 0));
  } /* end Table_Read */

/*******************************************************************************
* long Table_Read_Offset(t_Table *Table, char *name, int block_number, long *offset
*                        long max_rows)
*   ACTION: read a single Table from a text file, starting at offset
*     Same as Table_Read(..) except:
*   input   offset:    pointer to an offset (*offset should be 0 at start)
*           max_rows: max number of data rows to read from file (0 means all)
*   return  initialized single Table t_Table structure containing data, header, ...
*           number of read elements (-1: error, 0:header only)
*           updated *offset position (where end of reading occured)
*******************************************************************************/
  long Table_Read_Offset(t_Table *Table, char *File,
                         long block_number, long *offset,
                         long max_rows)
  { /* reads all/a data block in 'file' and returns a Table structure  */
    FILE *hfile;
    long  nelements=0;
    long  begin=0;
    long  filesize=0;
    char  name[1024];
    char  path[1024];
    struct stat stfile;

    /*Need to be able to store the pointer*/
    if (!Table) return(-1);

    /*TK: Valgrind flags it as usage of uninitialised variable: */
    Table->quiet = 0;

    //if (offset && *offset) snprintf(name, 1024, "%s@%li", File, *offset);
    //else                   
    strncpy(name, File, 1024);
    if(offset && *offset){
        begin=*offset;
    }
    /* Check if the table has already been read from file.
     * If so just reuse the table, if not (this is flagged by returning NULL
     * set up a new table and read the data into it */
    t_Table *tab_p= Table_File_List_find(name,block_number,begin);
    if ( tab_p!=NULL ){
        /*table was found in the Table_File_List*/
        *Table=*tab_p;
        MPI_MASTER(
            if(Table->quiet<1)
              printf("Reusing input file '%s' (Table_Read_Offset)\n", name);
            );
        return Table->rows*Table->columns;
    }

    /* open the file */
    hfile = Open_File(File, "r", path);
    if (!hfile) return(-1);
    else {
      MPI_MASTER(
          if(Table->quiet<1)
            printf("Opening input file '%s' (Table_Read_Offset)\n", path);
          );
    }
    
    /* read file state */
    stat(path,&stfile); filesize = stfile.st_size;
    if (offset && *offset) fseek(hfile, *offset, SEEK_SET);
    begin     = ftell(hfile);
    
    Table_Init(Table, 0, 0);

    /* read file content and set the Table */
    nelements = Table_Read_Handle(Table, hfile, block_number, max_rows, name);
    Table->begin = begin;
    Table->end   = ftell(hfile);
    Table->filesize = (filesize>0 ? filesize : 0);
    Table_Stat(Table);
    
    Table_File_List_store(Table);

    if (offset) *offset=Table->end;
    fclose(hfile);
    return(nelements);

  } /* end Table_Read_Offset */

/*******************************************************************************
* long Table_Read_Offset_Binary(t_Table *Table, char *File, char *type,
*                               long *offset, long rows, long columns)
*   ACTION: read a single Table from a binary file, starting at offset
*     Same as Table_Read_Offset(..) except that it handles binary files.
*   input   type: may be "float"/NULL or "double"
*           offset: pointer to an offset (*offset should be 0 at start)
*           rows   : number of rows (0 means read all)
*           columns: number of columns
*   return  initialized single Table t_Table structure containing data, header, ...
*           number of read elements (-1: error, 0:header only)
*           updated *offset position (where end of reading occured)
*******************************************************************************/
  long Table_Read_Offset_Binary(t_Table *Table, char *File, char *type,
                                long *offset, long rows, long columns)
  { /* reads all/a data block in binary 'file' and returns a Table structure  */
    long    nelements, sizeofelement;
    long    filesize;
    FILE   *hfile;
    char    path[1024];
    struct stat stfile;
    double *data    = NULL;
    double *datatmp = NULL;
    long    i;
    long    begin;

    if (!Table) return(-1);

    Table_Init(Table, 0, 0);
    
    /* open the file */
    hfile = Open_File(File, "r", path);
    if (!hfile) return(-1);
    else {
      MPI_MASTER(
          if(Table->quiet<1)
            printf("Opening input file '%s' (Table_Read, Binary)\n", path);
      );
    }
    
    /* read file state */
    stat(File,&stfile);
    filesize = stfile.st_size;
    Table->filesize=filesize;
    
    /* read file content */
    if (type && !strcmp(type,"double")) sizeofelement = sizeof(double);
    else  sizeofelement = sizeof(float);
    if (offset && *offset) fseek(hfile, *offset, SEEK_SET);
    begin     = ftell(hfile);
    if (rows && filesize > sizeofelement*columns*rows)
      nelements = columns*rows;
    else nelements = (long)(filesize/sizeofelement);
    if (!nelements || filesize <= *offset) return(0);
    data    = (double*)malloc(nelements*sizeofelement);
    if (!data) {
      if(!(Table->quiet>1))
        fprintf(stderr,"Error: allocating %ld elements for %s file '%s'. Too big (Table_Read_Offset_Binary).\n", nelements, type, File);
      exit(-1);
    }
    nelements = fread(data, sizeofelement, nelements, hfile);

    if (!data || !nelements)
    {
      if(!(Table->quiet>1))
        fprintf(stderr,"Error: reading %ld elements from %s file '%s' (Table_Read_Offset_Binary)\n", nelements, type, File);
      exit(-1);
    }
    Table->begin   = begin;
    Table->end     = ftell(hfile);
    if (offset) *offset=Table->end;
    fclose(hfile);

    datatmp = (double*)realloc(data, (double)nelements*sizeofelement);
    if (!datatmp) {
      free(data);
      fprintf(stderr,"Error: reallocating %ld elements for %s file '%s'. Too big (Table_Read_Offset_Binary).\n", nelements, type, File);
      exit(-1);
    } else {
      data = datatmp;
    }
    /* copy file data into Table */
    if (type && !strcmp(type,"double")) Table->data = data;
    else {
      float  *s;
      double *dataf;
      s     = (float*)data;
      dataf = (double*)malloc(sizeof(double)*nelements);
      if (!dataf) {
	fprintf(stderr, "Could not allocate data block of size %ld\n", nelements);
	exit(-1);
      }
      for (i=0; i<nelements; i++)
        dataf[i]=s[i];
      free(data);
      Table->data = dataf;
    }
    strncpy(Table->filename, File, 1024);
    Table->rows    = nelements/columns;
    Table->columns = columns;
    Table->array_length = 1;
    Table->block_number = 1;

    Table_Stat(Table);

    return(nelements);
  } /* end Table_Read_Offset_Binary */

/*******************************************************************************
* long Table_Read_Handle(t_Table *Table, FILE *fid, int block_number, long max_rows, char *name)
*   ACTION: read a single Table from a text file handle (private)
*   input   Table:pointer to a t_Table structure
*           fid:  pointer to FILE handle
*           block_number: if the file does contain more than one
*                 data block, then indicates which one to get (from index 1)
*                 a 0 value means append/catenate all
*           max_rows: if non 0, only reads that number of lines
*   return  initialized single Table t_Table structure containing data, header, ...
*           modified Table t_Table structure containing data, header, ...
*           number of read elements (-1: error, 0:header only)
* The routine stores any line starting with '#', '%' and ';' into the header
* Other lines are interpreted as numerical data, and stored.
* Data block should be a rectangular matrix or vector.
* Data block may be rebined with Table_Rebin (also sort in ascending order)
*******************************************************************************/
  long Table_Read_Handle(t_Table *Table, FILE *hfile,
                         long block_number, long max_rows, char *name)
  { /* reads all/a data block from 'file' handle and returns a Table structure  */
    double *Data              = NULL;
    double *Datatmp           = NULL;
    char *Header              = NULL;
    char *Headertmp           = NULL;
    long  malloc_size         = CHAR_BUF_LENGTH;
    long  malloc_size_h       = 4096;
    long  Rows = 0,   Columns = 0;
    long  count_in_array      = 0;
    long  count_in_header     = 0;
    long  count_invalid       = 0;
    long  block_Current_index = 0;
    char  flag_End_row_loop   = 0;

    if (!Table) return(-1);
    Table_Init(Table, 0, 0);
    if (name && name[0]!='\0') strncpy(Table->filename, name, 1024);

    if(!hfile) {
       fprintf(stderr, "Error: File handle is NULL (Table_Read_Handle).\n");
       return (-1);
    }
    Header = (char*)  calloc(malloc_size_h, sizeof(char));
    Data   = (double*)calloc(malloc_size,   sizeof(double));
    if ((Header == NULL) || (Data == NULL)) {
       fprintf(stderr, "Error: Could not allocate Table and Header (Table_Read_Handle).\n");
       return (-1);
    }

    int flag_In_array = 0;
    do { /* while (!flag_End_row_loop) */
      char  *line=malloc(1024*CHAR_BUF_LENGTH*sizeof(char));
      long  back_pos=0;   /* ftell start of line */

      if (!line) {
	fprintf(stderr,"Could not allocate line buffer\n");
	exit(-1);
      }
      back_pos = ftell(hfile);
      if (fgets(line, 1024*CHAR_BUF_LENGTH, hfile) != NULL) { /* analyse line */
        /* first skip blank and tabulation characters */
        int i = strspn(line, " \t");

        /* handle comments: stored in header */
        if (NULL != strchr("#%;/", line[i]))
        { /* line is a comment */
          count_in_header += strlen(line);
          if (count_in_header >= malloc_size_h) {
            /* if succeed and in array : add (and realloc if necessary) */
            malloc_size_h = count_in_header+4096;
            char *Headertmp = (char*)realloc(Header, malloc_size_h*sizeof(char));
	    if(!Headertmp) {
	      free(Header);
	             fprintf(stderr, "Error: Could not reallocate Header (Table_Read_Handle).\n");
		     free(Header);
		     return (-1);
	    } else {
	      Header = Headertmp;
	    }
          }
          strncat(Header, line, 4096);
          flag_In_array=0;
          /* exit line and file if passed desired block */
          if (block_number > 0 && block_number == block_Current_index) {
            flag_End_row_loop = 1;
          }

          /* Continue with next line */
          continue;
        }
        if (strstr(line, "***"))
        {
          count_invalid++;
          /* Continue with next line */
          continue;
        }

        /* get the number of columns splitting line with strtok */
        char  *lexeme;
        char  flag_End_Line = 0;
        long  block_Num_Columns = 0;
        const char seps[] = " ,;\t\n\r";

        lexeme = strtok(line, seps);
        while (!flag_End_Line) {
          if ((lexeme != NULL) && (lexeme[0] != '\0')) {
            /* reading line: the token is not empty */
            double X;
            int    count=1;
            /* test if we have 'NaN','Inf' */
            if (!strncasecmp(lexeme,"NaN",3))
              X = 0;
            else if (!strncasecmp(lexeme,"Inf",3) || !strncasecmp(lexeme,"+Inf",4))
              X = FLT_MAX;
            else if (!strncasecmp(lexeme,"-Inf",4))
              X = -FLT_MAX;
            else
              count = sscanf(lexeme,"%lg",&X);
            if (count == 1) {
              /* reading line: the token is a number in the line */
              if (!flag_In_array) {
                /* reading num: not already in a block: starts a new data block */
                block_Current_index++;
                flag_In_array    = 1;
                block_Num_Columns= 0;
                if (block_number > 0) {
                  /* initialise a new data block */
                  Rows = 0;
                  count_in_array = 0;
                } /* else append */
              }
              /* reading num: all blocks or selected block */
              if (flag_In_array && (block_number == 0 ||
                  block_number == block_Current_index)) {
                /* starting block: already the desired number of rows ? */
                if (block_Num_Columns == 0 &&
                    max_rows > 0 && Rows >= max_rows) {
                  flag_End_Line      = 1;
                  flag_End_row_loop  = 1;
                  flag_In_array      = 0;
                  /* reposition to begining of line (ignore line) */
                  fseek(hfile, back_pos, SEEK_SET);
                } else { /* store into data array */
                  if (count_in_array >= malloc_size) {
                    /* realloc data buffer if necessary */
                    malloc_size = count_in_array*1.5;
                    Datatmp = (double*) realloc(Data, malloc_size*sizeof(double));
                    if (Datatmp == NULL) {
                      fprintf(stderr, "Error: Can not re-allocate memory %zi (Table_Read_Handle).\n",
                              malloc_size*sizeof(double));
		      free(Data);
                      return (-1);
                    } else {
                      Data=Datatmp;
                    }
                  }
                  if (0 == block_Num_Columns) Rows++;
                  Data[count_in_array] = X;
                  count_in_array++;
                  block_Num_Columns++;
                }
              } /* reading num: end if flag_In_array */
            } /* end reading num: end if sscanf lexeme -> numerical */
            else {
              /* reading line: the token is not numerical in that line. end block */
              if (block_Current_index == block_number) {
                flag_End_Line = 1;
                flag_End_row_loop = 1;
              } else {
                flag_In_array = 0;
                flag_End_Line = 1;
              }
            }
          }
          else {
            /* no more tokens in line */
            flag_End_Line = 1;
            if (block_Num_Columns > 0) Columns = block_Num_Columns;
          }

          // parse next token
          lexeme = strtok(NULL, seps);

        } /* while (!flag_End_Line) */
      } /* end: if fgets */
      else flag_End_row_loop = 1; /* else fgets : end of file */
      free(line);
    } while (!flag_End_row_loop); /* end while flag_End_row_loop */

    Table->block_number = block_number;
    Table->array_length = 1;

    // shrink header to actual size (plus terminating 0-byte)
    if (count_in_header) {
      Headertmp = (char*)realloc(Header, count_in_header*sizeof(char) + 1);
      if(!Headertmp) {
	fprintf(stderr, "Error: Could not shrink Header (Table_Read_Handle).\n");
	free(Header);
	return (-1);
      } else {
        Header = Headertmp;
      }
    }
    Table->header = Header;

    if (count_in_array*Rows*Columns == 0)
    {
      Table->rows         = 0;
      Table->columns      = 0;
      free(Data);
      return (0);
    }
    if (Rows * Columns != count_in_array)
    {
      fprintf(stderr, "Warning: Read_Table :%s %s Data has %li values that should be %li x %li\n",
        (Table->filename[0] != '\0' ? Table->filename : ""),
        (!block_number ? " catenated" : ""),
        count_in_array, Rows, Columns);
      Columns = count_in_array; Rows = 1;
    }
    if (count_invalid)
    {
      fprintf(stderr,"Warning: Read_Table :%s %s Data has %li invalid lines (*****). Ignored.\n",
      (Table->filename[0] != '\0' ? Table->filename : ""),
        (!block_number ? " catenated" : ""),
        count_invalid);
    }
    Datatmp     = (double*)realloc(Data, count_in_array*sizeof(double));
    if(!Datatmp) {
      fprintf(stderr, "Error: Could reallocate Data block to %li doubles (Table_Read_Handle).\n", count_in_array);
      free(Data);
      return (-1);
    } else {
      Data = Datatmp;
    }
    Table->data         = Data;
    Table->rows         = Rows;
    Table->columns      = Columns;

    return (count_in_array);

  } /* end Table_Read_Handle */

/*******************************************************************************
* long Table_Rebin(t_Table *Table)
*   ACTION: rebin a single Table, sorting 1st column in ascending order
*   input   Table: single table containing data.
*                  The data block is reallocated in this process
*   return  updated Table with increasing, evenly spaced first column (index 0)
*           number of data elements (-1: error, 0:empty data)
*******************************************************************************/
  long Table_Rebin(t_Table *Table)
  {
    double new_step=0;
    long   i;
    /* performs linear interpolation on X axis (0-th column) */

    if (!Table) return(-1);
    if (!Table->data 
    || Table->rows*Table->columns == 0 || !Table->step_x)
      return(0);
    Table_Stat(Table); /* recompute statitstics and minimal step */
    new_step = Table->step_x; /* minimal step in 1st column */

    if (!(Table->constantstep)) /* not already evenly spaced */
    {
      long Length_Table;
      double *New_Table;

      Length_Table = ceil(fabs(Table->max_x - Table->min_x)/new_step)+1;
      /*return early if the rebinned table will become too large*/
      if (Length_Table > mcread_table_rebin_maxsize){
        fprintf(stderr,"WARNING: (Table_Rebin): Rebinning table from %s would exceed 1M rows. Skipping.\n", Table->filename); 
        return(Table->rows*Table->columns);
      }
      New_Table    = (double*)malloc(Length_Table*Table->columns*sizeof(double));
      if (!New_Table) {
	fprintf(stderr,"Could not allocate New_Table of size %ld x %ld\n", Length_Table, Table->columns);
	exit(-1);
      }
      for (i=0; i < Length_Table; i++)
      {
        long   j;
        double X;
        X = Table->min_x + i*new_step;
        New_Table[i*Table->columns] = X;
        for (j=1; j < Table->columns; j++)
          New_Table[i*Table->columns+j]
                = Table_Value(*Table, X, j);
      } /* end for i */

      Table->rows = Length_Table;
      Table->step_x = new_step;
      Table->max_x = Table->min_x + (Length_Table-1)*new_step; 
      /*max might not be the same anymore
       * Use Length_Table -1 since the first and laset rows are the limits of the defined interval.*/
      {
        double *Old_Table = Table->data;
        Table->data = New_Table;
        Table->constantstep=1;
        /* keep the file cache consistent: it may hold (a copy of) this Table */
        if (Table_File_List_Handler(REBIN, Table, Old_Table) == NULL)
          free(Old_Table);
      }
    } /* end else (!constantstep) */
    return (Table->rows*Table->columns);
  } /* end Table_Rebin */

/*******************************************************************************
* double Table_Index(t_Table Table, long i, long j)
*   ACTION: read an element [i,j] of a single Table
*   input   Table: table containing data
*           i : index of row      (0:Rows-1)
*           j : index of column   (0:Columns-1)
*   return  Value = data[i][j]
* Returns Value from the i-th row, j-th column of Table
* Tests are performed on indexes i,j to avoid errors
*******************************************************************************/

#ifndef MIN
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#endif

double Table_Index(t_Table Table, long i, long j)
{
  long AbsIndex;

  if (Table.rows == 1 || Table.columns == 1) {
    /* vector */
    j = MIN(MAX(0, i+j), Table.columns*Table.rows - 1);
    i = 0;
  } else {
    /* matrix */
    i = MIN(MAX(0, i), Table.rows - 1);
    j = MIN(MAX(0, j), Table.columns - 1);
  }

  /* handle vectors specifically */
  AbsIndex = i*(Table.columns)+j;

  if (Table.data != NULL)
    return (Table.data[AbsIndex]);
  else
    return 0;
} /* end Table_Index */

/*******************************************************************************
* void Table_SetElement(t_Table *Table, long i, long j, double value)
*   ACTION: set an element [i,j] of a single Table
*   input   Table: table containing data
*           i : index of row      (0:Rows-1)
*           j : index of column   (0:Columns-1)
*           value = data[i][j]
* Returns 0 in case of error
* Tests are performed on indexes i,j to avoid errors
*******************************************************************************/
int Table_SetElement(t_Table *Table, long i, long j,
                     double value)
{
  long AbsIndex;

  if (Table->rows == 1 || Table->columns == 1) {
    /* vector */
    j = MIN(MAX(0, i+j), Table->columns*Table->rows - 1); i=0;
  } else {
    /* matrix */
    i = MIN(MAX(0, i), Table->rows - 1);
    j = MIN(MAX(0, j), Table->columns - 1);
  }

  AbsIndex = i*(Table->columns)+j;
  if (Table->data != NULL) {
    Table->data[AbsIndex] = value;
    return 1;
  }

  return 0;
} /* end Table_SetElement */

/*******************************************************************************
* double Table_Value(t_Table Table, double X, long j)
*   ACTION: read column [j] of a single Table at row which 1st column is X
*   input   Table: table containing data.
*           X : data value in the first column (index 0)
*           j : index of column from which is extracted the Value (0:Columns-1)
*   return  Value = data[index for X][j] with linear interpolation
* Returns Value from the j-th column of Table corresponding to the
* X value for the 1st column (index 0)
* Tests are performed (within Table_Index) on indexes i,j to avoid errors
* NOTE: data should rather be monotonic, and evenly sampled.
*******************************************************************************/
double Table_Value(t_Table Table, double X, long j)
{
  long   Index = -1;
  double X1=0, Y1=0, X2=0, Y2=0;
  double ret=0;

  if (X > Table.max_x) return Table_Index(Table,Table.rows-1  ,j);
  if (X < Table.min_x) return Table_Index(Table,0  ,j);

  // Use constant-time lookup when possible
  if(Table.constantstep) {
    Index = (long)floor(
              (X - Table.min_x) / (Table.max_x - Table.min_x) * (Table.rows-1));
    X1 = Table_Index(Table,Index-1,0);
    X2 = Table_Index(Table,Index  ,0);
  }
  // Use binary search on large, monotonic tables
  else if(Table.monotonic && Table.rows > 100) {
    long left = Table.min_x;
    long right = Table.max_x;

    while (!((X1 <= X) && (X < X2)) && (right - left > 1)) {
      Index = (left + right) / 2;

      X1 = Table_Index(Table, Index-1, 0);
      X2 = Table_Index(Table, Index,   0);

      if (X < X1) {
        right = Index;
      } else {
        left  = Index;
      }
    }
  }

  // Fall back to linear search, if no-one else has set X1, X2 correctly
  if (!((X1 <= X) && (X < X2))) {
    /* look for index surrounding X in the table -> Index */
    for (Index=1; Index <= Table.rows-1; Index++) {
        X1 = Table_Index(Table, Index-1,0);
        X2 = Table_Index(Table, Index  ,0);
        if ((X1 <= X) && (X < X2)) break;
      } /* end for Index */
  }

  Y1 = Table_Index(Table,Index-1, j);
  Y2 = Table_Index(Table,Index  , j);

#ifdef OPENACC
#define strcmp(a,b) str_comp(a,b)
#endif

  if (!strcmp(Table.method,"linear")) {
    ret = Table_Interp1d(X, X1,Y1, X2,Y2);
  }
  else if (!strcmp(Table.method,"nearest")) {
    ret = Table_Interp1d_nearest(X, X1,Y1, X2,Y2);
  }

#ifdef OPENACC
#ifdef strcmp
#undef strcmp
#endif
#endif

  return ret;
} /* end Table_Value */

/*******************************************************************************
* double Table_Value2d(t_Table Table, double X, double Y)
*   ACTION: read element [X,Y] of a matrix Table
*   input   Table: table containing data.
*           X : row index, may be non integer
*           Y : column index, may be non integer
*   return  Value = data[index X][index Y] with bi-linear interpolation
* Returns Value for the indices [X,Y]
* Tests are performed (within Table_Index) on indexes i,j to avoid errors
* NOTE: data should rather be monotonic, and evenly sampled.
*******************************************************************************/
double Table_Value2d(t_Table Table, double X, double Y)
  {
    long   x1,x2,y1,y2;
    double z11,z12,z21,z22;
    double ret=0;

    x1 = (long)floor(X);
    y1 = (long)floor(Y);

    if (x1 > Table.rows-1 || x1 < 0) {
      x2 = x1;
    } else {
      x2 = x1 + 1;
    }

    if (y1 > Table.columns-1 || y1 < 0) {
      y2 = y1;
    } else {
      y2 = y1 + 1;
    }

    z11 = Table_Index(Table, x1, y1);

    if (y2 != y1) z12=Table_Index(Table, x1, y2); else z12 = z11;
    if (x2 != x1) z21=Table_Index(Table, x2, y1); else z21 = z11;
    if (y2 != y1) z22=Table_Index(Table, x2, y2); else z22 = z21;

#ifdef OPENACC
#define strcmp(a,b) str_comp(a,b)
#endif

    if (!strcmp(Table.method,"linear"))
      ret = Table_Interp2d(X,Y, x1,y1,x2,y2, z11,z12,z21,z22);
#ifdef OPENACC
#ifdef strcmp
#undef strcmp
#endif
#endif
    else {
      if (fabs(X-x1) < fabs(X-x2)) {
        if (fabs(Y-y1) < fabs(Y-y2)) ret = z11; else ret = z12;
      } else {
        if (fabs(Y-y1) < fabs(Y-y2)) ret = z21; else ret = z22;
      }
    }
    return ret;
  } /* end Table_Value2d */


/*******************************************************************************
* void Table_Free(t_Table *Table)
*   ACTION: free a single Table. First Call Table_File_list_gc. If this returns
*   non-zero it means there are more refernces to the table, and so the table
*   should not bee freed.
*   return: empty Table
*******************************************************************************/
  void Table_Free(t_Table *Table)
  {
    if( !Table_File_List_gc(Table) ){
       return;
    } 
    if (!Table) return;
    if (Table->data   != NULL) free(Table->data);
    if (Table->header != NULL) free(Table->header);
    Table->data   = NULL;
    Table->header = NULL;
  } /* end Table_Free */

/******************************************************************************
* void Table_Info(t_Table Table)
*    ACTION: print informations about a single Table
*******************************************************************************/
  long Table_Info(t_Table Table)
  {
    char buffer[256];
    long ret=0;

    if (!Table.block_number) strcpy(buffer, "catenated");
    else sprintf(buffer, "block %li", Table.block_number);
    printf("Table from file '%s' (%s)",
        Table.filename[0] != '\0' ? Table.filename : "", buffer);
    if ((Table.data != NULL) && (Table.rows*Table.columns))
    {
      printf(" is %li x %li ", Table.rows, Table.columns);
      if (Table.rows*Table.columns > 1)
        printf("(x=%g:%g)", Table.min_x, Table.max_x);
      else printf("(x=%g) ", Table.min_x);
      ret = Table.rows*Table.columns;
      if (Table.monotonic)    printf(", monotonic");
      if (Table.constantstep) printf(", constant step");
      printf(". interpolation: %s\n", Table.method);
    }
    else printf(" is empty.\n");

    if (Table.header && strlen(Table.header)) {
      char *header;
      int  i;
      header = malloc(80);
      if (!header) return(ret);
      for (i=0; i<80; header[i++]=0);
      strncpy(header, Table.header, 75);
      if (strlen(Table.header) > 75) {
        strcat( header, " ...");
      }
      for (i=0; i<strlen(header); i++)
        if (header[i] == '\n' || header[i] == '\r') header[i] = ';';
      printf("  '%s'\n", header);
      free(header);
    }

    return(ret);
  } /* end Table_Info */

/******************************************************************************
* long Table_Init(t_Table *Table, m, n)
*   ACTION: initialise a Table to empty m by n table
*   return: empty Table
******************************************************************************/
long Table_Init(t_Table *Table, long rows, long columns)
{
  double *data=NULL;
  long   i;

  if (!Table) return(0);

  Table->header  = NULL;
  Table->filename[0]= '\0';
  Table->filesize= 0;
  Table->min_x   = 0;
  Table->max_x   = 0;
  Table->step_x  = 0;
  Table->block_number = 0;
  Table->array_length = 0;
  Table->monotonic    = 0;
  Table->constantstep = 0;
  Table->begin   = 0;
  Table->end     = 0;
  strcpy(Table->method,"linear");

  if (rows*columns >= 1) {
    data    = (double*)malloc(rows*columns*sizeof(double));
    if (data) for (i=0; i < rows*columns; data[i++]=0);
    else {
      if(Table->quiet<2)
        fprintf(stderr,"Error: allocating %ld double elements."
            "Too big (Table_Init).\n", rows*columns);
      rows = columns = 0;
    }
  }
  Table->rows    = (rows >= 1 ? rows : 0);
  Table->columns = (columns >= 1 ? columns : 0);
  Table->data    = data;
  return(Table->rows*Table->columns);
} /* end Table_Init */

/******************************************************************************
* long Table_Write(t_Table Table, char *file, x1,x2, y1,y2)
*   ACTION: write a Table to disk (ascii).
*     when x1=x2=0 or y1=y2=0, the table default limits are used.
*   return: 0=all is fine, non-0: error
*******************************************************************************/
MCDETECTOR Table_Write(t_Table Table, char *file, char *xl, char *yl, 
  double x1, double x2, double y1, double y2)
{
  MCDETECTOR detector;

  if ((Table.data == NULL) && (Table.rows*Table.columns)) {
    detector.m = 0;
    detector.xmin = 0;
    detector.xmax = 0;
    detector.ymin = 0;
    detector.ymax = 0;
    detector.zmin = 0;
    detector.zmax = 0; 
    detector.intensity = 0;
    detector.error = 0;
    detector.events = 0;
    detector.min = 0;
    detector.max = 0;
    detector.mean = 0;
    detector.centerX = 0;
    detector.halfwidthX = 0;
    detector.centerY = 0;
    detector.halfwidthY = 0;
    detector.rank = 0;
    detector.istransposed = 0;
    detector.n = 0;
    detector.p = 0;
    detector.date_l = 0;
    detector.p0 = NULL;
    detector.p1 = NULL;
    detector.p2 = NULL;
    return(detector); /* Table is empty - nothing to do */
  }
  if (!x1 && !x2) {
    x1 = Table.min_x;
    x2 = Table.max_x;
  }
  if (!y1 && !y2) {
    y1 = 1;
    y2 = Table.columns;
  }

  /* transfer content of the Table into a 2D detector */
  Coords coords = { 0, 0, 0};
  Rotation rot;
  rot_set_rotation(rot, 0, 0, 0);
  
  if (Table.rows == 1 || Table.columns == 1) {
    detector = mcdetector_out_1D(Table.filename,
                      xl ? xl : "", yl ? yl : "",
                      "x", x1, x2,
                      Table.rows * Table.columns,
                      NULL, Table.data, NULL,
		      file, file, coords, rot,9999);
  } else {
    detector = mcdetector_out_2D(Table.filename,
                      xl ? xl : "", yl ? yl : "",
                      x1, x2, y1, y2,
                      Table.rows, Table.columns,
                      NULL, Table.data, NULL,
		      file, file, coords, rot,9999);
  }
  return(detector);
}

/******************************************************************************
* void Table_Stat(t_Table *Table)
*   ACTION: computes min/max/mean step of 1st column for a single table (private)
*   return: updated Table
*******************************************************************************/
  static void Table_Stat(t_Table *Table)
  {
    long   i;
    double max_x, min_x;
    double row=1;
    char   monotonic=1;
    char   constantstep=1;
    double step=0;
    long n;

    if (!Table) return;
    if (!Table->rows || !Table->columns) return;
    if (Table->rows == 1) row=0; // single row
    max_x = -FLT_MAX;
    min_x =  FLT_MAX;
    n     = (row ? Table->rows : Table->columns);
    /* get min and max of first column/vector */
    for (i=0; i < n; i++)
    {
      double X;
      X = (row ? Table_Index(*Table,i  ,0)
                               : Table_Index(*Table,0, i));
      if (X < min_x) min_x = X;
      if (X > max_x) max_x = X;
    } /* for */
    
    /* test for monotonicity and constant step if the table is an XY or single vector */
    if (n > 1) {
      /* mean step */
      step = (max_x - min_x)/(n-1);
      /* now test if table is monotonic on first column, and get minimal step size */
      for (i=0; i < n-1; i++) {
        double X, diff;;
        X    = (row ? Table_Index(*Table,i  ,0)
                    : Table_Index(*Table,0,  i));
        diff = (row ? Table_Index(*Table,i+1,0)
                    : Table_Index(*Table,0,  i+1)) - X;
        if (diff && fabs(diff) < fabs(step)) step = diff;
        /* change sign ? */
        if ((max_x - min_x)*diff < 0 && monotonic)
          monotonic = 0;
      } /* end for */
      
      /* now test if steps are constant within READ_TABLE_STEPTOL */
      if(!step){
        /*means there's a disconitnuity -> not constantstep*/
        constantstep=0;
      }else if (monotonic) {
        for (i=0; i < n-1; i++) {
          double X, diff;
          X    = (row ? Table_Index(*Table,i  ,0)
              : Table_Index(*Table,0,  i));
          diff = (row ? Table_Index(*Table,i+1,0)
              : Table_Index(*Table,0,  i+1)) - X;
          if ( fabs(step)*(1+READ_TABLE_STEPTOL) < fabs(diff) ||
                fabs(diff) < fabs(step)*(1-READ_TABLE_STEPTOL) )
          { constantstep = 0; break; }
        }
      }

    }
    Table->step_x= step;
    Table->max_x = max_x;
    Table->min_x = min_x;
    Table->monotonic = monotonic;
    Table->constantstep = constantstep;
  } /* end Table_Stat */

/******************************************************************************
* t_Table *Table_Read_Array(char *File, long *blocks)
*   ACTION: read as many data blocks as available, iteratively from file
*   return: initialized t_Table array, last element is an empty Table.
*           the number of extracted blocks in non NULL pointer *blocks
*******************************************************************************/
  t_Table *Table_Read_Array(char *File, long *blocks)
  {
    t_Table *Table_Array    = NULL;
    t_Table *Table_Arraytmp = NULL;
    long offset=0;
    long block_number=0;
    long allocated=256;
    long nelements=1;

    /* first allocate an initial empty t_Table array */
    Table_Array = (t_Table *)malloc(allocated*sizeof(t_Table));
    if (!Table_Array) {
      fprintf(stderr, "Error: Can not allocate memory %zi (Table_Read_Array).\n",
         allocated*sizeof(t_Table));
      *blocks = 0;
      return (NULL);
    }

    while (nelements > 0)
    {
      t_Table Table;

      /* if ok, set t_Table block number else exit loop */
      block_number++;
      Table.block_number = block_number;
      
      /* access file at offset and get following block. Block number is from the set offset
       * hence the hardcoded 1 - i.e. the next block counted from offset.*/
      nelements = Table_Read_Offset(&Table, File, 1, &offset,0);
      /*if the block is empty - don't store it*/
      if (nelements>0){
          /* if t_Table array is not long enough, expand and realocate */
          if (block_number >= allocated-1) {
              allocated += 256;
              Table_Arraytmp = (t_Table *)realloc(Table_Array,
                      allocated*sizeof(t_Table));
              if (!Table_Arraytmp) {
                  fprintf(stderr, "Error: Can not re-allocate memory %zi (Table_Read_Array).\n",
                          allocated*sizeof(t_Table));
                  free(Table_Array);
                  *blocks = 0;
                  return (NULL);
              } else {
                Table_Array = Table_Arraytmp;
              }
          }
          /* store it into t_Table array */
          //snprintf(Table.filename, 1024, "%s#%li", File, block_number-1);
          Table_Array[block_number-1] = Table;
      }
      /* continues until we find an empty block */
    }
    /* send back number of extracted blocks */
    if (blocks) *blocks = block_number-1;

    /* now store total number of elements in Table array */
    for (offset=0; offset < block_number;
      Table_Array[offset++].array_length = block_number-1);

    return(Table_Array);
  } /* end Table_Read_Array */
/*******************************************************************************
* void Table_Free_Array(t_Table *Table)
*   ACTION: free a Table array
*******************************************************************************/
  void Table_Free_Array(t_Table *Table)
  {
    long index;
    if (!Table) return;
    for (index=0;index < Table[0].array_length; index++){
            Table_Free(&Table[index]);
    }
    free(Table);
  } /* end Table_Free_Array */

/******************************************************************************
* long Table_Info_Array(t_Table *Table)
*    ACTION: print informations about a Table array
*    return: number of elements in the Table array
*******************************************************************************/
  long Table_Info_Array(t_Table *Table)
  {
    long index=0;

    if (!Table) return(-1);
    while (index < Table[index].array_length
       && (Table[index].data || Table[index].header)
       && (Table[index].rows*Table[index].columns) ) {
      Table_Info(Table[index]);
      index++;
    }
    printf("This Table array contains %li elements\n", index);
    return(index);
  } /* end Table_Info_Array */

/******************************************************************************
* char **Table_ParseHeader(char *header, symbol1, symbol2, ..., NULL)
*    ACTION: search for char* symbols in header and return their value or NULL
*            the search is not case sensitive.
*            Last argument MUST be NULL
*    return: array of char* with line following each symbol, or NULL if not found
*******************************************************************************/
#ifndef MyNL_ARGMAX
#define MyNL_ARGMAX 50
#endif

static int Table_ParseHeader_wordchar(char c) {
  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}

/* Find symbol in header as a whole word (like regex \b...\b), not case
   sensitive. Word boundaries are only required where the symbol itself starts
   or ends with a word character, so "sigma_a " or "e_min=" match as given.
   E.g. "Vc" must not match inside a file name such as /tmp/tmp.0.aVcX9q,
   which cif2hkl writes into the header before the real "Vc" line. */
static char *Table_ParseHeader_find(char *header, char *symbol) {
  size_t len = strlen(symbol);
  char *pos = header;
  while ((pos = (char*)strcasestr(pos, symbol))) {
    int start_ok = !Table_ParseHeader_wordchar(symbol[0])
                || pos == header || !Table_ParseHeader_wordchar(pos[-1]);
    int end_ok   = !Table_ParseHeader_wordchar(symbol[len-1])
                || !Table_ParseHeader_wordchar(pos[len]);
    if (start_ok && end_ok) return pos;
    pos++;
  }
  return NULL;
}

char **Table_ParseHeader_backend(char *header, ...){
  va_list ap;
  char exit_flag=0;
  int counter   =0;
  char **ret    =NULL;
  if (!header || header[0]=='\0') return(NULL);

  ret = (char**)calloc(MyNL_ARGMAX, sizeof(char*));
  if (!ret) {
    printf("Table_ParseHeader: Cannot allocate %i values array for Parser (Table_ParseHeader).\n",
      MyNL_ARGMAX);
    return(NULL);
  }
  for (counter=0; counter < MyNL_ARGMAX; ret[counter++] = NULL);
  counter=0;

  va_start(ap, header);
  while(!exit_flag && counter < MyNL_ARGMAX-1)
  {
    char *arg_char=NULL;
    char *pos     =NULL;
    /* get variable argument value as a char */
    arg_char = va_arg(ap, char *);
    if (!arg_char || arg_char[0]=='\0'){
      exit_flag = 1; break;
    }
    /* search for the symbol in the header */
    pos = Table_ParseHeader_find(header, arg_char);
    if (pos) {
      char *eol_pos;
      eol_pos = strchr(pos+strlen(arg_char), '\n');
      if (!eol_pos)
        eol_pos = strchr(pos+strlen(arg_char), '\r');
      if (!eol_pos)
        eol_pos = pos+strlen(pos)-1;
      ret[counter] = (char*)malloc(eol_pos - pos);
      if (!ret[counter]) {
        printf("Table_ParseHeader: Cannot allocate value[%i] array for Parser searching for %s (Table_ParseHeader).\n",
          counter, arg_char);
        exit_flag = 1; break;
      }
      strncpy(ret[counter], pos+strlen(arg_char), eol_pos - pos - strlen(arg_char));
      ret[counter][eol_pos - pos - strlen(arg_char)]='\0';
    }
    counter++;
  }
  va_end(ap);
  return(ret);
} /* Table_ParseHeader */

/******************************************************************************
* double Table_Interp1d(x, x1, y1, x2, y2)
*    ACTION: interpolates linearly at x between y1=f(x1) and y2=f(x2)
*    return: y=f(x) value
*******************************************************************************/
double Table_Interp1d(double x,
  double x1, double y1,
  double x2, double y2)
{
  double slope;
  if (x2 == x1) return (y1+y2)/2;
  if (y1 == y2) return  y1;
  slope = (y2 - y1)/(x2 - x1);
  return y1+slope*(x - x1);
} /* Table_Interp1d */

/******************************************************************************
* double Table_Interp1d_nearest(x, x1, y1, x2, y2)
*    ACTION: table lookup with nearest method at x between y1=f(x1) and y2=f(x2)
*    return: y=f(x) value
*******************************************************************************/
double Table_Interp1d_nearest(double x,
  double x1, double y1,
  double x2, double y2)
{
  if (fabs(x-x1) < fabs(x-x2)) return (y1);
  else return(y2);
} /* Table_Interp1d_nearest */

/******************************************************************************
* double Table_Interp2d(x,y, x1,y1, x2,y2, z11,z12,z21,z22)
*    ACTION: interpolates bi-linearly at (x,y) between z1=f(x1,y1) and z2=f(x2,y2)
*    return: z=f(x,y) value
*    x,y |   x1   x2
*    ----------------
*     y1 |   z11  z21
*     y2 |   z12  z22
*******************************************************************************/
double Table_Interp2d(double x, double y,
  double x1, double y1,
  double x2, double y2,
  double z11, double z12, double z21, double z22)
{
  double ratio_x, ratio_y;
  if (x2 == x1) return Table_Interp1d(y, y1,z11, y2,z12);
  if (y1 == y2) return Table_Interp1d(x, x1,z11, x2,z21);

  ratio_y = (y - y1)/(y2 - y1);
  ratio_x = (x - x1)/(x2 - x1);
  return (1-ratio_x)*(1-ratio_y)*z11 + ratio_x*(1-ratio_y)*z21
    + ratio_x*ratio_y*z22         + (1-ratio_x)*ratio_y*z12;
} /* Table_Interp2d */

/* end of read_table-lib.c */
#endif // READ_TABLE_LIB_C

/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Runtime: share/interoff-lib.h
*
* %Identification
* Written by: Reynald Arnerin
* Date:    Jun 12, 2008
* Release:
* Version:
*
* Object File Format intersection header for McStas/McXtrace.
*
* Such files may be obtained with e.g.
*   qhull < points.xyz Qx Qv Tv o > points.off
* where points.xyz has format:
*   3
*   <nb_points>
*   <x> <y> <z>
*   ...
* The resulting file should have its first line being changed from '3' into 'OFF'.
* It can then be displayed with geomview.
* A similar, but somewhat older solution is to use 'powercrust' with e.g.
*   powercrust -i points.xyz
* which will generate a 'pc.off' file to be renamed as suited.
*
* Supported file formats
*   OFF (and the NOFF/COFF/CNOFF/STOFF variants, extra vertex data is ignored)
*   PLY in 'format ascii' (x y z must be the first three vertex properties)
*
* Polygons may have any number (>=3) of vertices.
*
* Per-face properties (e.g. reflectivity)
*   Any numbers following the vertex indices of a face, on the same line, are
*   stored as per-face properties:
*     nv  i1 i2 ... inv   p0 p1 p2 ...
*   They are available as data.facePropArray (column-major, see off_struct)
*   or through off_face_prop(&data, face, k, default).
*   Reflecting components (Guide_anyshape with file_coatings=1) use the convention
*     p0 = m,  p1 = alpha [AA],  p2 = W [AA^-1]  [, p3 = R0, p4 = Qc [AA^-1]]
*   for which the convenience pointers face_m_Array, face_alpha_Array and
*   face_W_Array are set when at least 3 properties are present.
*   The face index returned by off_intersect_idx/off_x_intersect_idx is the
*   0-based order of the face in the file.
*
* This library replaces the former r-interoff-lib (which is now a thin
* compatibility wrapper around this one).
*
*******************************************************************************/



#ifndef INTEROFF_LIB_H
#define INTEROFF_LIB_H "$Revision$"

#ifndef OFF_EPSILON
#define OFF_EPSILON 1e-13
#endif

/* Only used with -DOFF_LEGACY (full sorted list of intersections) */
#ifndef OFF_INTERSECT_MAX
#ifdef OPENACC
#define OFF_INTERSECT_MAX 100
#else
#define OFF_INTERSECT_MAX 1024
#endif
#endif

#define N_VERTEX_DISPLAYED    200000

/* Conventional column indices for reflectivity face properties */
#define OFF_FACEPROP_M      0
#define OFF_FACEPROP_ALPHA  1
#define OFF_FACEPROP_W      2
#define OFF_FACEPROP_R0     3
#define OFF_FACEPROP_QC     4

typedef struct intersection {
	MCNUM time;  	  //time of the intersection
	Coords v;	      //intersection point
	Coords normal;  //normal vector of the surface intersected (unit length)
	short in_out;	  //1 if the ray enters the volume, -1 otherwise
	short edge;	    //1 if the intersection is on the boundary of the polygon, and error is possible
	unsigned long index; // index of the face
} intersection;

/* A polygon is a view into the global vertex table: no copy, no size limit */
typedef struct polygon {
  Coords*        vtx;   // global vertex table (off_struct.vtxArray)
  unsigned long* idx;   // npol vertex indices into vtx (points into off_struct.faceArray)
  int            npol;  // number of vertices
  Coords         normal;// unit normal
  double         D;     // plane equation: normal . r = D
} polygon;

typedef struct off_struct {
    long vtxSize;          // number of vertices
    long polySize;         // number of faces (polygons)
    long faceSize;         // length of faceArray
    Coords* vtxArray;
    #pragma acc shape(vtxArray[0:vtxSize]) init_needed(vtxSize)
    Coords* normalArray;   // unit normal per face
    #pragma acc shape(normalArray[0:polySize]) init_needed(polySize)
    unsigned long* faceArray; // [nv i1 .. inv | nv i1 .. inv | ...]
    #pragma acc shape(faceArray[0:faceSize]) init_needed(faceSize)
    double* DArray;        // plane constant per face: normal . r = D
    #pragma acc shape(DArray[0:polySize]) init_needed(polySize)
    /* optional per-face properties, read from the numbers following the vertex
       indices of each face. Property k of face i is facePropArray[k*polySize+i] */
    int     nfaceprops;    // number of property columns (0 when none are given)
    long    facePropSize;  // = nfaceprops*polySize
    double* facePropArray;
    #pragma acc shape(facePropArray[0:facePropSize]) init_needed(facePropSize)
    /* convenience views (m, alpha, W) into facePropArray, NULL unless nfaceprops>=3 */
    double* face_m_Array;
    #pragma acc shape(face_m_Array[0:polySize]) init_needed(polySize)
    double* face_alpha_Array;
    #pragma acc shape(face_alpha_Array[0:polySize]) init_needed(polySize)
    double* face_W_Array;
    #pragma acc shape(face_W_Array[0:polySize]) init_needed(polySize)
    Coords bbmin, bbmax;   // bounding box of the (scaled) vertices
    char *filename;
    int mantidflag;
    long mantidoffset;
#ifdef OFF_LEGACY
    intersection* intersects; // After a call to off_intersect_all contains the list of intersections.
    #pragma acc shape(intersects[0:OFF_INTERSECT_MAX])
#endif
    int nextintersect;     // face index of the 'next' intersection after call to off_intersect_all
    int numintersect;      // Number of intersections after call to off_intersect_all
} off_struct;

/*******************************************************************************
* long off_init(  char *offfile, double xwidth, double yheight, double zdepth, off_struct* data)
* ACTION: read an OFF file, optionally center object and rescale, initialize OFF data structure
* INPUT: 'offfile' OFF file to read
*        'xwidth,yheight,zdepth' if given as non-zero, apply bounding box.
*           Specifying only one of these will also use the same ratio on all axes
*        'notcenter' center the object to the (0,0,0) position in local frame when set to zero
* RETURN: number of polyhedra and 'data' OFF structure
*         per-face properties (if any) are stored in data->facePropArray
*******************************************************************************/
long off_init(  char *offfile, double xwidth, double yheight, double zdepth,
                int notcenter, off_struct* data);

/*******************************************************************************
* RESULT CONVENTION of off_intersect, off_intersect_all, off_x_intersect and
* their _idx variants (straight line or parabola through the object)
*
* All intersections of the trajectory with the faces are computed, for
* negative as well as positive times, and duplicates are merged (a hit on an
* edge or vertex shared by several faces counts once). Of these, the largest
* negative time and the smallest positive times are used:
*
*   situation                          t0                 t3                return
*   ---------------------------------  -----------------  ----------------  ------
*   no intersection at all             unchanged          unchanged         0
*   outside, object ahead              first hit (>0)     second hit (>0)   n >= 2
*   inside the object                  last hit (<0)      next hit (>0)     n >= 2
*   object entirely behind             last hit (<0)      0      (*)        1
*   one single hit ahead (open mesh,   the hit (>0)       FLT_MAX (*)       1
*     or grazing an edge)
*
*   (*) placeholder, not an intersection: n3 is then (0,0,0) and fi3 is 0.
*   n is the number of distinct intersections, capped at 4.
*
* So: a return value > 1 guarantees that t0 and t3 are both real intersections;
*     a return value of 1 means only t0 is real.
* The two placeholder values are chosen so that the usual idioms in components
* behave safely when only one intersection exists:
*   - 't3 > 0' tests and paths 't3 - max(t0,0)' see "nothing ahead" (t3 = 0)
*     when the object is behind,
*   - 'propagate to t0 when t0 > 0' works for a single hit ahead, and a
*     material path 't3 - t0' is then infinite (fully attenuated), never
*     negative.
* Times are in s for off_intersect*, lengths in m for off_x_intersect*.
* n0/n3 are unit normals of the faces hit (orientation as given by the vertex
* order in the file, not necessarily outward).
* With -DOFF_LEGACY the full sorted list is kept in data->intersects; the
* return value is then the number of intersections and t3 is left unchanged
* when there is only one.
*******************************************************************************/

/*******************************************************************************
* int off_intersect_all(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct *data )
* ACTION: computes intersection of neutron trajectory with an object.
* INPUT:  x,y,z and vx,vy,vz are the position and velocity of the neutron
*         ax, ay, az are the local acceleration vector
*         data points to the OFF data structure
* RETURN: see RESULT CONVENTION above (0: no intersection, 1: only t0 is an
*         intersection, >1: t0 and t3 are both intersections)
*         n0 and n3 are the corresponding (unit) normal vectors to the surface
*         data->numintersect is the number of distinct intersections (max 4)
*         data->nextintersect the index of the face hit at t0
*******************************************************************************/
#pragma acc routine
int off_intersect_all(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct *data );

/* Same as off_intersect_all, but also returns the (0-based) indices of the
   faces hit at t0 and t3 in fi0 and fi3 (NULL pointers are allowed). */
#pragma acc routine
int off_intersect_all_idx(double* t0, double* t3,
     Coords *n0, Coords *n3,
     unsigned long *fi0, unsigned long *fi3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct *data );

/*******************************************************************************
* int off_intersect(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct data )
* ACTION: computes intersection of neutron trajectory with an object.
* INPUT:  x,y,z and vx,vy,vz are the position and velocity of the neutron
*         ax, ay, az are the local acceleration vector
*         data points to the OFF data structure
* RETURN: see RESULT CONVENTION above (0: no intersection, 1: only t0 is an
*         intersection, >1: t0 and t3 are both intersections)
*         n0 and n3 are the corresponding (unit) normal vectors to the surface
*******************************************************************************/
#pragma acc routine
int off_intersect(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct data );

/* Same as off_intersect, also returning the indices of the faces hit */
#pragma acc routine
int off_intersect_idx(double* t0, double* t3,
     Coords *n0, Coords *n3,
     unsigned long *fi0, unsigned long *fi3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct data );

/*****************************************************************************
* int off_x_intersect(double* l0, double* l3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double kx, double ky, double kz,
     off_struct data )
* ACTION: computes intersection of an xray trajectory with an object.
* INPUT:  x,y,z and kx,ky,kz, are spatial coordinates and wavevector of the x-ray
*         respectively. data points to the OFF data structure.
* RETURN: see RESULT CONVENTION above, with lengths l0/l3 [m] instead of times
*         n0 and n3 are the corresponding (unit) normal vectors to the surface
*******************************************************************************/
#pragma acc routine
int off_x_intersect(double *l0,double *l3,
     Coords *n0, Coords *n3,
     double x,  double y,  double z,
     double kx, double ky, double kz,
     off_struct data );

/* Same as off_x_intersect, also returning the indices of the faces hit */
#pragma acc routine
int off_x_intersect_idx(double *l0,double *l3,
     Coords *n0, Coords *n3,
     unsigned long *fi0, unsigned long *fi3,
     double x,  double y,  double z,
     double kx, double ky, double kz,
     off_struct data );

/*******************************************************************************
* double off_face_prop(off_struct *data, unsigned long face, int k, double def)
* ACTION: return per-face property 'k' of face 'face', or 'def' when not defined
*******************************************************************************/
#pragma acc routine
double off_face_prop(off_struct *data, unsigned long face, int k, double def);

/*******************************************************************************
* void off_display(off_struct data)
* ACTION: display up to N_VERTEX_DISPLAYED points from the object
*******************************************************************************/
void off_display(off_struct);

/*******************************************************************************
void p_to_quadratic(Coords norm, MCNUM d, Coords acc, Coords pos, Coords vel,
                    double* teq)
* ACTION: define the quadratic for the intersection of a parabola with a plane
* INPUT: plane equation norm . r = d
*        'acc' acceleration vector
*        'vel' velocity of the particle
*        'pos' position of the particle
* RETURN: equation of parabola: teq(0) * t^2 + teq(1) * t + teq(2)
*******************************************************************************/
#pragma acc routine
void p_to_quadratic(Coords norm, MCNUM d, Coords acc, Coords pos, Coords vel,
		    double* teq);

/*******************************************************************************
int quadraticSolve(double eq[], double* x1, double* x2);
* ACTION: solves the quadratic for the roots x1 and x2
*         eq[0] * t^2 + eq[1] * t + eq[2] = 0
* INPUT: 'eq' the coefficients of the parabola
* RETURN: roots x1 and x2 and the number of solutions
*******************************************************************************/
#pragma acc routine
int quadraticSolve(double* eq, double* x1, double* x2);

#endif

/* end of interoff-lib.h */
/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Runtime: share/interoff-lib.c
*
* %Identification
* Written by: Reynald Arnerin
* Date:    Jun 12, 2008
* Origin: ILL
* Release: $Revision$
* Version: McStas X.Y
*
* Object File Format intersection library for McStas/McXtrace.
*
* Such files may be obtained with e.g.
*   qhull < points.xyz Qx Qv Tv o > points.off
* where points.xyz has format (it supports comments):
*   3
*   <nb_points>
*   <x> <y> <z>
*   ...
* The resulting file should have its first line being changed from '3' into 'OFF'.
* It can then be displayed with geomview.
* A similar, but somewhat older solution is to use 'powercrust' with e.g.
*   powercrust -i points.xyz
* which will generate a 'pc.off' file to be renamed as suited.
*
* Per-face properties (merged from r-interoff-lib by Peter Link / Gaetano
* Mangiapia, 2017/2022): numbers following the vertex indices of a face are
* stored per face, e.g. m, alpha and W supermirror values:
*   4  0 5 6 4   1.0 6.07 0.003
*
*******************************************************************************/

#ifndef INTEROFF_LIB_H
#include "interoff-lib.h"
#endif

#ifndef INTEROFF_LIB_C
#define INTEROFF_LIB_C "$Revision$"

#include <ctype.h>

#ifdef OPENACC // If on GPU map fprintf to printf
#define fprintf(stderr,...) printf(__VA_ARGS__)
#endif

#pragma acc routine
double off_F(double x, double y,double z,double A,double B,double C,double D) {
  return ( A*x + B*y + C*z + D );
}

#pragma acc routine
char off_sign(double a) {
  if (a<0)       return(-1);
  else if (a==0) return(0);
  else           return(1);
}

/* component k (0,1,2) of a Coords */
#pragma acc routine
double off_coord(Coords c, int k) {
  return (k==0 ? c.x : (k==1 ? c.y : c.z));
}

// off_normal ******************************************************************
// gives the unit normal vector of polygon p (Newell method, any number of vertices)
// returns the length of the non-normalised Newell vector (= 2*area)
#pragma acc routine
double off_normal(Coords* n, polygon p)
{
  int i=0,j=0;
  double len;
  n->x=0;n->y=0;n->z=0;
  for (i = 0, j = p.npol-1; i < p.npol; j = i++)
  {
    Coords v1=p.vtx[p.idx[i]];
    Coords v2=p.vtx[p.idx[j]];
    n->x += (v1.y - v2.y) * (v1.z + v2.z);
    n->y += (v1.z - v2.z) * (v1.x + v2.x);
    n->z += (v1.x - v2.x) * (v1.y + v2.y);
  }
  len = sqrt(n->x*n->x + n->y*n->y + n->z*n->z);
  if (len > 0) {
    n->x /= len; n->y /= len; n->z /= len;
  }
  return len;
} /* off_normal */

// off_pnpoly ******************************************************************
//based on http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
//The polygon is projected on the coordinate plane where its area is largest,
//selected from the (pre-computed) polygon normal.
//return 0 if the vertex is out
//    1 if it is in
//   -1 if on the boundary
#pragma acc routine
int off_pnpoly(polygon p, Coords v)
{
  int i=0, j=0, c = 0;
  int pol2dx=0,pol2dy=1;          //2d restriction of the poly
  double ax=fabs(p.normal.x), ay=fabs(p.normal.y), az=fabs(p.normal.z);
  double x, y;

  /* projected areas are proportional to the normal components: drop the largest */
  if(az<ax){
    if(ax<ay){
      pol2dy=2;   /* scratch y */
    }else{
      pol2dx=2;   /* scratch x */
    }
  }else if (az<ay){
    pol2dy=2;     /* scratch y */
  }
  x = off_coord(v, pol2dx);
  y = off_coord(v, pol2dy);

  //trace rays and test number of intersection
  for (i = 0, j = p.npol-1; i < p.npol; j = i++) {
    Coords vi = p.vtx[p.idx[i]], vj = p.vtx[p.idx[j]];
    double xi = off_coord(vi, pol2dx), yi = off_coord(vi, pol2dy);
    double xj = off_coord(vj, pol2dx), yj = off_coord(vj, pol2dy);
    double ex = xj - xi, ey = yj - yi;
    double px = x - xi,  py = y - yi;
    double cross = px*ey - py*ex;       /* = |e| * distance to the edge line */
    double len2  = ex*ex + ey*ey;

    /* is the point on the edge [vi,vj] (within OFF_EPSILON) ? */
    if (cross*cross <= OFF_EPSILON*OFF_EPSILON*len2) {
      double dot = px*ex + py*ey;
      if ((dot >= 0 && dot <= len2) || px*px+py*py <= OFF_EPSILON*OFF_EPSILON
          || (x-xj)*(x-xj)+(y-yj)*(y-yj) <= OFF_EPSILON*OFF_EPSILON) {
        c = -1;
        break;
      }
    }

    if ((((yi<=y) && (y<yj)) || ((yj<=y) && (y<yi))) &&
        (x < ex * (y - yi) / ey + xi))
      c = !c;
  }

  return c;
} /* off_pnpoly */

// off_intersectPoly ***********************************************************
//gives the intersection vertex between ray [a,b) and polygon p and its parametric value on (a b)
//based on http://geometryalgorithms.com/Archive/algorithm_0105/algorithm_0105.htm
#pragma acc routine
int off_intersectPoly(intersection *inter, Coords a, Coords b, polygon p)
{
  //direction vector of [a,b]
  Coords dir = {b.x-a.x, b.y-a.y, b.z-a.z};

  //the (unit) normal vector to the polygon, pre-computed at init
  Coords normale=p.normal;

  //scalar products
  MCNUM nw0  = p.D - scalar_prod(normale.x,normale.y,normale.z,a.x,a.y,a.z);
  MCNUM ndir = scalar_prod(normale.x,normale.y,normale.z,dir.x,dir.y,dir.z);
  inter->time = inter->edge = inter->in_out=0;
  inter->v = inter->normal = coords_set(0,0,1);
  inter->index = 0;

  if (fabs(ndir) < OFF_EPSILON)    // ray is parallel to polygon plane (or degenerate polygon)
    return 0;

  // get intersect point of ray with polygon plane
  inter->time = nw0 / ndir;            //parametric value the point on line (a,b)

  inter->v = coords_set(a.x + inter->time * dir.x,// intersect point of ray and plane
    a.y + inter->time * dir.y,
    a.z + inter->time * dir.z);

  int res=off_pnpoly(p,inter->v);

  inter->edge=(res==-1);
  if (ndir<0)
    inter->in_out=1;  //the negative dot product means we enter the surface
  else
    inter->in_out=-1;

  inter->normal=p.normal;

  return res;         //true if the intersection point lies inside the poly
} /* off_intersectPoly */

// off_insert4 *****************************************************************
// keep the 4 intersections of interest: t[0] is the largest negative time,
// t[1..3] are the three smallest positive times (sorted). Initially
// t = [-FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX].
// Duplicates (same time, same direction: hit on an edge/vertex shared by
// several faces) are only counted once.
#pragma acc routine
void off_insert4(intersection *t, int *t_size, intersection x)
{
  int k;
  intersection xtmp;
  for (k=0; k<4; k++)
    if (t[k].in_out == x.in_out && fabs(t[k].time - x.time) < OFF_EPSILON)
      return;
  if (*t_size < 4) (*t_size)++;
  if (x.time < 0) {
    if (x.time > t[0].time) t[0]=x;
  } else if (x.time < t[3].time) {
    t[3]=x;
    if (t[3].time < t[2].time) { xtmp = t[2]; t[2] = t[3]; t[3] = xtmp; }
    if (t[2].time < t[1].time) { xtmp = t[1]; t[1] = t[2]; t[2] = xtmp; }
  }
} /* off_insert4 */

// off_store_intersection ******************************************************
// store intersection x in t, either as full list (OFF_LEGACY) or 4 slots
#pragma acc routine
void off_store_intersection(intersection *t, int *t_size, intersection x)
{
#ifdef OFF_LEGACY
  if (*t_size >= OFF_INTERSECT_MAX) {
    #ifndef OPENACC
    static int warned=0;
    if (!warned++)
      fprintf(stderr, "Warning: number of intersection exceeded (%d) (interoff-lib/off_store_intersection)\n", OFF_INTERSECT_MAX);
    #endif
    return;
  }
  t[(*t_size)++]=x;
#else
  off_insert4(t, t_size, x);
#endif
}

// off_readline ****************************************************************
// read the rest of the current line (without '\n') into a growing buffer.
// returns the number of chars read, or -1 at EOF with nothing read.
long off_readline(FILE *f, char **buf, size_t *cap)
{
  long n=0;
  int  c;
  if (!*buf || !*cap) {
    *cap = CHAR_BUF_LENGTH;
    *buf = malloc(*cap);
    if (!*buf) { fprintf(stderr, "Error: memory allocation (interoff/off_readline)\n"); exit(-1); }
  }
  while ((c = fgetc(f)) != EOF && c != '\n') {
    if ((size_t)(n+1) >= *cap) {
      char *tmp = realloc(*buf, 2*(*cap));
      if (!tmp) { fprintf(stderr, "Error: memory allocation (interoff/off_readline)\n"); exit(-1); }
      *buf = tmp; *cap *= 2;
    }
    (*buf)[n++] = (char)c;
  }
  (*buf)[n] = '\0';
  if (c == EOF && n == 0) return -1;
  return n;
} /* off_readline */

// off_getBlocksIndex **********************************************************
/*reads the header of the OFF/PLY file:
OFF:
  line 1  [ST][C][N]OFF [nbVertex nbFaces nbEdges]
  line 2  nbVertex nbFaces nbEdges   (unless given on line 1)
PLY:
  ply / format ascii 1.0 / element vertex N / property ... / element face M / ... / end_header
'lineVertex' is set when vertex lines carry more than 3 numbers (to be skipped)
*/
FILE *off_getBlocksIndex(char* filename, long* vtxSize, long* polySize, int *lineVertex)
{
  FILE* f = Open_File(filename,"r", NULL); /* from read_table-lib: FILE *Open_File(char *name, char *Mode, char *path) */
  if (!f) return (f);

  char *line=NULL;
  size_t cap=0;
  long   len=0;
  *vtxSize = *polySize = 0;
  *lineVertex = 0;

  /* **************** start to read the file header */
  do { /* skip empty lines before the header */
    len = off_readline(f, &line, &cap);
    if (len < 0) {
      fprintf(stderr, "Error: Can not read 1st line in file %s (interoff/off_getBlocksIndex)\n", filename);
      exit(1);
    }
  } while (strspn(line, " \t\r") == (size_t)len);

  { /* a '\r' followed by other characters indicates classic-Mac line endings */
    char *cr = strchr(line, '\r');
    if (cr && cr[strspn(cr, "\r \t")] != '\0') {
      fprintf(stderr,"Error: First line in %s is not terminated by '\\n' (CR line endings?).\n"
              "       Please convert the file to Unix or DOS line endings.\n", filename);
      fclose(f); free(line);
      return(NULL);
    }
  }

  char *hdr = line + strspn(line, " \t");
  if (!strncmp(hdr,"ply",3)) {
    /* PLY file: read all lines until find 'end_header'
       and locate 'element face' and 'element vertex' */
    int in_vertex=0, nvprop=0, got_vertex=0;
    do
    {
      len = off_readline(f, &line, &cap);
      if (len < 0)
      {
        fprintf(stderr, "Error: Can not read line in file %s (interoff/off_getBlocksIndex)\n", filename);
        exit(1);
      }
      if (!strncmp(line,"element",7)) {
        in_vertex = 0;
        if (!strncmp(line,"element face",12)) {
          if (!got_vertex) {
            fprintf(stderr, "Error: PLY file %s defines faces before vertices, which is not supported (interoff/off_getBlocksIndex)\n", filename);
            exit(1);
          }
          sscanf(line,"element face %ld",polySize);
        } else if (!strncmp(line,"element vertex",14)) {
          sscanf(line,"element vertex %ld",vtxSize);
          in_vertex = got_vertex = 1;
        } else if (!got_vertex) {
          fprintf(stderr, "Error: PLY file %s has element '%s' before the vertices, which is not supported (interoff/off_getBlocksIndex)\n", filename, line);
          exit(1);
        }
      } else if (in_vertex && !strncmp(line,"property",8)) {
        char type[64]="", name[64]="";
        sscanf(line, "property %63s %63s", type, name);
        if ((nvprop==0 && strcmp(name,"x")) || (nvprop==1 && strcmp(name,"y")) || (nvprop==2 && strcmp(name,"z"))) {
          fprintf(stderr, "Error: PLY file %s: the first vertex properties must be x y z (got '%s') (interoff/off_getBlocksIndex)\n", filename, name);
          exit(1);
        }
        nvprop++;
      }
      else if (!strncmp(line,"format",6) && strncmp(line,"format ascii",12))
        exit(fprintf(stderr,
          "Error: Can not read binary PLY file %s, only 'format ascii' (interoff/off_getBlocksIndex)\n%s\n",
          filename, line));
    } while (strncmp(line,"end_header",10));
    *lineVertex = (nvprop > 3);
  } else {
    /* OFF file: [ST][C][N]OFF, or legacy '3' */
    char *p = hdr, *rest;
    if (*p == '3' && (p[1]=='\0' || isspace((unsigned char)p[1]))) {
      rest = p+1;
    } else {
      while (*p && strchr("STCN", *p)) p++;
      if (strncmp(p, "OFF", 3)) {
        fprintf(stderr, "Error: %s is probably not an OFF, NOFF or PLY file (interoff/off_getBlocksIndex).\n"
                        "       Requires first line to be 'OFF', '3' or 'ply'.\n",filename);
        fclose(f); free(line);
        return(NULL);
      }
      if (p[3] && !isspace((unsigned char)p[3])) {
        fprintf(stderr, "Error: %s: header '%s' is not supported (4OFF/nOFF). (interoff/off_getBlocksIndex).\n",
          filename, hdr);
        fclose(f); free(line);
        return(NULL);
      }
      *lineVertex = (p != hdr); /* extra vertex data (normals, colours, texture) */
      rest = p+3;
    }
    /* the counts may follow the keyword on the same line */
    if (sscanf(rest, "%ld %ld", vtxSize, polySize) != 2) {
      do  /* OFF file: skip # comments and empty lines which may be there */
      {
        len = off_readline(f, &line, &cap);
        if (len < 0)
        {
          fprintf(stderr, "Error: Can not read line in file %s (interoff/off_getBlocksIndex)\n", filename);
          exit(1);
        }
        hdr = line + strspn(line, " \t\r");
      } while (hdr[0]=='#' || hdr[0]=='\0');
      //line = nblines of vertex,faces and edges arrays
      if (sscanf(hdr,"%ld %ld",vtxSize,polySize) != 2) {
        fprintf(stderr, "Error: can not read number of vertices and faces in file %s: '%s' (interoff/off_getBlocksIndex)\n",
          filename, hdr);
        fclose(f); free(line);
        return(NULL);
      }
    }
  }
  free(line);
  if (*vtxSize <= 0 || *polySize <= 0) {
    fprintf(stderr, "Error: file %s defines %ld vertices and %ld faces (interoff/off_getBlocksIndex)\n",
      filename, *vtxSize, *polySize);
    fclose(f);
    return(NULL);
  }

  /* The FILE is left opened ready to read 'vtxSize' vertices (vtxSize *3 numbers)
     and then polySize polygons (rows) */

  return(f);
} /* off_getBlocksIndex */

// off_init_planes *************************************************************
//gives the equations of 2 independent planes which both contain the line (a,b):
//n.r + D = 0 with n = dir x e_i, e_i being the two coordinate axes which are not
//the dominant direction of dir (each normal thus has one zero component).
//Returns 0 when a==b.
#pragma acc routine
int off_init_planes(Coords a, Coords b, Coords *n1, MCNUM* D1, Coords *n2, MCNUM* D2)
{
  //direction vector of [a b]
  Coords dir={b.x-a.x, b.y-a.y, b.z-a.z};
  double ax=fabs(dir.x), ay=fabs(dir.y), az=fabs(dir.z);
  Coords dxe = coords_set(0, dir.z, -dir.y);   /* dir x e_x */
  Coords dye = coords_set(-dir.z, 0, dir.x);   /* dir x e_y */
  Coords dze = coords_set(dir.y, -dir.x, 0);   /* dir x e_z */

  if (ax==0 && ay==0 && az==0) return 0;
  if (az >= ax && az >= ay)      { *n1 = dxe; *n2 = dye; }
  else if (ay >= ax && ay >= az) { *n1 = dxe; *n2 = dze; }
  else                           { *n1 = dye; *n2 = dze; }
  *D1 = -scalar_prod(n1->x,n1->y,n1->z, a.x,a.y,a.z);
  *D2 = -scalar_prod(n2->x,n2->y,n2->z, a.x,a.y,a.z);
  return 1;
} /* off_init_planes */

// off_straddle ****************************************************************
// returns 1 when the vertices of face (npol indices in idx) are not all
// strictly on the same side of the plane n.r + D = 0
#pragma acc routine seq
int off_straddle(const Coords* vtxArray, const unsigned long *idx, int npol, const Coords *n, double D)
{
  int j;
  const Coords *v=&vtxArray[idx[0]];
  double f0 = n->x*v->x + n->y*v->y + n->z*v->z + D;
  if (f0 == 0) return 1;
  if (f0 > 0) {
    for (j=1; j<npol; j++) {
      v=&vtxArray[idx[j]];
      if (n->x*v->x + n->y*v->y + n->z*v->z + D <= 0) return 1;
    }
  } else {
    for (j=1; j<npol; j++) {
      v=&vtxArray[idx[j]];
      if (n->x*v->x + n->y*v->y + n->z*v->z + D >= 0) return 1;
    }
  }
  return 0;
} /* off_straddle */

// off_line_hits_box ***********************************************************
// returns 0 when the infinite line a + s*dir certainly misses the box [lo,hi]
// (slightly enlarged to be safe against rounding), 1 otherwise
#pragma acc routine
int off_line_hits_box(Coords a, Coords dir, Coords lo, Coords hi)
{
  double smin=-FLT_MAX, smax=FLT_MAX;
  int k;
  for (k=0; k<3; k++) {
    double ak=off_coord(a,k), dk=off_coord(dir,k);
    double l=off_coord(lo,k), h=off_coord(hi,k);
    double tol = 1e-9*(fabs(l)+fabs(h)+(h-l)) + OFF_EPSILON;
    l -= tol; h += tol;
    if (dk == 0) {
      if (ak < l || ak > h) return 0;
    } else {
      double s1=(l-ak)/dk, s2=(h-ak)/dk;
      if (s1 > s2) { double tmp=s1; s1=s2; s2=tmp; }
      if (s1 > smin) smin=s1;
      if (s2 < smax) smax=s2;
      if (smin > smax) return 0;
    }
  }
  return 1;
} /* off_line_hits_box */

// off_clip_3D_mod *************************************************************
// straight line (a,b) intersections with all faces
#pragma acc routine
int off_clip_3D_mod(intersection* t, Coords a, Coords b,
  Coords* vtxArray, unsigned long vtxSize, unsigned long* faceArray,
  unsigned long faceSize, Coords* normalArray, double* DArray)
{
  Coords n1, n2;
  MCNUM  D1=0, D2=0;      //planes containing [a,b]
  int t_size=0;
  unsigned long i=0,indPoly=0;

  if (!off_init_planes(a, b, &n1, &D1, &n2, &D2)) return 0;

  //exploring the polygons :
  while (i<faceSize)
  {
    polygon pol;
    pol.npol  = faceArray[i];                //nb vertex of polygon
    pol.vtx   = vtxArray;
    pol.idx   = &faceArray[i+1];             //polygon's vertex indices in vtxArray

    // a polygon hit by the line must straddle both planes containing it
    if (off_straddle(vtxArray, pol.idx, pol.npol, &n1, D1)
     && off_straddle(vtxArray, pol.idx, pol.npol, &n2, D2))
    {
      intersection x;
      pol.normal=normalArray[indPoly];
      pol.D     =DArray[indPoly];
      if (off_intersectPoly(&x, a, b, pol))
      {
        x.index = indPoly;
        off_store_intersection(t, &t_size, x);
      }
    }
    i += pol.npol+1;
    indPoly++;
  } /* while i<faceSize */
  return t_size;
} /* off_clip_3D_mod */

// off_clip_3D_mod_grav *************************************************************
/*******************************************************************************
parabolic trajectory pos + vel*t + acc*t^2/2 intersections with all faces.
All roots (negative and positive times) are kept, as for the straight line.
*******************************************************************************/
#pragma acc routine seq
int off_clip_3D_mod_grav(intersection* t, Coords pos, Coords vel, Coords acc,
  Coords* vtxArray, unsigned long vtxSize, unsigned long* faceArray,
  unsigned long faceSize, Coords* normalArray, double* DArray)
{
  int t_size=0;
  double quadratic [3];
  unsigned long i=0,indPoly=0;
  //exploring the polygons :
  while (i<faceSize)
  {
    polygon pol;
    double roots[2];
    int nsol, r;
    pol.npol  = faceArray[i];                //nb vertex of polygon
    pol.vtx   = vtxArray;
    pol.idx   = &faceArray[i+1];
    pol.normal= normalArray[indPoly];
    pol.D     = DArray[indPoly];

    p_to_quadratic(pol.normal, pol.D, acc, pos, vel, quadratic);
    nsol = quadraticSolve(quadratic, &roots[0], &roots[1]);

    for (r=0; r<nsol; r++) {
      double time = roots[r];
      intersection inters;
      double t2 = time * time * 0.5;
      inters.v = coords_set(pos.x + time * vel.x + t2 * acc.x,
                            pos.y + time * vel.y + t2 * acc.y,
                            pos.z + time * vel.z + t2 * acc.z);
      Coords tvel = coords_set(vel.x + time * acc.x,
                               vel.y + time * acc.y,
                               vel.z + time * acc.z);
      inters.time = time;
      inters.normal = pol.normal;
      inters.index = indPoly;
      int res=off_pnpoly(pol,inters.v);
      if (res != 0) {
        inters.edge=(res==-1);
        MCNUM ndir = scalar_prod(pol.normal.x,pol.normal.y,pol.normal.z,tvel.x,tvel.y,tvel.z);
        if (ndir<0) {
          inters.in_out=1;  //the negative dot product means we enter the surface
        } else {
          inters.in_out=-1;
        }
        off_store_intersection(t, &t_size, inters);
      }
    }
    i += pol.npol+1;
    indPoly++;
  } /* while i<faceSize */
  return t_size;
} /* off_clip_3D_mod_grav */

#ifdef OFF_LEGACY
// off_compare *****************************************************************
int off_compare (void const *a, void const *b)
{
   intersection const *pa = a;
   intersection const *pb = b;

   return off_sign(pa->time - pb->time);
} /* off_compare */

// off_cleanDouble *************************************************************
//given a sorted array of intersections throw those which appear several times
#pragma acc routine
int off_cleanDouble(intersection* t, int* t_size)
{
  int i=1;
  while (i<*t_size)
  {
    if (fabs(t[i-1].time-t[i].time)<OFF_EPSILON && t[i-1].in_out==t[i].in_out)
    {
      int k;
      for (k=i+1; k<*t_size; ++k) t[k-1]=t[k];
      *t_size-=1;
    }
    else ++i;
  }
  return 1;
} /* off_cleanDouble */

// off_cleanInOut **************************************************************
//given an array of intesections throw those which enter and exit in the same time
//Meaning the ray passes very close to the volume
//(such intersections must be adjacent in the array : run off_cleanDouble before)
#pragma acc routine
int off_cleanInOut(intersection* t, int* t_size)
{
  int i=1;
  while (i<*t_size)
  {
    if (fabs(t[i-1].time-t[i].time)<OFF_EPSILON && t[i-1].in_out!=t[i].in_out)
    {
      int j;
      for (j=i+1; j<*t_size; ++j) t[j-2]=t[j];
      *t_size-=2;
      if (i>1) i--;
    }
    else ++i;
  }
  return (*t_size);
} /* off_cleanInOut */
#endif

/* PUBLIC functions ******************************************************** */

/*******************************************************************************
* long off_init(  char *offfile, double xwidth, double yheight, double zdepth, off_struct* data)
* ACTION: read an OFF file, optionally center object and rescale, initialize OFF data structure
* INPUT: 'offfile' OFF file to read
*        'xwidth,yheight,zdepth' if given as non-zero, apply bounding box.
*           Specifying only one of these will also use the same ratio on all axes
*        'notcenter' center the object to the (0,0,0) position in local frame when set to zero
* RETURN: number of polyhedra and 'data' OFF structure
*******************************************************************************/
long off_init(  char *offfile, double xwidth, double yheight, double zdepth,
                int notcenter, off_struct* data)
{
  // data to be initialized
  long    vtxSize =0, polySize=0, i=0, ret=0, faceSize=0, faceCap=0;
  Coords* vtxArray        =NULL;
  Coords* normalArray     =NULL;
  double* DArray          =NULL;
  unsigned long* faceArray=NULL;
  double* propTmp         =NULL; /* per-face properties, row-major, growing */
  long    propTmpSize=0, propTmpCap=0;
  long*   propOffset      =NULL; /* start of face i properties in propTmp */
  int*    propCount       =NULL; /* number of properties of face i */
  int     nprops=0, nprops_mixed=0, lineVertex=0;
  long    ndegenerate=0;
  char*   line            =NULL;
  size_t  lineCap=0;
  FILE*   f               =NULL; /* the FILE with vertices and polygons */
  double minx=FLT_MAX,maxx=-FLT_MAX,miny=FLT_MAX,maxy=-FLT_MAX,minz=FLT_MAX,maxz=-FLT_MAX;

  // get the indexes
  if (!data) return(0);
  memset(data, 0, sizeof(off_struct));

  MPI_MASTER(
  printf("Loading geometry file (OFF/PLY): %s\n", offfile);
  );

  f=off_getBlocksIndex(offfile,&vtxSize,&polySize,&lineVertex);
  if (!f) return(0);

  // read vertex table = [x y z | x y z | ...] =================================
  // now we read the vertices as 'vtxSize*3' numbers and store it in vtxArray
  MPI_MASTER(
  printf("  Number of vertices: %ld\n", vtxSize);
  );
  vtxArray   = malloc(vtxSize*sizeof(Coords));
  if (!vtxArray) { fclose(f); return(0); }
  i=0;
  while (i<vtxSize)
  {
    double x,y,z;
    ret=fscanf(f, "%lg%lg%lg", &x,&y,&z);
    if (ret == 0) {
      // invalid line: we skip it (probably a comment)
      off_readline(f, &line, &lineCap);
      continue;
    }
    if (ret != 3) {
      fprintf(stderr, "Error: can not read [xyz] coordinates for vertex %li in file %s (interoff/off_init). Read %li values.\n",
        i, offfile, ret);
      exit(2);
    }
    if (lineVertex) off_readline(f, &line, &lineCap); /* skip normals/colours */
    vtxArray[i].x=x;
    vtxArray[i].y=y;
    vtxArray[i].z=z;

    //bounding box
    if (vtxArray[i].x<minx) minx=vtxArray[i].x;
    if (vtxArray[i].x>maxx) maxx=vtxArray[i].x;
    if (vtxArray[i].y<miny) miny=vtxArray[i].y;
    if (vtxArray[i].y>maxy) maxy=vtxArray[i].y;
    if (vtxArray[i].z<minz) minz=vtxArray[i].z;
    if (vtxArray[i].z>maxz) maxz=vtxArray[i].z;
    i++; // inquire next vertex
  }

  // resizing and repositioning params
  double centerx=0, centery=0, centerz=0;
  if (!notcenter) {
    centerx=(minx+maxx)*0.5;
    centery=(miny+maxy)*0.5;
    centerz=(minz+maxz)*0.5;
  }

  double rangex=-minx+maxx,
         rangey=-miny+maxy,
         rangez=-minz+maxz;

  double ratiox=1,ratioy=1,ratioz=1;

  if (xwidth && rangex)
  {
    ratiox=xwidth/rangex;
    ratioy=ratiox;
    ratioz=ratiox;
  }

  if (yheight && rangey)
  {
    ratioy=yheight/rangey;
    if(!xwidth)  ratiox=ratioy;
    ratioz=ratioy;
  }

  if (zdepth && rangez)
  {
    ratioz=zdepth/rangez;
    if(!xwidth)  ratiox=ratioz;
    if(!yheight) ratioy=ratioz;
  }

  rangex *= ratiox;
  rangey *= ratioy;
  rangez *= ratioz;

  //center and resize the object
  for (i=0; i<vtxSize; ++i)
  {
    vtxArray[i].x=(vtxArray[i].x-centerx)*ratiox+(!notcenter ? 0 : centerx);
    vtxArray[i].y=(vtxArray[i].y-centery)*ratioy+(!notcenter ? 0 : centery);
    vtxArray[i].z=(vtxArray[i].z-centerz)*ratioz+(!notcenter ? 0 : centerz);
  }

  // read face table = [nbvertex v1 v2 vn | nbvertex v1 v2 vn ...] =============
  MPI_MASTER(
  printf("  Number of polygons: %ld\n", polySize);
  );
  normalArray= malloc(polySize*sizeof(Coords));
  DArray     = malloc(polySize*sizeof(double));
  propOffset = malloc(polySize*sizeof(long));
  propCount  = malloc(polySize*sizeof(int));
  faceCap    = polySize*5;  // grows when needed: any number of vertices per polygon
  faceArray  = malloc(faceCap*sizeof(unsigned long));
  if (!normalArray || !faceArray || !DArray || !propOffset || !propCount) {
    fprintf(stderr, "Error: memory allocation for %ld polygons in file %s (interoff/off_init)\n", polySize, offfile);
    exit(-1);
  }

  // fill faces
  faceSize=0;
  i=0;
  while (i<polySize) {
    int  nbVertex=0, j=0;
    // read the length of this polygon
    ret=fscanf(f, "%d", &nbVertex);
    if (ret == 0) {
      // invalid line: we skip it (probably a comment)
      off_readline(f, &line, &lineCap);
      continue;
    }
    if (ret != 1) {
      fprintf(stderr, "Error: can not read polygon %li length in file %s (interoff/off_init)\n",
        i, offfile);
      exit(3);
    }
    if (nbVertex < 1) {
      fprintf(stderr, "Error: polygon %li has %d vertices in file %s (interoff/off_init)\n",
        i, nbVertex, offfile);
      exit(3);
    }
    if (faceSize + nbVertex + 1 > faceCap) {
      unsigned long *tmp;
      while (faceSize + nbVertex + 1 > faceCap) faceCap *= 2;
      tmp = realloc(faceArray, faceCap*sizeof(unsigned long));
      if (!tmp) {
        fprintf(stderr, "Error: memory allocation for polygon %li in file %s (interoff/off_init)\n", i, offfile);
        exit(-1);
      }
      faceArray = tmp;
    }
    faceArray[faceSize++] = nbVertex; // length of the polygon/face
    // then read the vertex ID's
    for (j=0; j<nbVertex; j++) {
      double vtx=-1;
      ret=fscanf(f, "%lg", &vtx);
      if (ret != 1 || vtx < 0 || vtx >= vtxSize || vtx != floor(vtx)) {
        fprintf(stderr, "Error: invalid vertex index #%i for polygon %li in file %s (interoff/off_init). Must be an integer in [0:%li]\n",
          j, i, offfile, vtxSize-1);
        exit(3);
      }
      faceArray[faceSize++] = (unsigned long)vtx;   // add vertices index after length of polygon
    }
    if (nbVertex < 3) ndegenerate++;
    // then the optional per-face properties, until the end of the line (or a '#')
    propOffset[i] = propTmpSize;
    propCount[i]  = 0;
    if (off_readline(f, &line, &lineCap) > 0) {
      char *s = line, *end;
      char *hash = strchr(line, '#');
      if (hash) *hash = '\0';
      for (;;) {
        double val = strtod(s, &end);
        if (end == s) break;
        if (propTmpSize >= propTmpCap) {
          double *tmp;
          propTmpCap = (propTmpCap ? 2*propTmpCap : 3*polySize+16);
          tmp = realloc(propTmp, propTmpCap*sizeof(double));
          if (!tmp) {
            fprintf(stderr, "Error: memory allocation for face properties in file %s (interoff/off_init)\n", offfile);
            exit(-1);
          }
          propTmp = tmp;
        }
        propTmp[propTmpSize++] = val;
        propCount[i]++;
        s = end;
      }
      s += strspn(s, " \t\r");
      if (*s) {
        fprintf(stderr, "Warning: unexpected text '%s' after polygon %li in file %s (interoff/off_init). Ignored.\n",
          s, i, offfile);
      }
    }
    if (i && propCount[i] != propCount[i-1]) nprops_mixed=1;
    if (propCount[i] > nprops) nprops = propCount[i];
    i++;
  }
  fclose(f); f=NULL;
  free(line); line=NULL;

  // store per-face properties column-wise: [k*polySize + face]
  data->nfaceprops    = nprops;
  data->facePropSize  = (long)nprops*polySize;
  data->facePropArray = NULL;
  if (nprops) {
    double *props = calloc((size_t)nprops*polySize, sizeof(double));
    int k;
    if (!props) {
      fprintf(stderr, "Error: memory allocation for face properties in file %s (interoff/off_init)\n", offfile);
      exit(-1);
    }
    for (i=0; i<polySize; i++)
      for (k=0; k<propCount[i]; k++)
        props[k*polySize+i] = propTmp[propOffset[i]+k];
    data->facePropArray = props;
    MPI_MASTER(
    printf("  Number of per-face properties: %d\n", nprops);
    if (nprops_mixed)
      printf("Warning: faces in %s do not all define the same number of properties.\n"
             "         Missing values are set to 0.\n", offfile);
    );
  }
  free(propTmp); free(propOffset); free(propCount);

  // precomputes normals
  long indNormal=0;//index in polyArray
  i=0;    //index in faceArray
  while (i<faceSize)
  {
    polygon p;
    p.npol=faceArray[i];
    p.vtx =vtxArray;
    p.idx =&faceArray[i+1];
    if (off_normal(&(p.normal),p) == 0) ndegenerate++;
    normalArray[indNormal]=p.normal;
    Coords v0 = vtxArray[p.idx[0]];
    DArray[indNormal] = scalar_prod(p.normal.x,p.normal.y,p.normal.z, v0.x,v0.y,v0.z);
    i += p.npol+1;
    indNormal++;
  }

  MPI_MASTER(
  if (ndegenerate)
    printf("Warning: %ld degenerate polygon(s) (less than 3 vertices or zero area) in %s.\n"
           "         They will never be intersected.\n", ndegenerate, offfile);
  if (ratiox!=ratioy || ratiox!=ratioz || ratioy!=ratioz)
    printf("Warning: Aspect ratio of the geometry %s was modified.\n"
           "         If you want to keep the original proportions, specifiy only one of the dimensions.\n",
           offfile);
  if ( xwidth==0 && yheight==0 && zdepth==0 ) {
    printf("Warning: Neither xwidth, yheight or zdepth are defined.\n"
	   "           The file-defined (non-scaled) geometry the OFF geometry %s will be applied!\n",
           offfile);
  }
  printf("  Bounding box dimensions for geometry %s:\n", offfile);
  printf("    Length=%f (%.3f%%)\n", rangex, ratiox*100);
  printf("    Width= %f (%.3f%%)\n", rangey, ratioy*100);
  printf("    Depth= %f (%.3f%%)\n", rangez, ratioz*100);
  );

  data->bbmin = coords_set( FLT_MAX, FLT_MAX, FLT_MAX);
  data->bbmax = coords_set(-FLT_MAX,-FLT_MAX,-FLT_MAX);
  for (i=0; i<vtxSize; i++) {
    if (vtxArray[i].x < data->bbmin.x) data->bbmin.x = vtxArray[i].x;
    if (vtxArray[i].y < data->bbmin.y) data->bbmin.y = vtxArray[i].y;
    if (vtxArray[i].z < data->bbmin.z) data->bbmin.z = vtxArray[i].z;
    if (vtxArray[i].x > data->bbmax.x) data->bbmax.x = vtxArray[i].x;
    if (vtxArray[i].y > data->bbmax.y) data->bbmax.y = vtxArray[i].y;
    if (vtxArray[i].z > data->bbmax.z) data->bbmax.z = vtxArray[i].z;
  }
  data->vtxArray   = vtxArray;
  data->normalArray= normalArray;
  data->DArray     = DArray;
  data->faceArray  = faceArray;
  data->vtxSize    = vtxSize;
  data->polySize   = polySize;
  data->faceSize   = faceSize;
  data->filename   = offfile;
  if (nprops >= 3) {
    data->face_m_Array     = data->facePropArray + OFF_FACEPROP_M    *polySize;
    data->face_alpha_Array = data->facePropArray + OFF_FACEPROP_ALPHA*polySize;
    data->face_W_Array     = data->facePropArray + OFF_FACEPROP_W    *polySize;
  }
#ifdef OFF_LEGACY
  data->intersects = malloc(OFF_INTERSECT_MAX*sizeof(intersection));
  if (!data->intersects) {
    fprintf(stderr, "Error: memory allocation for intersections (interoff/off_init)\n");
    exit(-1);
  }
#endif
  #ifdef OPENACC
  acc_attach((void *)&data->vtxArray);
  acc_attach((void *)&data->normalArray);
  acc_attach((void *)&data->faceArray);
  acc_attach((void *)&data->DArray);
  #endif

  return(polySize);
} /* off_init */

#ifdef OFF_LEGACY
#pragma acc routine
int Min_int(int x, int y) {
  return (x<y)? x :y;
}

#pragma acc routine
void merge(intersection *arr, int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 =  r - m;

/* create temp arrays */
intersection *L, *R;
 L = (intersection *)malloc(sizeof(intersection) * n1);
 R = (intersection *)malloc(sizeof(intersection) * n2);
 if (!L||!R) {
   fprintf(stderr,"Error allocating intersection arrays\n");
   exit(-1);
 }
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
    L[i] = arr[l + i];
for (j = 0; j < n2; j++)
    R[j] = arr[m + 1+ j];

/* Merge the temp arrays back into arr[l..r]*/
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
    if (L[i].time <= R[j].time) arr[k++] = L[i++];
    else                        arr[k++] = R[j++];
}
/* Copy the remaining elements of L[] and R[], if there are any */
while (i < n1) arr[k++] = L[i++];
while (j < n2) arr[k++] = R[j++];
free(L);
free(R);
}

#pragma acc routine
void gpusort(intersection *arr, int size)
{
  int curr_size;  // For current size of subarrays to be merged
  int left_start; // For picking starting index of left subarray
  for (curr_size=1; curr_size<=size-1; curr_size = 2*curr_size)
  {
    for (left_start=0; left_start<size-1; left_start += 2*curr_size)
    {
      int mid = left_start + curr_size - 1;
      int right_end = Min_int(left_start + 2*curr_size - 1, size-1);
      if (mid < right_end) merge(arr, left_start, mid, right_end);
    }
  }
}
#endif

/*******************************************************************************
void p_to_quadratic(Coords norm, MCNUM d, Coords acc, Coords pos, Coords vel,
                    double* teq)
* ACTION: define the quadratic for the intersection of a parabola with a plane
* INPUT: plane equation norm . r = d
*        'acc' acceleration vector
*        'vel' velocity of the particle
*        'pos' position of the particle
* RETURN: equation of parabola: teq(0) * t^2 + teq(1) * t + teq(2)
*******************************************************************************/
#pragma acc routine
void p_to_quadratic(Coords norm, MCNUM d, Coords acc, Coords pos, Coords vel,
		    double* teq)
{
  teq[0] = scalar_prod(norm.x, norm.y, norm.z, acc.x, acc.y, acc.z) * 0.5;
  teq[1] = scalar_prod(norm.x, norm.y, norm.z, vel.x, vel.y, vel.z);
  teq[2] = scalar_prod(norm.x, norm.y, norm.z, pos.x, pos.y, pos.z) - d;
  return;
}

/*******************************************************************************
int quadraticSolve(double eq[], double* x1, double* x2);
* ACTION: solves the quadratic for the roots x1 and x2
*         eq[0] * t^2 + eq[1] * t + eq[2] = 0
* INPUT: 'eq' the coefficients of the parabola
* RETURN: roots x1 and x2 and the number of solutions
*******************************************************************************/
#pragma acc routine
int quadraticSolve(double* eq, double* x1, double* x2)
{
  *x1 = *x2 = 1.0e36;
  if (eq[0] == 0.0) { // This is a linear equation
    if (eq[1] != 0.0) { // one solution
      *x1 = -eq[2]/eq[1];
      return 1;
    }
    return 0; // no solutions, 1.0e36 will be ignored.
  }
  double delta = eq[1]*eq[1]-4.0*eq[0]*eq[2];
  if (delta < 0.0) { // no solutions, both are imaginary
    return 0;
  }
  // numerically stable form
  double s = (eq[1] < 0 ? -1.0 : 1.0);
  double q = -0.5*(eq[1] + s * sqrt(delta));
  *x1 = q/eq[0];
  *x2 = (q != 0.0 ? eq[2]/q : 0.0); // q==0 only when eq[1]==eq[2]==0: double root at 0
  return 2;
}

// off_intersect_all_idx *******************************************************
#pragma acc routine
int off_intersect_all_idx(double* t0, double* t3,
     Coords *n0, Coords *n3,
     unsigned long *faceindex0, unsigned long *faceindex3,
     double x,  double y,  double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct *data )
{
    int t_size = 0;
    /* a curved trajectory is only needed with a non-zero acceleration */
    int use_grav = (mcgravitation && (ax != 0 || ay != 0 || az != 0));
#ifdef OFF_LEGACY
    intersection *t = data->intersects;
#else
    intersection t[4];
    int k;
    for (k=0; k<4; k++) {
      t[k].time   = (k==0 ? -FLT_MAX : FLT_MAX);
      t[k].v      = t[k].normal = coords_set(0,0,0);
      t[k].in_out = t[k].edge = 0;
      t[k].index  = 0;
    }
#endif

    if (use_grav) {
      Coords pos={ x,  y,  z};
      Coords vel={vx, vy, vz};
      Coords acc={ax, ay, az};
      t_size=off_clip_3D_mod_grav(t, pos, vel, acc,
				  data->vtxArray, data->vtxSize, data->faceArray,
				  data->faceSize, data->normalArray, data->DArray);
    } else {
      Coords A={x, y, z};
      Coords B={x+vx, y+vy, z+vz};
      Coords V={vx, vy, vz};
      /* quick rejection: the straight line misses the object bounding box */
      if (!off_line_hits_box(A, V, data->bbmin, data->bbmax)) return 0;
      t_size=off_clip_3D_mod(t, A, B,
			     data->vtxArray, data->vtxSize, data->faceArray,
			     data->faceSize, data->normalArray, data->DArray);
    }

#ifdef OFF_LEGACY
    #ifndef OPENACC
    qsort(t, t_size, sizeof(intersection),  off_compare);
    #else
    gpusort(t, t_size);
    #endif
    off_cleanDouble(t, &t_size);
    off_cleanInOut(t,  &t_size);
    data->numintersect=t_size;

    /*find intersections "closest" to 0 (favouring positive ones)*/
    if(t_size>0){
      int i=0;
      if(t_size>1) {
        for (i=1; i < t_size-1; i++){
          if (t[i-1].time > 0 && t[i].time > 0)
            break;
        }
        if (t0) *t0 = t[i-1].time;
        if (n0) *n0 = t[i-1].normal;
        if (faceindex0) *faceindex0 = t[i-1].index;
        if (t3) *t3 = t[i].time;
        if (n3) *n3 = t[i].normal;
        if (faceindex3) *faceindex3 = t[i].index;
        data->nextintersect=(int)t[i-1].index;
      } else {
        if (t0) *t0 = t[0].time;
        if (n0) *n0 = t[0].normal;
        if (faceindex0) *faceindex0 = t[0].index;
        data->nextintersect=(int)t[0].index;
      }
      return t_size;
    }
#else
    if(t_size>0){
      int i=0;
      if (t[0].time == -FLT_MAX) i=1;
      data->numintersect=t_size;
      if (t0) *t0 = t[i].time;
      if (n0) *n0 = t[i].normal;
      if (t3) *t3 = t[i+1].time;
      if (n3) *n3 = t[i+1].normal;
      if (faceindex0) *faceindex0 = t[i].index;
      if (faceindex3) *faceindex3 = t[i+1].index;

      /* placeholders when there is no second intersection (see RESULT CONVENTION
         in interoff-lib.h): FLT_MAX for a single hit ahead (set above, t[2]),
         0 when the object is entirely behind */
      if (t[1].time == FLT_MAX)
      {
        if (t3) *t3 = 0.0;
      }

      data->nextintersect=(int)t[i].index;
      /* > 1 only when t0 and t3 are both real intersections */
      if (t[i+1].time == FLT_MAX) return 1;
      return t_size;
    }
#endif
    return 0;
} /* off_intersect_all_idx */

/*******************************************************************************
* int off_intersect_all(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct *data )
* ACTION: computes intersection of neutron trajectory with an object.
* INPUT:  x,y,z and vx,vy,vz are the position and velocity of the neutron
*         ax, ay, az are the local acceleration vector
*         data points to the OFF data structure
* RETURN: the number of polyhedral which trajectory intersects
*         t0 and t3 are the smallest incoming and outgoing intersection times
*         n0 and n3 are the corresponding normal vectors to the surface
*         data is the full OFF structure, including a list intersection type
*******************************************************************************/
#pragma acc routine
int off_intersect_all(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x,  double y,  double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct *data )
{
  return off_intersect_all_idx(t0, t3, n0, n3, NULL, NULL,
    x, y, z, vx, vy, vz, ax, ay, az, data);
} /* off_intersect_all */

/*******************************************************************************
* int off_intersect(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double vx, double vy, double vz,
     off_struct data )
* ACTION: computes intersection of neutron trajectory with an object.
* INPUT:  x,y,z and vx,vy,vz are the position and velocity of the neutron
*         data points to the OFF data structure
* RETURN: the number of polyhedral which trajectory intersects
*         t0 and t3 are the smallest incoming and outgoing intersection times
*         n0 and n3 are the corresponding normal vectors to the surface
*******************************************************************************/
#pragma acc routine
int off_intersect(double* t0, double* t3,
     Coords *n0, Coords *n3,
     double x,  double y,  double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct data )
{
  return off_intersect_all_idx(t0, t3, n0, n3, NULL, NULL,
    x, y, z, vx, vy, vz, ax, ay, az, &data );
} /* off_intersect */

#pragma acc routine
int off_intersect_idx(double* t0, double* t3,
     Coords *n0, Coords *n3,
     unsigned long *faceindex0, unsigned long *faceindex3,
     double x,  double y,  double z,
     double vx, double vy, double vz,
     double ax, double ay, double az,
     off_struct data )
{
  return off_intersect_all_idx(t0, t3, n0, n3, faceindex0, faceindex3,
    x, y, z, vx, vy, vz, ax, ay, az, &data );
} /* off_intersect_idx */

/*****************************************************************************
* int off_x_intersect(double* l0, double* l3,
     Coords *n0, Coords *n3,
     double x, double y, double z,
     double kx, double ky, double kz,
     off_struct data )
* ACTION: computes intersection of an xray trajectory with an object.
* INPUT:  x,y,z and kx,ky,kz, are spatial coordinates and wavevector of the x-ray
*         respectively. data points to the OFF data structure.
* RETURN: the number of polyhedral the trajectory intersects
*         l0 and l3 are the smallest incoming and outgoing intersection lengths
*         n0 and n3 are the corresponding normal vectors to the surface
*******************************************************************************/
#pragma acc routine
int off_x_intersect_idx(double *l0,double *l3,
     Coords *n0, Coords *n3,
     unsigned long *faceindex0, unsigned long *faceindex3,
     double x,  double y,  double z,
     double kx, double ky, double kz,
     off_struct data )
{
  /*This function simply reformats and calls off_intersect (as for neutrons)
   *by normalizing the wavevector - this will yield the intersection lengths
   *in m*/
  double jx,jy,jz,invk;
  invk=1/sqrt(scalar_prod(kx,ky,kz,kx,ky,kz));
  jx=kx*invk;jy=ky*invk;jz=kz*invk;
  return off_intersect_all_idx(l0,l3,n0,n3,faceindex0,faceindex3,
    x,y,z,jx,jy,jz,0.0,0.0,0.0,&data);
} /* off_x_intersect_idx */

#pragma acc routine
int off_x_intersect(double *l0,double *l3,
     Coords *n0, Coords *n3,
     double x,  double y,  double z,
     double kx, double ky, double kz,
     off_struct data )
{
  return off_x_intersect_idx(l0,l3,n0,n3,NULL,NULL,x,y,z,kx,ky,kz,data);
} /* off_x_intersect */

/*******************************************************************************
* double off_face_prop(off_struct *data, unsigned long face, int k, double def)
* ACTION: return per-face property 'k' of face 'face', or 'def' when not defined
*******************************************************************************/
#pragma acc routine
double off_face_prop(off_struct *data, unsigned long face, int k, double def)
{
  if (!data || !data->facePropArray || k < 0 || k >= data->nfaceprops
   || face >= (unsigned long)data->polySize)
    return def;
  return data->facePropArray[(long)k*data->polySize + face];
} /* off_face_prop */

/* growing string buffer used by off_display */
typedef struct off_strbuf { char *s; size_t len, cap; } off_strbuf;

void off_strbuf_printf(off_strbuf *b, const char *fmt, ...)
{
  va_list ap;
  int n;
  if (!b->s) {
    b->cap = 4096; b->len = 0;
    b->s = malloc(b->cap);
    if (!b->s) { fprintf(stderr, "Error: memory allocation (interoff/off_display)\n"); exit(-1); }
    b->s[0] = '\0';
  }
  va_start(ap, fmt);
  n = vsnprintf(b->s + b->len, b->cap - b->len, fmt, ap);
  va_end(ap);
  if (n < 0) return;
  if (b->len + n + 1 > b->cap) {
    char *tmp;
    while (b->len + n + 1 > b->cap) b->cap *= 2;
    tmp = realloc(b->s, b->cap);
    if (!tmp) { fprintf(stderr, "Error: memory allocation (interoff/off_display)\n"); exit(-1); }
    b->s = tmp;
    va_start(ap, fmt);
    vsnprintf(b->s + b->len, b->cap - b->len, fmt, ap);
    va_end(ap);
  }
  b->len += n;
}

/*******************************************************************************
* void off_display(off_struct data)
* ACTION: display up to N_VERTEX_DISPLAYED polygons from the object
*******************************************************************************/
void off_display(off_struct data)
{
  long i;
  if (!data.faceSize || !data.vtxArray || !data.faceArray) return;
  if(mcdotrace==2){
    off_strbuf json = {NULL, 0, 0};
    off_strbuf_printf(&json, "{ \"vertices\": [");
    for (i = 0; i < data.vtxSize; i++) {
      off_strbuf_printf(&json, "[%g, %g, %g]", data.vtxArray[i].x, data.vtxArray[i].y, data.vtxArray[i].z);
      if (i < data.vtxSize - 1) off_strbuf_printf(&json, ", ");
    }
    off_strbuf_printf(&json, "], \"faces\": [");
    for (i = 0; i < data.faceSize;) {
      long j, num = data.faceArray[i];
      off_strbuf_printf(&json, "{ \"face\": [");
      for (j = 1; j <= num; j++) {
        off_strbuf_printf(&json, "%lu", data.faceArray[i + j]);
        if (j < num) off_strbuf_printf(&json, ", ");
      }
      off_strbuf_printf(&json, "]}");
      i += num + 1;
      if (i < data.faceSize) off_strbuf_printf(&json, ", ");
    }
    off_strbuf_printf(&json, "]}");
    mcdis_polyhedron(json.s);
    free(json.s);
  }
  else {
    double ratio=(double)(N_VERTEX_DISPLAYED)/(double)data.faceSize;
    long pixel=0;
    off_strbuf pixelinfo = {NULL, 0, 0};
    for (i=0; i<data.faceSize; ) {
      int j;
      int nbVertex = data.faceArray[i];
      double x0,y0,z0;
      x0 = data.vtxArray[data.faceArray[i+1]].x;
      y0 = data.vtxArray[data.faceArray[i+1]].y;
      z0 = data.vtxArray[data.faceArray[i+1]].z;
      double x1=x0,y1=y0,z1=z0;
      double cmx=0,cmy=0,cmz=0;

      int drawthis = rand01() < ratio;
      // First pass, calculate center of mass location...
      for (j=1; j<=nbVertex; j++) {
        cmx = cmx+data.vtxArray[data.faceArray[i+j]].x;
        cmy = cmy+data.vtxArray[data.faceArray[i+j]].y;
        cmz = cmz+data.vtxArray[data.faceArray[i+j]].z;
      }
      cmx /= nbVertex;
      cmy /= nbVertex;
      cmz /= nbVertex;

      if (data.mantidflag) {
        pixelinfo.len = 0;
        off_strbuf_printf(&pixelinfo, "%li,%li,%li,%i,%g,%g,%g,%g,%g,%g", data.mantidoffset+pixel, data.mantidoffset, data.mantidoffset+data.polySize-1, nbVertex, cmx, cmy, cmz, x1-cmx, y1-cmy, z1-cmz);
      }
      for (j=2; j<=nbVertex; j++) {
        double x2,y2,z2;
        x2 = data.vtxArray[data.faceArray[i+j]].x;
        y2 = data.vtxArray[data.faceArray[i+j]].y;
        z2 = data.vtxArray[data.faceArray[i+j]].z;
        if (data.mantidflag)
          off_strbuf_printf(&pixelinfo, ",%g,%g,%g", x2-cmx, y2-cmy, z2-cmz);
        if (ratio > 1 || drawthis) {
          mcdis_line(x1,y1,z1,x2,y2,z2);
        }
        x1 = x2; y1 = y2; z1 = z2;
      }
      if (ratio > 1 || drawthis) {
        mcdis_line(x1,y1,z1,x0,y0,z0);
      }
      if (data.mantidflag) {
        printf("MANTID_PIXEL: %s\n", pixelinfo.s);
        pixel++;
      }
      i += nbVertex+1;
    }
    free(pixelinfo.s);
  }
} /* off_display */

/* end of interoff-lib.c */
#endif // INTEROFF_LIB_C


/* Shared user declarations for all components types 'Mirror_curved'. */
/*****************************************************************************
*
* McStas, neutron ray-tracing package and McXtrace X-ray ray-tracing package
*         Copyright 1997-2025, All rights reserved
*         DTU Physics, Kongens Lyngby, Denmark
*
* Library: share/mccode-complex-lib.h
*
* %Identification
* Written by: Peter Willendrup
* Date: November, 2025
* Origin: DTU
*
* This file is to be imported by components requiring support for complex numbers.
* Includes solutions for MSVC on Windows which does not implement e.g. c99 complex.
*
* Usage: within SHARE
* %include "mccode-complex-lib"
*
****************************************************************************/

#ifndef MCCODE_COMPLEX_LIB_H
#define MCCODE_COMPLEX_LIB_H

// C99 environments without <complex.h> should define __STDC_NO_COMPLEX__
// https://en.cppreference.com/w/c/numeric/complex
#if !defined(__STD_NO_COMPLEX__)
#define HAVE_COMPLEX_H
#endif

#ifdef HAVE_COMPLEX_H
// Use C99 complex support for all operations.
#include <complex.h>
// NOT MSVC
#ifndef _MSC_EXTENSIONS
// Note: leave two spaces between double and cdouble because double->float
// in generate._convert_type is not clever enough.
typedef complex double  cdouble;
inline cdouble cplx(const double x, const double y) { return x + y*I; }
inline cdouble cneg(const cdouble a) { return -a; }
inline cdouble radd(const double a, const cdouble b) { return a+b; }
inline cdouble rmul(const double a, const cdouble b) { return a*b; }
inline cdouble cadd(const cdouble a, const cdouble b) { return a+b; }
inline cdouble csub(const cdouble a, const cdouble b) { return a-b; }
inline cdouble cmul(const cdouble a, const cdouble b) { return a*b; }
inline cdouble cdiv(const cdouble a, const cdouble b) { return a/b; }
#else
// MSVC
typedef _Dcomplex  cdouble;
inline cdouble cplx(const double x, const double y) { cdouble z = _Cbuild(x,y); return z; }
inline cdouble cneg(const cdouble a) { return cplx( -creal(a) , -cimag(a) ); }
inline cdouble radd(const double a, const cdouble b) { return cplx(a+creal(b),cimag(b)); }
inline cdouble rmul(const double a, const cdouble b) { return cplx(a*creal(b),a*cimag(b)); }
inline cdouble cadd(const cdouble a, const cdouble b) { return cplx(creal(a)+creal(b),cimag(a)+cimag(b)); }
inline cdouble csub(const cdouble a, const cdouble b) { return cplx(creal(a)-creal(b),cimag(a)-cimag(b)); }
inline cdouble cmul(const cdouble a, const cdouble b) { return cplx(creal(a)*creal(b) - cimag(a)*cimag(b), cimag(a)*creal(b) + creal(a)*cimag(b)); }
inline cdouble cdiv(const cdouble a, const cdouble b) { return cplx((creal(a)*creal(b)+cimag(a)*cimag(b))/(creal(b)*creal(b)+cimag(b)*cimag(b)),(cimag(a)*creal(b)-creal(a)*cimag(b))/(creal(b)*creal(b)+cimag(b)*cimag(b))); }
#endif

#else // Use simple structure to represent complex numbers

typedef struct { double x,y; } cdouble;
inline cdouble cplx(const double x, const double y) { cdouble z = {x,y}; return z; }
inline double cabs(const cdouble a) { return sqrt(a.x*a.x + a.y*a.y); }
inline cdouble cneg(const cdouble a) { return cplx(-a.x, -a.y); }
inline cdouble rmul(const double a, const cdouble b) { return cplx( a*b.x, a*b.y ); }
inline cdouble cadd(const cdouble a, const cdouble b) { return cplx( a.x+b.x, a.y+b.y ); }
inline cdouble csub(const cdouble a, const cdouble b) { return cplx( a.x-b.x, a.y-b.y ); }

#endif
#endif
/* end of mccode-complex-lib.h */
/*****************************************************************************
*
* McStas, neutron ray-tracing package and McXtrace X-ray ray-tracing package
*         Copyright 1997-2025, All rights reserved
*         DTU Physics, Kongens Lyngby, Denmark
*
* Library: share/mccode-complex-lib.h
*
* %Identification
* Written by: Peter Willendrup
* Date: November, 2025
* Origin: DTU
*
* This file is to be imported by components requiring support for complex numbers.
* Includes solutions for MSVC on Windows which does not implement e.g. c99 complex.
*
* Usage: within SHARE
* %include "mccode-complex-lib"
*
****************************************************************************/

/* This is in fact a header-only %include lib for now */
#ifndef MCCODE_COMPLEX_LIB_H
#include "mccode-complex-lib.h"
#endif

/* end of regular mccode-complex-lib.c */


/*A library for computing reflectivity in surfaces with multilayers etc.*/

#include <math.h>
#include <stdarg.h>
double Table_Value2d(t_Table, double, double);
enum reflec_Type  {COATING_UNDEFINED=0,CONSTANT=1,BARE, COATING, Q_PARAMETRIC, PARRATT, ETH_PARAMETRIC, KINEMATIC, UNDETERMINED};
#define NAME_CONSTANT "constant"
#define NAME_BARE "bare"
#define NAME_COATING "coating"
#define NAME_Q_PARAMETRIC "q"
#define NAME_PARRATT "parratt"
#define NAME_ETH_PARAMETRIC "eth"
#define NAME_KINEMATIC "kinematic"
typedef struct t_reflec_constant{
  double R;
} t_reflec_constant;
typedef struct t_reflec_bare{
  char matrl[256];
  double d;
} t_reflec_bare;
typedef struct t_reflec_coating{
  char matrl[256];
  t_Table *T;
  double d;
  double rho,Z,At;
}t_reflec_coating;
typedef struct t_reflec_q_prmtc{
  char fname[256];
  t_Table *T;
  double qmin,qmax;
} t_reflec_q_prmtc;
typedef struct t_reflec_parratt{
  int N;
  double *d, *delta, *beta;
} t_reflec_parratt;
/**Multilayer in the kinematical approximation*/
typedef struct t_reflec_kinematic{
  int N;/**The number of bilayers in the multilayer*/
  double Gamma;/**The fraction of thickness of high e-density material*/
  double Lambda;/**The thickness of the bilayer*/
  double rho_AB;/**Electron density contrast between material A and B*/
} t_reflec_kinematic;
typedef struct t_reflec_eth_prmtc{
  char fname[256];
  t_Table *T;
  double emin,emax,estep;/*energy range*/
  double thetamin,thetamax,thetastep;/*incidence angle range*/
} t_reflec_theta_e_prmtc;
typedef struct reflec_T {
  enum reflec_Type type;
  struct t_reflec_bare rb;
  struct t_reflec_coating rc;
  struct t_reflec_q_prmtc rqpm;
  struct t_reflec_parratt rp;
  struct t_reflec_constant rconst;
  struct t_reflec_kinematic rk;
  struct t_reflec_eth_prmtc rethpm;
} t_Reflec;
/* reflectivity-lib.c */
int reflec_Init(t_Reflec *R, enum reflec_Type type, char *file, void *pars);
int reflec_Init_File(t_Reflec *R, char* filename);
int reflec_Init_parratt(t_Reflec *R, int N, double *d, double *delta, double *beta);
int reflec_Init_kinematic(t_Reflec *R, int N, double Gamma, double Lambda, double rhoAB);
int reflec_Init_const(t_Reflec *R, double R0);
#pragma acc routine
cdouble refleccq(t_Reflec r_handle, double q, double g, double k, double theta );
#pragma acc routine
double reflecq(t_Reflec r_handle, double q, double g, double k, double theta );
#pragma acc routine
cdouble reflecc(t_Reflec r_handle, double kix, double kiy, double kiz, double kfx, double kfy, double kfz, double g );
#pragma acc routine
cdouble reflec_coating(t_Reflec r_handle, double q, double g, double k);
#pragma acc routine
cdouble reflec_bare(t_Reflec r_handle, double q, double g);
#pragma acc routine
cdouble reflec_q_prmtc(t_Reflec r_handle, double q, double g);
#pragma acc routine
cdouble reflec_parratt(t_Reflec r_handle, double q, double g, double k);
#pragma acc routine
cdouble reflec_kinematic(t_Reflec r_handle, double q, double g);
#pragma acc routine
cdouble parrat_reflec_bulk(int lc, double *delta, double *beta, double *d, double k, double q);
#pragma acc routine
cdouble reflec_eth_prmtc(t_Reflec r_handle, double e, double theta, double g);
enum reflec_Type get_table_reflec_type(t_Table *t);

#include <stdarg.h>
#include <math.h>

#ifdef REFLIBNAME
#undef REFLIBNAME
#endif
#define REFLIBNAME "reflectivity-lib"

/*Single entry point init function. This will determine the underlying init function base on the type paremeter.
  If the typoe is UNDEFINED, will try to read a datafile and guess from its structure.
  Else will try to unpack parameters from the array of doubles.

  Another option is to call the specific init functions directly. E.g reflec_Init_parratt etc.*/

int reflec_Init(t_Reflec *R, enum reflec_Type typ, char *file, void *pars){
  if (R==NULL){
    R=calloc(1,sizeof(t_Reflec));
    /* Exit if allocation failed */
    if (!R) {
      fprintf(stderr, "Error, allocting t_Reflect in reflec_Init - exit!\n");
      exit(-1);
    }
  }
  int status;
  R->type=typ;
  switch(typ){
    case COATING_UNDEFINED:
      {
        /*no type is given: Assume that it is stated as a #param=<TYPE>
          item in the datafile header*/
        reflec_Init_File(R,file);
        break;
      }
    case CONSTANT:
      {
          if (pars){
	    reflec_Init_const(R,((double *)pars)[0]);
          }else{
              reflec_Init_const(R,1.0);
	  }
	  break;
      }
    case PARRATT:
      {
          /*cast the first address to be a scalar integer. The latter ones are pointers to double arrays.*/
          int N=(unsigned int)((double **) pars)[0];
          if(pars){
              reflec_Init_parratt(R, N,((double **) pars)[1], ((double **) pars)[2], ((double **) pars)[3]);        
          }else{
              fprintf(stderr,"Warning: %s: No parameters specified to Parratt reflectivity algortihm. Setting R=1.0.\n",
                      REFLIBNAME);
              R->type=CONSTANT;
              R->rconst.R=1.0;
          }
          break;
      }
    case KINEMATIC:
      {
          if(pars){
	    reflec_Init_kinematic(R, (int) ((double *)pars)[0],((double *)pars)[1],((double *)pars)[2],((double *)pars)[3]);
          }else{
              fprintf(stderr,"Warning: %s: No parameters specified to KINEMATIC reflectivity algortihm. Setting R=1.0.\n",
                      REFLIBNAME);
              R->type=CONSTANT;
              R->rconst.R=1.0;
          }
          break;
      }
    case BARE:
      {
          stracpy(R->rb.matrl,file,255);
          reflec_Init_File(R,R->rb.matrl);
          break;
      }
    case COATING:
      {
          stracpy(R->rc.matrl,file,255);
          reflec_Init_File(R,R->rc.matrl);
          break;
      }
    case Q_PARAMETRIC:
      {
          stracpy(R->rqpm.fname,file,255);
          reflec_Init_File(R,R->rqpm.fname);
          break;
      }
    case ETH_PARAMETRIC:
      {
          stracpy(R->rethpm.fname,file,255);
          reflec_Init_File(R,R->rethpm.fname);
          break;
      }
    default:
      {
        fprintf(stderr,"Error: %s: Undetermined reflectivity parameterization type. ABORT.\n",
                REFLIBNAME);
	free(R);
	R=NULL;
	exit(-1);
      }
  }
  return 0;
}

int reflec_Init_parratt(t_Reflec *R, int N, double *d, double *delta, double *beta){
    R->type=PARRATT;
    R->rp.N=N;
    R->rp.d=d;
    R->rp.delta=delta;
    R->rp.beta=beta;
    return 0;
}

int reflec_Init_kinematic(t_Reflec *R, int N, double Gamma, double Lambda, double rhoAB){
    R->type=KINEMATIC;
    R->rk.N=N;
    R->rk.Gamma=Gamma;
    R->rk.Lambda=Lambda;
    R->rk.rho_AB=rhoAB;
    return 0;
}
 int reflec_Init_const(t_Reflec *R, double R0){
   R->type=CONSTANT;
   R->rconst.R=R0;
   return 0;
 }

/* Initialize a container object for various types of reflectivity parametrization using
 * an input file as source.*/

int reflec_Init_File(t_Reflec *R, char *filename){
    if (R==NULL){
      R=calloc(1,sizeof(t_Reflec));
    }
    /*a pointer representation has to be used here - otherwise the memory may be garbage collected
      upon return from this function.*/
    t_Table *table=malloc(sizeof(t_Table));

    /*if the filename is neither empty, blank, nor "NULL" read it, else return a constant opaque surface (R=0)*/
    int status;
    if(!(filename && strlen(filename) && strcmp(filename,"NULL") && (status = Table_Read(table, filename, 1)!=-1) ) ) {
      fprintf(stderr,"Warning: %s: No reflectivity file given. Surface is opaque.\n",
              REFLIBNAME);
      R->type=CONSTANT;
      R->rconst.R=0;
      return 0;
    }

    /*if the type has not already been set try to extract it from file header*/
    if (R->type==UNDETERMINED || R->type==COATING_UNDEFINED){
      R->type=get_table_reflec_type(table);
    }

    switch(R->type){
      case CONSTANT:
        {
          R->rconst.R=Table_Index(*table, 0, 0);
          break;
        }

      case BARE:
        {
          char** header_parsed=Table_ParseHeader(table->header,"material", "d", NULL);
          if(!header_parsed[0] || !header_parsed[1] ){
            fprintf(stderr,"Error: %s: Could not parse file \"%s\".\n",
                    REFLIBNAME, filename);
            exit(-1);
          }
          stracpy(R->rb.matrl,header_parsed[0],255);
          R->rb.d=strtod(header_parsed[1], NULL);
          break;
        }

      case COATING:
        {
          char **header_parsed=Table_ParseHeader(table->header, "material", "Z", "A[r]", "rho", "d", NULL);
          if(!(header_parsed[1] && header_parsed[2] && header_parsed[3])){
            fprintf(stderr,"Error: %s: Could not parse file \"%s\".\n",
                    REFLIBNAME,filename);
            exit(-1);
          } else {
            stracpy(R->rc.matrl,header_parsed[0],255);
            R->rc.T = table;
            R->rc.d = header_parsed[4] ? strtod(header_parsed[4], NULL) : 0; /* d is optional */
            R->rc.rho=strtod(header_parsed[3],NULL);
            R->rc.Z=strtod(header_parsed[1],NULL);
            R->rc.At=strtod(header_parsed[2],NULL);
          }
          break;
        }

      case Q_PARAMETRIC:
        {
          stracpy(R->rqpm.fname,filename,255);
          R->rqpm.T=table;
          R->rqpm.qmin=Table_Index(*table,0,0);
          R->rqpm.qmax=Table_Index(*table,table->rows,0);
          break;
        }

      case PARRATT:
        {
          char **header_parsed = Table_ParseHeader(table->header, "#N=", "#d=", "#delta=", "#beta=", NULL);
          if (! (header_parsed[0] && header_parsed[1] && header_parsed[2] && header_parsed[3])){
            fprintf(stderr,"Error: %s: Could not parse file \"%s\".\n",
                    REFLIBNAME,filename);
            exit(-1);
          }
          unsigned long N=strtol(header_parsed[0], NULL, 10);
          R->rp.N = N;
          R->rp.d = calloc(N,sizeof(double));
          *(R->rp.d) = strtod(header_parsed[1], NULL);
          R->rp.delta = calloc(N,sizeof(double));
          *(R->rp.delta) = strtod(header_parsed[2], NULL);
          R->rp.beta = calloc(N,sizeof(double));
          *(R->rp.beta) = strtod(header_parsed[3], NULL);
          break;
        }

      case KINEMATIC:
        {
          char **header_parsed = Table_ParseHeader(table->header, "#N=", "#gamma=", "#lambda=", "#rho_ab=", NULL);
          if (! (header_parsed[0] && header_parsed[1] && header_parsed[2] && header_parsed[3])){
            fprintf(stderr,"Error: %s: Could not parse file \"%s\".\n",
                    REFLIBNAME,filename);
            exit(-1);
          }

          R->rk.N = strtol(header_parsed[0], NULL, 10);
          R->rk.Gamma = strtod(header_parsed[1], NULL);
          R->rk.Lambda = strtod(header_parsed[2], NULL);
          R->rk.rho_AB = strtod(header_parsed[3], NULL);
          break;
        }

      case ETH_PARAMETRIC:
        {
          stracpy(R->rethpm.fname,filename,255);
          R->rethpm.T=table;

          /*parse header for E_min E_max etc.*/
          char **header_parsed = Table_ParseHeader(table->header,"e_min=","e_max=","theta_min=","theta_max=",NULL);
          if (!(header_parsed[0] && header_parsed[1] && header_parsed[2] && header_parsed[3])){
            fprintf(stderr,"Error: %s: Could not parse file \"%s\".\n",
                    REFLIBNAME,filename); //1619
            exit(-1);
          }
          R->rethpm.emin=strtod(header_parsed[0],NULL);
          R->rethpm.emax=strtod(header_parsed[1],NULL);
          R->rethpm.thetamin=strtod(header_parsed[2],NULL);
          R->rethpm.thetamax=strtod(header_parsed[3],NULL);
          int rows = R->rethpm.T->rows;
          int cols = R->rethpm.T->columns;
          if(rows == 0){ //implies cols == 0 as well
            fprintf(stderr,"Error: %s: File %s contains no table.\n",
                    REFLIBNAME, filename);
            exit(1);
          } else {
            if(rows == 1){
              printf("Warning: %s: File %s contains only a single row. Setting e_step = 0.\n",
                     REFLIBNAME, filename);
              R->rethpm.estep=0;
            } else {
              R->rethpm.estep=(R->rethpm.emax - R->rethpm.emin)/(rows-1);
            }
            if(cols == 1){
              printf("Warning: %s: File %s contains only a single column. Setting theta_step = 0.\n",
                     REFLIBNAME, filename);
              R->rethpm.thetastep=0;
            } else {
              R->rethpm.thetastep=(R->rethpm.thetamax - R->rethpm.thetamin)/(cols-1);
            }
          }
          break;
        }
      case UNDETERMINED:
      default:
        {
          fprintf(stderr,"Warning: %s: Undetermined reflectivity parametrization type. R set to 1.\n",
                  REFLIBNAME);
          return 1;
        }
    }
    return 0;
}

enum reflec_Type get_table_reflec_type(t_Table *t){
    char **header_parsed = Table_ParseHeader(t->header,"param=",NULL);
    char *type = header_parsed[0];
    if(!type){
      /*type of reflectivity file is not specified - try to guess instead*/
      header_parsed = Table_ParseHeader(t->header,"Z",NULL);
      long Z = header_parsed[0] ? strtol(header_parsed[0],NULL,0) : 0;
      if(Z >0 && Z<116){
        /*this appears to be a coating file similar to Pt.txt and Be.txt (in the mcxtrace data library*/
        printf("INFO: %s: Datafile type not explicit in reflectivity file %s.\n"
               "      Inferring type COATING from datafile.\n",
               REFLIBNAME, t->filename);
        return COATING;
      }else{
        fprintf(stderr,"Error: %s: Could not determine reflectivity type from file %s.\n",
                REFLIBNAME, t->filename);
        exit(-1);
      }
    }
    /*for this to work well we need to trim the type string*/
    while (isspace(*type)){
      type++;
    }
    char *back = type+strlen(type);
    while (isspace(*(--back))){
      *(back++)='\0';
    }

    printf("INFO: %s: Reflectivity parameterization type: \'%s\'\n",REFLIBNAME, type);
    if(strcmp(type, NAME_CONSTANT) == 0){
        return CONSTANT;
    } else if(strcmp(type, NAME_BARE) == 0){
        return BARE;
    } else if(strcmp(type, NAME_COATING) == 0){
        return COATING;
    } else if(strcmp(type, NAME_Q_PARAMETRIC) == 0){
        return Q_PARAMETRIC;
    } else if(strcmp(type, NAME_PARRATT) == 0){
        return PARRATT;
    } else if(strcmp(type, NAME_ETH_PARAMETRIC) == 0){
        return ETH_PARAMETRIC;
    } else if(strcmp(type, NAME_KINEMATIC) == 0){
        return KINEMATIC;
    } else {
        printf("Error: %s: \'%s\'; is not a known parametrization!", REFLIBNAME, type);
        exit(-1);
    }
}

/*This section contains the functions that compute the actual reflectivity*/
cdouble reflec_coating(t_Reflec r_handle, double q, double g, double k){
    struct t_reflec_coating *ptr=&(r_handle.rc);
    /*adjust p according to reflectivity*/
    double Qc,f1,f2,na,e;
    /*length of wavevector transfer may be compute from s and n_ above*/

    /*interpolate in material data*/
    e=K2E*k;
    f1=Table_Value(*(ptr->T),e,1);
    f2=Table_Value(*(ptr->T),e,2);
    /*the conversion factor in  the end is to transform the atomic density from cm^-3 to AA^-3
    -> therefore we get Q in AA^-1*/
    na=NA*ptr->rho/ptr->At*1e-24;
    Qc=4*sqrt(M_PI*na*RE*f1);

    cdouble qp,qn,rr;
    double b_mu,R;
    double qn_re;

    qn_re=q/Qc;
    qn=cplx(qn_re,0.0);
    /*delta=na*r0*2*M_PI/k2*f1;*/
    /*beta=na*r0*2*M_PI/k^2*f2; b_mu=beta*(2*k)^2 / Qc^2*/
    b_mu=8*M_PI*na*RE*f2/(Qc*Qc);
    if(qn_re==1){
        /*sqrt(b_mu)*(1+I)*/
        qp=rmul(sqrt(b_mu), cplx(1.0,1.0));
    }else {
        /*(qn*qn)-1+2*I*b_mu*/
        qp=csqrt(cadd(radd(-1.0, cmul(qn,qn)), cplx(0.0,2*b_mu)));
    }
    /*and from this compute the reflectivity*/
    rr=cdiv(csub(qn,qp), cadd(qn,qp));
    return rr;
}

cdouble reflec_bare(t_Reflec r_handle, double q, double g){
    return cplx(0.0,0.0);
}

cdouble reflec_kinematic(t_Reflec r_handle, double q, double g){
    cdouble r1,rN,num_factor,den_factor;
    struct t_reflec_kinematic *ptr=&(r_handle.rk);
    double zeta=ptr->Lambda*q/(2*M_PI);
    double beta=0;
    double r1_scale;

    /*-2*I*RE* ptr->rho_AB * (pow(ptr->Lambda,2.0)*ptr->Gamma/zeta) * sin(M_PI*ptr->Gamma*zeta)/(M_PI*ptr->Gamma*zeta)
      -- everything except the leading -2*I*RE factor is real, so collapse it to a real scale first*/
    r1_scale = ptr->rho_AB * (pow(ptr->Lambda,2.0)*ptr->Gamma/zeta) * sin(M_PI*ptr->Gamma*zeta)/(M_PI*ptr->Gamma*zeta);
    r1 = cplx(0.0, -2*RE*r1_scale);

    /*cexp(I*2*M_PI*zeta*ptr->N)*exp(-beta*ptr->N)*/
    num_factor = rmul(exp(-beta*ptr->N), cexp(cplx(0.0, 2*M_PI*zeta*ptr->N)));
    /*cexp(I*2*M_PI*zeta)*exp(beta)*/
    den_factor = rmul(exp(beta), cexp(cplx(0.0, 2*M_PI*zeta)));

    /*r1*(1-num_factor)/(1-den_factor)*/
    rN = cdiv(cmul(r1, radd(1.0, cneg(num_factor))), radd(1.0, cneg(den_factor)));
    return rN;
}

cdouble reflec_q_prmtc(t_Reflec r_handle, double q, double g){
    double r;
    struct t_reflec_q_prmtc *ptr=&(r_handle.rqpm);
    if (ptr->T->columns>2){
        double c=(ptr->T->columns-2)*g+1;
        r=Table_Value2d(*(ptr->T),ptr->T->rows*q/(ptr->qmax-ptr->qmin),c);
    }else{
        r=Table_Value(*(ptr->T),q,1);
    }
    return cplx(r,0.0);
}

cdouble reflec_eth_prmtc(t_Reflec r_handle, double g, double e, double th){
    double r,ec,thc;
    struct t_reflec_eth_prmtc *ptr=&(r_handle.rethpm);
    ec=(ptr->T->rows-1) * (e-ptr->emin)/(ptr->emax - ptr->emin);
    thc=(ptr->T->columns-1)*(th-ptr->thetamin)/(ptr->thetamax - ptr->thetamin);
    r=Table_Value2d(*(ptr->T),ec,thc);
    return cplx(r,0.0);
}

/* Entry function to Parratt's recursive algorithm for multilayers.*/
cdouble reflec_parratt(t_Reflec r_handle, double q, double g, double k){
    cdouble r,qp,rp;
    double k2=k*k;
    cdouble qinf;
    cdouble qpd,rd,p;
    t_reflec_parratt *pp=&(r_handle.rp);

    qp=cplx(q,0.0);
    /*q*q - 8*k2* *(pp->delta) + I*8*k2* *(pp->beta)*/
    qpd=csqrt(cplx(q*q - 8*k2* *(pp->delta), 8*k2* *(pp->beta)));
    k2=k*k;

    if (pp->N>0){
        rp=cdiv(csub(qp,qpd), cadd(qp,qpd));
        rd=parrat_reflec_bulk(pp->N,pp->delta,pp->beta,pp->d,k,q);
        /*I*qpd* *(pp->d)*/
        p=cexp(rmul(*(pp->d), cmul(cplx(0.0,1.0), qpd)));
        /*(rp+p*rd)/(1+rp*rd*p)*/
        r = cdiv(cadd(rp, cmul(p,rd)), radd(1.0, cmul(cmul(rp,rd),p)));
    }else{
        r = cdiv(csub(qp,qpd), cadd(qp,qpd));
    }
    return r;
}
/* Lower layer function fo rParratt's recursive algorithm. Here recursion
* takes place by calls to itself.*/
cdouble parrat_reflec_bulk(int N, double *delta, double *beta, double *d, double k, double q){
    cdouble qp,rp,rr;
    double k2=k*k;
    cdouble qinf;
    cdouble qpd,rpd,p;

    /*q*q - 8*k2* *delta + I*8*k2* *beta*/
    qp=csqrt(cplx(q*q - 8*k2* *delta, 8*k2* *beta));
    /*q*q - 8*k2* *(delta+1) + I*8*k2* *(beta+1)*/
    qpd=csqrt(cplx(q*q - 8*k2* *(delta+1), 8*k2* *(beta+1)));

    if (N>1){
        rp=cdiv(csub(qp,qpd), cadd(qp,qpd));
        rpd=parrat_reflec_bulk(N-1,(delta+1),(beta+1),(d+1),k,q);
        /*I*qpd* d[1]*/
        p=cexp(rmul(d[1], cmul(cplx(0.0,1.0), qpd)));
        /*(rp+p*rpd)/(1+rp*rpd*p)*/
        rr= cdiv(cadd(rp, cmul(p,rpd)), radd(1.0, cmul(cmul(rp,rpd),p)));
    }
    if (N==1){
        /*the bottom layer (on top of substrate)*/
        rr=cdiv(csub(qp,qpd), cadd(qp,qpd));
    }
    return rr;
}

/* Dispatcher functions that call the underlying computations depending on the type of reflectivity*/

cdouble refleccq( t_Reflec r_handle, double q, double g, double k, double theta){
    cdouble r;
    /*using the normalized coordinate g which lies along the grading direction*/

    switch(r_handle.type){
      case CONSTANT:
        {
          r=cplx(r_handle.rconst.R,0.0);
          break;
        }
      case BARE:
        {
          r=reflec_bare(r_handle,q,g);
          break;
        }
      case COATING:
        {
          r=reflec_coating(r_handle,q,g,k);
          break;
        }
      case Q_PARAMETRIC:
        {
          r=reflec_q_prmtc(r_handle,q,g);
          break;
        }
/*      case PARRATT:*/
/*        {*/
/*          r=reflec_parratt(r_handle,q,g,k);*/
/*          break;*/
/*        }*/
      case ETH_PARAMETRIC:
        {
          r=reflec_eth_prmtc(r_handle,g,k*K2E,theta);
          break;
        }
      case KINEMATIC:
        {
          r=reflec_kinematic(r_handle,q,g);
          break;
        }
      default:
        {
#ifndef OPENACC
          fprintf(stderr,"Error: %s: Undetermined reflectivity type. R set to 1.\n",
                  REFLIBNAME);
#endif
          r=cplx(1.0,0.0);
        }
    }
    return r;
}

double reflecq( t_Reflec r_handle, double q, double g, double k, double theta){
    double r;

    switch(r_handle.type){
      case CONSTANT:
        {
          r=1.0; //fabs(r_handle.rconst.R);
          break;
        }
    case BARE:
        {
          r=cabs(reflec_bare(r_handle,q,g));
          break;
        }
    case COATING:
        {
          cdouble rp;
          rp=reflec_coating(r_handle,q,g,k);
          r= sqrt(creal(cmul(rp, conj(rp))));
	  break;
        }
    case Q_PARAMETRIC:
        {
          r=cabs(reflec_q_prmtc(r_handle,q,g));
          break;
        }
    #ifndef OPENACC
    case PARRATT:
        {
          r=cabs(reflec_parratt(r_handle,q,g,k));
          break;
	}
    #endif
    case ETH_PARAMETRIC:
        {
            r=cabs(reflec_eth_prmtc(r_handle,g,k*K2E,theta));
            break;
        }
      case KINEMATIC:
        {
          r=cabs(reflec_kinematic(r_handle,q,g));
          break;
	  }
      default:
        {
#ifndef OPENACC
          fprintf(stderr,"Warning: %s: Undetermined reflectivity type. R set to 1.\n",
                  REFLIBNAME);
#endif
          r=1.0;
	}
    }
    return r;
}

double refleceth( t_Reflec r_handle,double e, double th, double g){
    double q;
    double k=e*E2K;
    q=k*2.0*sin(th);
    if(r_handle.type==PARRATT || r_handle.type==COATING){
      return reflecq(r_handle,q,g,k,0);
    }else{
      return reflecq(r_handle,q,g,k,th);
    }
}

cdouble reflecceth( t_Reflec r_handle,double e, double th, double g){
    double q;
    double k=e*E2K;
    q=k*2.0*sin(th);
    if(r_handle.type==PARRATT){
      return refleccq(r_handle,q,g,k,0);
    }else{
      return refleccq(r_handle,q,g,k,th);
    }
}


/* Shared user declarations for all components types 'Bragg_crystal'. */
#ifndef MX_CRYSTALS_H
#define MX_CRYSTALS_H



enum {Mx_crystal_explicit=0, Mx_crystal_diamond, Mx_crystal_fcc,Mx_crystal_bcc};

/* make proper function declaration to be standards-compliant */
#pragma acc routine
void Mx_CubicCrystalChi(cdouble *chi0, cdouble *chih, double *k0mag, double *hscale, double *thetaB,
                         double f00, double f0h, double fp, double fpp, double V, int h, int k, int l,
                         double debye_waller_B, double E,
                         int crystal_type, double fscaler, double fscalei);

#pragma acc routine
int Mx_DiffractionDispersion(cdouble kqvals[4], cdouble xi0[4], cdouble xih[4],
        const double k0[3], const double nhat[3],
        const double H[3],
        cdouble chi0, cdouble chih_chihbar, double C, int nroots);

#pragma acc routine
int Mx_DarwinReflectivityBC(double *Rsig, double *Rpi, double kh[3],
	const double k0hat[3], const double nhat[3],
	const double alpha[3],
	cdouble chi0, cdouble chih, cdouble chihbar,
	double k0mag, double hscale, double thetaB);

#pragma acc routine
int Mx_LaueReflectivityBC(double *Rsig, double *Rpi, double *Tsig, double *Tpi,
	double *Asig, double *Api, // primary attenuation
	double kh[3],
	const double k0hat[3], const double nhat[3],
	const double alpha[3],
	cdouble chi0, cdouble chih, cdouble chihbar,
	double k0mag, double hscale, double thetaB, double thickness);

/*This is the old Darwin function*/
#pragma acc routine
void Mx_DarwinReflectivity(double *R, double *Thetah, double *Theta0, double *DeltaTheta0,
        double f00, double f0h, double fp, double fpp, double V, double alpha, int h, int k, int l,
        double debye_waller_B, double E, double Thetain, int pol,
        int crystal_type, double fscaler, double fscalei);

#pragma acc routine
void cross(double res[3], const double v1[3], const double v2[3], int unitize);



#define vdot(a,b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
#define vplus(res, a, b) { res[0]=a[0]+b[0]; res[1]=a[1]+b[1]; res[2]=a[2]+b[2]; }
// solve a quadratic a x^2 + b x + c safely, a la Numerical Recipes.  r1 always has the larger magnitude
// a, b, c, r1, r2 are cdouble; sqrtfn is expected to be a cdouble->cdouble square root (e.g. csqrt)
#define qsolve(r1, r2, a, b, c, sqrtfn) { \
    if(creal(b) > 0) { r1=cdiv(csub(cneg(b),sqrtfn(csub(cmul(b,b),cmul(rmul(4.0,a),c)))),rmul(2.0,a)); } \
    else { r1=cdiv(cadd(cneg(b),sqrtfn(csub(cmul(b,b),cmul(rmul(4.0,a),c)))),rmul(2.0,a)); } \
    r2=cdiv(cdiv(c,a),r1); }
// real-coefficient counterpart of qsolve: a, b, c, r1, r2 are plain double; sqrtfn is e.g. sqrt.
// Native +,-,*,/ are fine here on both platforms since plain double is never the MSVC complex problem.
#define qsolve_real(r1, r2, a, b, c, sqrtfn) { \
    if(b > 0) { r1=(-b-sqrtfn(b*b-4*a*c))/(2*a); } \
    else { r1=(-b+sqrtfn(b*b-4*a*c))/(2*a); } \
    r2=(c/a)/r1; }

#endif /* MX_CRYSTALS_H SHARE section */
#ifndef MX_CRYSTALS_C
#define MX_CRYSTALS_C

void Mx_CubicCrystalChi(cdouble *chi0, cdouble *chih, double *k0mag, double *hscale, double *thetaB,
                         double f00, double f0h, double fp, double fpp, double V, int h, int k, int l,
                         double debye_waller_B, double E,
                         int crystal_type, double fscaler, double fscalei)
{
    double lambda, a, d;
    
    lambda = 2*PI/(E2K*E);  			/* wavelength in Å, E in keV, using built-in constants for safety    */
    a = cbrt(V); 				/* side length of unit cubic cell (Å)*/
    d = a/sqrt(h*h + k*k + l*l); 		/* d-spacing (Å)*/

    if (lambda>2*d){
      /*cannot close scattering triangle, set all returns to 0 and exit*/
      *thetaB=0;
      *k0mag=0;
      *hscale=0;
      *chi0=cplx(0.0,0.0);
      *chih=cplx(0.0,0.0);
      return;
    }

    *thetaB = asin(lambda/(2*d));  		/* kinematical bragg angle (rad) */
    *k0mag=2.0*M_PI/lambda; /* magnitude of k0 consistent with energy scale */
    *hscale=2.0*M_PI/d; /* minus sign to make it point into the crystal */
    
    /* structure factor rules from:
     https://en.wikipedia.org/wiki/Structure_factor section on diamond cubic crystals
     */
    
    cdouble fscaleh;
    double fscale0;
    
    switch(crystal_type) {
        case Mx_crystal_explicit:
            /* use explicitly provided structure factor scale factor */
            break;
        case Mx_crystal_diamond: /* diamond lattice rules */
            if (((h+k+l)%2) != 0){ 		/* (111) etc. odd sum eflection */
                fscaleh=cplx(4.0,4.0);
                fscale0=8;
            }
            else if (((h+k+l)%4)==0){ 		/* (400) etc. h+k+l=4n reflection */
                fscaleh=cplx(8.0,0.0);
                fscale0=8;
            } else {
                /* any other reflection is forbidden, will get a divide-by-zero somewhere, but user is
                 responsible for only using allowed reflections */
                fscaleh=cplx(0.0,0.0);
                fscale0=0;
            }
            break;
        case Mx_crystal_fcc: /* fcc lattice rules */
        {
            int hpar=h%2, kpar=k%2, lpar=l%2;
            if ( hpar==kpar && kpar==lpar ) { /* all parities the same */
                fscaleh=cplx(4.0,0.0);
                fscale0=4;
            }
            else { 		/* mixed parity forbidden */
                fscaleh=cplx(0.0,0.0);
                fscale0=0;
            }
        }
            break;
        case Mx_crystal_bcc: /* bcc lattice rules */
            if ( ((h+k+l)%2) == 0 ) { /* h+k+l even */
                fscaleh=cplx(2.0,0.0);
                fscale0=2;
            }
            else { 		/* otherwise forbidden */
                fscaleh=cplx(0.0,0.0);
                fscale0=0;
            }
            break;
        default:
            fscale0=0;
            fscaleh=cplx(0.0,0.0); /* fail later if unknown crystal type */
            break;
    }
    
    cdouble F0=rmul(fscale0, cplx(f00+fp, fpp)); // NEVER CHECKED for crystals other than diamond structure
    cdouble Fh=rmul(cabs(fscaleh), cplx(f0h+fp, fpp));
    
    double GAMMA=RE*lambda*lambda/(PI*V);
    double M=debye_waller_B*SQR(sin(*thetaB)/lambda)*(2./3.); /* isotropic temperature factor */
    *chi0 = rmul(GAMMA, cneg(F0));
    *chih = rmul(GAMMA*exp(-M), cneg(Fh));
}

int Mx_DarwinReflectivityBC(double *Rsig, double *Rpi, double kh[3],
                         const double k0hat[3], const double nhat[3],
                         const double alpha[3],
                         cdouble chi0, cdouble chih, cdouble chihbar,
                         double k0mag, double hscale, double thetaB
                         )
{
    double k0[3]={k0hat[0]*k0mag, k0hat[1]*k0mag, k0hat[2]*k0mag}; /* actual incoming k vector */
    double H[3]={alpha[0]*hscale, alpha[1]*hscale, alpha[2]*hscale};
    
    /* now we have to solve for the free-space kh vector outside the crystal.
     The requirement is that kh = Kh + q2 * nhat, and is pure real and has the same magnitude as k0.
     Thus, kh = k0 + q1 * nhat + H + q2 * nhat, |kh| = |k0|, and (q1 + q2) must be real to make kh real.
     if (q1 + q2) == q,
     q^2 + H^2 + 2 q (k0+H).nhat + 2 k0.H = 0
     Note that this is independent of the messy dispersion relationship, and the same for both polarizations.
     */
    double k0plusH[3];
    vplus(k0plusH, k0, H); // temporary k0+H as needed in second poly term above
    double bb=2*vdot(k0plusH, nhat);
    double cc = vdot(H,H) +2*vdot(k0,H);
    double root1, root2;
    qsolve_real(root1, root2, 1., bb, cc, sqrt); //root2 is the small root
    vplus(kh, k0plusH, root2*nhat);
    
    for (int i=0; i<2; i++) { // do reflectivity using shared geometry for both polarizations
        double C=(i==0)?fabs(cos(2*thetaB)) : 1; // polarization factor
        cdouble xi0;
        double K0[3], Kh[3];
        cdouble kqvals[4], xi0vals[4], xihvals[4];

        int fail=Mx_DiffractionDispersion(kqvals, xi0vals, xihvals,
                   k0, nhat, H, chi0, cmul(chih,chihbar), C, 1); // get first (interesting) root only

        cdouble kq=kqvals[0];
        xi0=xi0vals[0];
        vplus(K0, k0, creal(kq)*nhat);
        vplus(Kh, K0, H);

        /* compute the asymmetry b which is the ratio of the sizes of the footprint of the beam on the crystal */
        double b = (vdot(K0, nhat)/sqrt(vdot(K0,K0)))/(vdot(Kh, nhat)/sqrt(vdot(Kh, Kh)));
        
        if(fail) {
            *Rsig=0;
            *Rpi=0;
            return 1;
        }
        
        cdouble eq24=cdiv(rmul(2.0,xi0), rmul(k0mag*C,chih)); // B&C equation 24
        double eratio=cabs(eq24);
        
#ifdef MCDEBUG
#ifndef OPENACC
        fprintf(stderr,
                "Bragg Geometry results: k0=(%.3f %.3f %.3f), kh=(%.3f %.3f %.3f) "
                "xi0 = (%.3e + %.3e i) "
                "b0=%.4f "
                "eq24 = (%.3e + %.3e i) "
                "R = %.3e "
                "\n",
                k0[0], k0[1], k0[2], kh[0], kh[1], kh[2],
                creal(xi0), cimag(xi0),
                b,
                creal(eq24), cimag(eq24), eratio*eratio/fabs(b));
#endif
#endif
        
        if(i==0)  *Rpi=eratio*eratio/fabs(b); // the fabs(b0) is the footprint correction
        else      *Rsig=eratio*eratio/fabs(b);
    }
    return 0;
}

void cross(double res[3], const double v1[3], const double v2[3], int unitize)
{   // use our own cross product which takes arrays directly to reduce pointer shuffling
    res[0]=v1[1]*v2[2]-v1[2]*v2[1];
    res[1]=v1[2]*v2[0]-v1[0]*v2[2];
    res[2]=v1[0]*v2[1]-v1[1]*v2[0];
    if(unitize) {
        double l=sqrt(res[0]*res[0]+res[1]*res[1]+res[2]*res[2]);
        res[0]/=l;
        res[1]/=l;
        res[2]/=l;
    }
}
    
int Mx_DiffractionDispersion(cdouble kqvals[4], cdouble xi0[4], cdouble xih[4],
                          const double k0[3], const double nhat[3],
                          const double H[3],
                          cdouble chi0, cdouble chih_chihbar, double C, int nroots){
    /* compute the Batterman & Cole eq. 17 dispersion relation, and associated quantities.
       nroots sets how many roots to find.  They are sorted, with the first root being the attenuated incoming ray,
       then the amplified incoming ray, then the two 'big roots'.
       Normally only nroots=1 is interesting for Bragg diffraction.
     */

    double k0mag=sqrt(vdot(k0,k0));
    
    /* B&C equation 17 is ( |k0 + kq nhat|^2 - k0^2(1+chi0) ) ( |k0 + kq nhat + H|^2 - k0^2(1+chi0) ) = k^4 C^2 chih chihbar */
    double k0plusH[3];
    vplus(k0plusH, k0, H); // temporary k0+H as needed in second poly term above
    cdouble poly1[3], poly2[3], poly[5], deriv[4];
    poly1[2]=cplx(1.0,0.0);
    poly1[1]=cplx(2*vdot(k0,nhat), 0.0);
    poly1[0]=rmul(-k0mag*k0mag, chi0);
    poly2[2]=cplx(1.0,0.0);
    poly2[1]=cplx(2*vdot(k0plusH,nhat), 0.0);
    poly2[0]=radd(2*vdot(k0,H), radd(vdot(H,H), rmul(-k0mag*k0mag, chi0)));
    /* for multiplying these polys, just write it out explicitly */
    poly[0]=cmul(poly1[0],poly2[0]);
    poly[1]=cadd(cmul(poly1[0],poly2[1]), cmul(poly1[1],poly2[0]));
    poly[2]=cadd(cadd(cmul(poly1[0],poly2[2]), cmul(poly1[1],poly2[1])), cmul(poly1[2],poly2[0]));
    poly[3]=cadd(cmul(poly1[1],poly2[2]), cmul(poly1[2],poly2[1]));
    poly[4]=cmul(poly1[2],poly2[2]);
    cdouble epsilon=rmul(k0mag*k0mag*k0mag*k0mag*C*C, chih_chihbar); // right-hand side of dispersion
    poly[0]=csub(poly[0],epsilon);
    deriv[3]=rmul(4.0,poly[4]);
    deriv[2]=rmul(3.0,poly[3]);
    deriv[1]=rmul(2.0,poly[2]);
    deriv[0]=rmul(1.0,poly[1]);
    
    /* the dispersion polynomial is p1*p2-epsilon = 0; first, find big roots and factor out to leave only a quadratic with small (interesting) roots */
    /* big roots will be _close_ to big roots of p1 and p2, use these as guesses */
    cdouble p1b, p1s, p2b, p2s;
    // p1b and p2b are always larger root in magnitude
    qsolve(p1b, p1s, poly1[2], poly1[1], poly1[0], csqrt);
    qsolve(p2b, p2s, poly2[2], poly2[1], poly2[0], csqrt);
    
    /* now, (x-p1b)(x-p2b)(x-p1s)(x-p2s)-epsilon is the full poly, but near the interesting region around p1s, p2s, flatten first two terms */
    /* so x0 = (p1s+p2s)*0.5, this is (x-p1s)(x-p2s)-epsilon/((x0-p1b)*(x0-p2b)) = 0 to get approximate roots of full poly */
    cdouble x0=rmul(0.5, cadd(p1s,p2s));
    cdouble fp[3] = { csub(cmul(p1s,p2s), cdiv(epsilon, cmul(csub(x0,p1b), csub(x0,p2b)))),
                      cneg(cadd(p1s,p2s)),
                      cplx(1.0,0.0) };
    // factored poly roots, should be very close to exact roots
    // practical note:  looking at convergence, these roots are so close, one could probably drop the Newton's method refinement
    // completely.  However, since this code is intended to be pedantically correct, I will do the refinement.
    cdouble initroots[4];
    qsolve(initroots[0], initroots[1], fp[2], fp[1], fp[0], csqrt); // solution to factored polynomial is starting point for newton's method
    
    int rootloops, fail=0;
    // make sure the first root has im(k).re(k) < 0 so beam is attenuated. Since re(k) is nearly k0 and im(k) is im(kq)*nhat,
    // we need k0.nhat * im(k) < 0
    double kdotnhat=vdot(k0, nhat);
    if(cimag(initroots[0])*kdotnhat > 0) {
        if(cimag(initroots[1])*kdotnhat < 0) {
            cdouble swap;
            swap=initroots[0]; initroots[0]=initroots[1]; initroots[1]=swap;
        } else {
            // neither root has im(k) < 0, no physically possible solution.  Should never happen.
#ifndef OPENACC
            fprintf(stderr, "PerfectCrystal: No attenuating solution for incoming vector found, r1=(%.3e + %.3e i) 	r2=(%.3e + %.3e i) \n",
                    creal(initroots[0]), cimag(initroots[0]), creal(initroots[1]), cimag(initroots[1]));
#endif
            return -1;
        }
    }
    initroots[2]=p1b;
    initroots[3]=p2b; // the two big roots are last in the list

    for(rootloops=0; rootloops < nroots; rootloops++) {
        cdouble dd, kq, pv, dv;
        kq=initroots[rootloops];
#if MCDEBUG
#ifndef OPENACC
        fprintf(stderr,"Batterman Cole dispersion Newton Iterations, starting at root =(%.3e + %.3e i) \n", creal(kq), cimag(kq));
#endif
#endif
        int stepcount=0;
        do {
            pv=poly[4]; // poly value, evaluated via Horner's method
            pv=cadd(cmul(pv,kq),poly[3]);
            pv=cadd(cmul(pv,kq),poly[2]);
            pv=cadd(cmul(pv,kq),poly[1]);
            pv=cadd(cmul(pv,kq),poly[0]);
            dv=deriv[3]; // derivative value, evaluated via Horner's method
            dv=cadd(cmul(dv,kq),deriv[2]);
            dv=cadd(cmul(dv,kq),deriv[1]);
            dv=cadd(cmul(dv,kq),deriv[0]);
            dd=cdiv(cneg(pv),dv); // Newton's method step
            kq=cadd(kq,dd);
            stepcount++;
#ifdef MCDEBUG_EXTRA
#ifndef OPENACC
        fprintf(stderr,"Batterman Cole dispersion Newton Iterations, starting at root =(%.3e + %.3e i) \n",creal(kq), cimag(kq));
	fprintf(stderr,"Batterman Cole dispersion Newton Iterations, step count=%d, pv=%.3e dv=%.3e "
		"kq=(%.3e + %.3e I) shift=%.3e\n",
		stepcount, cabs(pv), cabs(dv), creal(kq), cimag(kq), cabs(dd) );
#endif
#endif
        } while ( ((cabs(dd) > 1e-15) && (stepcount < 20)) );
        kqvals[rootloops]=kq;

        fail= (stepcount == 20);
        if(fail) { // should never happen. always converges in about 3 steps!
#ifndef OPENACC
            fprintf(stderr,"****Newton's method convergence failure in Bragg_Geometry, killing particle!\n");
#endif
            kq=initroots[rootloops]; // leave offset plausible, close to quadratic start
        }


        // batterman and cole eq. 18, exact definitions of xi0 and xih
        // but adjust for numerical stability.
        // The smaller of xi0, xih depends on delicate cancellation of the polynomial.  The larger doesn't.
        // Thus, replace the small polynomial with epsilon / (large one)
        // This is equivalent to the Numerical Recipes trick for stable computation of quadratic roots
        cdouble poly1v=poly1[2];
        poly1v=cadd(cmul(poly1v,kq),poly1[1]);
        poly1v=cadd(cmul(poly1v,kq),poly1[0]);
        cdouble poly2v=poly2[2];
        poly2v=cadd(cmul(poly2v,kq),poly2[1]);
        poly2v=cadd(cmul(poly2v,kq),poly2[0]);
        if( fabs(creal(poly1v)) < fabs(creal(poly2v)) ) {
            poly1v=cdiv(epsilon,poly2v);
        } else {
            poly2v=cdiv(epsilon,poly1v);
        }
        xi0[rootloops]=rmul(1.0/(2*k0mag), poly1v);
        xih[rootloops]=rmul(1.0/(2*k0mag), poly2v);
        
    }
    return fail;
}

int Mx_LaueReflectivityBC(double *Rsig, double *Rpi, double *Tsig, double *Tpi,
                         double *Asig, double *Api, // primary attenuation
                         double kh[3],
                         const double k0hat[3], const double nhat[3],
                         const double alpha[3],
                         cdouble chi0, cdouble chih, cdouble chihbar,
                         double k0mag, double hscale, double thetaB, double thickness)
{
    double k0[3]={k0hat[0]*k0mag, k0hat[1]*k0mag, k0hat[2]*k0mag}; /* actual incoming k vector */
    double H[3]={alpha[0]*hscale, alpha[1]*hscale, alpha[2]*hscale};

    /* a bunch of precomputed dot products we will use over and over.*/
    double k0dotnhat=vdot(k0,nhat);
    double Hdotnhat=vdot(H, nhat);
    double k0dotH=vdot(k0,H);
    double HdotH=vdot(H,H);
    
    /* now we have to solve for the free-space kh vector outside the crystal.
     The requirement is that kh = Kh + e * nhat, and is pure real and has the same magnitude as k0.
     Thus, kh = k0 + kq*nhat + H + e*nhat, |kh| = |k0|, and kq+e must be real to make kh real.
     if kq+e == q,
     q^2 + H^2 + 2 q (k0+H).nhat + 2 k0.H = 0
     Note that this is independent of the messy dispersion relationship, and the same for both polarizations.
     */
    double k0plusH[3];
    vplus(k0plusH, k0, H);
    double bb=2*(k0dotnhat+Hdotnhat);
    double cc = HdotH +2*k0dotH;
    double root1, root2;
    qsolve_real(root1, root2, 1., bb, cc, sqrt); //root2 is the small root
    vplus(kh, k0plusH, root2*nhat);

    for (int i=0; i<2; i++) { // do reflectivity using shared geometry for both polarizations
        double C=(i==0)?fabs(cos(2*thetaB)) : 1; // polarization factor
        cdouble kqvals[4], xi0vals[4], xihvals[4];

        int fail=Mx_DiffractionDispersion(kqvals, xi0vals, xihvals,
                   k0, nhat, H, chi0, cmul(chih,chihbar), C, 2); // get first 2 (alpha and beta) roots only

        cdouble a1=cdiv(rmul(2.0,xi0vals[0]), rmul(k0mag*C,chih));  // complex Eha/E0a from B&C eq. 24
        cdouble a2=cdiv(rmul(2.0,xi0vals[1]), rmul(k0mag*C,chih));  // complex Ehb/E0a from B&C eq. 24

        // compute amplitudes from solving B&C eqns. 40
        cdouble i1=cdiv(a2,csub(a2,a1)); // e0a/e0i
        cdouble i2=cdiv(cneg(a1),csub(a2,a1)); // e0a/e0i
        cdouble ix=cplx(0.0,-thickness*1e10); // convert thickness to angstroms for absorption

        // factor out main K vector and difference explicitly,
        // so that dphi, the relative phase & amplitude of the alpha and beta
        // rays can be calculated to high accuracy
        // note: K0=k0 + r nhat, so K0.nhat = k0.nhat + r
        // similarly for Kh=k0 + H + r nhat so Kh.nhat = k0.nhat + H.nhat + r

        // we don't actually use the main phase (yet), so only compute real part
        // of transport exponentials
        // double complex phi0t=cexp((k0dotnhat+kqvals[0])*ix) #alpha transmitted wave factor
        // double complex phi0r=cexp((k0dotnhat+Hdotnhat+kqvals[0])*ix) #alpha reflected factor
        double phi0t=exp(creal(cmul(radd(k0dotnhat,kqvals[0]),ix))); // alpha transmitted wave factor
        double phi0r=exp(creal(cmul(radd(k0dotnhat+Hdotnhat,kqvals[0]),ix))); // alpha reflected factor
        cdouble dphi=cexp(cmul(csub(kqvals[1],kqvals[0]),ix)); // beta-alpha transmission ratio

        cdouble t0zz=rmul(phi0t, cadd(i1,cmul(i2,dphi))); // transmitted complex field amplitude at exit
        cdouble thzz=rmul(phi0r, cadd(cmul(a1,i1),cmul(cmul(a2,i2),dphi))); // reflected complex field amplitude at exit
#ifdef MCDEBUG
#ifndef OPENACC
        fprintf(stderr, "LAUE: "
        " k0 = (%.3f %.3f %.3f) thickness=%.3e"
        " a1=(%.3f + %.3fj) "
        " a2=(%.3f + %.3fj) "
        " i1=(%.3f + %.3fj) "
        " i2=(%.3f + %.3fj) "
        " phi0t = %.3e phi0r = %.3e "
        " dphi=(%.3f + %.3fj) "
        " t0zz=(%.3f + %.3fj) "
        " thzz=(%.3f + %.3fj) "
        " \n",
        k0[0], k0[1], k0[2], thickness,
        creal(a1), cimag(a1),
        creal(a2), cimag(a2),
        creal(i1), cimag(i1),
        creal(i2), cimag(i2),
        phi0t, phi0r,
        creal(dphi), cimag(dphi),
        creal(t0zz), cimag(t0zz),
        creal(thzz), cimag(thzz)
        );
#endif
#endif

        /* compute the asymmetry b which is the ratio of the sizes of the footprint of the beam on the crystal.
        Assume it is the same for alpha and beta branches!
        */
        double K0[3], Kh[3];
        vplus(K0, k0, creal(kqvals[0])*nhat);
        vplus(Kh, K0, H);
        double b = (vdot(K0, nhat)/sqrt(vdot(K0,K0)))/(vdot(Kh, nhat)/sqrt(vdot(Kh, Kh)));

        double R=cabs(cmul(thzz,thzz))/fabs(b); // the fabs(b) is the footprint correction
        double T=cabs(cmul(t0zz,t0zz))/fabs(b);

        if(i==0) {
            *Rpi= R; *Tpi= T; *Api=phi0t*phi0t;
        } else {
            *Rsig=R; *Tsig=T; *Asig=phi0t*phi0t;
        }
    }
    return 0;
}

/*This is the old Darwin function*/ 
void Mx_DarwinReflectivity(double *R, double *Thetah, double *Theta0, double *DeltaTheta0,
                             double f00, double f0h, double fp, double fpp, double V, double alpha, int h, int k, int l,
                             double debye_waller_B, double E, double Thetain, int pol,
                            int crystal_type, double fscaler, double fscalei
                             )
{

    double lambda,theta,theta0,DeltaThetas,a,d,b,C,W,kappa,g,L;
    double F0r,F0i,Fhr,Fhi,psi0r,psi0i,psihr,psihi;

    lambda = 2*PI/(E2K*E);  			/* wavelength in Å, E in keV, using built-in constants for safety    */
    a = cbrt(V); 				/* side length of unit cubic cell (Å)*/
    d = a/sqrt(h*h + k*k + l*l); 		/* d-spacing (Å)*/
    theta = asin(lambda/(2*d));  		/* kinematical bragg angle (rad) */
    b = sin(theta + alpha)/sin(theta - alpha);  /* asymmetry factor */

    *Theta0 = Thetain - alpha; 			/* (rad) angle between Bragg planes and incident ray */
    *Thetah = b*(*Theta0 - theta) + theta;   	/* (rad) Angle betweeb Bragg planes and reflected ray */
    /*check if Bragg angle is less than alpha. If so return 0 reflectivity*/
    if (theta<alpha) {
        *R=0;
        *DeltaTheta0 = -1; /*to mark it irrelevant*/
    }

    /* Define polarization factor: */
    switch(pol){
        case 0:
            C = (1 + fabs(cos(2*theta)))/2;         	/* unpolarized */
            break;
        case 1:
            C = fabs(cos(2*theta));  		/* polarization in the scattering plane */
            break;
        case 2:
            C = 1;                          	/* polarization perpendicular to the scattering plane*/
            break;
    }

    /* structure factor rules from:
https://en.wikipedia.org/wiki/Structure_factor section on diamond cubic crystals
     */

    switch(crystal_type) {
        case Mx_crystal_explicit:
            /* use explicitly provided structure factor scale factor */
            break;
        case Mx_crystal_diamond: /* diamond lattice rules */
            if (((h+k+l)%2) != 0){ 		/* (111) etc. odd sum eflection */
                fscaler=fscalei=4.0;
            }
            else if (((h+k+l)%4)==0){ 		/* (400) etc. h+k+l=4n reflection */
                fscaler=8; fscalei=0;
            } else {
                /* any other reflection is forbidden, will get a divide-by-zero somewhere, but user is
                   responsible for only using allowed reflections */
                fscaler=0; fscalei=0;
            }
            break;
        case Mx_crystal_fcc: /* fcc lattice rules */
            {
                int hpar=h%2, kpar=k%2, lpar=l%2;
                if ( hpar==kpar && kpar==lpar ) { /* all parities the same */
                    fscaler=4.0; fscalei=0.0;
                }
                else { 		/* mixed parity forbidden */
                    fscaler=0; fscalei=0;
                }
            }
            break;
        case Mx_crystal_bcc: /* bcc lattice rules */
            if ( ((h+k+l)%2) == 0 ) { /* h+k+l even */
                fscaler=2.0; fscalei=0.0;
            }
            else { 		/* otherwise forbidden */
                fscaler=0; fscalei=0;
            }
            break;
        default:
            fscaler=0; fscalei=0; /* fail later if unknown crystal type */
            break;
    }

    F0r=8*(f00+fp);
    F0i=8*fpp;
    double scalemag=sqrt(fscaler*fscaler+fscalei*fscalei);
    Fhr=scalemag*(f0h+fp);
    Fhi=scalemag*fpp;

    double main_scale=RE*lambda*lambda/(PI*V);
    double M=debye_waller_B*SQR(sin(Thetain)/lambda)*(2./3.); /* temperature factor */
    psi0r = F0r*main_scale;
    psi0i = F0i*main_scale;
    psihr = Fhr*main_scale*exp(-M); /* Eq 23*/
    psihi = Fhi*main_scale*exp(-M); /* only angle-dependent part gets scaled by temp factor */

    W = 0.5 * (sqrt(b) + 1/sqrt(b)) * psi0r/(C * psihr) +  sqrt(b)*sin(2*theta)*(theta - *Theta0)/(C * psihr); /* eq 28*/
    kappa = psihi/psihr;                                              	/* eq 22 */
    g = 0.5*(sqrt(b) + 1/sqrt(b))*psi0i/(C*psihr);               	/* eq 21 */
    L = (1/(1 + kappa*kappa))*( W*W + g*g + sqrt(SQR(W*W - g*g - 1 + kappa*kappa) + 4*SQR(g*W - kappa)));

    /* *R = L - sqrt(L*L - 1); */
    /* replace x-sqrt(x^2-1) with exactly equal 1/(x+sqrt(x^2-1)) to avoid roundoff when x is large ... MHM */
    *R = 1/(L + sqrt(L*L - 1));

    DeltaThetas = psi0r/sin(2*theta);               	/* eq 32 */
#ifdef MCDEBUG
#ifndef OPENACC
    printf("E,lambda= %f , %f \n",E,lambda);
    printf("theta= %f \n",theta*180/PI);
    printf("Theta0= %f \n",*Theta0*180/PI);
    printf("theta = %g rad, alpha=%g rad.\n",theta,alpha);
    printf("b,sqrt(b)= %f %f\n",b,sqrt(b));
    printf("1/sqrt(b)= %f \n",1/sqrt(b));
    printf("Fhr, Fhi, F0r, F0i= %g %g %g %g\n",Fhr, Fhi, F0r, F0i);
    printf("psihr, psihi, psi0r, psi0i= %g %g %g %g\n",psihr, psihi, psi0r, psi0i);
    printf("sqrt(b)*sin(2*theta)= %g \n",sqrt(b)*sin(2*theta));
    printf("C, pis0r,C * psihr= %g %g %g\n",C, psi0r,C * psihr);
    printf("W= %f \n",W);
    printf("kappa= %f \n",kappa);
    printf("g= %f \n",g);
    printf("L= %f \n",L);
    printf("R= %f \n",*R);
    printf("DeltaThetas %f \n",3600*DeltaThetas*180/PI);
#endif
#endif
    *DeltaTheta0 = 0.5*(1 + 1/b)*DeltaThetas;                        	/* center of reflectivity curve is at theta + DeltaTheta0 eq 31 */
}


#endif /* MX_CRYSTALS_C */


/* Shared user declarations for all components types 'FluoPowder'. */
  /* used for reading data table from file */


  /* Declare structures and functions only once in each instrument. */
  #ifndef POWDERN_DECL
  #define POWDERN_DECL
  // single reflection data
  struct line_data {
    double F2;       /* Value of structure factor */
    double q;        /* Qvector */
    int j;           /* Multiplicity */
    double DWfactor; /* Debye-Waller factor */
    double w;        /* Intrinsic line width */
  };

  // component data
  struct line_info_struct {
    struct line_data* list; /* Reflection array */
    int count;              /* Number of reflections */
    double Dd;
    double DWfactor;
    double V_0;
    double rho;
    double at_weight;
    double at_nb;
    char compname[256];
    int flag_barns;
    int shape;           /* 0 cylinder, 1 box, 2 sphere, 3 OFF file */
    int column_order[8]; /* column signification */
    int flag_warning;
    double dq;      /* wavevector transfer [Angs-1] */
    double Epsilon; /* global strain in ppm */
    double XsectionFactor;
    double my_s_k2_sum;
    double my_a;
    double my_inc;
    double lfree; // store mean free path for the last event;
    double *w, *q, *my_s_k2;
    double radius_i, xwidth_i, yheight_i, zdepth_i;
    double k; /* last velocity (cached) */
    double Nq;
    int nb_reuses, nb_refl, nb_refl_count;
    double k_min, k_max;
    double xs_Nq[CHAR_BUF_LENGTH];
    double xs_sum[CHAR_BUF_LENGTH];
    unsigned int photon_passed;
    long xs_compute, xs_reuse, xs_calls;
    t_Table mat_table;
    int mat_column_order[5]; /*column signification for the coeff. in material data file*/
  };

  // shared functions **********************************************************

  // sign = PN_list_compare(a,b)
  //   used for qsort, to sort reflections
  // input:  a,b: two 'line_data' reflection pointers.
  // output: -1,0,1 for a<b, a=b, a>b
  int
  PN_list_compare (const void* a, const void* b) {
    const struct line_data* pa = a;
    const struct line_data* pb = b;

    /* Sort by q */
    if (pa->q < pb->q)
      return -1;
    if (pa->q > pb->q)
      return 1;

    /* In case of tie, sort by F2 also */
    if (pa->F2 < pb->F2)
      return -1;
    if (pa->F2 > pb->F2)
      return 1;

    /* In case of tie, sort by j also */
    if (pa->j < pb->j)
      return -1;
    if (pa->j > pb->j)
      return 1;

    return 0;
  } /* PN_list_compare */

  #ifndef CIF2HKL
  #define CIF2HKL
  // hkl_filename = cif2hkl(file, options)
  //   used to convert CIF/CFL/INS file into F2(hkl)
  //   the CIF2HKL env var can point to a cif2hkl executable
  //   else the McCode binary is attempted, then the system.
  char*
  cif2hkl (char* infile, char* options) {
    char cmd[1024];
    int ret = 0;
    int found = 0;
    char* OUTFILE;
    char* inpath;

    // get filename extension
    const char* ext = strrchr (infile, '.');
    if (!ext || ext == infile)
      return infile;
    else
      ext++;

    // return input when no extension or not a CIF/FullProf/ShelX file
    if (strcasecmp (ext, "cif") && strcasecmp (ext, "pcr") && strcasecmp (ext, "cfl") && strcasecmp (ext, "shx") && strcasecmp (ext, "ins")
        && strcasecmp (ext, "res"))
      return infile;

    OUTFILE = malloc (1024);
    if (!OUTFILE)
      return infile;
    inpath = malloc (1024);
    if (!inpath)
      return infile;

    // get input file path from read-table:Open_File
    FILE* f_infile = Open_File (infile, "r", inpath);
    if (!f_infile)
      return infile;
    fclose (f_infile);

    strncpy (OUTFILE, tmpnam (NULL), 1024); // create an output temporary file name

    // try in order the CIF2HKL env var, then the system cif2hkl, then the McCode one
    if (!found && getenv ("CIF2HKL")) {
      snprintf (cmd, 1024, "%s -o %s %s %s", getenv ("CIF2HKL"), OUTFILE, options, inpath);
      ret = system (cmd);
      if (ret != -1 && ret != 127)
        found = 1;
    }
    if (!found) {
      // try with cif2hkl command from the system PATH
      snprintf (cmd, 1024, "%s -o %s %s %s", "cif2hkl", OUTFILE, options, inpath);
      ret = system (cmd);
      if (ret != -1 && ret != 127)
        found = 1;
    }
    if (!found) {
      // As a last resort, attempt with cif2hkl from $MCXTRACE/bin
      snprintf (cmd, 1024, "%s%c%s%c%s -o %s %s %s", getenv (FLAVOR_UPPER) ? getenv (FLAVOR_UPPER) : MCXTRACE, MC_PATHSEP_C, "bin", MC_PATHSEP_C, "cif2hkl",
                OUTFILE, options, inpath);
      ret = system (cmd);
    }
    // ret = -1:  child process could not be created
    // ret = 127: shell could not be executed in the child process
    if (ret == -1 || ret == 127) {
      free (OUTFILE);
      return (NULL);
    }

    // test if the result file has been created
    FILE* file = Open_File (OUTFILE, "r", NULL);
    if (!file)
      return (NULL);
    MPI_MASTER (printf ("%s: INFO: Converting %s into F2(HKL) list %s\n", __FILE__, infile, OUTFILE); printf ("%s\n", cmd););
    fflush (NULL);
    return (OUTFILE);
  } // cif2hkl
  #endif

  // count = read_line_data(filename, &info)
  //   read the given file to store F2(HKL) reflections and metadata.
  int
  read_line_data (char* SC_file, struct line_info_struct* info) {
    struct line_data* list = NULL;
    int size = 0;
    t_Table sTable; /* sample data table structure from SC_file */
    int i = 0;
    int mult_count = 0;
    char flag = 0;
    double q_count = 0, j_count = 0, F2_count = 0;
    char** parsing;
    int list_count = 0;
    double sum_F2 = 0;
    char* filename = NULL;

    if (!SC_file || !strlen (SC_file) || !strcmp (SC_file, "NULL")) {
      MPI_MASTER (printf ("PowderN: %s: Using incoherent elastic scattering only.\n", info->compname););
      info->count = 0;
      return (0);
    }
    filename = cif2hkl (SC_file, "--mode XRA");
    if (filename && filename != SC_file)
      info->flag_barns = 1; // cif2hkl returns barns

    /* read 1st block data from SC_file into sTable*/
    if (!filename || Table_Read (&sTable, filename, 1) < 0)
      exit (fprintf (stderr, "PowderN: ERROR: Could not open file %s - exiting!\n", filename));

    // remove temporary F2(hkl) file when giving CFL/CIF/ShelX file
    if (filename && filename != SC_file)
      unlink (filename);

    /* parsing of header */
    parsing = Table_ParseHeader (sTable.header, "Vc", "V_0", "column_j", "column_d", "column_F2", "column_DW", "column_Dd", "column_inv2d", "column_1/2d",
                                 "column_sintheta/lambda", "column_q", /* 10 */
                                 "DW", "Debye_Waller", "delta_d/d", "column_F ", "V_rho", "density", "weight", "nb_atoms", "multiplicity", NULL);

    if (parsing) {
      if (parsing[0] && !info->V_0)
        info->V_0 = atof (parsing[0]);
      if (parsing[1] && !info->V_0)
        info->V_0 = atof (parsing[1]);
      if (parsing[2])
        info->column_order[0] = atoi (parsing[2]);
      if (parsing[3])
        info->column_order[1] = atoi (parsing[3]);
      if (parsing[4])
        info->column_order[2] = atoi (parsing[4]);
      if (parsing[5])
        info->column_order[3] = atoi (parsing[5]);
      if (parsing[6])
        info->column_order[4] = atoi (parsing[6]);
      if (parsing[7])
        info->column_order[5] = atoi (parsing[7]);
      if (parsing[8])
        info->column_order[5] = atoi (parsing[8]);
      if (parsing[9])
        info->column_order[5] = atoi (parsing[9]);
      if (parsing[10])
        info->column_order[6] = atoi (parsing[10]);
      if (parsing[11] && info->DWfactor <= 0)
        info->DWfactor = atof (parsing[11]);
      if (parsing[12] && info->DWfactor <= 0)
        info->DWfactor = atof (parsing[12]);
      if (parsing[13] && info->Dd < 0)
        info->Dd = atof (parsing[13]);
      if (parsing[14])
        info->column_order[7] = atoi (parsing[14]);
      if (parsing[15] && !info->V_0)
        info->V_0 = 1 / atof (parsing[15]);
      if (parsing[16] && !info->rho)
        info->rho = atof (parsing[16]);
      if (parsing[17] && !info->at_weight)
        info->at_weight = atof (parsing[17]);
      if (parsing[18] && info->at_nb <= 1)
        info->at_nb = atof (parsing[18]);
      if (parsing[19] && info->at_nb <= 1)
        info->at_nb = atof (parsing[19]);
      for (i = 0; i <= 19; i++)
        if (parsing[i])
          free (parsing[i]);
      free (parsing);
    }

    if (!sTable.rows)
      exit (fprintf (stderr,
                     "PowderN: %s: Error: The number of rows in %s "
                     "should be at least %d\n",
                     info->compname, SC_file, 1));
    else
      size = sTable.rows;

    MPI_MASTER (Table_Info (sTable););

    if (filename == SC_file) { // only when not from cif2hkl
      if (info->column_order[0] == 4 && info->flag_barns != 0)
        MPI_MASTER (printf ("PowderN: %s: Powder file probably of type Crystallographica/Fullprof (lau)\n"
                            "WARNING: but F2 unit is set to barns=1 (barns). Intensity might be 100 times too high.\n",
                            info->compname););
      if (info->column_order[0] == 17 && info->flag_barns == 0)
        MPI_MASTER (printf ("PowderN: %s: Powder file probably of type Lazy Pulver (laz)\n"
                            "WARNING: but F2 unit is set to barns=0 (fm^2). Intensity might be 100 times too low.\n",
                            info->compname););
    }
    /* allocate line_data array */
    list = (struct line_data*)calloc (size, sizeof (struct line_data)); // zeroed: the multiplicity check may look one entry ahead

    for (i = 0; i < size; i++) {
      /*      printf("Reading in line %i\n",i);*/
      double j = 0, d = 0, w = 0, q = 0, DWfactor = 0, F2 = 0;
      int index;

      if (info->Dd >= 0)
        w = info->Dd;
      if (info->DWfactor > 0)
        DWfactor = info->DWfactor;

      /* get data from table using columns {j d F2 DW Dd inv2d q F} */
      /* column indexes start at 1, thus need to substract 1 */
      if (info->column_order[0] > 0)
        j = Table_Index (sTable, i, info->column_order[0] - 1);
      if (info->column_order[1] > 0)
        d = Table_Index (sTable, i, info->column_order[1] - 1);
      if (info->column_order[2] > 0)
        F2 = Table_Index (sTable, i, info->column_order[2] - 1);
      if (info->column_order[3] > 0)
        DWfactor = Table_Index (sTable, i, info->column_order[3] - 1);
      if (info->column_order[4] > 0)
        w = Table_Index (sTable, i, info->column_order[4] - 1);
      if (info->column_order[5] > 0 && !(info->column_order[1] > 0)) // Only use if d not read already
      {
        d = Table_Index (sTable, i, info->column_order[5] - 1);
        d = (d > 0 ? 1 / d / 2 : 0);
      }
      if (info->column_order[6] > 0 && !(info->column_order[1] > 0)) // Only use if d not read already
      {
        q = Table_Index (sTable, i, info->column_order[6] - 1);
        d = (q > 0 ? 2 * PI / q : 0);
      }
      if (info->column_order[7] > 0 && !F2) {
        F2 = Table_Index (sTable, i, info->column_order[7] - 1);
        F2 *= F2;
      }

      /* assign and check values */
      j = (j > 0 ? j : 0);
      q = (d > 0 ? 2 * PI / d : 0); /* this is q */
      DWfactor = (DWfactor > 0 ? DWfactor : 1);
      w = (w > 0 ? w : 0); /* this is q and d relative spreading */
      F2 = (F2 >= 0 ? F2 : 0);
      if (j == 0 || q == 0) {
        MPI_MASTER (printf ("PowderN: %s: line %i has invalid definition (mult=0 or q=0 or d=0)\n", info->compname, i););
        continue;
      }
      list[list_count].j = j;
      list[list_count].q = q;
      list[list_count].DWfactor = DWfactor;
      list[list_count].w = w;
      list[list_count].F2 = F2;
      sum_F2 += F2;

      /* adjust multiplicity if j-column + multiple d-spacing lines */
      /* if  d = previous d, increase line duplication index */
      if (!q_count)
        q_count = q;
      if (!j_count)
        j_count = j;
      if (!F2_count)
        F2_count = F2;
      if (fabs (q_count - q) < 0.0001 * fabs (q) && fabs (F2_count - F2) < 0.0001 * fabs (F2) && j_count == j) {
        mult_count++;
        flag = 0;
      } else
        flag = 1;
      if (i == size - 1)
        flag = 1;
      /* else if d != previous d : just passed equivalent lines */
      if (flag) {
        if (i == size - 1)
          list_count++;
        /*   if duplication index == previous multiplicity */
        /*      set back multiplicity of previous lines to 1 */
        if ((mult_count && list_count > 0)
            && (mult_count == list[list_count - 1].j || ((list_count < size) && (i == size - 1) && (mult_count == list[list_count].j)))) {
          MPI_MASTER (printf ("PowderN: %s: Set multiplicity to 1 for lines [%i:%i]\n"
                              "         (d-spacing %g is duplicated %i times)\n",
                              info->compname, list_count - mult_count, list_count - 1, list[list_count - 1].q, mult_count););
          for (index = list_count - mult_count; index < list_count; list[index++].j = 1)
            ;
          mult_count = 1;
          q_count = q;
          j_count = j;
          F2_count = F2;
        }
        if (i == size - 1)
          list_count--;
        flag = 0;
      }
      list_count++;
    } /* end for */

    Table_Free (&sTable);

    if (!sum_F2) {
      MPI_MASTER (fprintf (stderr, "PowderN: %s: ERROR: all %i structure factors in file '%s' are null. Check the reflection list.\n", info->compname, list_count,
                           SC_file););
      return (0);
    }

    /* sort the list with increasing q */
    qsort (list, list_count, sizeof (struct line_data), PN_list_compare);

    MPI_MASTER (printf ("PowderN: %s: Read %i reflections from file '%s'\n", info->compname, list_count, SC_file););

    info->list = list;
    info->count = list_count;

    return (list_count);
  } /* read_line_data */

  /* calc_xsect: computes the number of possible reflections (return value), and the total xsection 'sum' */
  /* this routine looks for a pre-computed value in the Nq and sum cache tables               */
  /* when found, the earch starts from the corresponding lower element in the table           */
  #pragma acc routine
  int
  calc_xsect (double k, double* q, double* my_s_k2, int count, double* sum, struct line_info_struct* line_info) {
    int Nq = 0, line = 0, line0 = 0;
    *sum = 0;

    /* check if a line_info element has been recorded already - not on OpenACC */
    #ifndef OPENACC
    if (k >= line_info->k_min && k <= line_info->k_max && line_info->photon_passed >= CHAR_BUF_LENGTH) {
      line = (int)floor (k - line_info->k_min) * CHAR_BUF_LENGTH / (line_info->k_max - line_info->k_min);
      Nq = line_info->xs_Nq[line];
      *sum = line_info->xs_sum[line];
      if (!Nq && *sum == 0) {
        /* not yet set: we compute the sum up to the corresponding wavevector in the table cache */
        double line_k = line_info->k_min + line * (line_info->k_max - line_info->k_min) / CHAR_BUF_LENGTH;
        for (line0 = 0; line0 < count; line0++) {
          if (q[line0] <= 2 * line_k) { /* q < 2*kf: restrict structural range */
            *sum += my_s_k2[line0];
            if (Nq < line0 + 1)
              Nq = line0 + 1; /* determine maximum line index which can scatter */
          } else
            break;
        }
        line_info->xs_Nq[line] = Nq;
        line_info->xs_sum[line] = *sum;
        line_info->xs_compute++;
      } else
        line_info->xs_reuse++;
      line0 = Nq;
    }

    line_info->xs_calls++;
    #endif

    for (line = line0; line < count; line++) {
      if (q[line] <= 2 * k) { /* q < 2*kf: restrict structural range */
        *sum += my_s_k2[line];
        if (Nq < line + 1)
          Nq = line + 1; /* determine maximum line index which can scatter */
      } else
        break;
    }

    return (Nq);
  } /* calc_xsect */

  #pragma acc routine
  int
  calc_abs_xsect (double k, double* abs, struct line_info_struct* line_info) {
    /* compute the absorption cross section.
     * amounts to a table lookup in material data_file by energy*/
    double e = k * K2E;
    *abs = Table_Value ((line_info->mat_table), e, line_info->mat_column_order[1]);
    *abs *= 100 * line_info->rho;
    return 0;
  }

  #pragma acc routine
  int
  calc_inc_xsect (double k, double* inc, struct line_info_struct* line_info) {
    /*TODO choose one of these bits*/

    /* compute the incoherent cross section.
     * amounts to a table lookup in material data_file by energy
     * In time this should be improved to actually handle Compton scattering.*/
    double e = k * K2E;

    double correction;
    int i = 2;
    /* To find the inc. scattering column in material datafiles,
     * Find the first non-zero column index (btw. 2..4).*/
    for (i = 2; i < 5; i++) {
      if (line_info->mat_column_order[i])
        break;
    }

    switch (i) {
    case 2:
      /*inc is explicitly in column i - no correction term.*/
      correction = 0;
      break;
    case 3:
      /*inc is given as inc+ćoh in column i*/
      correction = line_info->my_s_k2_sum / (k * k);
      break;
    case 4:
      /*inc is given as total attenuation = inc+coh+abs in column i*/
      correction = line_info->my_s_k2_sum / (k * k) + line_info->my_a;
      break;
    case 5:
      /*means no non-zero index has been found - set xsect to 0*/
      *inc = 0;
      return 1;
    }

    *inc = Table_Value ((line_info->mat_table), e, line_info->mat_column_order[i] - 1) - correction;
    if (*inc < 0) {
      *inc = 0;
    }
    *inc *= 100 * line_info->rho; /*scale by rho and 100 to get in units m^-1*/
    return 0;
  }

  #endif /* !POWDERN_DECL */

 // for OFF/PLY geometry

  #ifndef FLUORESCENCE_DECL
  #define FLUORESCENCE_DECL

  // WARNING: mush NOT use rand01 calls here, as they depend on _particle

  #define XRAYLIB_LINES_MAX 383
  #define FLUORESCENCE 0  // Fluo
  #define RAYLEIGH     1  // Coherent
  #define COMPTON      2  // Incoherent
  #define DIFFRACTION  3  // diffraction
  #define TRANSMISSION 4

  #include <xraylib/xraylib.h>
  
/* See XrayLib code (c) T. Schoonjans
 * /usr/include/xraylib/xraylib-parser.h      for compoundData
 * /usr/include/xraylib/xraylib.h             for XS
 */

/* inspired from:
 * https://github.com/golosio/xrmc src/photon/photon.cpp (c) Bruno Golosio    
 */
  
  /* XRMC_CrossSections: Compute interaction cross sections in [barn/atom]
   * When kissel=1, M-lines are computed, but computation is 10x slower.
   * Computes xs[FLUORESCENCE,RAYLEIGH,COMPTON] that must have been allocated.
   * Return total cross section, given Z and E0:
   *   total_xs = XRMC_CrossSections(Z, E0, xs[3], flag_kissel);
   */
  double XRMC_CrossSections(int Z, double E0, double *xs, int kissel) {
    int    i_line;
    
    if (xs == NULL) return 0;
    for(i_line=0; i_line<=COMPTON; i_line++) xs[i_line]=0;
    
    // loop on possible fluorescence lines
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { 
      // cumulative sum of the line cross sections
      xs[FLUORESCENCE] += kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
    }

    // coherent and incoherent cross sections
    xs[RAYLEIGH] = CSb_Rayl( Z, E0, NULL);
    xs[COMPTON]  = CSb_Compt(Z, E0, NULL);
    
    // total interaction cross section, should converge to CSb_Total(Z, E0, NULL)
    return xs[FLUORESCENCE] + xs[RAYLEIGH] + xs[COMPTON];
  } // XRMC_CrossSections

  /* XRMC_SelectFromDistribution: select a random element from a distribution
   *   index = XRMC_SelectFromDistribution(cum_sum[N], N);
   * index is returned within 0 and N-1
   * The x_arr must be a continuously increasing cumulated sum, which last element is the max.
   */
  int XRMC_SelectFromDistribution(double x_arr[], int N, double r)
  {
    if (x_arr == NULL || N <=0) return (0);
    double x = r*x_arr[N-1]; // the threshold cumulated value to search in distribution
    if (x<x_arr[0]) {    // x is smaller than lower limit
      return 0;
    }
    if (x>=x_arr[N-1]) { // x is greater or equal to upper limit
      return N-1;
    }
    int id=0, iu=N-1; // lower and upper index of the subarray to search
    while (iu-id>1) { // search until the size of the subarray to search is >1
      int im = (id + iu)/2; // use the midpoint for equal partition
      // decide which subarray to search
      if (x>=x_arr[im]) id=im; // change min index to search upper subarray
      else iu=im; // change max index to search lower subarray
    }

    return id;
  } // XRMC_SelectFromDistribution

  /* XRMC_SelectInteraction: select interaction type Fluo/Compton/Rayleigh
   * Return the interaction type from a random choice within cross sections 'xs'
   *   type = XRMC_SelectInteraction(xs[3], 3);
   * 'xs' is computed with XRMC_CrossSections. Can be unsorted.
   * type is e.g. one of FLUORESCENCE | RAYLEIGH | COMPTON
   */
  int XRMC_SelectInteraction(double *xs, int nb_processes, double r)
  {
    double sum_xs, *cum_xs;
    int    i;

    if (xs == NULL || nb_processes < 1) return 0;
    cum_xs = malloc((nb_processes+1)*sizeof(double));
    if (!cum_xs)          return 0;
    cum_xs[0]=sum_xs=0;
    for (i=0; i< nb_processes; i++) {
      sum_xs += xs[i];
      cum_xs[i+1]= sum_xs;
    }
    i = XRMC_SelectFromDistribution(cum_xs, nb_processes+1, r);
    free(cum_xs);
    return i;
  } // XRMC_SelectInteraction

  /* XRMC_SelectFluorescenceEnergy: select outgoing fluo photon energy, when incoming with 'E0'
   * When kissel=1, M-lines are included, but computation is 10x slower
   *   Ef = XRMC_SelectFluorescenceEnergy(Z, E0, &dE, kissel);
   */
  double XRMC_SelectFluorescenceEnergy(int Z, double E0, double *dE, int kissel, double r)
  {
    int i_line;
    double sum_xs, cum_xs_lines[XRAYLIB_LINES_MAX+1];

    // compute cumulated XS for all fluo lines
    cum_xs_lines[0] = sum_xs = 0;
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { // loop on fluorescent lines
      double xs = kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
      // when a line is inactive: E=xs=0
      sum_xs += xs;
      cum_xs_lines[i_line+1] = sum_xs; // cumulative sum of their cross sections
    }
    // select randomly one of these lines
    i_line = XRMC_SelectFromDistribution(cum_xs_lines, XRAYLIB_LINES_MAX, r); // extract a line
    // get the K shell line width as approximation of fluorescence line width
    if (dE) *dE = AtomicLevelWidth(Z, K_SHELL, NULL); // keV, full-width in keV

    return LineEnergy(Z, -i_line, NULL); // fluorescent line energy
  } // XRMC_SelectFluorescenceEnergy

  // Function removing spaces from string
  char * removeSpacesFromStr(char *string)
  {
      // non_space_count to keep the frequency of non space characters
      int non_space_count = 0;
      if (string == NULL) return NULL;
   
      //Traverse a string and if it is non space character then, place it at index non_space_count
      for (int i = 0; string[i] != '\0'; i++)
      {
          if (isalpha(string[i]) || isdigit(string[i]))
          {
              string[non_space_count] = string[i];
              non_space_count++; //non_space_count incremented
          }    
      }
      
      //Finally placing final character at the string end
      string[non_space_count] = '\0';
      return string;
  }

  // ok = fluo_get_material(material, formula)
  // extracts material atoms from file header
  // the result is concatenated into 'formula'
  int fluo_get_material(char *filename, char *formula) {
  
    int  ret = 0;
    char Line[65535];
    int  flag_found_cif=0;
    if (filename == NULL || formula == NULL) return (0);
    FILE *file = Open_File(filename, "r", NULL);
    if (!file)
      exit(fprintf(stderr, "%s: ERROR: can not open file %s\n", 
      __FILE__, filename));
    
    // Read the file, and search tokens in rows
    formula[0]=0;
    while (fgets(Line, sizeof(Line), file) != NULL) {
      char *token = NULL;
      int   flag_exit=0;
      char *first_non_space=NULL;
      char *next_non_space =NULL;
      // CIF: _chemical_formula_structural 'chemical_formulae'
      // CIF: _chemical_formula_sum 'chemical_formulae'
      // LAZ/LAU: # ATOM <at> <trailing>
      // LAZ/LAU: # Atom <at> <trailing>
      // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
      // CFL: Title <chemical_formulae>
      // CFL: Atom <at> <trailing>
      
      // search for CIF token
      // single line: search " '\'" delimiter after CIF token, marks reading the formula
      if (!strncasecmp(Line, "_chemical_formula_structural", 28) 
       || !strncasecmp(Line, "_chemical_formula_sum", 21) 
       || !strncasecmp(Line, "_chemical_formula_moiety", 24)
       || flag_found_cif) {
        if  (flag_found_cif) { flag_found_cif=0; /* can not span on more that 2 lines */} 
        else flag_found_cif=1;
        // search for delimiter after the CIF token
        char *first_space_after_token=strpbrk(Line, " \'\n");
        if (first_space_after_token) {
          // search for the characters that may compose the formula
          first_non_space = strpbrk(first_space_after_token, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()[]");
          if (strchr(first_space_after_token,'?')) {
            // we have an invalid/unknown formula in the CIF. Skip CIF token/line
            flag_found_cif=0;
            continue;
          }
        }
        if (first_non_space) 
          next_non_space  = strpbrk(first_non_space+1, "\'\n\r"); // position of formula end
        if (next_non_space) { 
          flag_exit = 1;
          token = first_non_space;
        }
      } else if (!strncasecmp(Line, "# TITLE", 7) && strchr(Line, '['))
        token = Line+7;
      else if (!strncasecmp(Line, "# Atom", 6))
        token = Line+6;
      else if (!strncasecmp(Line, "Atom", 4))
        token = Line+4;
      else if (!strncasecmp(Line, "Title", 5))
        token = Line+7;
      if (!token) continue;
      if (!strncasecmp(Line, "# TITLE", 7)) {
        first_non_space = Line+7;
        next_non_space  = strchr(Line+7, '[');
        if (next_non_space) flag_exit = 1;
      }
      if (!first_non_space) first_non_space = strtok(token, " \t\n");
      if (!first_non_space) continue;
      if (!next_non_space)  next_non_space  = strtok(NULL,  " \t\n"); // end of formulae
      if (!next_non_space)  next_non_space = Line+strlen(Line);
      // remove spaces
      strncat(formula, first_non_space, next_non_space-first_non_space);
      ret++;
      if (flag_exit) break;
    }
    fclose(file);
    removeSpacesFromStr(formula);
    return(ret);
  } // fluo_get_material
  
  #endif // FLUORESCENCE_DECL

/* Shared user declarations for all components types 'Wiggler'. */
  #ifndef MCCODE_BESSELKNU
  #define MCCODE_BESSELKNU 1

  #pragma acc routine seq
  double
  besselKnu (double nu, double x) {
    const double h = 0.5;
    double KK = 0, dK;
    int r = 0;
    const int maxiter = 1000;
    KK = exp (-x) / 2.0;
    dK = 1;
    while (dK > DBL_EPSILON && r < maxiter) {
      r++;
      dK = exp (-x * cosh (r * h)) * cosh (nu * r * h);
      KK += dK;
    }
    #ifndef OPENACC
    if (r >= maxiter) {
      fprintf (stderr, "Warning: Maximum number of iterations exceeded in besselKnu(%g,%g).\n", nu, x);
    }
    #endif
    KK *= h;
    return KK;
  }
  #endif /*MCCODE_BESSELKNU*/

  #ifndef M_SQRT1_2
  #define M_SQRT1_2 0.70710678118654752440
  #endif

/* Shared user declarations for all components types 'Mask'. */

  #if USE_PNG
  #include <png.h>
  #endif

/* Shared user declarations for all components types 'Mirror_toroid_pothole'. */
  #include <complex.h>


  struct potholestruct {
    double e_min, e_max, e_step, theta_min, theta_max, theta_step;
    int use_reflec_table;
  };

/* Shared user declarations for all components types 'Mirror'. */




  #ifndef SHAPES_T
  #define SHAPES_T
  enum shapes_t { NONE = -1, SPHERE, CYLINDER, CUBE, ELLIPSOID, ANY };
  #endif

/* Shared user declarations for all components types 'Mirror_elliptic'. */





/* Shared user declarations for all components types 'Grating_reflect'. */



/* Shared user declarations for all components types 'Undulator'. */

  #include <gsl/gsl_sf_bessel.h>
  #include <gsl/gsl_errno.h>
  #include <gsl/gsl_integration.h>

  double
  mxundulator_Bsig_integrand (double x, void* params) {
    double w_w1 = *((double*)params);
    double p = *((double*)params + 1);
    double q = *((double*)params + 2);
    double angle_term = *((double*)params + 3); /* xi*gamma/K  horizontal angle term*/

    double f1 = angle_term - cos (x);
    double inner = w_w1 * x - p * sin (x) + q * sin (2 * x);
    double f2 = cos (inner);

    return f1 * f2;
  }

  double
  mxundulator_Bpi_integrand (double x, void* params) {
    double w_w1 = *((double*)params);
    double p = *((double*)params + 1);
    double q = *((double*)params + 2);
    double angle_term = *((double*)params + 3); /*phi*gamma/K vertical angle term*/

    double f1 = angle_term;
    double inner = w_w1 * x - p * sin (x) + q * sin (2 * x);
    double f2 = cos (inner);

    return f1 * f2;
  }

  double
  mxundulator_S_N (double w_w1, int N) {
    return pow (sin (N * M_PI * w_w1) / (N * sin (M_PI * w_w1)), 2.0);
  }

/* Shared user declarations for all components types 'Mirror_toroid'. */



/* Shared user declarations for all components types 'FluoCrystal'. */
  /* used for reading data table from file */


  /* Declare structures and functions only once in each instrument. */
  #ifndef SINGLE_CRYSTAL_DECL
  #define SINGLE_CRYSTAL_DECL

  #ifndef Mosaic_AB_Undefined
  #define Mosaic_AB_Undefined {0,0, 0,0,0, 0,0,0}
  #endif

  #ifndef MCSX_REFL_SLIST_SIZE
  #define MCSX_REFL_SLIST_SIZE 128
  #endif

  struct hkl_data {
    int h, k, l;                /* Indices for this reflection */
    double F2;                  /* Value of structure factor */
    double tau_x, tau_y, tau_z; /* Coordinates in reciprocal space */
    double tau;                 /* Length of (tau_x, tau_y, tau_z) */
    double u1x, u1y, u1z;       /* First axis of local coordinate system */
    double u2x, u2y, u2z;       /* Second axis of local coordinate system */
    double u3x, u3y, u3z;       /* Third axis of local coordinate system */
    double sig123;              /* The product sig1*sig2*sig3 = volume of spot */
    double m1, m2, m3;          /* Diagonal matrix representation of Gauss */
    double cutoff;              /* Cutoff value for Gaussian tails */
  };

  struct tau_data {
    int index; /* Index into reflection table */
    double refl;
    double xsect;
    /* The following vectors are in local koordinates. */
    double rho_x, rho_y, rho_z; /* The vector ki - tau */
    double rho;                 /* Length of rho vector */
    double ox, oy, oz;          /* Origin of Ewald sphere tangent plane */
    double b1x, b1y, b1z;       /* Spanning vectors of Ewald sphere tangent */
    double b2x, b2y, b2z;
    double l11, l12, l22; /* Cholesky decomposition L of 2D Gauss */
    double y0x, y0y;      /* 2D Gauss center in tangent plane */
  };

  struct hkl_info_struct {
    int count;                  /* Number of reflections */
    double m_delta_d_d;         /* Delta-d/d FWHM */
    double m_ax, m_ay, m_az;    /* First unit cell axis (direct space, AA) */
    double m_bx, m_by, m_bz;    /* Second unit cell axis */
    double m_cx, m_cy, m_cz;    /* Third unit cell axis */
    double asx, asy, asz;       /* First reciprocal lattice axis (1/AA) */
    double bsx, bsy, bsz;       /* Second reciprocal lattice axis */
    double csx, csy, csz;       /* Third reciprocal lattice axis */
    double m_a, m_b, m_c;       /* length of lattice parameter lengths */
    double m_aa, m_bb, m_cc;    /* lattice angles */
    double sigma_i;             /* inc X sect */
    double rho;                 /* density [at/Angs^3] */
    double mat_weight;          /* material atomic weight [g/mol] */
    double mat_density;         /* material atomic density [g/cm3] */
    double V0;                  /* Unit cell volume (AA**3) */
    int column_order[5];        /* column signification [h,k,l,F,F2] */
    int recip;                  /* Flag to indicate if recip or direct cell axes given */
    int shape;                  /* 0:cylinder, 1:box, 2:sphere 3:any shape*/
    int flag_warning;           /* number of warnings */
    int flag_barns;             /* 1: F2 in barns, 0: in fm^2 */
    char type;                  /* type of last event: t=transmit,c=coherent or i=incoherent */
    int h, k, l;                /* last coherent scattering momentum transfer indices */
    int tau_count;              /* Number of reflections within cutoff */
    double coh_refl, coh_xsect; /* cross section computed with last tau_list */
    double kix, kiy, kiz;       /* last incoming photon ki */
    int nb_reuses, nb_refl, nb_refl_count;
    int max_tau_count;
    int ctr_size;
    double* ctr_k;
    double* ctr_FT2;
    double* ctr_dir;
    char compname[256];
  };

  #pragma acc routine
  // sign = SX_list_compare(a,b)
  //   used for qsort, to sort reflections
  // input:  a,b: two 'line_data' reflection pointers.
  // output: -1,0,1 for a<b, a=b, a>b
  int
  SX_list_compare (void const* a, void const* b) {
    struct hkl_data const* pa = a;
    struct hkl_data const* pb = b;

    /* Sort by tau */
    if (pa->tau < pb->tau)
      return -1;
    if (pa->tau > pb->tau)
      return 1;

    /* Sort by tau_x */
    if (pa->tau_x < pb->tau_x)
      return -1;
    if (pa->tau_x > pb->tau_x)
      return 1;

    /* Sort by tau_y */
    if (pa->tau_y < pb->tau_y)
      return -1;
    if (pa->tau_y > pb->tau_y)
      return 1;

    /* Sort by tau_z */
    if (pa->tau_z < pb->tau_z)
      return -1;
    if (pa->tau_z > pb->tau_z)
      return 1;

    /* In case of tie, sort by F2 also */
    if (pa->F2 < pb->F2)
      return -1;
    if (pa->F2 > pb->F2)
      return 1;

    return 0;
  } /* SX_list_compare */

  #ifndef CIF2HKL
  #define CIF2HKL
  // hkl_filename = cif2hkl(file, options)
  //   used to convert CIF/CFL/INS file into F2(hkl)
  //   the CIF2HKL env var can point to a cif2hkl executable
  //   else the McCode binary is attempted, then the system.
  char*
  cif2hkl (char* infile, char* options) {
    char cmd[1024];
    int ret = 0;
    int found = 0;
    char* OUTFILE;
    char* inpath;

    // get filename extension
    const char* ext = strrchr (infile, '.');
    if (!ext || ext == infile)
      return infile;
    else
      ext++;

    // return input when no extension or not a CIF/FullProf/ShelX file
    if (strcasecmp (ext, "cif") && strcasecmp (ext, "pcr") && strcasecmp (ext, "cfl") && strcasecmp (ext, "shx") && strcasecmp (ext, "ins")
        && strcasecmp (ext, "res"))
      return infile;

    OUTFILE = malloc (1024);
    if (!OUTFILE) {
      free (OUTFILE);
      return infile;
    }
    inpath = malloc (1024);
    if (!inpath) {
      free (OUTFILE);
      free (inpath);
      return infile;
    }

    // get input file path from read-table:Open_File
    FILE* f_infile = Open_File (infile, "r", inpath);
    if (!f_infile) {
      free (OUTFILE);
      free (inpath);
      free (f_infile);
      return infile;
    }
    fclose (f_infile);

    strncpy (OUTFILE, tmpnam (NULL), 1024); // create an output temporary file name

    // try in order the CIF2HKL env var, then the system cif2hkl, then the McCode one
    if (!found && getenv ("CIF2HKL")) {
      snprintf (cmd, 1024, "%s -o %s %s %s", getenv ("CIF2HKL"), OUTFILE, options, inpath);
      ret = system (cmd);
      if (ret != -1 && ret != 127)
        found = 1;
    }
    if (!found) {
      // try with cif2hkl command from the system PATH
      snprintf (cmd, 1024, "%s -o %s %s %s", "cif2hkl", OUTFILE, options, inpath);
      ret = system (cmd);
      if (ret != -1 && ret != 127)
        found = 1;
    }
    if (!found) {
      // As a last resort, attempt with cif2hkl from $MCXTRACE/bin
      snprintf (cmd, 1024, "%s%c%s%c%s -o %s %s %s", getenv (FLAVOR_UPPER) ? getenv (FLAVOR_UPPER) : MCXTRACE, MC_PATHSEP_C, "bin", MC_PATHSEP_C, "cif2hkl",
                OUTFILE, options, inpath);
      ret = system (cmd);
    }
    // ret = -1:  child process could not be created
    // ret = 127: shell could not be executed in the child process
    if (ret == -1 || ret == 127) {
      free (OUTFILE);
      return (NULL);
    }

    // test if the result file has been created
    FILE* file = fopen (OUTFILE, "r");
    if (!file) {
      free (OUTFILE);
      return (NULL);
    }
    MPI_MASTER (printf ("%s: INFO: Converting %s into F2(HKL) list %s\n", __FILE__, infile, OUTFILE); printf ("%s\n", cmd););
    fflush (NULL);
    fclose (file);
    return (OUTFILE);
  } // cif2hkl
  #endif

  /* ------------------------------------------------------------------------ */

  // count = read_hkl_data(filename, &info, ...)
  //   read the given file to store F2(HKL) reflections and metadata.
  int
  read_hkl_data (char* SC_file, struct hkl_info_struct* info, struct hkl_data** hkl_list, double SC_mosaic, double SC_mosaic_a, double SC_mosaic_b,
                 double SC_mosaic_c, double* SC_mosaic_AB, int surf_size, double* surf_k, double* surf_FT2, double* surf_dir) {
    struct hkl_data* list = NULL;
    int size = 0;
    t_Table sTable; /* sample data table structure from SC_file */
    int i = 0, j = 0, J = 0;
    double tmp_x, tmp_y, tmp_z;
    char** parsing;
    char flag = 0;
    double nb_atoms = 1;
    double sum_F2 = 0;
    char* filename = NULL;

    if (!SC_file || !strlen (SC_file) || !strcmp (SC_file, "NULL") || !strcmp (SC_file, "0"))
      return (0);

    filename = cif2hkl (SC_file, "--xtal --mode XRA");
    if (filename && filename != SC_file)
      info->flag_barns = 1; // cif2hkl returns barns

    if (!filename || Table_Read (&sTable, filename, 1) < 0)
      exit (fprintf (stderr, "Single_crystal: %s: ERROR: Could not open file %s - exiting!\n", info->compname, filename));

    // remove temporary F2(hkl) file when giving CFL/CIF/ShelX file
    if (filename && filename != SC_file)
      unlink (filename);

    if (sTable.columns < 4) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: The number of columns in %s should be at least %d for [h,k,l,F2]\n", info->compname, SC_file, 4););
      return (0);
    }
    if (!sTable.rows) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: The number of rows in %s should be at least %d\n", info->compname, SC_file, 1););
      return (0);
    } else
      size = sTable.rows;

    /* parsing of header */
    parsing = Table_ParseHeader (sTable.header, "sigma_abs", "sigma_a ", // 0-1
                                 "sigma_inc", "sigma_i ", "column_h", "column_k", "column_l", "column_F ", "column_F2",
                                 "Delta_d/d",                                                                                                    // 9
                                 "lattice_a ", "lattice_b ", "lattice_c ", "lattice_aa", "lattice_bb", "lattice_cc", "nb_atoms", "multiplicity", // 17
                                 "Vc", "V_0", "V_rho", "density", "weight", NULL);

    if (parsing) {
      // if (parsing[0] && !info->sigma_a) info->sigma_a=atof(parsing[0]);
      // if (parsing[1] && !info->sigma_a) info->sigma_a=atof(parsing[1]);
      if (parsing[2] && !info->sigma_i)
        info->sigma_i = atof (parsing[2]);
      if (parsing[3] && !info->sigma_i)
        info->sigma_i = atof (parsing[3]);
      if (parsing[4])
        info->column_order[0] = atoi (parsing[4]);
      if (parsing[5])
        info->column_order[1] = atoi (parsing[5]);
      if (parsing[6])
        info->column_order[2] = atoi (parsing[6]);
      if (parsing[7])
        info->column_order[3] = atoi (parsing[7]);
      if (parsing[8])
        info->column_order[4] = atoi (parsing[8]);
      if (parsing[9] && info->m_delta_d_d <= 0)
        info->m_delta_d_d = atof (parsing[9]);
      if (parsing[10] && !info->m_a)
        info->m_a = atof (parsing[10]);
      if (parsing[11] && !info->m_b)
        info->m_b = atof (parsing[11]);
      if (parsing[12] && !info->m_c)
        info->m_c = atof (parsing[12]);
      if (parsing[13] && !info->m_aa)
        info->m_aa = atof (parsing[13]);
      if (parsing[14] && !info->m_bb)
        info->m_bb = atof (parsing[14]);
      if (parsing[15] && !info->m_cc)
        info->m_cc = atof (parsing[15]);
      if (parsing[16])
        nb_atoms = atof (parsing[16]);
      if (parsing[17])
        nb_atoms = atof (parsing[17]);
      if (parsing[18] && !info->rho)
        info->rho = 1 / atof (parsing[18]);
      if (parsing[19] && !info->rho)
        info->rho = 1 / atof (parsing[19]);
      if (parsing[20] && !info->rho)
        info->rho = atof (parsing[20]);
      if (parsing[21] && !info->mat_density)
        info->mat_density = atof (parsing[21]);
      if (parsing[22] && !info->mat_weight)
        info->mat_weight = atof (parsing[22]);

      for (i = 0; i <= 22; i++)
        if (parsing[i])
          free (parsing[i]);
      free (parsing);
    }

    if (!info->column_order[0] || !info->column_order[1] || !info->column_order[2]) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong h,k,l column definition\n", SC_file););
      return (0);
    }
    if (!info->column_order[3] && !info->column_order[4]) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong F,F2 column definition\n", SC_file););
      return (0);
    }

    if (!info->rho && info->mat_density > 0 && info->mat_weight > 0 && nb_atoms > 0) {
      /* molar volume [cm^3/mol] = weight [g/mol] / density [g/cm^3] */
      /* atom density per Angs^3 = [mol/cm^3] * N_Avogadro *(1e-8)^3 */
      info->rho = info->mat_density / (info->mat_weight * nb_atoms) / 1e24 * NA;
    }

    if (nb_atoms > 1) {
      info->sigma_i *= nb_atoms;
    }
    if (info->m_delta_d_d <= 0) {
      info->m_delta_d_d = SC_mosaic > 0 ? SC_mosaic * MIN2RAD : MIN2RAD; // MIN2RAD = 3e-4
      MPI_MASTER (
          fprintf (stderr, "Single_crystal: %s: WARNING: Delta_d/d is <=0 (longitudinal mosaic). Setting delta_d_d=%g\n", info->compname, info->m_delta_d_d););
    } else if (SC_mosaic < 0 && SC_mosaic_a < 0 && SC_mosaic_b < 0 && SC_mosaic_c < 0) {
      if (info->m_delta_d_d > 0)
        SC_mosaic = info->m_delta_d_d / MIN2RAD;
    }

    /* special cases for the structure definition */
    if (info->m_ax || info->m_ay || info->m_az) {
      info->m_a = 0;
      info->m_aa = 0;
    } /* means we specify by hand the vectors */
    if (info->m_bx || info->m_by || info->m_bz) {
      info->m_b = 0;
      info->m_bb = 0;
    }
    if (info->m_cx || info->m_cy || info->m_cz) {
      info->m_c = 0;
      info->m_cc = 0;
    };

    /* compute the norm from vector a if missing */
    if (info->m_ax || info->m_ay || info->m_az) {
      double as = sqrt (info->m_ax * info->m_ax + info->m_ay * info->m_ay + info->m_az * info->m_az);
      if (!info->m_bx && !info->m_by && !info->m_bz)
        info->m_a = info->m_b = as;
      if (!info->m_cx && !info->m_cy && !info->m_cz)
        info->m_a = info->m_c = as;
    }
    if (info->m_a && !info->m_b)
      info->m_b = info->m_a;
    if (info->m_b && !info->m_c)
      info->m_c = info->m_b;

    /* compute the lattive angles if not set from data file. Not used when in vector mode. */
    if (info->m_a && !info->m_aa)
      info->m_aa = 90;
    if (info->m_aa && !info->m_bb)
      info->m_bb = info->m_aa;
    if (info->m_bb && !info->m_cc)
      info->m_cc = info->m_bb;

    /* parameters consistency checks */
    if (!info->m_ax && !info->m_ay && !info->m_az && !info->m_a) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong a lattice vector definition\n", info->compname););
      return (0);
    }
    if (!info->m_bx && !info->m_by && !info->m_bz && !info->m_b) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong b lattice vector definition\n", info->compname););
      return (0);
    }
    if (!info->m_cx && !info->m_cy && !info->m_cz && !info->m_c) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong c lattice vector definition\n", info->compname););
      return (0);
    }
    if (info->m_aa && info->m_bb && info->m_cc && info->recip) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Selecting reciprocal cell and angles is unmeaningful.\n", info->compname););
      return (0);
    }

    /* when lengths a,b,c + angles are given (instead of vectors a,b,c) */
    if (info->m_aa && info->m_bb && info->m_cc) {
      double as, bs, cs;
      if (info->m_a)
        as = info->m_a;
      else
        as = sqrt (info->m_ax * info->m_ax + info->m_ay * info->m_ay + info->m_az * info->m_az);
      if (info->m_b)
        bs = info->m_b;
      else
        bs = sqrt (info->m_bx * info->m_bx + info->m_by * info->m_by + info->m_bz * info->m_bz);
      if (info->m_c)
        cs = info->m_c;
      else
        cs = sqrt (info->m_cx * info->m_cx + info->m_cy * info->m_cy + info->m_cz * info->m_cz);

      /* Real-space vectors with b along z and a in the yz-plane at the angle
         gamma to b; c then has cos(alpha) along b, cos(beta) against a, and a
         positive x component, which makes (a, b, c) right-handed.  Each vector
         carries its own length: a = as, b = bs, c = cs.  (Before, a was given
         the length bs and b the length as, and alpha/beta were exchanged in c,
         so for a != b every |F(h,k,l)|^2 ended up at the position of (k,h,l).) */
      info->m_bx = 0;
      info->m_by = 0;
      info->m_bz = bs;
      info->m_ax = 0;
      info->m_ay = as * sin (info->m_cc * DEG2RAD);
      info->m_az = as * cos (info->m_cc * DEG2RAD);
      info->m_cz = cs * cos (info->m_aa * DEG2RAD);
      info->m_cy = cs * (cos (info->m_bb * DEG2RAD) - cos (info->m_cc * DEG2RAD) * cos (info->m_aa * DEG2RAD)) / sin (info->m_cc * DEG2RAD);
      info->m_cx = sqrt (cs * cs - info->m_cz * info->m_cz - info->m_cy * info->m_cy);

      MPI_MASTER (printf ("Single_crystal: %s: %s structure a=%g b=%g c=%g aa=%g bb=%g cc=%g ", info->compname, SC_file, as, bs, cs, info->m_aa, info->m_bb,
                          info->m_cc););
    } else {
      MPI_MASTER (
          if (!info->recip) {
            printf ("Single_crystal: %s: %s structure a=[%g,%g,%g] b=[%g,%g,%g] c=[%g,%g,%g] ", info->compname, SC_file, info->m_ax, info->m_ay, info->m_az,
                    info->m_bx, info->m_by, info->m_bz, info->m_cx, info->m_cy, info->m_cz);
          } else {
            printf ("Single_crystal: %s: %s structure a*=[%g,%g,%g] b*=[%g,%g,%g] c*=[%g,%g,%g] ", info->compname, SC_file, info->m_ax, info->m_ay, info->m_az,
                    info->m_bx, info->m_by, info->m_bz, info->m_cx, info->m_cy, info->m_cz);
          });
    }
    /* Compute reciprocal or direct lattice vectors. */
    if (!info->recip) {
      vec_prod (tmp_x, tmp_y, tmp_z, info->m_bx, info->m_by, info->m_bz, info->m_cx, info->m_cy, info->m_cz);
      info->V0 = fabs (scalar_prod (info->m_ax, info->m_ay, info->m_az, tmp_x, tmp_y, tmp_z));
      if (!info->V0 || isnan (info->V0)) {
        MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Lattice cell volume is found invalid V0=%g. Check crystal cell parameters.\n", info->compname,
                             info->V0));
        return (0);
      }

      info->asx = 2 * PI / info->V0 * tmp_x;
      info->asy = 2 * PI / info->V0 * tmp_y;
      info->asz = 2 * PI / info->V0 * tmp_z;
      vec_prod (tmp_x, tmp_y, tmp_z, info->m_cx, info->m_cy, info->m_cz, info->m_ax, info->m_ay, info->m_az);
      info->bsx = 2 * PI / info->V0 * tmp_x;
      info->bsy = 2 * PI / info->V0 * tmp_y;
      info->bsz = 2 * PI / info->V0 * tmp_z;
      vec_prod (tmp_x, tmp_y, tmp_z, info->m_ax, info->m_ay, info->m_az, info->m_bx, info->m_by, info->m_bz);
      info->csx = 2 * PI / info->V0 * tmp_x;
      info->csy = 2 * PI / info->V0 * tmp_y;
      info->csz = 2 * PI / info->V0 * tmp_z;
    } else {
      info->asx = info->m_ax;
      info->asy = info->m_ay;
      info->asz = info->m_az;
      info->bsx = info->m_bx;
      info->bsy = info->m_by;
      info->bsz = info->m_bz;
      info->csx = info->m_cx;
      info->csy = info->m_cy;
      info->csz = info->m_cz;

      vec_prod (tmp_x, tmp_y, tmp_z, info->bsx / (2 * PI), info->bsy / (2 * PI), info->bsz / (2 * PI), info->csx / (2 * PI), info->csy / (2 * PI),
                info->csz / (2 * PI));
      info->V0 = scalar_prod (info->asx / (2 * PI), info->asy / (2 * PI), info->asz / (2 * PI), tmp_x, tmp_y, tmp_z);
      if (!info->V0 || isnan (info->V0)) {
        MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Lattice reciprocal cell volume is found invalid V0=%g. Check crystal cell parameters.\n",
                             info->compname, info->V0));
        return (0);
      }
      info->V0 = 1 / fabs (info->V0);

      /*compute the direct cell parameters, for completeness*/
      info->m_ax = tmp_x * info->V0;
      info->m_ay = tmp_y * info->V0;
      info->m_az = tmp_z * info->V0;
      vec_prod (tmp_x, tmp_y, tmp_z, info->csx / (2 * PI), info->csy / (2 * PI), info->csz / (2 * PI), info->asx / (2 * PI), info->asy / (2 * PI),
                info->asz / (2 * PI));
      info->m_bx = tmp_x * info->V0;
      info->m_by = tmp_y * info->V0;
      info->m_bz = tmp_z * info->V0;
      vec_prod (tmp_x, tmp_y, tmp_z, info->asx / (2 * PI), info->asy / (2 * PI), info->asz / (2 * PI), info->bsx / (2 * PI), info->bsy / (2 * PI),
                info->bsz / (2 * PI));
      info->m_cx = tmp_x * info->V0;
      info->m_cy = tmp_y * info->V0;
      info->m_cz = tmp_z * info->V0;
    }
    MPI_MASTER (printf ("V0=%g\n", info->V0););

    /* allocate hkl_data array */

    if (surf_size <= 0 || !surf_k || !surf_FT2 || !surf_dir)
      surf_size = 1;
    list = (struct hkl_data*)malloc (size * surf_size * sizeof (struct hkl_data));
    if (!list) {
      fprintf (stderr, "Single_crystal: Error allocating reflection list\n");
      return (0);
    }

    for (i = 0; i < size; i++)
      for (j = 0; j < surf_size; j++) {
        double h = 0, k = 0, l = 0, F2 = 0;
        double b1[3], b2[3];
        double sig1, sig2, sig3;

        /* get data from table */
        h = Table_Index (sTable, i, info->column_order[0] - 1);
        k = Table_Index (sTable, i, info->column_order[1] - 1);
        l = Table_Index (sTable, i, info->column_order[2] - 1);
        if (info->column_order[3]) {
          F2 = Table_Index (sTable, i, info->column_order[3] - 1);
          F2 *= F2;
        } else if (info->column_order[4])
          F2 = Table_Index (sTable, i, info->column_order[4] - 1);

        list[J].h = h;
        list[J].k = k;
        list[J].l = l;
        list[J].F2 = F2;
        sum_F2 += F2;

        /* Precompute some values */
        list[J].tau_x = h * info->asx + k * info->bsx + l * info->csx;
        list[J].tau_y = h * info->asy + k * info->bsy + l * info->csy;
        list[J].tau_z = h * info->asz + k * info->bsz + l * info->csz;

        // create satellite peaks from e.g. surface truncation (CTR)
        if (surf_size > 1 && surf_FT2 && surf_k && surf_FT2[j] > 0 && surf_k[j]) {
          list[J].tau_x += surf_dir[0] * surf_k[j];
          list[J].tau_y += surf_dir[1] * surf_k[j];
          list[J].tau_z += surf_dir[2] * surf_k[j];
          list[J].F2 *= surf_FT2[j];
        }

        list[J].tau = sqrt (list[J].tau_x * list[J].tau_x + list[J].tau_y * list[J].tau_y + list[J].tau_z * list[J].tau_z);
        list[J].u1x = list[J].tau_x / list[J].tau;
        list[J].u1y = list[J].tau_y / list[J].tau;
        list[J].u1z = list[J].tau_z / list[J].tau;
        sig1 = FWHM2RMS * info->m_delta_d_d * list[J].tau;

        /* Find two arbitrary axes perpendicular to tau and each other. */
        normal_vec (&b1[0], &b1[1], &b1[2], list[J].u1x, list[J].u1y, list[J].u1z);
        vec_prod (b2[0], b2[1], b2[2], list[J].u1x, list[J].u1y, list[J].u1z, b1[0], b1[1], b1[2]);

        /* Find the two mosaic axes perpendicular to tau. */
        if (SC_mosaic > 0) {
          /* Use isotropic mosaic. */
          list[J].u2x = b1[0];
          list[J].u2y = b1[1];
          list[J].u2z = b1[2];
          sig2 = FWHM2RMS * list[J].tau * MIN2RAD * SC_mosaic;
          list[J].u3x = b2[0];
          list[J].u3y = b2[1];
          list[J].u3z = b2[2];
          sig3 = FWHM2RMS * list[J].tau * MIN2RAD * SC_mosaic;

        } else if (SC_mosaic_a > 0 && SC_mosaic_b > 0 && SC_mosaic_c > 0) {
          /* Use anisotropic mosaic. */
          MPI_MASTER (fprintf (stderr, "Single_crystal: WARNING: you are using an experimental feature:\n"
                                       "  anistropic mosaicity. Please examine your data carefully.\n"););
          /* compute the jacobian of (tau_v,tau_n) from rotations around the unit cell vectors. */
          struct hkl_data* l = &(list[J]);
          double xia_x, xia_y, xia_z, xib_x, xib_y, xib_z, xic_x, xic_y, xic_z;
          /*input parameters are in arc minutes*/
          double sig_fi_a = SC_mosaic_a * MIN2RAD;
          double sig_fi_b = SC_mosaic_b * MIN2RAD;
          double sig_fi_c = SC_mosaic_c * MIN2RAD;
          if (info->m_a == 0)
            info->m_a = sqrt (scalar_prod (info->m_ax, info->m_ay, info->m_az, info->m_ax, info->m_ay, info->m_az));
          if (info->m_b == 0)
            info->m_b = sqrt (scalar_prod (info->m_bx, info->m_by, info->m_bz, info->m_bx, info->m_by, info->m_bz));
          if (info->m_c == 0)
            info->m_c = sqrt (scalar_prod (info->m_cx, info->m_cy, info->m_cz, info->m_cx, info->m_cy, info->m_cz));

          l->u2x = b1[0];
          l->u2y = b1[1];
          l->u2z = b1[2];
          l->u3x = b2[0];
          l->u3y = b2[1];
          l->u3z = b2[2];

          xia_x = l->tau_x - (M_2_PI * h / info->m_a) * info->asx;
          xia_y = l->tau_y - (M_2_PI * h / info->m_a) * info->asy;
          xia_z = l->tau_z - (M_2_PI * h / info->m_a) * info->asz;
          xib_x = l->tau_x - (M_2_PI * h / info->m_b) * info->bsx;
          xib_y = l->tau_y - (M_2_PI * h / info->m_b) * info->bsy;
          xib_z = l->tau_z - (M_2_PI * h / info->m_b) * info->bsz;
          xic_x = l->tau_x - (M_2_PI * h / info->m_c) * info->csx;
          xic_y = l->tau_y - (M_2_PI * h / info->m_c) * info->csy;
          xic_z = l->tau_z - (M_2_PI * h / info->m_c) * info->csz;

          double xia = sqrt (xia_x * xia_x + xia_y * xia_y + xia_z * xia_z);
          double xib = sqrt (xib_x * xib_x + xib_y * xib_y + xib_z * xib_z);
          double xic = sqrt (xic_x * xic_x + xic_y * xic_y + xic_z * xic_z);

          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u2x, l->u2y, l->u2z);
          double J_n_fia = xia / info->m_a / l->tau * scalar_prod (info->asx, info->asy, info->asz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u2x, l->u2y, l->u2z);
          double J_n_fib = xib / info->m_b / l->tau * scalar_prod (info->bsx, info->bsy, info->bsz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u2x, l->u2y, l->u2z);
          double J_n_fic = xic / info->m_c / l->tau * scalar_prod (info->csx, info->csy, info->csz, tmp_x, tmp_y, tmp_z);

          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u3x, l->u3y, l->u3z);
          double J_v_fia = xia / info->m_a / l->tau * scalar_prod (info->asx, info->asy, info->asz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u3x, l->u3y, l->u3z);
          double J_v_fib = xib / info->m_b / l->tau * scalar_prod (info->bsx, info->bsy, info->bsz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u3x, l->u3y, l->u3z);
          double J_v_fic = xic / info->m_c / l->tau * scalar_prod (info->csx, info->csy, info->csz, tmp_x, tmp_y, tmp_z);

          /*with the jacobian we can compute the sigmas in terms of the orthogonal vectors u2 and u3*/
          sig2 = sig_fi_a * fabs (J_v_fia) + sig_fi_b * fabs (J_v_fib) + sig_fi_c * fabs (J_v_fic);
          sig3 = sig_fi_a * fabs (J_n_fia) + sig_fi_b * fabs (J_n_fib) + sig_fi_c * fabs (J_n_fic);

        } else if (SC_mosaic_AB[0] != 0 && SC_mosaic_AB[1] != 0) {
          /* Use isotropic mosaic via mosaic matrix */
          if ((SC_mosaic_AB[2] == 0 && SC_mosaic_AB[3] == 0 && SC_mosaic_AB[4] == 0) || (SC_mosaic_AB[5] == 0 && SC_mosaic_AB[6] == 0 && SC_mosaic_AB[7] == 0)) {
            MPI_MASTER (fprintf (stderr,
                                 "Single_crystal: %s: ERROR: in-plane mosaics are specified but one (or both)\n"
                                 "  in-plane reciprocal vector is the zero vector.\n",
                                 info->compname););
            return (0);
          }
          MPI_MASTER (fprintf (stderr,
                               "Single_crystal: %s: WARNING: you are using an experimental feature: \n"
                               "  \"in-plane\" anistropic mosaicity. Please examine your data carefully.\n",
                               info->compname););

          /*for given reflection in list - compute linear comb of tau_a and tau_b*/
          /*check for not in plane - f.i. check if (tau_a X tau_b).tau_i)==0*/
          struct hkl_data* l = &(list[J]);
          double det, c1, c2, sig_tau_c;
          double em_x, em_y, em_z, tmp_x, tmp_y, tmp_z;
          double tau_a[3], tau_b[3];
          /*convert Miller indices to taus*/
          if (info->m_a == 0)
            info->m_a = sqrt (scalar_prod (info->m_ax, info->m_ay, info->m_az, info->m_ax, info->m_ay, info->m_az));
          if (info->m_b == 0)
            info->m_b = sqrt (scalar_prod (info->m_bx, info->m_by, info->m_bz, info->m_bx, info->m_by, info->m_bz));
          if (info->m_c == 0)
            info->m_c = sqrt (scalar_prod (info->m_cx, info->m_cy, info->m_cz, info->m_cx, info->m_cy, info->m_cz));
          tau_a[0] = M_2_PI * ((SC_mosaic_AB[2] / info->m_a) * info->asx + (SC_mosaic_AB[3] / info->m_b) * info->bsx + (SC_mosaic_AB[4] / info->m_c) * info->csx);
          tau_a[1] = M_2_PI * ((SC_mosaic_AB[2] / info->m_a) * info->asy + (SC_mosaic_AB[3] / info->m_b) * info->bsy + (SC_mosaic_AB[4] / info->m_c) * info->csy);
          tau_a[2] = M_2_PI * ((SC_mosaic_AB[2] / info->m_a) * info->asz + (SC_mosaic_AB[3] / info->m_b) * info->bsz + (SC_mosaic_AB[4] / info->m_c) * info->csz);
          tau_b[0] = M_2_PI * ((SC_mosaic_AB[5] / info->m_a) * info->asx + (SC_mosaic_AB[6] / info->m_b) * info->bsx + (SC_mosaic_AB[7] / info->m_c) * info->csx);
          tau_b[1] = M_2_PI * ((SC_mosaic_AB[5] / info->m_a) * info->asy + (SC_mosaic_AB[6] / info->m_b) * info->bsy + (SC_mosaic_AB[7] / info->m_c) * info->csy);
          tau_b[2] = M_2_PI * ((SC_mosaic_AB[5] / info->m_a) * info->asz + (SC_mosaic_AB[6] / info->m_b) * info->bsz + (SC_mosaic_AB[7] / info->m_c) * info->csz);

          /*check determinants to see how we should compute the linear combination of a and b (to match c)*/
	  c1 = c2 = 0;
          if ((det = tau_a[0] * tau_b[1] - tau_a[1] * tau_b[0]) != 0) {
            c1 = (l->tau_x * tau_b[1] - l->tau_y * tau_b[0]) / det;
            c2 = (tau_a[0] * l->tau_y - tau_a[1] * l->tau_x) / det;
          } else if ((det = tau_a[1] * tau_b[2] - tau_a[2] * tau_b[1]) != 0) {
            c1 = (l->tau_y * tau_b[2] - l->tau_z * tau_b[1]) / det;
            c2 = (tau_a[1] * l->tau_z - tau_a[2] * l->tau_y) / det;
          } else if ((det = tau_a[0] * tau_b[2] - tau_a[2] * tau_b[0]) != 0) {
            c1 = (l->tau_x * tau_b[2] - l->tau_z * tau_b[0]) / det;
            c2 = (tau_a[0] * l->tau_z - tau_a[2] * l->tau_x) / det;
          }
          if ((c1 == 0) && (c2 == 0)) {
            MPI_MASTER (fprintf (stderr,
                                 "Single_crystal: %s: WARNING: reflection tau[%i]=(%g %g %g) "
                                 "has no component in defined mosaic plane\n",
                                 info->compname, i, l->tau_x, l->tau_y, l->tau_z););
          }
          /*compute linear combination => sig_tau_i = | c1*sig_tau_a + c2*sig_tau_b |  - also add in the minute to radian scaling factor*/;
          sig_tau_c = MIN2RAD * sqrt (c1 * SC_mosaic_AB[0] * c1 * SC_mosaic_AB[0] + c2 * SC_mosaic_AB[1] * c2 * SC_mosaic_AB[1]);
          l->u2x = b1[0];
          l->u2y = b1[1];
          l->u2z = b1[2];
          l->u3x = b2[0];
          l->u3y = b2[1];
          l->u3z = b2[2];

          /*so now let's compute the rotation around planenormal tau_a X tau_b*/
          /*g_bar (unit normal of rotation plane) = tau_a X tau_b / norm(tau_a X tau_b)*/
          vec_prod (tmp_x, tmp_y, tmp_z, tau_a[0], tau_a[1], tau_a[2], tau_b[0], tau_b[1], tau_b[2]);
          vec_prod (em_x, em_y, em_z, l->tau_x, l->tau_y, l->tau_z, tmp_x, tmp_y, tmp_z);
          NORM (em_x, em_y, em_z);
          sig2 = l->tau * sig_tau_c * fabs (scalar_prod (em_x, em_y, em_z, l->u2x, l->u2y, l->u2z));
          sig3 = l->tau * sig_tau_c * fabs (scalar_prod (em_x, em_y, em_z, l->u3x, l->u3y, l->u3z));
          /*protect against collapsing gaussians. These seem to be sensible values.*/
          if (sig2 < 1e-5)
            sig2 = 1e-5;
          if (sig3 < 1e-5)
            sig3 = 1e-5;
        } /* end moisaic stuff */
        else {
          MPI_MASTER (fprintf (stderr,
                               "Single_crystal: %s: ERROR: EITHER mosaic OR (mosaic_a, mosaic_b, mosaic_c)\n"
                               "  must be given and be >0.\n",
                               info->compname););
          return (0);
        }

        list[J].sig123 = sig1 * sig2 * sig3;
        list[J].m1 = 1 / (2 * sig1 * sig1);
        list[J].m2 = 1 / (2 * sig2 * sig2);
        list[J].m3 = 1 / (2 * sig3 * sig3);
        /* Set Gauss cutoff to 5 times the maximal sigma. */
        if (sig1 > sig2)
          list[J].cutoff = 5 * (sig1 > sig3 ? sig1 : sig3);
        else
          list[J].cutoff = 5 * (sig2 > sig3 ? sig2 : sig3);

        if (!isnan (list[J].F2) && !isnan (list[J].cutoff) && !isnan (list[J].tau))
          J++; // switch to next HKL Bragg element in hkl_data

      } // for i, j
    Table_Free (&sTable);

    if (!sum_F2) {
      MPI_MASTER (exit (fprintf (stderr, "Single_crystal: %s: ERROR: all %i structure factors in file '%s' are null. Check the reflection list.\n",
                                 info->compname, i, SC_file)););
    }

    /* sort the list with increasing tau */
    qsort (list, J, sizeof (struct hkl_data), SX_list_compare);

    *hkl_list = list;
    info->count = J;

    return (info->count);
  } /* read_hkl_data */

  /* ------------------------------------------------------------------------ */
  /* hkl_search
    search the HKL reflections which are on the Ewald sphere
    input:
      L,T,count,V0: constants for all calls
      kix,kiy,kiz: may be different for each call
    this function returns:
      tau_count (return), coh_refl, coh_xsect, T (updated elements in the array up to [j])
   */
  #pragma acc routine
  int
  hkl_search (struct hkl_data* L, void* TT, int count, double V0, double kix, double kiy, double kiz, double tau_max, double* coh_refl, double* coh_xsect) {

    int i, j = 0;
    double ki = sqrt (kix * kix + kiy * kiy + kiz * kiz);
    struct tau_data* T = (struct tau_data*)TT;

    /* Common factor in coherent cross-section */
    double xsect_factor = pow (2 * PI, 5.0 / 2.0) / (V0 * ki * ki);
    for (i = 0; i < count; i++) {
      /* Assuming reflections are sorted, stop search when max tau exceeded. */
      double rho, rho_x, rho_y, rho_z;
      double diff;

      if (L[i].tau > tau_max)
        break; // passed max tau found in crystal reflections

      /* Check if this reciprocal lattice point is close enough to the
         Ewald sphere to make scattering possible. */
      rho_x = kix - L[i].tau_x; /* rho = |ki - tau| = |kf| = |ki| within cutoff on the Ewald sphere */
      rho_y = kiy - L[i].tau_y;
      rho_z = kiz - L[i].tau_z;
      rho = sqrt (rho_x * rho_x + rho_y * rho_y + rho_z * rho_z);
      diff = fabs (rho - ki);

      /* Check if scattering is possible (cutoff of Gaussian tails). */
      if (diff <= L[i].cutoff) {
        double ox, oy, oz;
        double b1x, b1y, b1z, b2x, b2y, b2z, kx, ky, kz, nx, ny, nz;
        double n11, n22, n12, det_N, inv_n11, inv_n22, inv_n12, l11, l22, l12, det_L;
        double Bt_D_O_x, Bt_D_O_y, y0x, y0y, alpha;
        /* Store reflection. */
        T[j].index = i;
        /* Get ki vector in local coordinates. */
        kx = kix * L[i].u1x + kiy * L[i].u1y + kiz * L[i].u1z;
        ky = kix * L[i].u2x + kiy * L[i].u2y + kiz * L[i].u2z;
        kz = kix * L[i].u3x + kiy * L[i].u3y + kiz * L[i].u3z;
        T[j].rho_x = kx - L[i].tau;
        T[j].rho_y = ky;
        T[j].rho_z = kz;
        T[j].rho = rho;
        /* Compute the tangent plane of the Ewald sphere. */
        nx = T[j].rho_x / T[j].rho;
        ny = T[j].rho_y / T[j].rho;
        nz = T[j].rho_z / T[j].rho;
        ox = (ki - T[j].rho) * nx;
        oy = (ki - T[j].rho) * ny;
        oz = (ki - T[j].rho) * nz;
        T[j].ox = ox;
        T[j].oy = oy;
        T[j].oz = oz;
        /* Compute unit vectors b1 and b2 that span the tangent plane. */
        normal_vec (&b1x, &b1y, &b1z, nx, ny, nz);
        vec_prod (b2x, b2y, b2z, nx, ny, nz, b1x, b1y, b1z);
        T[j].b1x = b1x;
        T[j].b1y = b1y;
        T[j].b1z = b1z;
        T[j].b2x = b2x;
        T[j].b2y = b2y;
        T[j].b2z = b2z;
        /* Compute the 2D projection of the 3D Gauss of the reflection. */
        /* The symmetric 2x2 matrix N describing the 2D gauss. */
        n11 = L[i].m1 * b1x * b1x + L[i].m2 * b1y * b1y + L[i].m3 * b1z * b1z;
        n12 = L[i].m1 * b1x * b2x + L[i].m2 * b1y * b2y + L[i].m3 * b1z * b2z;
        n22 = L[i].m1 * b2x * b2x + L[i].m2 * b2y * b2y + L[i].m3 * b2z * b2z;
        /* The (symmetric) inverse matrix of N. */
        det_N = n11 * n22 - n12 * n12;
        inv_n11 = n22 / det_N;
        inv_n12 = -n12 / det_N;
        inv_n22 = n11 / det_N;
        /* The Cholesky decomposition of 1/2*inv_n (lower triangular L). */
        l11 = sqrt (inv_n11 / 2);
        l12 = inv_n12 / (2 * l11);
        l22 = sqrt (inv_n22 / 2 - l12 * l12);
        T[j].l11 = l11;
        T[j].l12 = l12;
        T[j].l22 = l22;
        det_L = l11 * l22;
        /* The product B^T D o. */
        Bt_D_O_x = b1x * L[i].m1 * ox + b1y * L[i].m2 * oy + b1z * L[i].m3 * oz;
        Bt_D_O_y = b2x * L[i].m1 * ox + b2y * L[i].m2 * oy + b2z * L[i].m3 * oz;
        /* Center of 2D Gauss in plane coordinates. */
        y0x = -(Bt_D_O_x * inv_n11 + Bt_D_O_y * inv_n12);
        y0y = -(Bt_D_O_x * inv_n12 + Bt_D_O_y * inv_n22);
        T[j].y0x = y0x;
        T[j].y0y = y0y;
        /* Factor alpha for the distance of the 2D Gauss from the origin. */
        alpha = L[i].m1 * ox * ox + L[i].m2 * oy * oy + L[i].m3 * oz * oz - (y0x * y0x * n11 + y0y * y0y * n22 + 2 * y0x * y0y * n12);
        T[j].refl = xsect_factor * det_L * exp (-alpha) / L[i].sig123; /* intensity of that Bragg */
        *coh_refl += T[j].refl;                                        /* total scatterable intensity */
        T[j].xsect = T[j].refl * L[i].F2;
        *coh_xsect += T[j].xsect;
        j++;
      }
      /*protect against tau shortlist buffer overrrun*/
      if (j == MCSX_REFL_SLIST_SIZE) {
        break;
      }
    } /* end for */
    return (j); // this is 'tau_count', i.e. number of reachable reflections
  } /* end hkl_search */

  #pragma acc routine
  int
  hkl_select (struct tau_data* T, int tau_count, double coh_refl, double* sum, _class_particle* _particle) {
    int j;
    double r = rand0max (coh_refl);
    *sum = 0;
    for (j = 0; j < tau_count; j++) {
      *sum += T[j].refl;
      if (*sum > r)
        break;
    }
    return j;
  }

  /* Functions for "reorientation", powder mode */
  /* Powder, forward */
  #pragma acc routine
  void
  randrotate (double* nx, double* ny, double* nz, double a, double b, double c) {
    double x1, y1, z1, x2, y2, z2;
    rotate (x1, y1, z1, *nx, *ny, *nz, a, 1, 0, 0); /* <1> = rot(<n>,a) */
    rotate (x2, y2, z2, x1, y1, z1, b, 0, 1, 0);    /* <2> = rot(<1>,b) */
    rotate (*nx, *ny, *nz, x2, y2, z2, c, 0, 0, 1); /* <n> = rot(<2>,c) */
  }
  /* Powder, back */
  #pragma acc routine
  void
  randderotate (double* nx, double* ny, double* nz, double a, double b, double c) {
    double x1, y1, z1, x2, y2, z2;
    rotate (x1, y1, z1, *nx, *ny, *nz, -c, 0, 0, 1);
    rotate (x2, y2, z2, x1, y1, z1, -b, 0, 1, 0);
    rotate (*nx, *ny, *nz, x2, y2, z2, -a, 1, 0, 0);
  }

  #pragma acc routine
  /* rotate vector counterclockwise */
  void
  vec_rotate_2d (double* x, double* y, double angle) {
    double c, s;
    double newx, newy;

    c = cos (angle);
    s = sin (angle);

    newx = *x * c - *y * s;
    newy = *x * s + *y * c;

    *x = newx;
    *y = newy;
  }

  struct sx_abs_data {
    int muc; // column where mu is to be found
    double atomic_weight;
    double delta_prefactor;
    t_Table table;
  };

  int
  sx_read_abs_data (char* ABS_file, struct sx_abs_data* abs, struct hkl_info_struct info) {
    int status;
    char** parsing;
    double Z;

    if (ABS_file && strlen (ABS_file) && strcmp (ABS_file, "NULL") && strcmp (ABS_file, "0")) {
      if ((status = Table_Read (&(abs->table), ABS_file, 0)) == -1) {
        MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Could not parse file \"%s\"\n", info.compname, ABS_file););
        exit (-1);
      }
      abs->muc = (abs->table.columns == 3 ? 1 : 5);

      parsing = Table_ParseHeader (abs->table.header, "Z", "A[r]", "rho", NULL);
      if (parsing) {
        if (parsing[0])
          Z = strtol (parsing[0], NULL, 10);
        if (parsing[1] && !info.mat_weight)
          info.mat_weight = strtod (parsing[1], NULL); // aka A[r] in g/mol
        if (parsing[2] && !info.rho)
          info.rho = strtod (parsing[2], NULL);
      }

      if (info.rho && info.mat_weight)
        abs->delta_prefactor = NA * (info.rho * 1e-24) / info.mat_weight * 2.0 * M_PI * RE;

      abs->atomic_weight = info.mat_weight;

      return 1;
    } else {
      // init an empty table with absorption 0
      Table_Init (&(abs->table), 2, 2);
      abs->table.data[0] = 0;
      abs->table.data[1] = 0;
      abs->table.data[2] = FLT_MAX;
      abs->table.data[3] = 0;
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: WARNING: material file %s not found. Absorption set to 0.\n", info.compname, ABS_file));
      return 0;
    }
  } // sx_read_abs_data

  #endif /* !SINGLE_CRYSTAL_DECL */

 // for OFF/PLY geometry

  #ifndef FLUORESCENCE_DECL
  #define FLUORESCENCE_DECL

  // WARNING: mush NOT use rand01 calls here, as they depend on _particle

  #define XRAYLIB_LINES_MAX 383
  #define FLUORESCENCE 0  // Fluo
  #define RAYLEIGH     1  // Coherent
  #define COMPTON      2  // Incoherent
  #define DIFFRACTION  3  // diffraction
  #define TRANSMISSION 4

  #include <xraylib/xraylib.h>
  
/* See XrayLib code (c) T. Schoonjans
 * /usr/include/xraylib/xraylib-parser.h      for compoundData
 * /usr/include/xraylib/xraylib.h             for XS
 */

/* inspired from:
 * https://github.com/golosio/xrmc src/photon/photon.cpp (c) Bruno Golosio    
 */
  
  /* XRMC_CrossSections: Compute interaction cross sections in [barn/atom]
   * When kissel=1, M-lines are computed, but computation is 10x slower.
   * Computes xs[FLUORESCENCE,RAYLEIGH,COMPTON] that must have been allocated.
   * Return total cross section, given Z and E0:
   *   total_xs = XRMC_CrossSections(Z, E0, xs[3], flag_kissel);
   */
  double XRMC_CrossSections(int Z, double E0, double *xs, int kissel) {
    int    i_line;
    
    if (xs == NULL) return 0;
    for(i_line=0; i_line<=COMPTON; i_line++) xs[i_line]=0;
    
    // loop on possible fluorescence lines
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { 
      // cumulative sum of the line cross sections
      xs[FLUORESCENCE] += kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
    }

    // coherent and incoherent cross sections
    xs[RAYLEIGH] = CSb_Rayl( Z, E0, NULL);
    xs[COMPTON]  = CSb_Compt(Z, E0, NULL);
    
    // total interaction cross section, should converge to CSb_Total(Z, E0, NULL)
    return xs[FLUORESCENCE] + xs[RAYLEIGH] + xs[COMPTON];
  } // XRMC_CrossSections

  /* XRMC_SelectFromDistribution: select a random element from a distribution
   *   index = XRMC_SelectFromDistribution(cum_sum[N], N);
   * index is returned within 0 and N-1
   * The x_arr must be a continuously increasing cumulated sum, which last element is the max.
   */
  int XRMC_SelectFromDistribution(double x_arr[], int N, double r)
  {
    if (x_arr == NULL || N <=0) return (0);
    double x = r*x_arr[N-1]; // the threshold cumulated value to search in distribution
    if (x<x_arr[0]) {    // x is smaller than lower limit
      return 0;
    }
    if (x>=x_arr[N-1]) { // x is greater or equal to upper limit
      return N-1;
    }
    int id=0, iu=N-1; // lower and upper index of the subarray to search
    while (iu-id>1) { // search until the size of the subarray to search is >1
      int im = (id + iu)/2; // use the midpoint for equal partition
      // decide which subarray to search
      if (x>=x_arr[im]) id=im; // change min index to search upper subarray
      else iu=im; // change max index to search lower subarray
    }

    return id;
  } // XRMC_SelectFromDistribution

  /* XRMC_SelectInteraction: select interaction type Fluo/Compton/Rayleigh
   * Return the interaction type from a random choice within cross sections 'xs'
   *   type = XRMC_SelectInteraction(xs[3], 3);
   * 'xs' is computed with XRMC_CrossSections. Can be unsorted.
   * type is e.g. one of FLUORESCENCE | RAYLEIGH | COMPTON
   */
  int XRMC_SelectInteraction(double *xs, int nb_processes, double r)
  {
    double sum_xs, *cum_xs;
    int    i;

    if (xs == NULL || nb_processes < 1) return 0;
    cum_xs = malloc((nb_processes+1)*sizeof(double));
    if (!cum_xs)          return 0;
    cum_xs[0]=sum_xs=0;
    for (i=0; i< nb_processes; i++) {
      sum_xs += xs[i];
      cum_xs[i+1]= sum_xs;
    }
    i = XRMC_SelectFromDistribution(cum_xs, nb_processes+1, r);
    free(cum_xs);
    return i;
  } // XRMC_SelectInteraction

  /* XRMC_SelectFluorescenceEnergy: select outgoing fluo photon energy, when incoming with 'E0'
   * When kissel=1, M-lines are included, but computation is 10x slower
   *   Ef = XRMC_SelectFluorescenceEnergy(Z, E0, &dE, kissel);
   */
  double XRMC_SelectFluorescenceEnergy(int Z, double E0, double *dE, int kissel, double r)
  {
    int i_line;
    double sum_xs, cum_xs_lines[XRAYLIB_LINES_MAX+1];

    // compute cumulated XS for all fluo lines
    cum_xs_lines[0] = sum_xs = 0;
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { // loop on fluorescent lines
      double xs = kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
      // when a line is inactive: E=xs=0
      sum_xs += xs;
      cum_xs_lines[i_line+1] = sum_xs; // cumulative sum of their cross sections
    }
    // select randomly one of these lines
    i_line = XRMC_SelectFromDistribution(cum_xs_lines, XRAYLIB_LINES_MAX, r); // extract a line
    // get the K shell line width as approximation of fluorescence line width
    if (dE) *dE = AtomicLevelWidth(Z, K_SHELL, NULL); // keV, full-width in keV

    return LineEnergy(Z, -i_line, NULL); // fluorescent line energy
  } // XRMC_SelectFluorescenceEnergy

  // Function removing spaces from string
  char * removeSpacesFromStr(char *string)
  {
      // non_space_count to keep the frequency of non space characters
      int non_space_count = 0;
      if (string == NULL) return NULL;
   
      //Traverse a string and if it is non space character then, place it at index non_space_count
      for (int i = 0; string[i] != '\0'; i++)
      {
          if (isalpha(string[i]) || isdigit(string[i]))
          {
              string[non_space_count] = string[i];
              non_space_count++; //non_space_count incremented
          }    
      }
      
      //Finally placing final character at the string end
      string[non_space_count] = '\0';
      return string;
  }

  // ok = fluo_get_material(material, formula)
  // extracts material atoms from file header
  // the result is concatenated into 'formula'
  int fluo_get_material(char *filename, char *formula) {
  
    int  ret = 0;
    char Line[65535];
    int  flag_found_cif=0;
    if (filename == NULL || formula == NULL) return (0);
    FILE *file = Open_File(filename, "r", NULL);
    if (!file)
      exit(fprintf(stderr, "%s: ERROR: can not open file %s\n", 
      __FILE__, filename));
    
    // Read the file, and search tokens in rows
    formula[0]=0;
    while (fgets(Line, sizeof(Line), file) != NULL) {
      char *token = NULL;
      int   flag_exit=0;
      char *first_non_space=NULL;
      char *next_non_space =NULL;
      // CIF: _chemical_formula_structural 'chemical_formulae'
      // CIF: _chemical_formula_sum 'chemical_formulae'
      // LAZ/LAU: # ATOM <at> <trailing>
      // LAZ/LAU: # Atom <at> <trailing>
      // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
      // CFL: Title <chemical_formulae>
      // CFL: Atom <at> <trailing>
      
      // search for CIF token
      // single line: search " '\'" delimiter after CIF token, marks reading the formula
      if (!strncasecmp(Line, "_chemical_formula_structural", 28) 
       || !strncasecmp(Line, "_chemical_formula_sum", 21) 
       || !strncasecmp(Line, "_chemical_formula_moiety", 24)
       || flag_found_cif) {
        if  (flag_found_cif) { flag_found_cif=0; /* can not span on more that 2 lines */} 
        else flag_found_cif=1;
        // search for delimiter after the CIF token
        char *first_space_after_token=strpbrk(Line, " \'\n");
        if (first_space_after_token) {
          // search for the characters that may compose the formula
          first_non_space = strpbrk(first_space_after_token, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()[]");
          if (strchr(first_space_after_token,'?')) {
            // we have an invalid/unknown formula in the CIF. Skip CIF token/line
            flag_found_cif=0;
            continue;
          }
        }
        if (first_non_space) 
          next_non_space  = strpbrk(first_non_space+1, "\'\n\r"); // position of formula end
        if (next_non_space) { 
          flag_exit = 1;
          token = first_non_space;
        }
      } else if (!strncasecmp(Line, "# TITLE", 7) && strchr(Line, '['))
        token = Line+7;
      else if (!strncasecmp(Line, "# Atom", 6))
        token = Line+6;
      else if (!strncasecmp(Line, "Atom", 4))
        token = Line+4;
      else if (!strncasecmp(Line, "Title", 5))
        token = Line+7;
      if (!token) continue;
      if (!strncasecmp(Line, "# TITLE", 7)) {
        first_non_space = Line+7;
        next_non_space  = strchr(Line+7, '[');
        if (next_non_space) flag_exit = 1;
      }
      if (!first_non_space) first_non_space = strtok(token, " \t\n");
      if (!first_non_space) continue;
      if (!next_non_space)  next_non_space  = strtok(NULL,  " \t\n"); // end of formulae
      if (!next_non_space)  next_non_space = Line+strlen(Line);
      // remove spaces
      strncat(formula, first_non_space, next_non_space-first_non_space);
      ret++;
      if (flag_exit) break;
    }
    fclose(file);
    removeSpacesFromStr(formula);
    return(ret);
  } // fluo_get_material
  
  #endif // FLUORESCENCE_DECL

/* Shared user declarations for all components types 'Single_crystal'. */
  /* used for reading data table from file */


  /* Declare structures and functions only once in each instrument. */
  #ifndef SINGLE_CRYSTAL_DECL
  #define SINGLE_CRYSTAL_DECL

  #ifndef Mosaic_AB_Undefined
  #define Mosaic_AB_Undefined {0,0, 0,0,0, 0,0,0}
  #endif

  #ifndef MCSX_REFL_SLIST_SIZE
  #define MCSX_REFL_SLIST_SIZE 128
  #endif

  struct hkl_data {
    int h, k, l;                /* Indices for this reflection */
    double F2;                  /* Value of structure factor */
    double tau_x, tau_y, tau_z; /* Coordinates in reciprocal space */
    double tau;                 /* Length of (tau_x, tau_y, tau_z) */
    double u1x, u1y, u1z;       /* First axis of local coordinate system */
    double u2x, u2y, u2z;       /* Second axis of local coordinate system */
    double u3x, u3y, u3z;       /* Third axis of local coordinate system */
    double sig123;              /* The product sig1*sig2*sig3 = volume of spot */
    double m1, m2, m3;          /* Diagonal matrix representation of Gauss */
    double cutoff;              /* Cutoff value for Gaussian tails */
  };

  struct tau_data {
    int index; /* Index into reflection table */
    double refl;
    double xsect;
    /* The following vectors are in local koordinates. */
    double rho_x, rho_y, rho_z; /* The vector ki - tau */
    double rho;                 /* Length of rho vector */
    double ox, oy, oz;          /* Origin of Ewald sphere tangent plane */
    double b1x, b1y, b1z;       /* Spanning vectors of Ewald sphere tangent */
    double b2x, b2y, b2z;
    double l11, l12, l22; /* Cholesky decomposition L of 2D Gauss */
    double y0x, y0y;      /* 2D Gauss center in tangent plane */
  };

  struct hkl_info_struct {
    int count;                  /* Number of reflections */
    double m_delta_d_d;         /* Delta-d/d FWHM */
    double m_ax, m_ay, m_az;    /* First unit cell axis (direct space, AA) */
    double m_bx, m_by, m_bz;    /* Second unit cell axis */
    double m_cx, m_cy, m_cz;    /* Third unit cell axis */
    double asx, asy, asz;       /* First reciprocal lattice axis (1/AA) */
    double bsx, bsy, bsz;       /* Second reciprocal lattice axis */
    double csx, csy, csz;       /* Third reciprocal lattice axis */
    double m_a, m_b, m_c;       /* length of lattice parameter lengths */
    double m_aa, m_bb, m_cc;    /* lattice angles */
    double sigma_i;             /* inc X sect */
    double rho;                 /* density [at/Angs^3] */
    double mat_weight;          /* material atomic weight [g/mol] */
    double mat_density;         /* material atomic density [g/cm3] */
    double V0;                  /* Unit cell volume (AA**3) */
    int column_order[5];        /* column signification [h,k,l,F,F2] */
    int recip;                  /* Flag to indicate if recip or direct cell axes given */
    int shape;                  /* 0:cylinder, 1:box, 2:sphere 3:any shape*/
    int flag_warning;           /* number of warnings */
    int flag_barns;             /* 1: F2 in barns, 0: in fm^2 */
    char type;                  /* type of last event: t=transmit,c=coherent or i=incoherent */
    int h, k, l;                /* last coherent scattering momentum transfer indices */
    int tau_count;              /* Number of reflections within cutoff */
    double coh_refl, coh_xsect; /* cross section computed with last tau_list */
    double kix, kiy, kiz;       /* last incoming photon ki */
    int nb_reuses, nb_refl, nb_refl_count;
    int max_tau_count;
    int ctr_size;
    double* ctr_k;
    double* ctr_FT2;
    double* ctr_dir;
    char compname[256];
  };

  #pragma acc routine
  // sign = SX_list_compare(a,b)
  //   used for qsort, to sort reflections
  // input:  a,b: two 'line_data' reflection pointers.
  // output: -1,0,1 for a<b, a=b, a>b
  int
  SX_list_compare (void const* a, void const* b) {
    struct hkl_data const* pa = a;
    struct hkl_data const* pb = b;

    /* Sort by tau */
    if (pa->tau < pb->tau)
      return -1;
    if (pa->tau > pb->tau)
      return 1;

    /* Sort by tau_x */
    if (pa->tau_x < pb->tau_x)
      return -1;
    if (pa->tau_x > pb->tau_x)
      return 1;

    /* Sort by tau_y */
    if (pa->tau_y < pb->tau_y)
      return -1;
    if (pa->tau_y > pb->tau_y)
      return 1;

    /* Sort by tau_z */
    if (pa->tau_z < pb->tau_z)
      return -1;
    if (pa->tau_z > pb->tau_z)
      return 1;

    /* In case of tie, sort by F2 also */
    if (pa->F2 < pb->F2)
      return -1;
    if (pa->F2 > pb->F2)
      return 1;

    return 0;
  } /* SX_list_compare */

  #ifndef CIF2HKL
  #define CIF2HKL
  // hkl_filename = cif2hkl(file, options)
  //   used to convert CIF/CFL/INS file into F2(hkl)
  //   the CIF2HKL env var can point to a cif2hkl executable
  //   else the McCode binary is attempted, then the system.
  char*
  cif2hkl (char* infile, char* options) {
    char cmd[1024];
    int ret = 0;
    int found = 0;
    char* OUTFILE;
    char* inpath;

    // get filename extension
    const char* ext = strrchr (infile, '.');
    if (!ext || ext == infile)
      return infile;
    else
      ext++;

    // return input when no extension or not a CIF/FullProf/ShelX file
    if (strcasecmp (ext, "cif") && strcasecmp (ext, "pcr") && strcasecmp (ext, "cfl") && strcasecmp (ext, "shx") && strcasecmp (ext, "ins")
        && strcasecmp (ext, "res"))
      return infile;

    OUTFILE = malloc (1024);
    if (!OUTFILE) {
      free (OUTFILE);
      return infile;
    }
    inpath = malloc (1024);
    if (!inpath) {
      free (OUTFILE);
      free (inpath);
      return infile;
    }

    // get input file path from read-table:Open_File
    FILE* f_infile = Open_File (infile, "r", inpath);
    if (!f_infile) {
      free (OUTFILE);
      free (inpath);
      free (f_infile);
      return infile;
    }
    fclose (f_infile);

    strncpy (OUTFILE, tmpnam (NULL), 1024); // create an output temporary file name

    // try in order the CIF2HKL env var, then the system cif2hkl, then the McCode one
    if (!found && getenv ("CIF2HKL")) {
      snprintf (cmd, 1024, "%s -o %s %s %s", getenv ("CIF2HKL"), OUTFILE, options, inpath);
      ret = system (cmd);
      if (ret != -1 && ret != 127)
        found = 1;
    }
    if (!found) {
      // try with cif2hkl command from the system PATH
      snprintf (cmd, 1024, "%s -o %s %s %s", "cif2hkl", OUTFILE, options, inpath);
      ret = system (cmd);
      if (ret != -1 && ret != 127)
        found = 1;
    }
    if (!found) {
      // As a last resort, attempt with cif2hkl from $MCXTRACE/bin
      snprintf (cmd, 1024, "%s%c%s%c%s -o %s %s %s", getenv (FLAVOR_UPPER) ? getenv (FLAVOR_UPPER) : MCXTRACE, MC_PATHSEP_C, "bin", MC_PATHSEP_C, "cif2hkl",
                OUTFILE, options, inpath);
      ret = system (cmd);
    }
    // ret = -1:  child process could not be created
    // ret = 127: shell could not be executed in the child process
    if (ret == -1 || ret == 127) {
      free (OUTFILE);
      return (NULL);
    }

    // test if the result file has been created
    FILE* file = fopen (OUTFILE, "r");
    if (!file) {
      free (OUTFILE);
      return (NULL);
    }
    MPI_MASTER (printf ("%s: INFO: Converting %s into F2(HKL) list %s\n", __FILE__, infile, OUTFILE); printf ("%s\n", cmd););
    fflush (NULL);
    fclose (file);
    return (OUTFILE);
  } // cif2hkl
  #endif

  /* ------------------------------------------------------------------------ */

  // count = read_hkl_data(filename, &info, ...)
  //   read the given file to store F2(HKL) reflections and metadata.
  int
  read_hkl_data (char* SC_file, struct hkl_info_struct* info, struct hkl_data** hkl_list, double SC_mosaic, double SC_mosaic_a, double SC_mosaic_b,
                 double SC_mosaic_c, double* SC_mosaic_AB, int surf_size, double* surf_k, double* surf_FT2, double* surf_dir) {
    struct hkl_data* list = NULL;
    int size = 0;
    t_Table sTable; /* sample data table structure from SC_file */
    int i = 0, j = 0, J = 0;
    double tmp_x, tmp_y, tmp_z;
    char** parsing;
    char flag = 0;
    double nb_atoms = 1;
    double sum_F2 = 0;
    char* filename = NULL;

    if (!SC_file || !strlen (SC_file) || !strcmp (SC_file, "NULL") || !strcmp (SC_file, "0"))
      return (0);

    filename = cif2hkl (SC_file, "--xtal --mode XRA");
    if (filename && filename != SC_file)
      info->flag_barns = 1; // cif2hkl returns barns

    if (!filename || Table_Read (&sTable, filename, 1) < 0)
      exit (fprintf (stderr, "Single_crystal: %s: ERROR: Could not open file %s - exiting!\n", info->compname, filename));

    // remove temporary F2(hkl) file when giving CFL/CIF/ShelX file
    if (filename && filename != SC_file)
      unlink (filename);

    if (sTable.columns < 4) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: The number of columns in %s should be at least %d for [h,k,l,F2]\n", info->compname, SC_file, 4););
      return (0);
    }
    if (!sTable.rows) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: The number of rows in %s should be at least %d\n", info->compname, SC_file, 1););
      return (0);
    } else
      size = sTable.rows;

    /* parsing of header */
    parsing = Table_ParseHeader (sTable.header, "sigma_abs", "sigma_a ", // 0-1
                                 "sigma_inc", "sigma_i ", "column_h", "column_k", "column_l", "column_F ", "column_F2",
                                 "Delta_d/d",                                                                                                    // 9
                                 "lattice_a ", "lattice_b ", "lattice_c ", "lattice_aa", "lattice_bb", "lattice_cc", "nb_atoms", "multiplicity", // 17
                                 "Vc", "V_0", "V_rho", "density", "weight", NULL);

    if (parsing) {
      // if (parsing[0] && !info->sigma_a) info->sigma_a=atof(parsing[0]);
      // if (parsing[1] && !info->sigma_a) info->sigma_a=atof(parsing[1]);
      if (parsing[2] && !info->sigma_i)
        info->sigma_i = atof (parsing[2]);
      if (parsing[3] && !info->sigma_i)
        info->sigma_i = atof (parsing[3]);
      if (parsing[4])
        info->column_order[0] = atoi (parsing[4]);
      if (parsing[5])
        info->column_order[1] = atoi (parsing[5]);
      if (parsing[6])
        info->column_order[2] = atoi (parsing[6]);
      if (parsing[7])
        info->column_order[3] = atoi (parsing[7]);
      if (parsing[8])
        info->column_order[4] = atoi (parsing[8]);
      if (parsing[9] && info->m_delta_d_d <= 0)
        info->m_delta_d_d = atof (parsing[9]);
      if (parsing[10] && !info->m_a)
        info->m_a = atof (parsing[10]);
      if (parsing[11] && !info->m_b)
        info->m_b = atof (parsing[11]);
      if (parsing[12] && !info->m_c)
        info->m_c = atof (parsing[12]);
      if (parsing[13] && !info->m_aa)
        info->m_aa = atof (parsing[13]);
      if (parsing[14] && !info->m_bb)
        info->m_bb = atof (parsing[14]);
      if (parsing[15] && !info->m_cc)
        info->m_cc = atof (parsing[15]);
      if (parsing[16])
        nb_atoms = atof (parsing[16]);
      if (parsing[17])
        nb_atoms = atof (parsing[17]);
      if (parsing[18] && !info->rho)
        info->rho = 1 / atof (parsing[18]);
      if (parsing[19] && !info->rho)
        info->rho = 1 / atof (parsing[19]);
      if (parsing[20] && !info->rho)
        info->rho = atof (parsing[20]);
      if (parsing[21] && !info->mat_density)
        info->mat_density = atof (parsing[21]);
      if (parsing[22] && !info->mat_weight)
        info->mat_weight = atof (parsing[22]);

      for (i = 0; i <= 22; i++)
        if (parsing[i])
          free (parsing[i]);
      free (parsing);
    }

    if (!info->column_order[0] || !info->column_order[1] || !info->column_order[2]) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong h,k,l column definition\n", SC_file););
      return (0);
    }
    if (!info->column_order[3] && !info->column_order[4]) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong F,F2 column definition\n", SC_file););
      return (0);
    }

    if (!info->rho && info->mat_density > 0 && info->mat_weight > 0 && nb_atoms > 0) {
      /* molar volume [cm^3/mol] = weight [g/mol] / density [g/cm^3] */
      /* atom density per Angs^3 = [mol/cm^3] * N_Avogadro *(1e-8)^3 */
      info->rho = info->mat_density / (info->mat_weight * nb_atoms) / 1e24 * NA;
    }

    if (nb_atoms > 1) {
      info->sigma_i *= nb_atoms;
    }
    if (info->m_delta_d_d <= 0) {
      info->m_delta_d_d = SC_mosaic > 0 ? SC_mosaic * MIN2RAD : MIN2RAD; // MIN2RAD = 3e-4
      MPI_MASTER (
          fprintf (stderr, "Single_crystal: %s: WARNING: Delta_d/d is <=0 (longitudinal mosaic). Setting delta_d_d=%g\n", info->compname, info->m_delta_d_d););
    } else if (SC_mosaic < 0 && SC_mosaic_a < 0 && SC_mosaic_b < 0 && SC_mosaic_c < 0) {
      if (info->m_delta_d_d > 0)
        SC_mosaic = info->m_delta_d_d / MIN2RAD;
    }

    /* special cases for the structure definition */
    if (info->m_ax || info->m_ay || info->m_az) {
      info->m_a = 0;
      info->m_aa = 0;
    } /* means we specify by hand the vectors */
    if (info->m_bx || info->m_by || info->m_bz) {
      info->m_b = 0;
      info->m_bb = 0;
    }
    if (info->m_cx || info->m_cy || info->m_cz) {
      info->m_c = 0;
      info->m_cc = 0;
    };

    /* compute the norm from vector a if missing */
    if (info->m_ax || info->m_ay || info->m_az) {
      double as = sqrt (info->m_ax * info->m_ax + info->m_ay * info->m_ay + info->m_az * info->m_az);
      if (!info->m_bx && !info->m_by && !info->m_bz)
        info->m_a = info->m_b = as;
      if (!info->m_cx && !info->m_cy && !info->m_cz)
        info->m_a = info->m_c = as;
    }
    if (info->m_a && !info->m_b)
      info->m_b = info->m_a;
    if (info->m_b && !info->m_c)
      info->m_c = info->m_b;

    /* compute the lattive angles if not set from data file. Not used when in vector mode. */
    if (info->m_a && !info->m_aa)
      info->m_aa = 90;
    if (info->m_aa && !info->m_bb)
      info->m_bb = info->m_aa;
    if (info->m_bb && !info->m_cc)
      info->m_cc = info->m_bb;

    /* parameters consistency checks */
    if (!info->m_ax && !info->m_ay && !info->m_az && !info->m_a) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong a lattice vector definition\n", info->compname););
      return (0);
    }
    if (!info->m_bx && !info->m_by && !info->m_bz && !info->m_b) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong b lattice vector definition\n", info->compname););
      return (0);
    }
    if (!info->m_cx && !info->m_cy && !info->m_cz && !info->m_c) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Wrong c lattice vector definition\n", info->compname););
      return (0);
    }
    if (info->m_aa && info->m_bb && info->m_cc && info->recip) {
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Selecting reciprocal cell and angles is unmeaningful.\n", info->compname););
      return (0);
    }

    /* when lengths a,b,c + angles are given (instead of vectors a,b,c) */
    if (info->m_aa && info->m_bb && info->m_cc) {
      double as, bs, cs;
      if (info->m_a)
        as = info->m_a;
      else
        as = sqrt (info->m_ax * info->m_ax + info->m_ay * info->m_ay + info->m_az * info->m_az);
      if (info->m_b)
        bs = info->m_b;
      else
        bs = sqrt (info->m_bx * info->m_bx + info->m_by * info->m_by + info->m_bz * info->m_bz);
      if (info->m_c)
        cs = info->m_c;
      else
        cs = sqrt (info->m_cx * info->m_cx + info->m_cy * info->m_cy + info->m_cz * info->m_cz);

      /* Real-space vectors with b along z and a in the yz-plane at the angle
         gamma to b; c then has cos(alpha) along b, cos(beta) against a, and a
         positive x component, which makes (a, b, c) right-handed.  Each vector
         carries its own length: a = as, b = bs, c = cs.  (Before, a was given
         the length bs and b the length as, and alpha/beta were exchanged in c,
         so for a != b every |F(h,k,l)|^2 ended up at the position of (k,h,l).) */
      info->m_bx = 0;
      info->m_by = 0;
      info->m_bz = bs;
      info->m_ax = 0;
      info->m_ay = as * sin (info->m_cc * DEG2RAD);
      info->m_az = as * cos (info->m_cc * DEG2RAD);
      info->m_cz = cs * cos (info->m_aa * DEG2RAD);
      info->m_cy = cs * (cos (info->m_bb * DEG2RAD) - cos (info->m_cc * DEG2RAD) * cos (info->m_aa * DEG2RAD)) / sin (info->m_cc * DEG2RAD);
      info->m_cx = sqrt (cs * cs - info->m_cz * info->m_cz - info->m_cy * info->m_cy);

      MPI_MASTER (printf ("Single_crystal: %s: %s structure a=%g b=%g c=%g aa=%g bb=%g cc=%g ", info->compname, SC_file, as, bs, cs, info->m_aa, info->m_bb,
                          info->m_cc););
    } else {
      MPI_MASTER (
          if (!info->recip) {
            printf ("Single_crystal: %s: %s structure a=[%g,%g,%g] b=[%g,%g,%g] c=[%g,%g,%g] ", info->compname, SC_file, info->m_ax, info->m_ay, info->m_az,
                    info->m_bx, info->m_by, info->m_bz, info->m_cx, info->m_cy, info->m_cz);
          } else {
            printf ("Single_crystal: %s: %s structure a*=[%g,%g,%g] b*=[%g,%g,%g] c*=[%g,%g,%g] ", info->compname, SC_file, info->m_ax, info->m_ay, info->m_az,
                    info->m_bx, info->m_by, info->m_bz, info->m_cx, info->m_cy, info->m_cz);
          });
    }
    /* Compute reciprocal or direct lattice vectors. */
    if (!info->recip) {
      vec_prod (tmp_x, tmp_y, tmp_z, info->m_bx, info->m_by, info->m_bz, info->m_cx, info->m_cy, info->m_cz);
      info->V0 = fabs (scalar_prod (info->m_ax, info->m_ay, info->m_az, tmp_x, tmp_y, tmp_z));
      if (!info->V0 || isnan (info->V0)) {
        MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Lattice cell volume is found invalid V0=%g. Check crystal cell parameters.\n", info->compname,
                             info->V0));
        return (0);
      }

      info->asx = 2 * PI / info->V0 * tmp_x;
      info->asy = 2 * PI / info->V0 * tmp_y;
      info->asz = 2 * PI / info->V0 * tmp_z;
      vec_prod (tmp_x, tmp_y, tmp_z, info->m_cx, info->m_cy, info->m_cz, info->m_ax, info->m_ay, info->m_az);
      info->bsx = 2 * PI / info->V0 * tmp_x;
      info->bsy = 2 * PI / info->V0 * tmp_y;
      info->bsz = 2 * PI / info->V0 * tmp_z;
      vec_prod (tmp_x, tmp_y, tmp_z, info->m_ax, info->m_ay, info->m_az, info->m_bx, info->m_by, info->m_bz);
      info->csx = 2 * PI / info->V0 * tmp_x;
      info->csy = 2 * PI / info->V0 * tmp_y;
      info->csz = 2 * PI / info->V0 * tmp_z;
    } else {
      info->asx = info->m_ax;
      info->asy = info->m_ay;
      info->asz = info->m_az;
      info->bsx = info->m_bx;
      info->bsy = info->m_by;
      info->bsz = info->m_bz;
      info->csx = info->m_cx;
      info->csy = info->m_cy;
      info->csz = info->m_cz;

      vec_prod (tmp_x, tmp_y, tmp_z, info->bsx / (2 * PI), info->bsy / (2 * PI), info->bsz / (2 * PI), info->csx / (2 * PI), info->csy / (2 * PI),
                info->csz / (2 * PI));
      info->V0 = scalar_prod (info->asx / (2 * PI), info->asy / (2 * PI), info->asz / (2 * PI), tmp_x, tmp_y, tmp_z);
      if (!info->V0 || isnan (info->V0)) {
        MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Lattice reciprocal cell volume is found invalid V0=%g. Check crystal cell parameters.\n",
                             info->compname, info->V0));
        return (0);
      }
      info->V0 = 1 / fabs (info->V0);

      /*compute the direct cell parameters, for completeness*/
      info->m_ax = tmp_x * info->V0;
      info->m_ay = tmp_y * info->V0;
      info->m_az = tmp_z * info->V0;
      vec_prod (tmp_x, tmp_y, tmp_z, info->csx / (2 * PI), info->csy / (2 * PI), info->csz / (2 * PI), info->asx / (2 * PI), info->asy / (2 * PI),
                info->asz / (2 * PI));
      info->m_bx = tmp_x * info->V0;
      info->m_by = tmp_y * info->V0;
      info->m_bz = tmp_z * info->V0;
      vec_prod (tmp_x, tmp_y, tmp_z, info->asx / (2 * PI), info->asy / (2 * PI), info->asz / (2 * PI), info->bsx / (2 * PI), info->bsy / (2 * PI),
                info->bsz / (2 * PI));
      info->m_cx = tmp_x * info->V0;
      info->m_cy = tmp_y * info->V0;
      info->m_cz = tmp_z * info->V0;
    }
    MPI_MASTER (printf ("V0=%g\n", info->V0););

    /* allocate hkl_data array */

    if (surf_size <= 0 || !surf_k || !surf_FT2 || !surf_dir)
      surf_size = 1;
    list = (struct hkl_data*)malloc (size * surf_size * sizeof (struct hkl_data));
    if (!list) {
      fprintf (stderr, "Single_crystal: Error allocating reflection list\n");
      return (0);
    }

    for (i = 0; i < size; i++)
      for (j = 0; j < surf_size; j++) {
        double h = 0, k = 0, l = 0, F2 = 0;
        double b1[3], b2[3];
        double sig1, sig2, sig3;

        /* get data from table */
        h = Table_Index (sTable, i, info->column_order[0] - 1);
        k = Table_Index (sTable, i, info->column_order[1] - 1);
        l = Table_Index (sTable, i, info->column_order[2] - 1);
        if (info->column_order[3]) {
          F2 = Table_Index (sTable, i, info->column_order[3] - 1);
          F2 *= F2;
        } else if (info->column_order[4])
          F2 = Table_Index (sTable, i, info->column_order[4] - 1);

        list[J].h = h;
        list[J].k = k;
        list[J].l = l;
        list[J].F2 = F2;
        sum_F2 += F2;

        /* Precompute some values */
        list[J].tau_x = h * info->asx + k * info->bsx + l * info->csx;
        list[J].tau_y = h * info->asy + k * info->bsy + l * info->csy;
        list[J].tau_z = h * info->asz + k * info->bsz + l * info->csz;

        // create satellite peaks from e.g. surface truncation (CTR)
        if (surf_size > 1 && surf_FT2 && surf_k && surf_FT2[j] > 0 && surf_k[j]) {
          list[J].tau_x += surf_dir[0] * surf_k[j];
          list[J].tau_y += surf_dir[1] * surf_k[j];
          list[J].tau_z += surf_dir[2] * surf_k[j];
          list[J].F2 *= surf_FT2[j];
        }

        list[J].tau = sqrt (list[J].tau_x * list[J].tau_x + list[J].tau_y * list[J].tau_y + list[J].tau_z * list[J].tau_z);
        list[J].u1x = list[J].tau_x / list[J].tau;
        list[J].u1y = list[J].tau_y / list[J].tau;
        list[J].u1z = list[J].tau_z / list[J].tau;
        sig1 = FWHM2RMS * info->m_delta_d_d * list[J].tau;

        /* Find two arbitrary axes perpendicular to tau and each other. */
        normal_vec (&b1[0], &b1[1], &b1[2], list[J].u1x, list[J].u1y, list[J].u1z);
        vec_prod (b2[0], b2[1], b2[2], list[J].u1x, list[J].u1y, list[J].u1z, b1[0], b1[1], b1[2]);

        /* Find the two mosaic axes perpendicular to tau. */
        if (SC_mosaic > 0) {
          /* Use isotropic mosaic. */
          list[J].u2x = b1[0];
          list[J].u2y = b1[1];
          list[J].u2z = b1[2];
          sig2 = FWHM2RMS * list[J].tau * MIN2RAD * SC_mosaic;
          list[J].u3x = b2[0];
          list[J].u3y = b2[1];
          list[J].u3z = b2[2];
          sig3 = FWHM2RMS * list[J].tau * MIN2RAD * SC_mosaic;

        } else if (SC_mosaic_a > 0 && SC_mosaic_b > 0 && SC_mosaic_c > 0) {
          /* Use anisotropic mosaic. */
          MPI_MASTER (fprintf (stderr, "Single_crystal: WARNING: you are using an experimental feature:\n"
                                       "  anistropic mosaicity. Please examine your data carefully.\n"););
          /* compute the jacobian of (tau_v,tau_n) from rotations around the unit cell vectors. */
          struct hkl_data* l = &(list[J]);
          double xia_x, xia_y, xia_z, xib_x, xib_y, xib_z, xic_x, xic_y, xic_z;
          /*input parameters are in arc minutes*/
          double sig_fi_a = SC_mosaic_a * MIN2RAD;
          double sig_fi_b = SC_mosaic_b * MIN2RAD;
          double sig_fi_c = SC_mosaic_c * MIN2RAD;
          if (info->m_a == 0)
            info->m_a = sqrt (scalar_prod (info->m_ax, info->m_ay, info->m_az, info->m_ax, info->m_ay, info->m_az));
          if (info->m_b == 0)
            info->m_b = sqrt (scalar_prod (info->m_bx, info->m_by, info->m_bz, info->m_bx, info->m_by, info->m_bz));
          if (info->m_c == 0)
            info->m_c = sqrt (scalar_prod (info->m_cx, info->m_cy, info->m_cz, info->m_cx, info->m_cy, info->m_cz));

          l->u2x = b1[0];
          l->u2y = b1[1];
          l->u2z = b1[2];
          l->u3x = b2[0];
          l->u3y = b2[1];
          l->u3z = b2[2];

          xia_x = l->tau_x - (M_2_PI * h / info->m_a) * info->asx;
          xia_y = l->tau_y - (M_2_PI * h / info->m_a) * info->asy;
          xia_z = l->tau_z - (M_2_PI * h / info->m_a) * info->asz;
          xib_x = l->tau_x - (M_2_PI * h / info->m_b) * info->bsx;
          xib_y = l->tau_y - (M_2_PI * h / info->m_b) * info->bsy;
          xib_z = l->tau_z - (M_2_PI * h / info->m_b) * info->bsz;
          xic_x = l->tau_x - (M_2_PI * h / info->m_c) * info->csx;
          xic_y = l->tau_y - (M_2_PI * h / info->m_c) * info->csy;
          xic_z = l->tau_z - (M_2_PI * h / info->m_c) * info->csz;

          double xia = sqrt (xia_x * xia_x + xia_y * xia_y + xia_z * xia_z);
          double xib = sqrt (xib_x * xib_x + xib_y * xib_y + xib_z * xib_z);
          double xic = sqrt (xic_x * xic_x + xic_y * xic_y + xic_z * xic_z);

          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u2x, l->u2y, l->u2z);
          double J_n_fia = xia / info->m_a / l->tau * scalar_prod (info->asx, info->asy, info->asz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u2x, l->u2y, l->u2z);
          double J_n_fib = xib / info->m_b / l->tau * scalar_prod (info->bsx, info->bsy, info->bsz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u2x, l->u2y, l->u2z);
          double J_n_fic = xic / info->m_c / l->tau * scalar_prod (info->csx, info->csy, info->csz, tmp_x, tmp_y, tmp_z);

          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u3x, l->u3y, l->u3z);
          double J_v_fia = xia / info->m_a / l->tau * scalar_prod (info->asx, info->asy, info->asz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u3x, l->u3y, l->u3z);
          double J_v_fib = xib / info->m_b / l->tau * scalar_prod (info->bsx, info->bsy, info->bsz, tmp_x, tmp_y, tmp_z);
          vec_prod (tmp_x, tmp_y, tmp_z, l->tau_x, l->tau_y, l->tau_z, l->u3x, l->u3y, l->u3z);
          double J_v_fic = xic / info->m_c / l->tau * scalar_prod (info->csx, info->csy, info->csz, tmp_x, tmp_y, tmp_z);

          /*with the jacobian we can compute the sigmas in terms of the orthogonal vectors u2 and u3*/
          sig2 = sig_fi_a * fabs (J_v_fia) + sig_fi_b * fabs (J_v_fib) + sig_fi_c * fabs (J_v_fic);
          sig3 = sig_fi_a * fabs (J_n_fia) + sig_fi_b * fabs (J_n_fib) + sig_fi_c * fabs (J_n_fic);

        } else if (SC_mosaic_AB[0] != 0 && SC_mosaic_AB[1] != 0) {
          /* Use isotropic mosaic via mosaic matrix */
          if ((SC_mosaic_AB[2] == 0 && SC_mosaic_AB[3] == 0 && SC_mosaic_AB[4] == 0) || (SC_mosaic_AB[5] == 0 && SC_mosaic_AB[6] == 0 && SC_mosaic_AB[7] == 0)) {
            MPI_MASTER (fprintf (stderr,
                                 "Single_crystal: %s: ERROR: in-plane mosaics are specified but one (or both)\n"
                                 "  in-plane reciprocal vector is the zero vector.\n",
                                 info->compname););
            return (0);
          }
          MPI_MASTER (fprintf (stderr,
                               "Single_crystal: %s: WARNING: you are using an experimental feature: \n"
                               "  \"in-plane\" anistropic mosaicity. Please examine your data carefully.\n",
                               info->compname););

          /*for given reflection in list - compute linear comb of tau_a and tau_b*/
          /*check for not in plane - f.i. check if (tau_a X tau_b).tau_i)==0*/
          struct hkl_data* l = &(list[J]);
          double det, c1, c2, sig_tau_c;
          double em_x, em_y, em_z, tmp_x, tmp_y, tmp_z;
          double tau_a[3], tau_b[3];
          /*convert Miller indices to taus*/
          if (info->m_a == 0)
            info->m_a = sqrt (scalar_prod (info->m_ax, info->m_ay, info->m_az, info->m_ax, info->m_ay, info->m_az));
          if (info->m_b == 0)
            info->m_b = sqrt (scalar_prod (info->m_bx, info->m_by, info->m_bz, info->m_bx, info->m_by, info->m_bz));
          if (info->m_c == 0)
            info->m_c = sqrt (scalar_prod (info->m_cx, info->m_cy, info->m_cz, info->m_cx, info->m_cy, info->m_cz));
          tau_a[0] = M_2_PI * ((SC_mosaic_AB[2] / info->m_a) * info->asx + (SC_mosaic_AB[3] / info->m_b) * info->bsx + (SC_mosaic_AB[4] / info->m_c) * info->csx);
          tau_a[1] = M_2_PI * ((SC_mosaic_AB[2] / info->m_a) * info->asy + (SC_mosaic_AB[3] / info->m_b) * info->bsy + (SC_mosaic_AB[4] / info->m_c) * info->csy);
          tau_a[2] = M_2_PI * ((SC_mosaic_AB[2] / info->m_a) * info->asz + (SC_mosaic_AB[3] / info->m_b) * info->bsz + (SC_mosaic_AB[4] / info->m_c) * info->csz);
          tau_b[0] = M_2_PI * ((SC_mosaic_AB[5] / info->m_a) * info->asx + (SC_mosaic_AB[6] / info->m_b) * info->bsx + (SC_mosaic_AB[7] / info->m_c) * info->csx);
          tau_b[1] = M_2_PI * ((SC_mosaic_AB[5] / info->m_a) * info->asy + (SC_mosaic_AB[6] / info->m_b) * info->bsy + (SC_mosaic_AB[7] / info->m_c) * info->csy);
          tau_b[2] = M_2_PI * ((SC_mosaic_AB[5] / info->m_a) * info->asz + (SC_mosaic_AB[6] / info->m_b) * info->bsz + (SC_mosaic_AB[7] / info->m_c) * info->csz);

          /*check determinants to see how we should compute the linear combination of a and b (to match c)*/
	  c1 = c2 = 0;
          if ((det = tau_a[0] * tau_b[1] - tau_a[1] * tau_b[0]) != 0) {
            c1 = (l->tau_x * tau_b[1] - l->tau_y * tau_b[0]) / det;
            c2 = (tau_a[0] * l->tau_y - tau_a[1] * l->tau_x) / det;
          } else if ((det = tau_a[1] * tau_b[2] - tau_a[2] * tau_b[1]) != 0) {
            c1 = (l->tau_y * tau_b[2] - l->tau_z * tau_b[1]) / det;
            c2 = (tau_a[1] * l->tau_z - tau_a[2] * l->tau_y) / det;
          } else if ((det = tau_a[0] * tau_b[2] - tau_a[2] * tau_b[0]) != 0) {
            c1 = (l->tau_x * tau_b[2] - l->tau_z * tau_b[0]) / det;
            c2 = (tau_a[0] * l->tau_z - tau_a[2] * l->tau_x) / det;
          }
          if ((c1 == 0) && (c2 == 0)) {
            MPI_MASTER (fprintf (stderr,
                                 "Single_crystal: %s: WARNING: reflection tau[%i]=(%g %g %g) "
                                 "has no component in defined mosaic plane\n",
                                 info->compname, i, l->tau_x, l->tau_y, l->tau_z););
          }
          /*compute linear combination => sig_tau_i = | c1*sig_tau_a + c2*sig_tau_b |  - also add in the minute to radian scaling factor*/;
          sig_tau_c = MIN2RAD * sqrt (c1 * SC_mosaic_AB[0] * c1 * SC_mosaic_AB[0] + c2 * SC_mosaic_AB[1] * c2 * SC_mosaic_AB[1]);
          l->u2x = b1[0];
          l->u2y = b1[1];
          l->u2z = b1[2];
          l->u3x = b2[0];
          l->u3y = b2[1];
          l->u3z = b2[2];

          /*so now let's compute the rotation around planenormal tau_a X tau_b*/
          /*g_bar (unit normal of rotation plane) = tau_a X tau_b / norm(tau_a X tau_b)*/
          vec_prod (tmp_x, tmp_y, tmp_z, tau_a[0], tau_a[1], tau_a[2], tau_b[0], tau_b[1], tau_b[2]);
          vec_prod (em_x, em_y, em_z, l->tau_x, l->tau_y, l->tau_z, tmp_x, tmp_y, tmp_z);
          NORM (em_x, em_y, em_z);
          sig2 = l->tau * sig_tau_c * fabs (scalar_prod (em_x, em_y, em_z, l->u2x, l->u2y, l->u2z));
          sig3 = l->tau * sig_tau_c * fabs (scalar_prod (em_x, em_y, em_z, l->u3x, l->u3y, l->u3z));
          /*protect against collapsing gaussians. These seem to be sensible values.*/
          if (sig2 < 1e-5)
            sig2 = 1e-5;
          if (sig3 < 1e-5)
            sig3 = 1e-5;
        } /* end moisaic stuff */
        else {
          MPI_MASTER (fprintf (stderr,
                               "Single_crystal: %s: ERROR: EITHER mosaic OR (mosaic_a, mosaic_b, mosaic_c)\n"
                               "  must be given and be >0.\n",
                               info->compname););
          return (0);
        }

        list[J].sig123 = sig1 * sig2 * sig3;
        list[J].m1 = 1 / (2 * sig1 * sig1);
        list[J].m2 = 1 / (2 * sig2 * sig2);
        list[J].m3 = 1 / (2 * sig3 * sig3);
        /* Set Gauss cutoff to 5 times the maximal sigma. */
        if (sig1 > sig2)
          list[J].cutoff = 5 * (sig1 > sig3 ? sig1 : sig3);
        else
          list[J].cutoff = 5 * (sig2 > sig3 ? sig2 : sig3);

        if (!isnan (list[J].F2) && !isnan (list[J].cutoff) && !isnan (list[J].tau))
          J++; // switch to next HKL Bragg element in hkl_data

      } // for i, j
    Table_Free (&sTable);

    if (!sum_F2) {
      MPI_MASTER (exit (fprintf (stderr, "Single_crystal: %s: ERROR: all %i structure factors in file '%s' are null. Check the reflection list.\n",
                                 info->compname, i, SC_file)););
    }

    /* sort the list with increasing tau */
    qsort (list, J, sizeof (struct hkl_data), SX_list_compare);

    *hkl_list = list;
    info->count = J;

    return (info->count);
  } /* read_hkl_data */

  /* ------------------------------------------------------------------------ */
  /* hkl_search
    search the HKL reflections which are on the Ewald sphere
    input:
      L,T,count,V0: constants for all calls
      kix,kiy,kiz: may be different for each call
    this function returns:
      tau_count (return), coh_refl, coh_xsect, T (updated elements in the array up to [j])
   */
  #pragma acc routine
  int
  hkl_search (struct hkl_data* L, void* TT, int count, double V0, double kix, double kiy, double kiz, double tau_max, double* coh_refl, double* coh_xsect) {

    int i, j = 0;
    double ki = sqrt (kix * kix + kiy * kiy + kiz * kiz);
    struct tau_data* T = (struct tau_data*)TT;

    /* Common factor in coherent cross-section */
    double xsect_factor = pow (2 * PI, 5.0 / 2.0) / (V0 * ki * ki);
    for (i = 0; i < count; i++) {
      /* Assuming reflections are sorted, stop search when max tau exceeded. */
      double rho, rho_x, rho_y, rho_z;
      double diff;

      if (L[i].tau > tau_max)
        break; // passed max tau found in crystal reflections

      /* Check if this reciprocal lattice point is close enough to the
         Ewald sphere to make scattering possible. */
      rho_x = kix - L[i].tau_x; /* rho = |ki - tau| = |kf| = |ki| within cutoff on the Ewald sphere */
      rho_y = kiy - L[i].tau_y;
      rho_z = kiz - L[i].tau_z;
      rho = sqrt (rho_x * rho_x + rho_y * rho_y + rho_z * rho_z);
      diff = fabs (rho - ki);

      /* Check if scattering is possible (cutoff of Gaussian tails). */
      if (diff <= L[i].cutoff) {
        double ox, oy, oz;
        double b1x, b1y, b1z, b2x, b2y, b2z, kx, ky, kz, nx, ny, nz;
        double n11, n22, n12, det_N, inv_n11, inv_n22, inv_n12, l11, l22, l12, det_L;
        double Bt_D_O_x, Bt_D_O_y, y0x, y0y, alpha;
        /* Store reflection. */
        T[j].index = i;
        /* Get ki vector in local coordinates. */
        kx = kix * L[i].u1x + kiy * L[i].u1y + kiz * L[i].u1z;
        ky = kix * L[i].u2x + kiy * L[i].u2y + kiz * L[i].u2z;
        kz = kix * L[i].u3x + kiy * L[i].u3y + kiz * L[i].u3z;
        T[j].rho_x = kx - L[i].tau;
        T[j].rho_y = ky;
        T[j].rho_z = kz;
        T[j].rho = rho;
        /* Compute the tangent plane of the Ewald sphere. */
        nx = T[j].rho_x / T[j].rho;
        ny = T[j].rho_y / T[j].rho;
        nz = T[j].rho_z / T[j].rho;
        ox = (ki - T[j].rho) * nx;
        oy = (ki - T[j].rho) * ny;
        oz = (ki - T[j].rho) * nz;
        T[j].ox = ox;
        T[j].oy = oy;
        T[j].oz = oz;
        /* Compute unit vectors b1 and b2 that span the tangent plane. */
        normal_vec (&b1x, &b1y, &b1z, nx, ny, nz);
        vec_prod (b2x, b2y, b2z, nx, ny, nz, b1x, b1y, b1z);
        T[j].b1x = b1x;
        T[j].b1y = b1y;
        T[j].b1z = b1z;
        T[j].b2x = b2x;
        T[j].b2y = b2y;
        T[j].b2z = b2z;
        /* Compute the 2D projection of the 3D Gauss of the reflection. */
        /* The symmetric 2x2 matrix N describing the 2D gauss. */
        n11 = L[i].m1 * b1x * b1x + L[i].m2 * b1y * b1y + L[i].m3 * b1z * b1z;
        n12 = L[i].m1 * b1x * b2x + L[i].m2 * b1y * b2y + L[i].m3 * b1z * b2z;
        n22 = L[i].m1 * b2x * b2x + L[i].m2 * b2y * b2y + L[i].m3 * b2z * b2z;
        /* The (symmetric) inverse matrix of N. */
        det_N = n11 * n22 - n12 * n12;
        inv_n11 = n22 / det_N;
        inv_n12 = -n12 / det_N;
        inv_n22 = n11 / det_N;
        /* The Cholesky decomposition of 1/2*inv_n (lower triangular L). */
        l11 = sqrt (inv_n11 / 2);
        l12 = inv_n12 / (2 * l11);
        l22 = sqrt (inv_n22 / 2 - l12 * l12);
        T[j].l11 = l11;
        T[j].l12 = l12;
        T[j].l22 = l22;
        det_L = l11 * l22;
        /* The product B^T D o. */
        Bt_D_O_x = b1x * L[i].m1 * ox + b1y * L[i].m2 * oy + b1z * L[i].m3 * oz;
        Bt_D_O_y = b2x * L[i].m1 * ox + b2y * L[i].m2 * oy + b2z * L[i].m3 * oz;
        /* Center of 2D Gauss in plane coordinates. */
        y0x = -(Bt_D_O_x * inv_n11 + Bt_D_O_y * inv_n12);
        y0y = -(Bt_D_O_x * inv_n12 + Bt_D_O_y * inv_n22);
        T[j].y0x = y0x;
        T[j].y0y = y0y;
        /* Factor alpha for the distance of the 2D Gauss from the origin. */
        alpha = L[i].m1 * ox * ox + L[i].m2 * oy * oy + L[i].m3 * oz * oz - (y0x * y0x * n11 + y0y * y0y * n22 + 2 * y0x * y0y * n12);
        T[j].refl = xsect_factor * det_L * exp (-alpha) / L[i].sig123; /* intensity of that Bragg */
        *coh_refl += T[j].refl;                                        /* total scatterable intensity */
        T[j].xsect = T[j].refl * L[i].F2;
        *coh_xsect += T[j].xsect;
        j++;
      }
      /*protect against tau shortlist buffer overrrun*/
      if (j == MCSX_REFL_SLIST_SIZE) {
        break;
      }
    } /* end for */
    return (j); // this is 'tau_count', i.e. number of reachable reflections
  } /* end hkl_search */

  #pragma acc routine
  int
  hkl_select (struct tau_data* T, int tau_count, double coh_refl, double* sum, _class_particle* _particle) {
    int j;
    double r = rand0max (coh_refl);
    *sum = 0;
    for (j = 0; j < tau_count; j++) {
      *sum += T[j].refl;
      if (*sum > r)
        break;
    }
    return j;
  }

  /* Functions for "reorientation", powder mode */
  /* Powder, forward */
  #pragma acc routine
  void
  randrotate (double* nx, double* ny, double* nz, double a, double b, double c) {
    double x1, y1, z1, x2, y2, z2;
    rotate (x1, y1, z1, *nx, *ny, *nz, a, 1, 0, 0); /* <1> = rot(<n>,a) */
    rotate (x2, y2, z2, x1, y1, z1, b, 0, 1, 0);    /* <2> = rot(<1>,b) */
    rotate (*nx, *ny, *nz, x2, y2, z2, c, 0, 0, 1); /* <n> = rot(<2>,c) */
  }
  /* Powder, back */
  #pragma acc routine
  void
  randderotate (double* nx, double* ny, double* nz, double a, double b, double c) {
    double x1, y1, z1, x2, y2, z2;
    rotate (x1, y1, z1, *nx, *ny, *nz, -c, 0, 0, 1);
    rotate (x2, y2, z2, x1, y1, z1, -b, 0, 1, 0);
    rotate (*nx, *ny, *nz, x2, y2, z2, -a, 1, 0, 0);
  }

  #pragma acc routine
  /* rotate vector counterclockwise */
  void
  vec_rotate_2d (double* x, double* y, double angle) {
    double c, s;
    double newx, newy;

    c = cos (angle);
    s = sin (angle);

    newx = *x * c - *y * s;
    newy = *x * s + *y * c;

    *x = newx;
    *y = newy;
  }

  struct sx_abs_data {
    int muc; // column where mu is to be found
    double atomic_weight;
    double delta_prefactor;
    t_Table table;
  };

  int
  sx_read_abs_data (char* ABS_file, struct sx_abs_data* abs, struct hkl_info_struct info) {
    int status;
    char** parsing;
    double Z;

    if (ABS_file && strlen (ABS_file) && strcmp (ABS_file, "NULL") && strcmp (ABS_file, "0")) {
      if ((status = Table_Read (&(abs->table), ABS_file, 0)) == -1) {
        MPI_MASTER (fprintf (stderr, "Single_crystal: %s: ERROR: Could not parse file \"%s\"\n", info.compname, ABS_file););
        exit (-1);
      }
      abs->muc = (abs->table.columns == 3 ? 1 : 5);

      parsing = Table_ParseHeader (abs->table.header, "Z", "A[r]", "rho", NULL);
      if (parsing) {
        if (parsing[0])
          Z = strtol (parsing[0], NULL, 10);
        if (parsing[1] && !info.mat_weight)
          info.mat_weight = strtod (parsing[1], NULL); // aka A[r] in g/mol
        if (parsing[2] && !info.rho)
          info.rho = strtod (parsing[2], NULL);
      }

      if (info.rho && info.mat_weight)
        abs->delta_prefactor = NA * (info.rho * 1e-24) / info.mat_weight * 2.0 * M_PI * RE;

      abs->atomic_weight = info.mat_weight;

      return 1;
    } else {
      // init an empty table with absorption 0
      Table_Init (&(abs->table), 2, 2);
      abs->table.data[0] = 0;
      abs->table.data[1] = 0;
      abs->table.data[2] = FLT_MAX;
      abs->table.data[3] = 0;
      MPI_MASTER (fprintf (stderr, "Single_crystal: %s: WARNING: material file %s not found. Absorption set to 0.\n", info.compname, ABS_file));
      return 0;
    }
  } // sx_read_abs_data

  #endif /* !SINGLE_CRYSTAL_DECL */

/* Shared user declarations for all components types 'SAXSPDBFast'. */
  // for Open_File


  #include <gsl/gsl_sf_legendre.h>
  #include <gsl/gsl_sf_bessel.h>

  #ifndef SAXSPDB
  #define SAXSPDB
  #define SAXSPDBOrderOfHarmonics 21

  void**
  matrix2d_new (size_t esize, size_t idim, size_t jdim) {
    size_t const ptrs_size = sizeof (void*) * idim;
    size_t const row_size = esize * jdim;
    void** const rows = malloc (ptrs_size);
    for (size_t i = 0; i < idim; ++i)
      rows[i] = malloc (row_size);
    return rows;
  }
  // Simple mathematical functions
  int
  Sign (double x) {
    int Sign;

    if (x > 0) {
      Sign = 1;
    } else if (x < 0) {
      Sign = -1;
    } else {
      Sign = 0;
    }

    return Sign;
  }

  void
  complex_print_matrix (cdouble** Matrix, int N, int M) {
    int i, j;
    for (i = 0; i < N; ++i) {
      for (j = 0; j < M; ++j) {
        cdouble z = Matrix[i][j];
        fprintf (stderr, "(%.12e,%.12e)%s", creal (z), cimag (z), (j < M - 1) ? " " : "\n");
      }
    }
  }

  cdouble
  Polar (double R, double Concentration) {
    cdouble Polar;

    Polar = cplx (R * cos (Concentration), R * sin (Concentration));

    return Polar;
  }

  // Protein structs
  struct Bead {
    double x;
    double y;
    double z;

    double xv;
    double yv;
    double zv;

    double Volume;
    double ScatteringLength;
    char Atom;
  };
  typedef struct Bead BeadStruct;

  struct Protein {
    BeadStruct* Beads;
    int NumberOfResidues;
  };
  typedef struct Protein ProteinStruct;

  // functions for the INITIALIZE ----------------------------------------------

  // Function used to determine the number of residues in the .pdb-file
  int
  CountResidues (char* PDBFilepath) {
    // Declarations
    double Dummy1;
    double Dummy2;
    double Dummy3;
    char Line[65535];
    char DummyChar;
    char Atom;
    int NumberOfResidues = 0;
    int ResidueID;
    int PreviousResidueID = 0;
    FILE* PDBFile;

    // I/O
    PDBFile = Open_File (PDBFilepath, "r", NULL);
    if (PDBFile == NULL) {
      exit (fprintf (stderr, "SAXSPDBFast: %s: ERROR: Cannot open %s... \n", __FILE__, PDBFilepath));
    }

    while (fgets (Line, sizeof (Line), PDBFile) != NULL) {
      ResidueID = 0;
      if (strncmp (Line, "ATOM", 4))
        continue;
      if (sscanf (Line, "ATOM%*18c%d%*4c%lf%lf%lf", &ResidueID, &Dummy1, &Dummy2, &Dummy3) == 4) {
        if (ResidueID != PreviousResidueID && ResidueID != 0)
          ++NumberOfResidues;
        PreviousResidueID = ResidueID;
      }
    }
    fclose (PDBFile);
    return NumberOfResidues;
  } // CountResidues

  // Function used to read .pdb-file
  int
  ReadAminoPDB (char* PDBFilename, ProteinStruct* Protein) {
    // Declarations and input
    int NumberOfResidues = Protein->NumberOfResidues;
    BeadStruct* Residue = Protein->Beads;
    FILE* PDBFile;

    int i = 0;
    int PreviousResidueID = 0;
    int ResidueID = 0;

    double Weight = 0.0;
    double W = 0.0;

    double Aweight = 0.0;
    double A = 0.0;

    double x;
    double y;
    double z;

    double X = 0.0;
    double Y = 0.0;
    double Z = 0.0;

    double XA = 0.0;
    double YA = 0.0;
    double ZA = 0.0;

    char Atom;

    char Buffer[65535];
    char DummyChar;

    // Atomic weighing factors
    const double WH = 5.15;
    const double WC = 16.44;
    const double WN = 2.49;
    const double WO = 9.13;
    const double WS = 19.86;
    const double WP = 5.73;

    // Scattering lengths
    const double AH = 1 * 2.82e-13;
    const double AD = 1 * 2.82e-13;
    const double AC = 6 * 2.82e-13;
    const double AN = 7 * 2.82e-13;
    const double AO = 8 * 2.82e-13;
    const double AP = 15 * 2.82e-13;
    const double AS = 16 * 2.82e-13;

    // Program
    if (NumberOfResidues <= 0 || (PDBFile = Open_File (PDBFilename, "r", NULL)) == 0) {
      exit (printf ("ERROR: Cannot open file: %s. \n", PDBFilename));
    }

    while (fgets (Buffer, sizeof (Buffer), PDBFile) != NULL) {
      // a typical line is:
      // ATOM   8726  N   VAL B 576      76.450  47.214  58.026  1.00111.85           N
      Atom = 0;
      ResidueID = 0;
      if (strncmp (Buffer, "ATOM", 4))
        continue;
      if (!sscanf (Buffer, "ATOM%*9c%c%*8c%d%*4c%lf%lf%lf%*23c%c", &DummyChar, &ResidueID, &x, &y, &z, &Atom)) {
        fprintf (stderr, "SAXSPDBFast: %s: ReadAminoPDB: [%i] invalid PDB line %s\n", __FILE__, i, Buffer);
        continue;
      }

      if (ResidueID != PreviousResidueID && ResidueID != 0) {

        if (PreviousResidueID != 0 && Aweight && Weight) {

          // Assign center of scattering
          Residue[i].xv = X / Weight;
          Residue[i].yv = Y / Weight;
          Residue[i].zv = Z / Weight;

          // Assign center of mass
          Residue[i].x = XA / Aweight;
          Residue[i].y = YA / Aweight;
          Residue[i].z = ZA / Aweight;

          // Other residue attributes
          Residue[i].Volume = Weight;
          Residue[i].ScatteringLength = Aweight;
          Residue[i].Atom = Atom;

          X = Y = Z = Weight = 0.0;
          XA = YA = ZA = Aweight = 0.0;

          ++i;
        }

        PreviousResidueID = ResidueID;
      }

      // Finish the final amino acid
      if (i == NumberOfResidues - 1 && Aweight && Weight) {
        Residue[i].xv = X / Weight;
        Residue[i].yv = Y / Weight;
        Residue[i].zv = Z / Weight;

        // Assign center of mass
        Residue[i].x = XA / Aweight;
        Residue[i].y = YA / Aweight;
        Residue[i].z = ZA / Aweight;

        // Other residue attributes
        Residue[i].Volume = Weight;
        Residue[i].ScatteringLength = Aweight;
        Residue[i].Atom = 'X';
      }

      switch (Atom) {
      case 'C':
        A = AC;
        W = WC;
        break;

      case 'N':
        A = AN;
        W = WN;
        break;

      case 'O':
        A = AO;
        W = WO;
        break;

      case 'S':
        A = AS;
        W = WS;
        break;

      case 'H':
        A = AH;
        W = WH;
        break;

      case 'P':
        A = AP;
        W = WP;
        break;

      default:
        A = 0.0;
        W = 0.0;
      }

      Weight += W;
      Aweight += A;

      X += W * x;
      Y += W * y;
      Z += W * z;

      XA += A * x;
      YA += A * y;
      ZA += A * z;
    }

    fclose (PDBFile);

    return (NumberOfResidues);
  } // ReadAminoPDB\


  #endif /*SAXSPDB*/

/* Shared user declarations for all components types 'Fluorescence'. */

 // for OFF/PLY geometry

  #ifndef FLUORESCENCE_DECL
  #define FLUORESCENCE_DECL

  // WARNING: mush NOT use rand01 calls here, as they depend on _particle

  #define XRAYLIB_LINES_MAX 383
  #define FLUORESCENCE 0  // Fluo
  #define RAYLEIGH     1  // Coherent
  #define COMPTON      2  // Incoherent
  #define DIFFRACTION  3  // diffraction
  #define TRANSMISSION 4

  #include <xraylib/xraylib.h>
  
/* See XrayLib code (c) T. Schoonjans
 * /usr/include/xraylib/xraylib-parser.h      for compoundData
 * /usr/include/xraylib/xraylib.h             for XS
 */

/* inspired from:
 * https://github.com/golosio/xrmc src/photon/photon.cpp (c) Bruno Golosio    
 */
  
  /* XRMC_CrossSections: Compute interaction cross sections in [barn/atom]
   * When kissel=1, M-lines are computed, but computation is 10x slower.
   * Computes xs[FLUORESCENCE,RAYLEIGH,COMPTON] that must have been allocated.
   * Return total cross section, given Z and E0:
   *   total_xs = XRMC_CrossSections(Z, E0, xs[3], flag_kissel);
   */
  double XRMC_CrossSections(int Z, double E0, double *xs, int kissel) {
    int    i_line;
    
    if (xs == NULL) return 0;
    for(i_line=0; i_line<=COMPTON; i_line++) xs[i_line]=0;
    
    // loop on possible fluorescence lines
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { 
      // cumulative sum of the line cross sections
      xs[FLUORESCENCE] += kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
    }

    // coherent and incoherent cross sections
    xs[RAYLEIGH] = CSb_Rayl( Z, E0, NULL);
    xs[COMPTON]  = CSb_Compt(Z, E0, NULL);
    
    // total interaction cross section, should converge to CSb_Total(Z, E0, NULL)
    return xs[FLUORESCENCE] + xs[RAYLEIGH] + xs[COMPTON];
  } // XRMC_CrossSections

  /* XRMC_SelectFromDistribution: select a random element from a distribution
   *   index = XRMC_SelectFromDistribution(cum_sum[N], N);
   * index is returned within 0 and N-1
   * The x_arr must be a continuously increasing cumulated sum, which last element is the max.
   */
  int XRMC_SelectFromDistribution(double x_arr[], int N, double r)
  {
    if (x_arr == NULL || N <=0) return (0);
    double x = r*x_arr[N-1]; // the threshold cumulated value to search in distribution
    if (x<x_arr[0]) {    // x is smaller than lower limit
      return 0;
    }
    if (x>=x_arr[N-1]) { // x is greater or equal to upper limit
      return N-1;
    }
    int id=0, iu=N-1; // lower and upper index of the subarray to search
    while (iu-id>1) { // search until the size of the subarray to search is >1
      int im = (id + iu)/2; // use the midpoint for equal partition
      // decide which subarray to search
      if (x>=x_arr[im]) id=im; // change min index to search upper subarray
      else iu=im; // change max index to search lower subarray
    }

    return id;
  } // XRMC_SelectFromDistribution

  /* XRMC_SelectInteraction: select interaction type Fluo/Compton/Rayleigh
   * Return the interaction type from a random choice within cross sections 'xs'
   *   type = XRMC_SelectInteraction(xs[3], 3);
   * 'xs' is computed with XRMC_CrossSections. Can be unsorted.
   * type is e.g. one of FLUORESCENCE | RAYLEIGH | COMPTON
   */
  int XRMC_SelectInteraction(double *xs, int nb_processes, double r)
  {
    double sum_xs, *cum_xs;
    int    i;

    if (xs == NULL || nb_processes < 1) return 0;
    cum_xs = malloc((nb_processes+1)*sizeof(double));
    if (!cum_xs)          return 0;
    cum_xs[0]=sum_xs=0;
    for (i=0; i< nb_processes; i++) {
      sum_xs += xs[i];
      cum_xs[i+1]= sum_xs;
    }
    i = XRMC_SelectFromDistribution(cum_xs, nb_processes+1, r);
    free(cum_xs);
    return i;
  } // XRMC_SelectInteraction

  /* XRMC_SelectFluorescenceEnergy: select outgoing fluo photon energy, when incoming with 'E0'
   * When kissel=1, M-lines are included, but computation is 10x slower
   *   Ef = XRMC_SelectFluorescenceEnergy(Z, E0, &dE, kissel);
   */
  double XRMC_SelectFluorescenceEnergy(int Z, double E0, double *dE, int kissel, double r)
  {
    int i_line;
    double sum_xs, cum_xs_lines[XRAYLIB_LINES_MAX+1];

    // compute cumulated XS for all fluo lines
    cum_xs_lines[0] = sum_xs = 0;
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { // loop on fluorescent lines
      double xs = kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
      // when a line is inactive: E=xs=0
      sum_xs += xs;
      cum_xs_lines[i_line+1] = sum_xs; // cumulative sum of their cross sections
    }
    // select randomly one of these lines
    i_line = XRMC_SelectFromDistribution(cum_xs_lines, XRAYLIB_LINES_MAX, r); // extract a line
    // get the K shell line width as approximation of fluorescence line width
    if (dE) *dE = AtomicLevelWidth(Z, K_SHELL, NULL); // keV, full-width in keV

    return LineEnergy(Z, -i_line, NULL); // fluorescent line energy
  } // XRMC_SelectFluorescenceEnergy

  // Function removing spaces from string
  char * removeSpacesFromStr(char *string)
  {
      // non_space_count to keep the frequency of non space characters
      int non_space_count = 0;
      if (string == NULL) return NULL;
   
      //Traverse a string and if it is non space character then, place it at index non_space_count
      for (int i = 0; string[i] != '\0'; i++)
      {
          if (isalpha(string[i]) || isdigit(string[i]))
          {
              string[non_space_count] = string[i];
              non_space_count++; //non_space_count incremented
          }    
      }
      
      //Finally placing final character at the string end
      string[non_space_count] = '\0';
      return string;
  }

  // ok = fluo_get_material(material, formula)
  // extracts material atoms from file header
  // the result is concatenated into 'formula'
  int fluo_get_material(char *filename, char *formula) {
  
    int  ret = 0;
    char Line[65535];
    int  flag_found_cif=0;
    if (filename == NULL || formula == NULL) return (0);
    FILE *file = Open_File(filename, "r", NULL);
    if (!file)
      exit(fprintf(stderr, "%s: ERROR: can not open file %s\n", 
      __FILE__, filename));
    
    // Read the file, and search tokens in rows
    formula[0]=0;
    while (fgets(Line, sizeof(Line), file) != NULL) {
      char *token = NULL;
      int   flag_exit=0;
      char *first_non_space=NULL;
      char *next_non_space =NULL;
      // CIF: _chemical_formula_structural 'chemical_formulae'
      // CIF: _chemical_formula_sum 'chemical_formulae'
      // LAZ/LAU: # ATOM <at> <trailing>
      // LAZ/LAU: # Atom <at> <trailing>
      // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
      // CFL: Title <chemical_formulae>
      // CFL: Atom <at> <trailing>
      
      // search for CIF token
      // single line: search " '\'" delimiter after CIF token, marks reading the formula
      if (!strncasecmp(Line, "_chemical_formula_structural", 28) 
       || !strncasecmp(Line, "_chemical_formula_sum", 21) 
       || !strncasecmp(Line, "_chemical_formula_moiety", 24)
       || flag_found_cif) {
        if  (flag_found_cif) { flag_found_cif=0; /* can not span on more that 2 lines */} 
        else flag_found_cif=1;
        // search for delimiter after the CIF token
        char *first_space_after_token=strpbrk(Line, " \'\n");
        if (first_space_after_token) {
          // search for the characters that may compose the formula
          first_non_space = strpbrk(first_space_after_token, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()[]");
          if (strchr(first_space_after_token,'?')) {
            // we have an invalid/unknown formula in the CIF. Skip CIF token/line
            flag_found_cif=0;
            continue;
          }
        }
        if (first_non_space) 
          next_non_space  = strpbrk(first_non_space+1, "\'\n\r"); // position of formula end
        if (next_non_space) { 
          flag_exit = 1;
          token = first_non_space;
        }
      } else if (!strncasecmp(Line, "# TITLE", 7) && strchr(Line, '['))
        token = Line+7;
      else if (!strncasecmp(Line, "# Atom", 6))
        token = Line+6;
      else if (!strncasecmp(Line, "Atom", 4))
        token = Line+4;
      else if (!strncasecmp(Line, "Title", 5))
        token = Line+7;
      if (!token) continue;
      if (!strncasecmp(Line, "# TITLE", 7)) {
        first_non_space = Line+7;
        next_non_space  = strchr(Line+7, '[');
        if (next_non_space) flag_exit = 1;
      }
      if (!first_non_space) first_non_space = strtok(token, " \t\n");
      if (!first_non_space) continue;
      if (!next_non_space)  next_non_space  = strtok(NULL,  " \t\n"); // end of formulae
      if (!next_non_space)  next_non_space = Line+strlen(Line);
      // remove spaces
      strncat(formula, first_non_space, next_non_space-first_non_space);
      ret++;
      if (flag_exit) break;
    }
    fclose(file);
    removeSpacesFromStr(formula);
    return(ret);
  } // fluo_get_material
  
  #endif // FLUORESCENCE_DECL

/* Shared user declarations for all components types 'Filter'. */



  #ifndef SHAPES_T
  #define SHAPES_T
  enum shapes_t { NONE = -1, SPHERE, CYLINDER, CUBE, ELLIPSOID, ANY };
  #endif

  #pragma acc routine
  int
  filter_refract (double* kx, double* ky, double* kz, double nx, double ny, double nz, double delta0, double delta1) {
    const double n2 = scalar_prod (nx, ny, nz, nx, ny, nz);
    const double k = sqrt (scalar_prod (*kx, *ky, *kz, *kx, *ky, *kz));
    const double nr = (1.0 - delta0) / (1.0 - delta1);
    double kxi = *kx;
    double kyi = *ky;
    double kzi = *kz;
    double s;

    NORM (kxi, kyi, kzi);
    if (n2 != 1) {
      NORM (nx, ny, nz);
    }
    // kinv=1.0/sqrt(k2);
    s = scalar_prod (nx, ny, nz, kxi, kyi, kzi);
    if (s > 0) {
      /*n points in the direction of k - i.e. into material 1, so use -n instead*/
      double sinth2 = nr * nr * (1.0 - (s) * (s));
      *kx = nr * (kxi) - (nr * (-s) + sqrt (1.0 - sinth2)) * (-nx);
      *ky = nr * (kyi) - (nr * (-s) + sqrt (1.0 - sinth2)) * (-ny);
      *kz = nr * (kzi) - (nr * (-s) + sqrt (1.0 - sinth2)) * (-nz);
    } else {
      /*n points oppsite to k - i.e. out of material 1, into mat. 0*/
      double sinth2 = nr * nr * (1.0 - s * s);
      *kx = nr * (kxi) - (nr * s + sqrt (1.0 - sinth2)) * nx;
      *ky = nr * (kyi) - (nr * s + sqrt (1.0 - sinth2)) * ny;
      *kz = nr * (kzi) - (nr * s + sqrt (1.0 - sinth2)) * nz;
    }
    *kx *= k;
    *ky *= k;
    *kz *= k;
    return 1;
  }

/* Shared user declarations for all components types 'PSD_monitor_coh'. */


/* Shared user declarations for all components types 'Fluo_detector'. */

 // for OFF/PLY geometry

  #ifndef FLUORESCENCE_DECL
  #define FLUORESCENCE_DECL

  // WARNING: mush NOT use rand01 calls here, as they depend on _particle

  #define XRAYLIB_LINES_MAX 383
  #define FLUORESCENCE 0  // Fluo
  #define RAYLEIGH     1  // Coherent
  #define COMPTON      2  // Incoherent
  #define DIFFRACTION  3  // diffraction
  #define TRANSMISSION 4

  #include <xraylib/xraylib.h>
  
/* See XrayLib code (c) T. Schoonjans
 * /usr/include/xraylib/xraylib-parser.h      for compoundData
 * /usr/include/xraylib/xraylib.h             for XS
 */

/* inspired from:
 * https://github.com/golosio/xrmc src/photon/photon.cpp (c) Bruno Golosio    
 */
  
  /* XRMC_CrossSections: Compute interaction cross sections in [barn/atom]
   * When kissel=1, M-lines are computed, but computation is 10x slower.
   * Computes xs[FLUORESCENCE,RAYLEIGH,COMPTON] that must have been allocated.
   * Return total cross section, given Z and E0:
   *   total_xs = XRMC_CrossSections(Z, E0, xs[3], flag_kissel);
   */
  double XRMC_CrossSections(int Z, double E0, double *xs, int kissel) {
    int    i_line;
    
    if (xs == NULL) return 0;
    for(i_line=0; i_line<=COMPTON; i_line++) xs[i_line]=0;
    
    // loop on possible fluorescence lines
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { 
      // cumulative sum of the line cross sections
      xs[FLUORESCENCE] += kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
    }

    // coherent and incoherent cross sections
    xs[RAYLEIGH] = CSb_Rayl( Z, E0, NULL);
    xs[COMPTON]  = CSb_Compt(Z, E0, NULL);
    
    // total interaction cross section, should converge to CSb_Total(Z, E0, NULL)
    return xs[FLUORESCENCE] + xs[RAYLEIGH] + xs[COMPTON];
  } // XRMC_CrossSections

  /* XRMC_SelectFromDistribution: select a random element from a distribution
   *   index = XRMC_SelectFromDistribution(cum_sum[N], N);
   * index is returned within 0 and N-1
   * The x_arr must be a continuously increasing cumulated sum, which last element is the max.
   */
  int XRMC_SelectFromDistribution(double x_arr[], int N, double r)
  {
    if (x_arr == NULL || N <=0) return (0);
    double x = r*x_arr[N-1]; // the threshold cumulated value to search in distribution
    if (x<x_arr[0]) {    // x is smaller than lower limit
      return 0;
    }
    if (x>=x_arr[N-1]) { // x is greater or equal to upper limit
      return N-1;
    }
    int id=0, iu=N-1; // lower and upper index of the subarray to search
    while (iu-id>1) { // search until the size of the subarray to search is >1
      int im = (id + iu)/2; // use the midpoint for equal partition
      // decide which subarray to search
      if (x>=x_arr[im]) id=im; // change min index to search upper subarray
      else iu=im; // change max index to search lower subarray
    }

    return id;
  } // XRMC_SelectFromDistribution

  /* XRMC_SelectInteraction: select interaction type Fluo/Compton/Rayleigh
   * Return the interaction type from a random choice within cross sections 'xs'
   *   type = XRMC_SelectInteraction(xs[3], 3);
   * 'xs' is computed with XRMC_CrossSections. Can be unsorted.
   * type is e.g. one of FLUORESCENCE | RAYLEIGH | COMPTON
   */
  int XRMC_SelectInteraction(double *xs, int nb_processes, double r)
  {
    double sum_xs, *cum_xs;
    int    i;

    if (xs == NULL || nb_processes < 1) return 0;
    cum_xs = malloc((nb_processes+1)*sizeof(double));
    if (!cum_xs)          return 0;
    cum_xs[0]=sum_xs=0;
    for (i=0; i< nb_processes; i++) {
      sum_xs += xs[i];
      cum_xs[i+1]= sum_xs;
    }
    i = XRMC_SelectFromDistribution(cum_xs, nb_processes+1, r);
    free(cum_xs);
    return i;
  } // XRMC_SelectInteraction

  /* XRMC_SelectFluorescenceEnergy: select outgoing fluo photon energy, when incoming with 'E0'
   * When kissel=1, M-lines are included, but computation is 10x slower
   *   Ef = XRMC_SelectFluorescenceEnergy(Z, E0, &dE, kissel);
   */
  double XRMC_SelectFluorescenceEnergy(int Z, double E0, double *dE, int kissel, double r)
  {
    int i_line;
    double sum_xs, cum_xs_lines[XRAYLIB_LINES_MAX+1];

    // compute cumulated XS for all fluo lines
    cum_xs_lines[0] = sum_xs = 0;
    for (i_line=0; i_line<XRAYLIB_LINES_MAX; i_line++) { // loop on fluorescent lines
      double xs = kissel && Z >= 50 ?
        CSb_FluorLine_Kissel(Z, -i_line, E0, NULL) /* XRayLib lines are negative integers */
      : CSb_FluorLine(Z, -i_line, E0, NULL);
      // when a line is inactive: E=xs=0
      sum_xs += xs;
      cum_xs_lines[i_line+1] = sum_xs; // cumulative sum of their cross sections
    }
    // select randomly one of these lines
    i_line = XRMC_SelectFromDistribution(cum_xs_lines, XRAYLIB_LINES_MAX, r); // extract a line
    // get the K shell line width as approximation of fluorescence line width
    if (dE) *dE = AtomicLevelWidth(Z, K_SHELL, NULL); // keV, full-width in keV

    return LineEnergy(Z, -i_line, NULL); // fluorescent line energy
  } // XRMC_SelectFluorescenceEnergy

  // Function removing spaces from string
  char * removeSpacesFromStr(char *string)
  {
      // non_space_count to keep the frequency of non space characters
      int non_space_count = 0;
      if (string == NULL) return NULL;
   
      //Traverse a string and if it is non space character then, place it at index non_space_count
      for (int i = 0; string[i] != '\0'; i++)
      {
          if (isalpha(string[i]) || isdigit(string[i]))
          {
              string[non_space_count] = string[i];
              non_space_count++; //non_space_count incremented
          }    
      }
      
      //Finally placing final character at the string end
      string[non_space_count] = '\0';
      return string;
  }

  // ok = fluo_get_material(material, formula)
  // extracts material atoms from file header
  // the result is concatenated into 'formula'
  int fluo_get_material(char *filename, char *formula) {
  
    int  ret = 0;
    char Line[65535];
    int  flag_found_cif=0;
    if (filename == NULL || formula == NULL) return (0);
    FILE *file = Open_File(filename, "r", NULL);
    if (!file)
      exit(fprintf(stderr, "%s: ERROR: can not open file %s\n", 
      __FILE__, filename));
    
    // Read the file, and search tokens in rows
    formula[0]=0;
    while (fgets(Line, sizeof(Line), file) != NULL) {
      char *token = NULL;
      int   flag_exit=0;
      char *first_non_space=NULL;
      char *next_non_space =NULL;
      // CIF: _chemical_formula_structural 'chemical_formulae'
      // CIF: _chemical_formula_sum 'chemical_formulae'
      // LAZ/LAU: # ATOM <at> <trailing>
      // LAZ/LAU: # Atom <at> <trailing>
      // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
      // CFL: Title <chemical_formulae>
      // CFL: Atom <at> <trailing>
      
      // search for CIF token
      // single line: search " '\'" delimiter after CIF token, marks reading the formula
      if (!strncasecmp(Line, "_chemical_formula_structural", 28) 
       || !strncasecmp(Line, "_chemical_formula_sum", 21) 
       || !strncasecmp(Line, "_chemical_formula_moiety", 24)
       || flag_found_cif) {
        if  (flag_found_cif) { flag_found_cif=0; /* can not span on more that 2 lines */} 
        else flag_found_cif=1;
        // search for delimiter after the CIF token
        char *first_space_after_token=strpbrk(Line, " \'\n");
        if (first_space_after_token) {
          // search for the characters that may compose the formula
          first_non_space = strpbrk(first_space_after_token, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()[]");
          if (strchr(first_space_after_token,'?')) {
            // we have an invalid/unknown formula in the CIF. Skip CIF token/line
            flag_found_cif=0;
            continue;
          }
        }
        if (first_non_space) 
          next_non_space  = strpbrk(first_non_space+1, "\'\n\r"); // position of formula end
        if (next_non_space) { 
          flag_exit = 1;
          token = first_non_space;
        }
      } else if (!strncasecmp(Line, "# TITLE", 7) && strchr(Line, '['))
        token = Line+7;
      else if (!strncasecmp(Line, "# Atom", 6))
        token = Line+6;
      else if (!strncasecmp(Line, "Atom", 4))
        token = Line+4;
      else if (!strncasecmp(Line, "Title", 5))
        token = Line+7;
      if (!token) continue;
      if (!strncasecmp(Line, "# TITLE", 7)) {
        first_non_space = Line+7;
        next_non_space  = strchr(Line+7, '[');
        if (next_non_space) flag_exit = 1;
      }
      if (!first_non_space) first_non_space = strtok(token, " \t\n");
      if (!first_non_space) continue;
      if (!next_non_space)  next_non_space  = strtok(NULL,  " \t\n"); // end of formulae
      if (!next_non_space)  next_non_space = Line+strlen(Line);
      // remove spaces
      strncat(formula, first_non_space, next_non_space-first_non_space);
      ret++;
      if (flag_exit) break;
    }
    fclose(file);
    removeSpacesFromStr(formula);
    return(ret);
  } // fluo_get_material
  
  #endif // FLUORESCENCE_DECL
#ifndef FLUO_DETECTOR
#define FLUO_DETECTOR

#define SDD_ESCAPE 5 // Detector escape      peak fluorescence
#define SDD_PILEUP 6 // Detector pile-up/sum peak fluorescence
#endif

/* Shared user declarations for all components types 'Shape'. */





/* ************************************************************************** */
/*             End of SHARE user declarations for all components              */
/* ************************************************************************** */


/* ********************** component definition declarations. **************** */

/* component origin=Arm() [1] DECLARE */
/* Parameter definition for component type 'Arm' */
struct _struct_Arm_parameters {
  char Arm_has_no_parameters;
}; /* _struct_Arm_parameters */
typedef struct _struct_Arm_parameters _class_Arm_parameters;

/* Parameters for component type 'Arm' */
struct _struct_Arm {
  char     _name[256]; /* e.g. origin */
  char     _type[256]; /* Arm */
  long     _index; /* e.g. 1 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Arm_parameters _parameters;
};
typedef struct _struct_Arm _class_Arm;
_class_Arm _origin_var;
#pragma acc declare create ( _origin_var )

_class_Arm _jumper_var;
#pragma acc declare create ( _jumper_var )

/* component beamdump=Beamstop() [3] DECLARE */
/* Parameter definition for component type 'Beamstop' */
struct _struct_Beamstop_parameters {
  /* Component type 'Beamstop' setting parameters */
  MCNUM xmin;
  MCNUM xmax;
  MCNUM ymin;
  MCNUM ymax;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM radius;
}; /* _struct_Beamstop_parameters */
typedef struct _struct_Beamstop_parameters _class_Beamstop_parameters;

/* Parameters for component type 'Beamstop' */
struct _struct_Beamstop {
  char     _name[256]; /* e.g. beamdump */
  char     _type[256]; /* Beamstop */
  long     _index; /* e.g. 3 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Beamstop_parameters _parameters;
};
typedef struct _struct_Beamstop _class_Beamstop;
_class_Beamstop _beamdump_var;
#pragma acc declare create ( _beamdump_var )

/* component ODE_pos=Text() [4] DECLARE */
/* Parameter definition for component type 'Text' */
struct _struct_Text_parameters {
  /* Component type 'Text' setting parameters */
  char text[16384];
  MCNUM size;
  char plane[16384];
  MCNUM pen_thickness;
  /* Component type 'Text' private parameters */
  int  pl;
}; /* _struct_Text_parameters */
typedef struct _struct_Text_parameters _class_Text_parameters;

/* Parameters for component type 'Text' */
struct _struct_Text {
  char     _name[256]; /* e.g. ODE_pos */
  char     _type[256]; /* Text */
  long     _index; /* e.g. 4 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Text_parameters _parameters;
};
typedef struct _struct_Text _class_Text;
_class_Text _ODE_pos_var;
#pragma acc declare create ( _ODE_pos_var )

_class_Text _SMIS_pos_var;
#pragma acc declare create ( _SMIS_pos_var )

_class_Text _AILES_pos_var;
#pragma acc declare create ( _AILES_pos_var )

_class_Text _MARS_pos_var;
#pragma acc declare create ( _MARS_pos_var )

_class_Arm _MARS_var;
#pragma acc declare create ( _MARS_var )

/* component MARS_Source=Bending_magnet() [9] DECLARE */
/* Parameter definition for component type 'Bending_magnet' */
struct _struct_Bending_magnet_parameters {
  /* Component type 'Bending_magnet' setting parameters */
  MCNUM E0;
  MCNUM dE;
  MCNUM lambda0;
  MCNUM dlambda;
  MCNUM phase;
  MCNUM randomphase;
  MCNUM Ee;
  MCNUM Ie;
  MCNUM B;
  MCNUM sigey;
  MCNUM sigex;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM dist;
  MCNUM gauss_t;
  /* Component type 'Bending_magnet' private parameters */
  double  gamma;
  double  gamma2;
  double  igamma;
  double  kc;
  double  s1x;
  double  s1y;
  double  p0;
}; /* _struct_Bending_magnet_parameters */
typedef struct _struct_Bending_magnet_parameters _class_Bending_magnet_parameters;

/* Parameters for component type 'Bending_magnet' */
struct _struct_Bending_magnet {
  char     _name[256]; /* e.g. MARS_Source */
  char     _type[256]; /* Bending_magnet */
  long     _index; /* e.g. 9 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Bending_magnet_parameters _parameters;
};
typedef struct _struct_Bending_magnet _class_Bending_magnet;
_class_Bending_magnet _MARS_Source_var;
#pragma acc declare create ( _MARS_Source_var )

/* component MARS_displaySourceLength=Monitor_nD() [10] DECLARE */
/* Parameter definition for component type 'Monitor_nD' */
struct _struct_Monitor_nD_parameters {
  /* Component type 'Monitor_nD' setting parameters */
  char user0[16384];
  char user1[16384];
  char user2[16384];
  char user3[16384];
  char user4[16384];
  char user5[16384];
  char user6[16384];
  char user7[16384];
  char user8[16384];
  char user9[16384];
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  int bins;
  MCNUM min;
  MCNUM max;
  MCNUM restore_xray;
  MCNUM radius;
  char options[16384];
  char filename[16384];
  char geometry[16384];
  int nowritefile;
  char username0[16384];
  char username1[16384];
  char username2[16384];
  char username3[16384];
  char username4[16384];
  char username5[16384];
  char username6[16384];
  char username7[16384];
  char username8[16384];
  char username9[16384];
  /* Component type 'Monitor_nD' private parameters */
  MonitornD_Defines_type  DEFS;
  MonitornD_Variables_type  Vars;
  MCDETECTOR  detector;
  off_struct  offdata;
}; /* _struct_Monitor_nD_parameters */
typedef struct _struct_Monitor_nD_parameters _class_Monitor_nD_parameters;

/* Parameters for component type 'Monitor_nD' */
struct _struct_Monitor_nD {
  char     _name[256]; /* e.g. MARS_displaySourceLength */
  char     _type[256]; /* Monitor_nD */
  long     _index; /* e.g. 10 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Monitor_nD_parameters _parameters;
};
typedef struct _struct_Monitor_nD _class_Monitor_nD;
_class_Monitor_nD _MARS_displaySourceLength_var;
#pragma acc declare create ( _MARS_displaySourceLength_var )

/* component MARS_displaySource=PSD_monitor() [11] DECLARE */
/* Parameter definition for component type 'PSD_monitor' */
struct _struct_PSD_monitor_parameters {
  /* Component type 'PSD_monitor' setting parameters */
  char filename[16384];
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM radius;
  MCNUM restore_xray;
  int nowritefile;
  int nx;
  int ny;
  int nr;
  /* Component type 'PSD_monitor' private parameters */
  DArray2d  PSD_N;
  DArray2d  PSD_p;
  DArray2d  PSD_p2;
  double  xmin;
  double  xmax;
  double  ymin;
  double  ymax;
}; /* _struct_PSD_monitor_parameters */
typedef struct _struct_PSD_monitor_parameters _class_PSD_monitor_parameters;

/* Parameters for component type 'PSD_monitor' */
struct _struct_PSD_monitor {
  char     _name[256]; /* e.g. MARS_displaySource */
  char     _type[256]; /* PSD_monitor */
  long     _index; /* e.g. 11 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_PSD_monitor_parameters _parameters;
};
typedef struct _struct_PSD_monitor _class_PSD_monitor;
_class_PSD_monitor _MARS_displaySource_var;
#pragma acc declare create ( _MARS_displaySource_var )

/* component MARS_slit1=Slit() [12] DECLARE */
/* Parameter definition for component type 'Slit' */
struct _struct_Slit_parameters {
  /* Component type 'Slit' setting parameters */
  MCNUM xmin;
  MCNUM xmax;
  MCNUM ymin;
  MCNUM ymax;
  MCNUM radius;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM dist;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM focus_x0;
  MCNUM focus_y0;
}; /* _struct_Slit_parameters */
typedef struct _struct_Slit_parameters _class_Slit_parameters;

/* Parameters for component type 'Slit' */
struct _struct_Slit {
  char     _name[256]; /* e.g. MARS_slit1 */
  char     _type[256]; /* Slit */
  long     _index; /* e.g. 12 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Slit_parameters _parameters;
};
typedef struct _struct_Slit _class_Slit;
_class_Slit _MARS_slit1_var;
#pragma acc declare create ( _MARS_slit1_var )

_class_Slit _MARS_slit2_var;
#pragma acc declare create ( _MARS_slit2_var )

_class_Arm _MARS_M1_arm_translation_var;
#pragma acc declare create ( _MARS_M1_arm_translation_var )

_class_Arm _MARS_M1_arm_rotation_1_var;
#pragma acc declare create ( _MARS_M1_arm_rotation_1_var )

/* component MARS_mirror_M1=Mirror_curved() [16] DECLARE */
/* Parameter definition for component type 'Mirror_curved' */
struct _struct_Mirror_curved_parameters {
  /* Component type 'Mirror_curved' setting parameters */
  MCNUM radius;
  MCNUM R0;
  char coating[16384];
  MCNUM zdepth;
  MCNUM yheight;
  MCNUM length;
  MCNUM width;
  /* Component type 'Mirror_curved' private parameters */
  int  Z;
  double  At;
  double  rho;
  t_Table  T;
  t_Reflec  re;
}; /* _struct_Mirror_curved_parameters */
typedef struct _struct_Mirror_curved_parameters _class_Mirror_curved_parameters;

/* Parameters for component type 'Mirror_curved' */
struct _struct_Mirror_curved {
  char     _name[256]; /* e.g. MARS_mirror_M1 */
  char     _type[256]; /* Mirror_curved */
  long     _index; /* e.g. 16 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Mirror_curved_parameters _parameters;
};
typedef struct _struct_Mirror_curved _class_Mirror_curved;
_class_Mirror_curved _MARS_mirror_M1_var;
#pragma acc declare create ( _MARS_mirror_M1_var )

_class_Arm _MARS_M1_arm_rotation_2_var;
#pragma acc declare create ( _MARS_M1_arm_rotation_2_var )

_class_Arm _MARS_M1_arm_rotation_2_undo_var;
#pragma acc declare create ( _MARS_M1_arm_rotation_2_undo_var )

_class_Arm _MARS_beam_arm_before_crystal_var;
#pragma acc declare create ( _MARS_beam_arm_before_crystal_var )

/* component MARS_dcm_xtal0=Bragg_crystal() [20] DECLARE */
/* Parameter definition for component type 'Bragg_crystal' */
struct _struct_Bragg_crystal_parameters {
  /* Component type 'Bragg_crystal' setting parameters */
  MCNUM length;
  MCNUM width;
  MCNUM V;
  char form_factors[16384];
  char material[16384];
  MCNUM alpha;
  MCNUM R0;
  MCNUM debye_waller_B;
  int crystal_type;
  int h;
  int k;
  int l;
  MCNUM structure_factor_scale_r;
  MCNUM structure_factor_scale_i;
  /* Component type 'Bragg_crystal' private parameters */
  int  Z;
  double  rho;
  double  At;
  double  f_rel;
  double  f_nt;
  t_Table  m_t;
  t_Table  f0_t;
}; /* _struct_Bragg_crystal_parameters */
typedef struct _struct_Bragg_crystal_parameters _class_Bragg_crystal_parameters;

/* Parameters for component type 'Bragg_crystal' */
struct _struct_Bragg_crystal {
  char     _name[256]; /* e.g. MARS_dcm_xtal0 */
  char     _type[256]; /* Bragg_crystal */
  long     _index; /* e.g. 20 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Bragg_crystal_parameters _parameters;
};
typedef struct _struct_Bragg_crystal _class_Bragg_crystal;
_class_Bragg_crystal _MARS_dcm_xtal0_var;
#pragma acc declare create ( _MARS_dcm_xtal0_var )

_class_Arm _MARS_dcm0_var;
#pragma acc declare create ( _MARS_dcm0_var )

_class_Bragg_crystal _MARS_dcm_xtal1_var;
#pragma acc declare create ( _MARS_dcm_xtal1_var )

_class_Arm _MARS_dcm1_var;
#pragma acc declare create ( _MARS_dcm1_var )

/* component MARS_emon_dcm0=E_monitor() [24] DECLARE */
/* Parameter definition for component type 'E_monitor' */
struct _struct_E_monitor_parameters {
  /* Component type 'E_monitor' setting parameters */
  MCNUM nE;
  char filename[16384];
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM Emin;
  MCNUM Emax;
  MCNUM restore_xray;
  /* Component type 'E_monitor' private parameters */
  DArray1d  E_N;
  DArray1d  E_p;
  DArray1d  E_p2;
  double  xmin;
  double  xmax;
  double  ymin;
  double  ymax;
}; /* _struct_E_monitor_parameters */
typedef struct _struct_E_monitor_parameters _class_E_monitor_parameters;

/* Parameters for component type 'E_monitor' */
struct _struct_E_monitor {
  char     _name[256]; /* e.g. MARS_emon_dcm0 */
  char     _type[256]; /* E_monitor */
  long     _index; /* e.g. 24 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_E_monitor_parameters _parameters;
};
typedef struct _struct_E_monitor _class_E_monitor;
_class_E_monitor _MARS_emon_dcm0_var;
#pragma acc declare create ( _MARS_emon_dcm0_var )

_class_PSD_monitor _MARS_displayMono_var;
#pragma acc declare create ( _MARS_displayMono_var )

_class_E_monitor _MARS_displayMonoLength_var;
#pragma acc declare create ( _MARS_displayMonoLength_var )

_class_Arm _MARS_M2_arm_translation_var;
#pragma acc declare create ( _MARS_M2_arm_translation_var )

_class_Arm _MARS_M2_arm_rotation_1_var;
#pragma acc declare create ( _MARS_M2_arm_rotation_1_var )

_class_Mirror_curved _MARS_mirror_M2_var;
#pragma acc declare create ( _MARS_mirror_M2_var )

_class_Arm _MARS_M2_arm_rotation_2_var;
#pragma acc declare create ( _MARS_M2_arm_rotation_2_var )

_class_Arm _MARS_M2_arm_rotation_2_undo_var;
#pragma acc declare create ( _MARS_M2_arm_rotation_2_undo_var )

_class_Slit _MARS_slitSecon1_var;
#pragma acc declare create ( _MARS_slitSecon1_var )

_class_Slit _MARS_slitSecon2_var;
#pragma acc declare create ( _MARS_slitSecon2_var )

_class_E_monitor _MARS_emon_dcm1_var;
#pragma acc declare create ( _MARS_emon_dcm1_var )

_class_PSD_monitor _MARS_displaySlit2_var;
#pragma acc declare create ( _MARS_displaySlit2_var )

/* component MARS_Sample=FluoPowder() [36] DECLARE */
/* Parameter definition for component type 'FluoPowder' */
struct _struct_FluoPowder_parameters {
  /* Component type 'FluoPowder' setting parameters */
  char geometry[16384];
  MCNUM radius;
  MCNUM thickness;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  int concentric;
  char material[16384];
  MCNUM packing_factor;
  MCNUM density;
  MCNUM weight;
  MCNUM p_interact;
  MCNUM target_x;
  MCNUM target_y;
  MCNUM target_z;
  MCNUM focus_r;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM focus_aw;
  MCNUM focus_ah;
  int target_index;
  int flag_compton;
  int flag_rayleigh;
  int flag_lorentzian;
  int flag_powder;
  int flag_kissel;
  char powder_refl[16384];
  MCNUM powder_format[8];
  MCNUM Vc;
  MCNUM delta_d_d;
  MCNUM DW;
  MCNUM d_phi;
  int nb_atoms;
  int barns;
  int tth_sign;
  int order;
  /* Component type 'FluoPowder' private parameters */
  struct line_info_struct  line_info;
  double*  columns;
  double*  mat_columns;
  off_struct  offdata;
  double  tgt_x;
  double  tgt_y;
  double  tgt_z;
  struct   compoundData * compound;
  DArray1d  cum_massFractions;
  DArray1d  cum_xs_fluo;
  DArray1d  cum_xs_Compton;
  DArray1d  cum_xs_Rayleigh;
  int     shape;
  int     n_fluo;
  int     n_Compton;
  int     n_Rayleigh;
  double  p_fluo;
  double  p_Compton;
  double  p_Rayleigh;
  int     n_diff;
  double  p_diff;
  double  fluo_rho;
  double    reuse_cum_xs_diffraction;
  int     reuse_nb;
  int     reuse_intersect;
  double  reuse_ki;
  double  reuse_l0;
  double  reuse_l1;
  double  reuse_l2;
  double  reuse_l3;
  double  reuse_sigma_barn;
  DArray1d  reuse_cum_xs_fluo;
  DArray1d  reuse_cum_xs_Compton;
  DArray1d  reuse_cum_xs_Rayleigh;
  int     reuse_Nq;
  double  reuse_my_s_k2_sum;
}; /* _struct_FluoPowder_parameters */
typedef struct _struct_FluoPowder_parameters _class_FluoPowder_parameters;

/* Parameters for component type 'FluoPowder' */
struct _struct_FluoPowder {
  char     _name[256]; /* e.g. MARS_Sample */
  char     _type[256]; /* FluoPowder */
  long     _index; /* e.g. 36 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_FluoPowder_parameters _parameters;
};
typedef struct _struct_FluoPowder _class_FluoPowder;
_class_FluoPowder _MARS_Sample_var;
#pragma acc declare create ( _MARS_Sample_var )

_class_Monitor_nD _MARS_detector_diffraction_var;
#pragma acc declare create ( _MARS_detector_diffraction_var )

_class_Monitor_nD _MARS_detector_fluo_var;
#pragma acc declare create ( _MARS_detector_fluo_var )

_class_Beamstop _beamdump_40_var;
#pragma acc declare create ( _beamdump_40_var )

_class_Text _PSICHE_pos_var;
#pragma acc declare create ( _PSICHE_pos_var )

_class_Arm _PSICHE_var;
#pragma acc declare create ( _PSICHE_var )

/* component PSICHE_source=Wiggler() [42] DECLARE */
/* Parameter definition for component type 'Wiggler' */
struct _struct_Wiggler_parameters {
  /* Component type 'Wiggler' setting parameters */
  MCNUM E0;
  MCNUM dE;
  MCNUM lambda0;
  MCNUM dlambda;
  MCNUM phase;
  MCNUM randomphase;
  MCNUM Ee;
  MCNUM Ie;
  MCNUM B;
  MCNUM K;
  int Nper;
  MCNUM length;
  MCNUM sigey;
  MCNUM sigex;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM dist;
  MCNUM gauss_t;
  int verbose;
  MCNUM Br;
  /* Component type 'Wiggler' private parameters */
  double  gamma;
  double  gamma2;
  double  igamma;
  double  kc;
  double  s1x;
  double  s1y;
  double  lu;
  double  gap;
  double  p0;
}; /* _struct_Wiggler_parameters */
typedef struct _struct_Wiggler_parameters _class_Wiggler_parameters;

/* Parameters for component type 'Wiggler' */
struct _struct_Wiggler {
  char     _name[256]; /* e.g. PSICHE_source */
  char     _type[256]; /* Wiggler */
  long     _index; /* e.g. 42 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Wiggler_parameters _parameters;
};
typedef struct _struct_Wiggler _class_Wiggler;
_class_Wiggler _PSICHE_source_var;
#pragma acc declare create ( _PSICHE_source_var )

_class_Monitor_nD _PSICHE_mon_src_e_var;
#pragma acc declare create ( _PSICHE_mon_src_e_var )

_class_Monitor_nD _PSICHE_mon_src_xy_var;
#pragma acc declare create ( _PSICHE_mon_src_xy_var )

_class_Arm _PSICHE_DCM_location_var;
#pragma acc declare create ( _PSICHE_DCM_location_var )

_class_Bragg_crystal _PSICHE_dcm_xtal0_var;
#pragma acc declare create ( _PSICHE_dcm_xtal0_var )

_class_Arm _PSICHE_dcm0_var;
#pragma acc declare create ( _PSICHE_dcm0_var )

_class_Bragg_crystal _PSICHE_dcm_xtal1_var;
#pragma acc declare create ( _PSICHE_dcm_xtal1_var )

_class_Arm _PSICHE_dcm1_var;
#pragma acc declare create ( _PSICHE_dcm1_var )

_class_Monitor_nD _PSICHE_mon_dcm_e_var;
#pragma acc declare create ( _PSICHE_mon_dcm_e_var )

_class_Monitor_nD _PSICHE_mon_dcm_xy_var;
#pragma acc declare create ( _PSICHE_mon_dcm_xy_var )

_class_Slit _PSICHE_slit_var;
#pragma acc declare create ( _PSICHE_slit_var )

_class_Arm _PSICHE_sample_stage_var;
#pragma acc declare create ( _PSICHE_sample_stage_var )

_class_FluoPowder _PSICHE_sample_var;
#pragma acc declare create ( _PSICHE_sample_var )

_class_Arm _PSICHE_fluo_holder_var;
#pragma acc declare create ( _PSICHE_fluo_holder_var )

_class_Monitor_nD _PSICHE_mon_spl_fluo_var;
#pragma acc declare create ( _PSICHE_mon_spl_fluo_var )

_class_Monitor_nD _PSICHE_mon_spl_e_var;
#pragma acc declare create ( _PSICHE_mon_spl_e_var )

_class_Monitor_nD _PSICHE_mon_spl_xy_var;
#pragma acc declare create ( _PSICHE_mon_spl_xy_var )

_class_Beamstop _beamdump_61_var;
#pragma acc declare create ( _beamdump_61_var )

_class_Text _PLEIADES_pos_var;
#pragma acc declare create ( _PLEIADES_pos_var )

_class_Text _DISCO_pos_var;
#pragma acc declare create ( _DISCO_pos_var )

_class_Arm _DISCO_var;
#pragma acc declare create ( _DISCO_var )

_class_Bending_magnet _DISCO_Source_var;
#pragma acc declare create ( _DISCO_Source_var )

/* component DISCO_ColdFinger=Mask() [64] DECLARE */
/* Parameter definition for component type 'Mask' */
struct _struct_Mask_parameters {
  /* Component type 'Mask' setting parameters */
  MCNUM xwidth;
  MCNUM yheight;
  char mask[16384];
  MCNUM invert;
  MCNUM virtual;
  /* Component type 'Mask' private parameters */
  t_Table  table;
  int  ny;
  int  nx;
  double  xmin;
  double  ymin;
  double  xmax;
  double  ymax;
  int  filter_row;
  double  maskval;
}; /* _struct_Mask_parameters */
typedef struct _struct_Mask_parameters _class_Mask_parameters;

/* Parameters for component type 'Mask' */
struct _struct_Mask {
  char     _name[256]; /* e.g. DISCO_ColdFinger */
  char     _type[256]; /* Mask */
  long     _index; /* e.g. 64 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Mask_parameters _parameters;
};
typedef struct _struct_Mask _class_Mask;
_class_Mask _DISCO_ColdFinger_var;
#pragma acc declare create ( _DISCO_ColdFinger_var )

_class_Arm _DISCO_M1_location_var;
#pragma acc declare create ( _DISCO_M1_location_var )

_class_Arm _DISCO_M1_rotated_var;
#pragma acc declare create ( _DISCO_M1_rotated_var )

_class_Arm _DISCO_M1_x_var;
#pragma acc declare create ( _DISCO_M1_x_var )

_class_Mirror_curved _DISCO_M1_var;
#pragma acc declare create ( _DISCO_M1_var )

_class_Arm _DISCO_M1_takeoff_var;
#pragma acc declare create ( _DISCO_M1_takeoff_var )

_class_Arm _DISCO_M1_x_takeoff_var;
#pragma acc declare create ( _DISCO_M1_x_takeoff_var )

_class_Arm _DISCO_M2_location_var;
#pragma acc declare create ( _DISCO_M2_location_var )

_class_Arm _DISCO_M2_rotated_x_var;
#pragma acc declare create ( _DISCO_M2_rotated_x_var )

_class_Arm _DISCO_M2_rotated_var;
#pragma acc declare create ( _DISCO_M2_rotated_var )

_class_Arm _DISCO_M2_other_side_var;
#pragma acc declare create ( _DISCO_M2_other_side_var )

/* component DISCO_M2=Mirror_toroid_pothole() [75] DECLARE */
/* Parameter definition for component type 'Mirror_toroid_pothole' */
struct _struct_Mirror_toroid_pothole_parameters {
  /* Component type 'Mirror_toroid_pothole' setting parameters */
  MCNUM zdepth;
  MCNUM xwidth;
  MCNUM radius;
  MCNUM radius_o;
  MCNUM R0;
  char coating[16384];
  /* Component type 'Mirror_toroid_pothole' private parameters */
  struct potholestruct  prms;
  t_Table  reflec_table;
  t_Reflec  re;
}; /* _struct_Mirror_toroid_pothole_parameters */
typedef struct _struct_Mirror_toroid_pothole_parameters _class_Mirror_toroid_pothole_parameters;

/* Parameters for component type 'Mirror_toroid_pothole' */
struct _struct_Mirror_toroid_pothole {
  char     _name[256]; /* e.g. DISCO_M2 */
  char     _type[256]; /* Mirror_toroid_pothole */
  long     _index; /* e.g. 75 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Mirror_toroid_pothole_parameters _parameters;
};
typedef struct _struct_Mirror_toroid_pothole _class_Mirror_toroid_pothole;
_class_Mirror_toroid_pothole _DISCO_M2_var;
#pragma acc declare create ( _DISCO_M2_var )

_class_Arm _DISCO_M2_other_side_back_var;
#pragma acc declare create ( _DISCO_M2_other_side_back_var )

_class_Arm _DISCO_M2_takeoff_var;
#pragma acc declare create ( _DISCO_M2_takeoff_var )

_class_Arm _DISCO_HFP_location_var;
#pragma acc declare create ( _DISCO_HFP_location_var )

_class_PSD_monitor _DISCO_HFP_var;
#pragma acc declare create ( _DISCO_HFP_var )

_class_Arm _DISCO_M3_arm_var;
#pragma acc declare create ( _DISCO_M3_arm_var )

_class_Mirror_curved _DISCO_M3_var;
#pragma acc declare create ( _DISCO_M3_var )

_class_Arm _DISCO_M3_takeoff_var;
#pragma acc declare create ( _DISCO_M3_takeoff_var )

_class_Arm _DISCO_M3_yz_var;
#pragma acc declare create ( _DISCO_M3_yz_var )

_class_Arm _DISCO_M4_yz_var;
#pragma acc declare create ( _DISCO_M4_yz_var )

/* component DISCO_M4=Mirror() [85] DECLARE */
/* Parameter definition for component type 'Mirror' */
struct _struct_Mirror_parameters {
  /* Component type 'Mirror' setting parameters */
  MCNUM zdepth;
  MCNUM xwidth;
  MCNUM yheight;
  char coating[16384];
  MCNUM R0;
  char geometry[16384];
  /* Component type 'Mirror' private parameters */
  t_Reflec  re;
  off_struct  offdata;
  int  shape;
}; /* _struct_Mirror_parameters */
typedef struct _struct_Mirror_parameters _class_Mirror_parameters;

/* Parameters for component type 'Mirror' */
struct _struct_Mirror {
  char     _name[256]; /* e.g. DISCO_M4 */
  char     _type[256]; /* Mirror */
  long     _index; /* e.g. 85 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Mirror_parameters _parameters;
};
typedef struct _struct_Mirror _class_Mirror;
_class_Mirror _DISCO_M4_var;
#pragma acc declare create ( _DISCO_M4_var )

_class_Arm _DISCO_M4_takeoff_var;
#pragma acc declare create ( _DISCO_M4_takeoff_var )

_class_Arm _DISCO_M4_arm_back_var;
#pragma acc declare create ( _DISCO_M4_arm_back_var )

_class_Arm _DISCO_VFP_location_var;
#pragma acc declare create ( _DISCO_VFP_location_var )

_class_PSD_monitor _DISCO_VFP_var;
#pragma acc declare create ( _DISCO_VFP_var )

_class_Arm _DISCO_M51_position_var;
#pragma acc declare create ( _DISCO_M51_position_var )

_class_Arm _DISCO_M51_rotation_var;
#pragma acc declare create ( _DISCO_M51_rotation_var )

/* component DISCO_M51=Mirror_elliptic() [92] DECLARE */
/* Parameter definition for component type 'Mirror_elliptic' */
struct _struct_Mirror_elliptic_parameters {
  /* Component type 'Mirror_elliptic' setting parameters */
  MCNUM x_a;
  MCNUM y_b;
  MCNUM z_c;
  MCNUM zdepth;
  MCNUM xwidth;
  MCNUM R0;
  char coating[16384];
  MCNUM length;
  MCNUM width;
  MCNUM radius;
  /* Component type 'Mirror_elliptic' private parameters */
  double  a2inv;
  double  b2inv;
  double  c2inv;
  t_Reflec  re;
}; /* _struct_Mirror_elliptic_parameters */
typedef struct _struct_Mirror_elliptic_parameters _class_Mirror_elliptic_parameters;

/* Parameters for component type 'Mirror_elliptic' */
struct _struct_Mirror_elliptic {
  char     _name[256]; /* e.g. DISCO_M51 */
  char     _type[256]; /* Mirror_elliptic */
  long     _index; /* e.g. 92 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Mirror_elliptic_parameters _parameters;
};
typedef struct _struct_Mirror_elliptic _class_Mirror_elliptic;
_class_Mirror_elliptic _DISCO_M51_var;
#pragma acc declare create ( _DISCO_M51_var )

_class_Arm _DISCO_arm_var;
#pragma acc declare create ( _DISCO_arm_var )

_class_Arm _DISCO_M51_arm_back_var;
#pragma acc declare create ( _DISCO_M51_arm_back_var )

_class_Arm _DISCO_M52_position_var;
#pragma acc declare create ( _DISCO_M52_position_var )

_class_Arm _DISCO_M52_x_var;
#pragma acc declare create ( _DISCO_M52_x_var )

_class_Mirror_curved _DISCO_M52_var;
#pragma acc declare create ( _DISCO_M52_var )

_class_Arm _DISCO_M52_takeoff_var;
#pragma acc declare create ( _DISCO_M52_takeoff_var )

_class_Arm _DISCO_M52_x_takeoff_var;
#pragma acc declare create ( _DISCO_M52_x_takeoff_var )

_class_Arm _DISCO_second_HFP_location_var;
#pragma acc declare create ( _DISCO_second_HFP_location_var )

_class_PSD_monitor _DISCO_second_HFP_var;
#pragma acc declare create ( _DISCO_second_HFP_var )

_class_Arm _DISCO_M53_location_var;
#pragma acc declare create ( _DISCO_M53_location_var )

_class_Arm _DISCO_M53_rotated_var;
#pragma acc declare create ( _DISCO_M53_rotated_var )

_class_Mirror_toroid_pothole _DISCO_M53_var;
#pragma acc declare create ( _DISCO_M53_var )

_class_Arm _DISCO_M53_takeoff_var;
#pragma acc declare create ( _DISCO_M53_takeoff_var )

_class_Arm _DISCO_M54_location_var;
#pragma acc declare create ( _DISCO_M54_location_var )

_class_Arm _DISCO_M54_rotated_var;
#pragma acc declare create ( _DISCO_M54_rotated_var )

_class_Mirror_toroid_pothole _DISCO_M54_var;
#pragma acc declare create ( _DISCO_M54_var )

_class_Arm _DISCO_M54_takeoff_var;
#pragma acc declare create ( _DISCO_M54_takeoff_var )

_class_Arm _DISCO_Mtoroids_arm_back_var;
#pragma acc declare create ( _DISCO_Mtoroids_arm_back_var )

_class_Arm _DISCO_M1_position_var;
#pragma acc declare create ( _DISCO_M1_position_var )

_class_Arm _DISCO_M1_rotation_var;
#pragma acc declare create ( _DISCO_M1_rotation_var )

_class_Mirror_elliptic _DISCO_mirror_m1_var;
#pragma acc declare create ( _DISCO_mirror_m1_var )

_class_Arm _DISCO_armm_var;
#pragma acc declare create ( _DISCO_armm_var )

_class_Arm _DISCO_M1_arm_back_var;
#pragma acc declare create ( _DISCO_M1_arm_back_var )

_class_Arm _DISCO_Grating_position_var;
#pragma acc declare create ( _DISCO_Grating_position_var )

_class_Arm _DISCO_Grating_rotation_var;
#pragma acc declare create ( _DISCO_Grating_rotation_var )

_class_Arm _DISCO_Grating_rotation_lines_grating_var;
#pragma acc declare create ( _DISCO_Grating_rotation_lines_grating_var )

_class_Arm _DISCO_Grating_rotation_nine_degrees_var;
#pragma acc declare create ( _DISCO_Grating_rotation_nine_degrees_var )

/* component DISCO_reflective_grating=Grating_reflect() [120] DECLARE */
/* Parameter definition for component type 'Grating_reflect' */
struct _struct_Grating_reflect_parameters {
  /* Component type 'Grating_reflect' setting parameters */
  MCNUM d_phi;
  MCNUM R0;
  MCNUM rho_l;
  MCNUM order;
  MCNUM phi0;
  MCNUM zdepth;
  MCNUM xwidth;
  int verbose;
  /* Component type 'Grating_reflect' private parameters */
  double  pdir;
  double  d;
  double  b;
  int  nslits;
}; /* _struct_Grating_reflect_parameters */
typedef struct _struct_Grating_reflect_parameters _class_Grating_reflect_parameters;

/* Parameters for component type 'Grating_reflect' */
struct _struct_Grating_reflect {
  char     _name[256]; /* e.g. DISCO_reflective_grating */
  char     _type[256]; /* Grating_reflect */
  long     _index; /* e.g. 120 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Grating_reflect_parameters _parameters;
};
typedef struct _struct_Grating_reflect _class_Grating_reflect;
_class_Grating_reflect _DISCO_reflective_grating_var;
#pragma acc declare create ( _DISCO_reflective_grating_var )

_class_Arm _DISCO_Grating_rotation_lines_grating_back_var;
#pragma acc declare create ( _DISCO_Grating_rotation_lines_grating_back_var )

_class_Arm _DISCO_Grating_arm_back_var;
#pragma acc declare create ( _DISCO_Grating_arm_back_var )

_class_Arm _DISCO_Grating_arm_back_2_var;
#pragma acc declare create ( _DISCO_Grating_arm_back_2_var )

_class_Arm _DISCO_Grating_arm_back_3_var;
#pragma acc declare create ( _DISCO_Grating_arm_back_3_var )

_class_Arm _DISCO_M22_location_var;
#pragma acc declare create ( _DISCO_M22_location_var )

_class_Arm _DISCO_M22_rotated_var;
#pragma acc declare create ( _DISCO_M22_rotated_var )

_class_Mirror_elliptic _DISCO_mirror_m2_var;
#pragma acc declare create ( _DISCO_mirror_m2_var )

_class_Arm _DISCO_arm2_var;
#pragma acc declare create ( _DISCO_arm2_var )

_class_Arm _DISCO_M44_arm_back_var;
#pragma acc declare create ( _DISCO_M44_arm_back_var )

_class_Arm _DISCO_arm3_var;
#pragma acc declare create ( _DISCO_arm3_var )

_class_PSD_monitor _DISCO_psd_before_slit_var;
#pragma acc declare create ( _DISCO_psd_before_slit_var )

_class_Slit _DISCO_slit_var;
#pragma acc declare create ( _DISCO_slit_var )

_class_PSD_monitor _DISCO_psd_monitor_var;
#pragma acc declare create ( _DISCO_psd_monitor_var )

_class_PSD_monitor _DISCO_psd_giant_after_grating_var;
#pragma acc declare create ( _DISCO_psd_giant_after_grating_var )

_class_Monitor_nD _DISCO_e_monitor_var;
#pragma acc declare create ( _DISCO_e_monitor_var )

_class_Monitor_nD _DISCO_w_monitor_var;
#pragma acc declare create ( _DISCO_w_monitor_var )

_class_Beamstop _beamdump_140_var;
#pragma acc declare create ( _beamdump_140_var )

_class_Text _DESIRS_pos_var;
#pragma acc declare create ( _DESIRS_pos_var )

_class_Text _METRO_pos_var;
#pragma acc declare create ( _METRO_pos_var )

_class_Text _PUMA_pos_var;
#pragma acc declare create ( _PUMA_pos_var )

_class_Arm _PUMA_var;
#pragma acc declare create ( _PUMA_var )

_class_Wiggler _PUMA_Source_var;
#pragma acc declare create ( _PUMA_Source_var )

_class_Slit _PUMA_slit1_var;
#pragma acc declare create ( _PUMA_slit1_var )

_class_Slit _PUMA_slit2_var;
#pragma acc declare create ( _PUMA_slit2_var )

_class_E_monitor _PUMA_mon_src_e_var;
#pragma acc declare create ( _PUMA_mon_src_e_var )

_class_PSD_monitor _PUMA_mon_src_xy_var;
#pragma acc declare create ( _PUMA_mon_src_xy_var )

_class_Arm _PUMA_HFM_location_var;
#pragma acc declare create ( _PUMA_HFM_location_var )

_class_Arm _PUMA_HFM_rotated_var;
#pragma acc declare create ( _PUMA_HFM_rotated_var )

_class_Mirror_curved _PUMA_mirror_HFM_var;
#pragma acc declare create ( _PUMA_mirror_HFM_var )

_class_Arm _PUMA_HFM_out_var;
#pragma acc declare create ( _PUMA_HFM_out_var )

_class_PSD_monitor _PUMA_mon_HFM_out_xy_var;
#pragma acc declare create ( _PUMA_mon_HFM_out_xy_var )

_class_Arm _PUMA_DCM_location_var;
#pragma acc declare create ( _PUMA_DCM_location_var )

_class_Bragg_crystal _PUMA_DCM_xtal1_var;
#pragma acc declare create ( _PUMA_DCM_xtal1_var )

_class_Arm _PUMA_DCM_xtal1_out_var;
#pragma acc declare create ( _PUMA_DCM_xtal1_out_var )

_class_PSD_monitor _PUMA_mon_DCM_xtal1_only_xy_var;
#pragma acc declare create ( _PUMA_mon_DCM_xtal1_only_xy_var )

_class_Bragg_crystal _PUMA_DCM_xtal2_var;
#pragma acc declare create ( _PUMA_DCM_xtal2_var )

_class_Arm _PUMA_DCM_xtal2_out_var;
#pragma acc declare create ( _PUMA_DCM_xtal2_out_var )

_class_E_monitor _PUMA_mon_DCM_out_e_var;
#pragma acc declare create ( _PUMA_mon_DCM_out_e_var )

_class_PSD_monitor _PUMA_mon_DCM_out_xy_var;
#pragma acc declare create ( _PUMA_mon_DCM_out_xy_var )

_class_Slit _PUMA_slit3_var;
#pragma acc declare create ( _PUMA_slit3_var )

_class_Slit _PUMA_slit4_var;
#pragma acc declare create ( _PUMA_slit4_var )

_class_Slit _PUMA_slit5_var;
#pragma acc declare create ( _PUMA_slit5_var )

_class_Arm _PUMA_KB_VFM_location_var;
#pragma acc declare create ( _PUMA_KB_VFM_location_var )

_class_PSD_monitor _PUMA_mon_KB_in_xy_var;
#pragma acc declare create ( _PUMA_mon_KB_in_xy_var )

_class_Arm _PUMA_KB_VFM_rotated_var;
#pragma acc declare create ( _PUMA_KB_VFM_rotated_var )

_class_Mirror_curved _PUMA_mirror_KB_VFM_var;
#pragma acc declare create ( _PUMA_mirror_KB_VFM_var )

_class_Arm _PUMA_KB_VFM_out_var;
#pragma acc declare create ( _PUMA_KB_VFM_out_var )

_class_PSD_monitor _PUMA_mon_KB_VFM_out_xy_var;
#pragma acc declare create ( _PUMA_mon_KB_VFM_out_xy_var )

_class_Arm _PUMA_KB_HFM_location_var;
#pragma acc declare create ( _PUMA_KB_HFM_location_var )

_class_Arm _PUMA_KB_HFM_rotated_var;
#pragma acc declare create ( _PUMA_KB_HFM_rotated_var )

_class_Mirror_curved _PUMA_mirror_KB_HFM_var;
#pragma acc declare create ( _PUMA_mirror_KB_HFM_var )

_class_Arm _PUMA_KB_HFM_out_var;
#pragma acc declare create ( _PUMA_KB_HFM_out_var )

_class_PSD_monitor _PUMA_mon_KB_HFM_out_xy_var;
#pragma acc declare create ( _PUMA_mon_KB_HFM_out_xy_var )

_class_Arm _PUMA_sample_location_var;
#pragma acc declare create ( _PUMA_sample_location_var )

_class_PSD_monitor _PUMA_mon_sample_xy_var;
#pragma acc declare create ( _PUMA_mon_sample_xy_var )

_class_E_monitor _PUMA_mon_sample_e_var;
#pragma acc declare create ( _PUMA_mon_sample_e_var )

_class_Beamstop _beamdump_181_var;
#pragma acc declare create ( _beamdump_181_var )

_class_Text _CRISTAL_pos_var;
#pragma acc declare create ( _CRISTAL_pos_var )

_class_Arm _CRISTAL_var;
#pragma acc declare create ( _CRISTAL_var )

/* component CRISTAL_Source=Undulator() [180] DECLARE */
/* Parameter definition for component type 'Undulator' */
struct _struct_Undulator_parameters {
  /* Component type 'Undulator' setting parameters */
  MCNUM E0;
  MCNUM dE;
  MCNUM phase;
  MCNUM randomphase;
  MCNUM Ee;
  MCNUM dEe;
  MCNUM Ie;
  MCNUM B;
  MCNUM K;
  int Nper;
  MCNUM lu;
  MCNUM sigey;
  MCNUM sigex;
  MCNUM sigepx;
  MCNUM sigepy;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM dist;
  MCNUM quick_integ;
  MCNUM E1st;
  int verbose;
  MCNUM Br;
  /* Component type 'Undulator' private parameters */
  double  gamma;
  double  gamma2;
  double  igamma;
  double  s1x;
  double  s1y;
  double  length;
  double  kc;
  double  pmul;
  double  gap;
  gsl_function  Bsig;
  gsl_function  Bpi;
  gsl_integration_workspace*  gsl_int_ws;
  double  alpha;
  double  MELE;
}; /* _struct_Undulator_parameters */
typedef struct _struct_Undulator_parameters _class_Undulator_parameters;

/* Parameters for component type 'Undulator' */
struct _struct_Undulator {
  char     _name[256]; /* e.g. CRISTAL_Source */
  char     _type[256]; /* Undulator */
  long     _index; /* e.g. 180 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Undulator_parameters _parameters;
};
typedef struct _struct_Undulator _class_Undulator;
_class_Undulator _CRISTAL_Source_var;
#pragma acc declare create ( _CRISTAL_Source_var )

_class_Slit _CRISTAL_slit1_var;
#pragma acc declare create ( _CRISTAL_slit1_var )

_class_Arm _CRISTAL_dcm_location_var;
#pragma acc declare create ( _CRISTAL_dcm_location_var )

_class_Bragg_crystal _CRISTAL_dcm_xtal0_var;
#pragma acc declare create ( _CRISTAL_dcm_xtal0_var )

_class_Arm _CRISTAL_arm_xtal0_var;
#pragma acc declare create ( _CRISTAL_arm_xtal0_var )

_class_Bragg_crystal _CRISTAL_dcm_xtal1_var;
#pragma acc declare create ( _CRISTAL_dcm_xtal1_var )

_class_Arm _CRISTAL_arm_xtal1_var;
#pragma acc declare create ( _CRISTAL_arm_xtal1_var )

_class_E_monitor _CRISTAL_emon_dcm_var;
#pragma acc declare create ( _CRISTAL_emon_dcm_var )

_class_Arm _CRISTAL_M1_location_var;
#pragma acc declare create ( _CRISTAL_M1_location_var )

_class_Arm _CRISTAL_M1_rotated_var;
#pragma acc declare create ( _CRISTAL_M1_rotated_var )

_class_Mirror_curved _CRISTAL_M1_var;
#pragma acc declare create ( _CRISTAL_M1_var )

_class_Arm _CRISTAL_M1_out_var;
#pragma acc declare create ( _CRISTAL_M1_out_var )

_class_Arm _CRISTAL_M2_location_var;
#pragma acc declare create ( _CRISTAL_M2_location_var )

_class_Arm _CRISTAL_M2_rotated_var;
#pragma acc declare create ( _CRISTAL_M2_rotated_var )

_class_Mirror_curved _CRISTAL_M2_var;
#pragma acc declare create ( _CRISTAL_M2_var )

_class_Arm _CRISTAL_M2_out_var;
#pragma acc declare create ( _CRISTAL_M2_out_var )

_class_Slit _CRISTAL_slit2_var;
#pragma acc declare create ( _CRISTAL_slit2_var )

_class_PSD_monitor _CRISTAL_psd_slit2_var;
#pragma acc declare create ( _CRISTAL_psd_slit2_var )

_class_Arm _CRISTAL_sample_stage_var;
#pragma acc declare create ( _CRISTAL_sample_stage_var )

_class_FluoPowder _CRISTAL_fluo_var;
#pragma acc declare create ( _CRISTAL_fluo_var )

_class_Monitor_nD _CRISTAL_detector_diffraction_var;
#pragma acc declare create ( _CRISTAL_detector_diffraction_var )

_class_Monitor_nD _CRISTAL_detector_fluo_var;
#pragma acc declare create ( _CRISTAL_detector_fluo_var )

_class_Beamstop _beamdump_207_var;
#pragma acc declare create ( _beamdump_207_var )

_class_Text _DEIMOS_pos_var;
#pragma acc declare create ( _DEIMOS_pos_var )

_class_Text _GALAXIES_pos_var;
#pragma acc declare create ( _GALAXIES_pos_var )

_class_Arm _GALAXIES_var;
#pragma acc declare create ( _GALAXIES_var )

_class_Undulator _GALAXIES_Source_U20_var;
#pragma acc declare create ( _GALAXIES_Source_U20_var )

_class_Monitor_nD _GALAXIES_mon_src_xy_var;
#pragma acc declare create ( _GALAXIES_mon_src_xy_var )

_class_Monitor_nD _GALAXIES_mon_src_e_var;
#pragma acc declare create ( _GALAXIES_mon_src_e_var )

_class_Slit _GALAXIES_absorber_var;
#pragma acc declare create ( _GALAXIES_absorber_var )

_class_Slit _GALAXIES_diaphragme_var;
#pragma acc declare create ( _GALAXIES_diaphragme_var )

_class_Slit _GALAXIES_fentes_primaires_var;
#pragma acc declare create ( _GALAXIES_fentes_primaires_var )

_class_Monitor_nD _GALAXIES_mon_prim_xy_var;
#pragma acc declare create ( _GALAXIES_mon_prim_xy_var )

_class_Arm _GALAXIES_DCM_location_var;
#pragma acc declare create ( _GALAXIES_DCM_location_var )

_class_Bragg_crystal _GALAXIES_dcm_xtal0_var;
#pragma acc declare create ( _GALAXIES_dcm_xtal0_var )

_class_Arm _GALAXIES_dcm0_var;
#pragma acc declare create ( _GALAXIES_dcm0_var )

_class_Bragg_crystal _GALAXIES_dcm_xtal1_var;
#pragma acc declare create ( _GALAXIES_dcm_xtal1_var )

_class_Arm _GALAXIES_dcm1_var;
#pragma acc declare create ( _GALAXIES_dcm1_var )

_class_Monitor_nD _GALAXIES_mon_dcm_e_var;
#pragma acc declare create ( _GALAXIES_mon_dcm_e_var )

_class_Monitor_nD _GALAXIES_mon_dcm_xy_var;
#pragma acc declare create ( _GALAXIES_mon_dcm_xy_var )

_class_Arm _GALAXIES_M1_location_var;
#pragma acc declare create ( _GALAXIES_M1_location_var )

_class_Arm _GALAXIES_M1_rotated_var;
#pragma acc declare create ( _GALAXIES_M1_rotated_var )

_class_Mirror_curved _GALAXIES_M1_var;
#pragma acc declare create ( _GALAXIES_M1_var )

_class_Arm _GALAXIES_M1_out_var;
#pragma acc declare create ( _GALAXIES_M1_out_var )

_class_Slit _GALAXIES_HRM_gate_in_var;
#pragma acc declare create ( _GALAXIES_HRM_gate_in_var )

_class_Arm _GALAXIES_M2A_location_var;
#pragma acc declare create ( _GALAXIES_M2A_location_var )

_class_Arm _GALAXIES_M2A_rotated_var;
#pragma acc declare create ( _GALAXIES_M2A_rotated_var )

/* component GALAXIES_M2A=Mirror_toroid() [227] DECLARE */
/* Parameter definition for component type 'Mirror_toroid' */
struct _struct_Mirror_toroid_parameters {
  /* Component type 'Mirror_toroid' setting parameters */
  char coating[16384];
  MCNUM zdepth;
  MCNUM xwidth;
  MCNUM radius;
  MCNUM radius_o;
  MCNUM R0;
  /* Component type 'Mirror_toroid' private parameters */
  t_Reflec  re;
}; /* _struct_Mirror_toroid_parameters */
typedef struct _struct_Mirror_toroid_parameters _class_Mirror_toroid_parameters;

/* Parameters for component type 'Mirror_toroid' */
struct _struct_Mirror_toroid {
  char     _name[256]; /* e.g. GALAXIES_M2A */
  char     _type[256]; /* Mirror_toroid */
  long     _index; /* e.g. 227 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Mirror_toroid_parameters _parameters;
};
typedef struct _struct_Mirror_toroid _class_Mirror_toroid;
_class_Mirror_toroid _GALAXIES_M2A_var;
#pragma acc declare create ( _GALAXIES_M2A_var )

_class_Arm _GALAXIES_M2A_out_var;
#pragma acc declare create ( _GALAXIES_M2A_out_var )

_class_Slit _GALAXIES_secondary_slits_var;
#pragma acc declare create ( _GALAXIES_secondary_slits_var )

_class_Monitor_nD _GALAXIES_mon_sec_xy_var;
#pragma acc declare create ( _GALAXIES_mon_sec_xy_var )

_class_Arm _GALAXIES_M2B_location_var;
#pragma acc declare create ( _GALAXIES_M2B_location_var )

_class_Arm _GALAXIES_M2B_rotated_var;
#pragma acc declare create ( _GALAXIES_M2B_rotated_var )

_class_Mirror_toroid _GALAXIES_M2B_var;
#pragma acc declare create ( _GALAXIES_M2B_var )

_class_Arm _GALAXIES_M2B_out_var;
#pragma acc declare create ( _GALAXIES_M2B_out_var )

_class_Arm _GALAXIES_VFM_location_var;
#pragma acc declare create ( _GALAXIES_VFM_location_var )

_class_Arm _GALAXIES_VFM_rotated_var;
#pragma acc declare create ( _GALAXIES_VFM_rotated_var )

_class_Mirror_curved _GALAXIES_VFM_var;
#pragma acc declare create ( _GALAXIES_VFM_var )

_class_Arm _GALAXIES_VFM_out_var;
#pragma acc declare create ( _GALAXIES_VFM_out_var )

_class_Arm _GALAXIES_HFM_rotated_var;
#pragma acc declare create ( _GALAXIES_HFM_rotated_var )

_class_Mirror_curved _GALAXIES_HFM_var;
#pragma acc declare create ( _GALAXIES_HFM_var )

_class_Arm _GALAXIES_HFM_out_var;
#pragma acc declare create ( _GALAXIES_HFM_out_var )

_class_Monitor_nD _GALAXIES_mon_sample_xy_kb_var;
#pragma acc declare create ( _GALAXIES_mon_sample_xy_kb_var )

_class_Monitor_nD _GALAXIES_mon_sample_e_var;
#pragma acc declare create ( _GALAXIES_mon_sample_e_var )

_class_Arm _GALAXIES_sample_stage_var;
#pragma acc declare create ( _GALAXIES_sample_stage_var )

/* component GALAXIES_sample=FluoCrystal() [245] DECLARE */
/* Parameter definition for component type 'FluoCrystal' */
struct _struct_FluoCrystal_parameters {
  /* Component type 'FluoCrystal' setting parameters */
  char geometry[16384];
  MCNUM radius;
  MCNUM thickness;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  int concentric;
  char material[16384];
  MCNUM packing_factor;
  MCNUM density;
  MCNUM weight;
  MCNUM p_interact;
  MCNUM target_x;
  MCNUM target_y;
  MCNUM target_z;
  MCNUM focus_r;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM focus_aw;
  MCNUM focus_ah;
  int target_index;
  int flag_compton;
  int flag_rayleigh;
  int flag_lorentzian;
  int flag_kissel;
  char sx_refl[16384];
  int flag_sx;
  MCNUM delta_d_d;
  int barns;
  MCNUM recip_cell;
  MCNUM ax;
  MCNUM ay;
  MCNUM az;
  MCNUM bx;
  MCNUM by;
  MCNUM bz;
  MCNUM cx;
  MCNUM cy;
  MCNUM cz;
  MCNUM aa;
  MCNUM bb;
  MCNUM cc;
  MCNUM mosaic_AB[8];
  MCNUM mosaic;
  MCNUM mosaic_a;
  MCNUM mosaic_b;
  MCNUM mosaic_c;
  int order;
  /* Component type 'FluoCrystal' private parameters */
  struct hkl_info_struct  hkl_info;
  off_struct  offdata;
  struct hkl_data*  hkl_list;
  struct tau_data  tau_list[MCSX_REFL_SLIST_SIZE];
  struct sx_abs_data  abs_info;
  struct   compoundData * compound;
  DArray1d  cum_massFractions;
  DArray1d  cum_xs_fluo;
  DArray1d  cum_xs_Compton;
  DArray1d  cum_xs_Rayleigh;
  int     shape;
  int     n_fluo;
  int     n_Compton;
  int     n_Rayleigh;
  int     n_diff;
  double  p_fluo;
  double  p_Compton;
  double  p_Rayleigh;
  double  p_diff;
  double  fluo_rho;
  int     reuse_nb;
  int     reuse_intersect;
  double  reuse_ki;
  double  reuse_l0;
  double  reuse_l1;
  double  reuse_l2;
  double  reuse_l3;
  double  reuse_sigma_barn;
  DArray1d  reuse_cum_xs_fluo;
  DArray1d  reuse_cum_xs_Compton;
  DArray1d  reuse_cum_xs_Rayleigh;
  double    reuse_cum_xs_diffraction;
  double    reuse_coh_refl;
  double    reuse_coh_xsect;
  int       reuse_tau_count;
}; /* _struct_FluoCrystal_parameters */
typedef struct _struct_FluoCrystal_parameters _class_FluoCrystal_parameters;

/* Parameters for component type 'FluoCrystal' */
struct _struct_FluoCrystal {
  char     _name[256]; /* e.g. GALAXIES_sample */
  char     _type[256]; /* FluoCrystal */
  long     _index; /* e.g. 245 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_FluoCrystal_parameters _parameters;
};
typedef struct _struct_FluoCrystal _class_FluoCrystal;
_class_FluoCrystal _GALAXIES_sample_var;
#pragma acc declare create ( _GALAXIES_sample_var )

_class_Arm _GALAXIES_sample_out_var;
#pragma acc declare create ( _GALAXIES_sample_out_var )

_class_Arm _GALAXIES_ana_arm_var;
#pragma acc declare create ( _GALAXIES_ana_arm_var )

_class_Bragg_crystal _GALAXIES_analyzer_var;
#pragma acc declare create ( _GALAXIES_analyzer_var )

_class_Arm _GALAXIES_ana_out_var;
#pragma acc declare create ( _GALAXIES_ana_out_var )

_class_Monitor_nD _GALAXIES_IXS_det_var;
#pragma acc declare create ( _GALAXIES_IXS_det_var )

_class_Beamstop _beamdump_257_var;
#pragma acc declare create ( _beamdump_257_var )

_class_Text _TEMPO_pos_var;
#pragma acc declare create ( _TEMPO_pos_var )

_class_Text _SAMBA_pos_var;
#pragma acc declare create ( _SAMBA_pos_var )

_class_Arm _SAMBA_var;
#pragma acc declare create ( _SAMBA_var )

_class_Bending_magnet _SAMBA_BM_source_var;
#pragma acc declare create ( _SAMBA_BM_source_var )

_class_Arm _SAMBA_M1_location_var;
#pragma acc declare create ( _SAMBA_M1_location_var )

_class_Arm _SAMBA_M1_rotated_var;
#pragma acc declare create ( _SAMBA_M1_rotated_var )

_class_Mirror_curved _SAMBA_M1_var;
#pragma acc declare create ( _SAMBA_M1_var )

_class_Monitor_nD _SAMBA_M1_out_var;
#pragma acc declare create ( _SAMBA_M1_out_var )

_class_Arm _SAMBA_DCM_location_var;
#pragma acc declare create ( _SAMBA_DCM_location_var )

_class_Bragg_crystal _SAMBA_bragg_crystal_var;
#pragma acc declare create ( _SAMBA_bragg_crystal_var )

_class_Arm _SAMBA_arm_crystal1_var;
#pragma acc declare create ( _SAMBA_arm_crystal1_var )

_class_Bragg_crystal _SAMBA_bragg_crystal_two_var;
#pragma acc declare create ( _SAMBA_bragg_crystal_two_var )

_class_Arm _SAMBA_arm_crystal2_var;
#pragma acc declare create ( _SAMBA_arm_crystal2_var )

_class_Monitor_nD _SAMBA_DCM_out_var;
#pragma acc declare create ( _SAMBA_DCM_out_var )

_class_Monitor_nD _SAMBA_DCM_out_div_var;
#pragma acc declare create ( _SAMBA_DCM_out_div_var )

_class_Monitor_nD _SAMBA_DCM_out_e_var;
#pragma acc declare create ( _SAMBA_DCM_out_e_var )

_class_Arm _SAMBA_M2_loc_var;
#pragma acc declare create ( _SAMBA_M2_loc_var )

_class_Arm _SAMBA_M2_rotated_var;
#pragma acc declare create ( _SAMBA_M2_rotated_var )

_class_Mirror_curved _SAMBA_M2_var;
#pragma acc declare create ( _SAMBA_M2_var )

_class_Monitor_nD _SAMBA_M2_out_var;
#pragma acc declare create ( _SAMBA_M2_out_var )

_class_Monitor_nD _SAMBA_sample_stage_var;
#pragma acc declare create ( _SAMBA_sample_stage_var )

_class_FluoPowder _SAMBA_fluo_var;
#pragma acc declare create ( _SAMBA_fluo_var )

_class_Monitor_nD _SAMBA_det_trans_var;
#pragma acc declare create ( _SAMBA_det_trans_var )

_class_Monitor_nD _SAMBA_det_fluo_var;
#pragma acc declare create ( _SAMBA_det_fluo_var )

_class_Beamstop _beamdump_283_var;
#pragma acc declare create ( _beamdump_283_var )

_class_Text _HERMES_pos_var;
#pragma acc declare create ( _HERMES_pos_var )

_class_Text _PX1_pos_var;
#pragma acc declare create ( _PX1_pos_var )

_class_Arm _PX1_var;
#pragma acc declare create ( _PX1_var )

_class_Undulator _PX1_undulator_var;
#pragma acc declare create ( _PX1_undulator_var )

_class_Arm _PX1_bragg_crystal_location_var;
#pragma acc declare create ( _PX1_bragg_crystal_location_var )

_class_Bragg_crystal _PX1_bragg_crystal_var;
#pragma acc declare create ( _PX1_bragg_crystal_var )

_class_Arm _PX1_arm_var;
#pragma acc declare create ( _PX1_arm_var )

_class_Bragg_crystal _PX1_bragg_crystal_two_var;
#pragma acc declare create ( _PX1_bragg_crystal_two_var )

_class_Arm _PX1_arm_two_var;
#pragma acc declare create ( _PX1_arm_two_var )

_class_E_monitor _PX1_bragg_crystal_out_var;
#pragma acc declare create ( _PX1_bragg_crystal_out_var )

_class_Slit _PX1_secondary_slits_var;
#pragma acc declare create ( _PX1_secondary_slits_var )

_class_Monitor_nD _PX1_vfm_location_var;
#pragma acc declare create ( _PX1_vfm_location_var )

_class_Arm _PX1_vfm_in_xz_plane_var;
#pragma acc declare create ( _PX1_vfm_in_xz_plane_var )

_class_Mirror_curved _PX1_vfm_var;
#pragma acc declare create ( _PX1_vfm_var )

_class_Monitor_nD _PX1_vfm_takeoff_var;
#pragma acc declare create ( _PX1_vfm_takeoff_var )

_class_Monitor_nD _PX1_hfm_location_var;
#pragma acc declare create ( _PX1_hfm_location_var )

_class_Mirror_curved _PX1_hfm_var;
#pragma acc declare create ( _PX1_hfm_var )

_class_Monitor_nD _PX1_hfm_takeoff_var;
#pragma acc declare create ( _PX1_hfm_takeoff_var )

_class_Arm _PX1_sample_stage_var;
#pragma acc declare create ( _PX1_sample_stage_var )

_class_Monitor_nD _PX1_sample_monitor_var;
#pragma acc declare create ( _PX1_sample_monitor_var )

/* component PX1_sample=Single_crystal() [297] DECLARE */
/* Parameter definition for component type 'Single_crystal' */
struct _struct_Single_crystal_parameters {
  /* Component type 'Single_crystal' setting parameters */
  char reflections[16384];
  char geometry[16384];
  MCNUM mosaic_AB[8];
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  MCNUM radius;
  MCNUM delta_d_d;
  MCNUM mosaic;
  MCNUM mosaic_a;
  MCNUM mosaic_b;
  MCNUM mosaic_c;
  MCNUM recip_cell;
  MCNUM barns;
  MCNUM ax;
  MCNUM ay;
  MCNUM az;
  MCNUM bx;
  MCNUM by;
  MCNUM bz;
  MCNUM cx;
  MCNUM cy;
  MCNUM cz;
  MCNUM p_transmit;
  MCNUM sigma_inc;
  MCNUM aa;
  MCNUM bb;
  MCNUM cc;
  MCNUM order;
  MCNUM extra_order;
  MCNUM RX;
  MCNUM RY;
  MCNUM powder;
  MCNUM deltak;
  char material_datafile[16384];
  int surf_size;
  MCNUM* surf_k;
  MCNUM* surf_FT2;
  MCNUM surf_dir[3];
  /* Component type 'Single_crystal' private parameters */
  struct hkl_info_struct  hkl_info;
  off_struct  offdata;
  struct hkl_data*  hkl_list;
  struct tau_data  tau_list[MCSX_REFL_SLIST_SIZE];
  struct sx_abs_data  abs_info;
}; /* _struct_Single_crystal_parameters */
typedef struct _struct_Single_crystal_parameters _class_Single_crystal_parameters;

/* Parameters for component type 'Single_crystal' */
struct _struct_Single_crystal {
  char     _name[256]; /* e.g. PX1_sample */
  char     _type[256]; /* Single_crystal */
  long     _index; /* e.g. 297 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Single_crystal_parameters _parameters;
};
typedef struct _struct_Single_crystal _class_Single_crystal;
_class_Single_crystal _PX1_sample_var;
#pragma acc declare create ( _PX1_sample_var )

/* component PX1_psd4pi=PSD_monitor_4PI() [298] DECLARE */
/* Parameter definition for component type 'PSD_monitor_4PI' */
struct _struct_PSD_monitor_4PI_parameters {
  /* Component type 'PSD_monitor_4PI' setting parameters */
  MCNUM radius;
  MCNUM restore_xray;
  int nx;
  int ny;
  char filename[16384];
  /* Component type 'PSD_monitor_4PI' private parameters */
  DArray2d  PSD_N;
  DArray2d  PSD_p;
  DArray2d  PSD_p2;
}; /* _struct_PSD_monitor_4PI_parameters */
typedef struct _struct_PSD_monitor_4PI_parameters _class_PSD_monitor_4PI_parameters;

/* Parameters for component type 'PSD_monitor_4PI' */
struct _struct_PSD_monitor_4PI {
  char     _name[256]; /* e.g. PX1_psd4pi */
  char     _type[256]; /* PSD_monitor_4PI */
  long     _index; /* e.g. 298 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_PSD_monitor_4PI_parameters _parameters;
};
typedef struct _struct_PSD_monitor_4PI _class_PSD_monitor_4PI;
_class_PSD_monitor_4PI _PX1_psd4pi_var;
#pragma acc declare create ( _PX1_psd4pi_var )

_class_PSD_monitor _PX1_EigerX16M_var;
#pragma acc declare create ( _PX1_EigerX16M_var )

_class_Beamstop _beamdump_308_var;
#pragma acc declare create ( _beamdump_308_var )

_class_Text _PX2a_pos_var;
#pragma acc declare create ( _PX2a_pos_var )

_class_Arm _PX2a_var;
#pragma acc declare create ( _PX2a_var )

_class_Undulator _PX2a_undulator_var;
#pragma acc declare create ( _PX2a_undulator_var )

_class_Arm _PX2a_bragg_crystal_location_var;
#pragma acc declare create ( _PX2a_bragg_crystal_location_var )

_class_Bragg_crystal _PX2a_bragg_crystal_var;
#pragma acc declare create ( _PX2a_bragg_crystal_var )

_class_Arm _PX2a_arm_var;
#pragma acc declare create ( _PX2a_arm_var )

_class_Bragg_crystal _PX2a_bragg_crystal_two_var;
#pragma acc declare create ( _PX2a_bragg_crystal_two_var )

_class_Arm _PX2a_arm_two_var;
#pragma acc declare create ( _PX2a_arm_two_var )

_class_E_monitor _PX2a_bragg_crystal_out_var;
#pragma acc declare create ( _PX2a_bragg_crystal_out_var )

_class_Arm _PX2a_hpm_location_var;
#pragma acc declare create ( _PX2a_hpm_location_var )

_class_Arm _PX2a_hpm_in_yz_plane_var;
#pragma acc declare create ( _PX2a_hpm_in_yz_plane_var )

_class_Mirror_toroid _PX2a_hpm_var;
#pragma acc declare create ( _PX2a_hpm_var )

_class_Arm _PX2a_hpm_takeoff_var;
#pragma acc declare create ( _PX2a_hpm_takeoff_var )

_class_Monitor_nD _PX2a_vfm_location_var;
#pragma acc declare create ( _PX2a_vfm_location_var )

_class_Arm _PX2a_vfm_in_xz_plane_var;
#pragma acc declare create ( _PX2a_vfm_in_xz_plane_var )

_class_Mirror_curved _PX2a_vfm_var;
#pragma acc declare create ( _PX2a_vfm_var )

_class_Monitor_nD _PX2a_vfm_takeoff_var;
#pragma acc declare create ( _PX2a_vfm_takeoff_var )

_class_Monitor_nD _PX2a_hfm_location_var;
#pragma acc declare create ( _PX2a_hfm_location_var )

_class_Mirror_curved _PX2a_hfm_var;
#pragma acc declare create ( _PX2a_hfm_var )

_class_Monitor_nD _PX2a_hfm_takeoff_var;
#pragma acc declare create ( _PX2a_hfm_takeoff_var )

_class_Arm _PX2a_sample_stage_var;
#pragma acc declare create ( _PX2a_sample_stage_var )

_class_Monitor_nD _PX2a_sample_monitor_var;
#pragma acc declare create ( _PX2a_sample_monitor_var )

_class_Single_crystal _PX2a_sample_var;
#pragma acc declare create ( _PX2a_sample_var )

_class_PSD_monitor_4PI _PX2a_psd4pi_var;
#pragma acc declare create ( _PX2a_psd4pi_var )

_class_PSD_monitor _PX2a_Eiger9M_var;
#pragma acc declare create ( _PX2a_Eiger9M_var )

_class_Beamstop _beamdump_335_var;
#pragma acc declare create ( _beamdump_335_var )

_class_Text _SWING_pos_var;
#pragma acc declare create ( _SWING_pos_var )

_class_Arm _SWING_var;
#pragma acc declare create ( _SWING_var )

_class_Undulator _SWING_Source_U20_var;
#pragma acc declare create ( _SWING_Source_U20_var )

_class_Monitor_nD _SWING_mon_src_xy_var;
#pragma acc declare create ( _SWING_mon_src_xy_var )

_class_Monitor_nD _SWING_mon_src_e_var;
#pragma acc declare create ( _SWING_mon_src_e_var )

_class_Slit _SWING_slit_var;
#pragma acc declare create ( _SWING_slit_var )

_class_Monitor_nD _SWING_slit_mon_xy_var;
#pragma acc declare create ( _SWING_slit_mon_xy_var )

_class_Arm _SWING_DCM_location_var;
#pragma acc declare create ( _SWING_DCM_location_var )

_class_Bragg_crystal _SWING_dcm_xtal0_var;
#pragma acc declare create ( _SWING_dcm_xtal0_var )

_class_Arm _SWING_dcm0_var;
#pragma acc declare create ( _SWING_dcm0_var )

_class_Bragg_crystal _SWING_dcm_xtal1_var;
#pragma acc declare create ( _SWING_dcm_xtal1_var )

_class_Arm _SWING_dcm1_var;
#pragma acc declare create ( _SWING_dcm1_var )

_class_Monitor_nD _SWING_mon_dcm_e_var;
#pragma acc declare create ( _SWING_mon_dcm_e_var )

_class_Monitor_nD _SWING_mon_dcm_xy_var;
#pragma acc declare create ( _SWING_mon_dcm_xy_var )

_class_Monitor_nD _SWING_vfm_location_var;
#pragma acc declare create ( _SWING_vfm_location_var )

_class_Arm _SWING_vfm_in_xz_plane_var;
#pragma acc declare create ( _SWING_vfm_in_xz_plane_var )

_class_Mirror_curved _SWING_vfm_var;
#pragma acc declare create ( _SWING_vfm_var )

_class_Monitor_nD _SWING_vfm_takeoff_var;
#pragma acc declare create ( _SWING_vfm_takeoff_var )

_class_Monitor_nD _SWING_hfm_location_var;
#pragma acc declare create ( _SWING_hfm_location_var )

_class_Mirror_curved _SWING_hfm_var;
#pragma acc declare create ( _SWING_hfm_var )

_class_Monitor_nD _SWING_hfm_takeoff_var;
#pragma acc declare create ( _SWING_hfm_takeoff_var )

_class_Monitor_nD _SWING_sample_stage_var;
#pragma acc declare create ( _SWING_sample_stage_var )

/* component SWING_sample_test=Saxs_spheres() [349] DECLARE */
/* Parameter definition for component type 'Saxs_spheres' */
struct _struct_Saxs_spheres_parameters {
  /* Component type 'Saxs_spheres' setting parameters */
  char sphere_mtrl[16384];
  MCNUM R;
  MCNUM Phi;
  MCNUM Delta_rho;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  MCNUM radius;
  MCNUM target_x;
  MCNUM target_y;
  MCNUM target_z;
  int target_index;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM focus_aw;
  MCNUM focus_ah;
  MCNUM focus_r;
  MCNUM mu_c;
  /* Component type 'Saxs_spheres' private parameters */
  double  my_s_pre;
  int  shape;
  int  Z;
  double  At;
  double  rho;
  t_Table  T;
  int  mu_ci;
  int  abs_data;
}; /* _struct_Saxs_spheres_parameters */
typedef struct _struct_Saxs_spheres_parameters _class_Saxs_spheres_parameters;

/* Parameters for component type 'Saxs_spheres' */
struct _struct_Saxs_spheres {
  char     _name[256]; /* e.g. SWING_sample_test */
  char     _type[256]; /* Saxs_spheres */
  long     _index; /* e.g. 349 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Saxs_spheres_parameters _parameters;
};
typedef struct _struct_Saxs_spheres _class_Saxs_spheres;
_class_Saxs_spheres _SWING_sample_test_var;
#pragma acc declare create ( _SWING_sample_test_var )

/* component SWING_sample=SAXSPDBFast() [350] DECLARE */
/* Parameter definition for component type 'SAXSPDBFast' */
struct _struct_SAXSPDBFast_parameters {
  /* Component type 'SAXSPDBFast' setting parameters */
  MCNUM RhoSolvent;
  MCNUM Concentration;
  MCNUM AbsorptionCrosssection;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  MCNUM SampleToDetectorDistance;
  MCNUM DetectorRadius;
  MCNUM qMin;
  MCNUM qMax;
  int NumberOfQBins;
  char PDBFilepath[16384];
  /* Component type 'SAXSPDBFast' private parameters */
  double  Absorption;
  double  NumberDensity;
  DArray1d  qArray;
  DArray1d  IArray;
}; /* _struct_SAXSPDBFast_parameters */
typedef struct _struct_SAXSPDBFast_parameters _class_SAXSPDBFast_parameters;

/* Parameters for component type 'SAXSPDBFast' */
struct _struct_SAXSPDBFast {
  char     _name[256]; /* e.g. SWING_sample */
  char     _type[256]; /* SAXSPDBFast */
  long     _index; /* e.g. 350 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_SAXSPDBFast_parameters _parameters;
};
typedef struct _struct_SAXSPDBFast _class_SAXSPDBFast;
_class_SAXSPDBFast _SWING_sample_var;
#pragma acc declare create ( _SWING_sample_var )

_class_Arm _SWING_sample_out_var;
#pragma acc declare create ( _SWING_sample_out_var )

_class_Monitor_nD _SWING_Eiger4M_var;
#pragma acc declare create ( _SWING_Eiger4M_var )

/* component SWING_QMonitor=SAXSQMonitor() [353] DECLARE */
/* Parameter definition for component type 'SAXSQMonitor' */
struct _struct_SAXSQMonitor_parameters {
  /* Component type 'SAXSQMonitor' setting parameters */
  char RFilename[16384];
  char qFilename[16384];
  int NumberOfBins;
  MCNUM restore_xray;
  MCNUM RadiusDetector;
  MCNUM DistanceFromSample;
  MCNUM LambdaMin;
  MCNUM Lambda0;
  MCNUM qMax;
  /* Component type 'SAXSQMonitor' private parameters */
  DArray1d  Nofq;
  DArray1d  Iofq;
  DArray1d  IofqSquared;
  DArray1d  NofR;
  DArray1d  IofR;
  DArray1d  IofRSquared;
}; /* _struct_SAXSQMonitor_parameters */
typedef struct _struct_SAXSQMonitor_parameters _class_SAXSQMonitor_parameters;

/* Parameters for component type 'SAXSQMonitor' */
struct _struct_SAXSQMonitor {
  char     _name[256]; /* e.g. SWING_QMonitor */
  char     _type[256]; /* SAXSQMonitor */
  long     _index; /* e.g. 353 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_SAXSQMonitor_parameters _parameters;
};
typedef struct _struct_SAXSQMonitor _class_SAXSQMonitor;
_class_SAXSQMonitor _SWING_QMonitor_var;
#pragma acc declare create ( _SWING_QMonitor_var )

_class_Beamstop _beamdump_364_var;
#pragma acc declare create ( _beamdump_364_var )

_class_Text _ANTARES_pos_var;
#pragma acc declare create ( _ANTARES_pos_var )

_class_Text _ROCK_pos_var;
#pragma acc declare create ( _ROCK_pos_var )

_class_Arm _ROCK_var;
#pragma acc declare create ( _ROCK_var )

_class_Bending_magnet _ROCK_Source_var;
#pragma acc declare create ( _ROCK_Source_var )

_class_Slit _ROCK_slit1_var;
#pragma acc declare create ( _ROCK_slit1_var )

_class_Slit _ROCK_slit2_var;
#pragma acc declare create ( _ROCK_slit2_var )

_class_Mirror_toroid_pothole _ROCK_mirror_m1_var;
#pragma acc declare create ( _ROCK_mirror_m1_var )

_class_Arm _ROCK_mirror_m1_out_var;
#pragma acc declare create ( _ROCK_mirror_m1_out_var )

_class_PSD_monitor _ROCK_slit3_xy_var;
#pragma acc declare create ( _ROCK_slit3_xy_var )

/* component ROCK_slit3_div=Divergence_monitor() [364] DECLARE */
/* Parameter definition for component type 'Divergence_monitor' */
struct _struct_Divergence_monitor_parameters {
  /* Component type 'Divergence_monitor' setting parameters */
  int nh;
  int nv;
  int rad;
  char filename[16384];
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM maxdiv_h;
  MCNUM maxdiv_v;
  MCNUM restore_xray;
  MCNUM nx;
  MCNUM ny;
  MCNUM nz;
  int nowritefile;
  /* Component type 'Divergence_monitor' private parameters */
  DArray2d  Div_N;
  DArray2d  Div_p;
  DArray2d  Div_p2;
  double  xmin;
  double  xmax;
  double  ymin;
  double  ymax;
}; /* _struct_Divergence_monitor_parameters */
typedef struct _struct_Divergence_monitor_parameters _class_Divergence_monitor_parameters;

/* Parameters for component type 'Divergence_monitor' */
struct _struct_Divergence_monitor {
  char     _name[256]; /* e.g. ROCK_slit3_div */
  char     _type[256]; /* Divergence_monitor */
  long     _index; /* e.g. 364 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Divergence_monitor_parameters _parameters;
};
typedef struct _struct_Divergence_monitor _class_Divergence_monitor;
_class_Divergence_monitor _ROCK_slit3_div_var;
#pragma acc declare create ( _ROCK_slit3_div_var )

_class_Slit _ROCK_slit3_var;
#pragma acc declare create ( _ROCK_slit3_var )

_class_Mirror _ROCK_mirror_m2a_var;
#pragma acc declare create ( _ROCK_mirror_m2a_var )

_class_Arm _ROCK_mirror_m2a_out_var;
#pragma acc declare create ( _ROCK_mirror_m2a_out_var )

_class_PSD_monitor _ROCK_slit4_in_var;
#pragma acc declare create ( _ROCK_slit4_in_var )

_class_Slit _ROCK_slit4_var;
#pragma acc declare create ( _ROCK_slit4_var )

_class_Arm _ROCK_arm_crystal0_var;
#pragma acc declare create ( _ROCK_arm_crystal0_var )

_class_Bragg_crystal _ROCK_bragg_crystal_var;
#pragma acc declare create ( _ROCK_bragg_crystal_var )

_class_Arm _ROCK_arm_crystal1_var;
#pragma acc declare create ( _ROCK_arm_crystal1_var )

_class_Bragg_crystal _ROCK_bragg_crystal_two_var;
#pragma acc declare create ( _ROCK_bragg_crystal_two_var )

_class_Arm _ROCK_arm_crystal2_var;
#pragma acc declare create ( _ROCK_arm_crystal2_var )

_class_PSD_monitor _ROCK_bragg_crystal_out_var;
#pragma acc declare create ( _ROCK_bragg_crystal_out_var )

_class_Slit _ROCK_slit5_var;
#pragma acc declare create ( _ROCK_slit5_var )

_class_Slit _ROCK_slit6_var;
#pragma acc declare create ( _ROCK_slit6_var )

_class_Mirror_curved _ROCK_mirror_m2b_var;
#pragma acc declare create ( _ROCK_mirror_m2b_var )

_class_Arm _ROCK_mirror_m2b_out_var;
#pragma acc declare create ( _ROCK_mirror_m2b_out_var )

_class_Monitor_nD _ROCK_EnergyMonitor_before_sample_var;
#pragma acc declare create ( _ROCK_EnergyMonitor_before_sample_var )

_class_Monitor_nD _ROCK_e_repartition_after_m2b_var;
#pragma acc declare create ( _ROCK_e_repartition_after_m2b_var )

_class_PSD_monitor _ROCK_sample_in_var;
#pragma acc declare create ( _ROCK_sample_in_var )

/* component ROCK_absorption_sample=Fluorescence() [383] DECLARE */
/* Parameter definition for component type 'Fluorescence' */
struct _struct_Fluorescence_parameters {
  /* Component type 'Fluorescence' setting parameters */
  char geometry[16384];
  MCNUM radius;
  MCNUM thickness;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  int concentric;
  char material[16384];
  MCNUM packing_factor;
  MCNUM rho;
  MCNUM density;
  MCNUM weight;
  MCNUM p_interact;
  MCNUM target_x;
  MCNUM target_y;
  MCNUM target_z;
  MCNUM focus_r;
  MCNUM focus_xw;
  MCNUM focus_yh;
  MCNUM focus_aw;
  MCNUM focus_ah;
  int target_index;
  int flag_compton;
  int flag_rayleigh;
  int flag_lorentzian;
  int flag_kissel;
  int flag_low_z;
  int order;
  /* Component type 'Fluorescence' private parameters */
  struct   compoundData * compound;
  DArray1d  cum_massFractions;
  DArray1d  cum_xs_fluo;
  DArray1d  cum_xs_Compton;
  DArray1d  cum_xs_Rayleigh;
  DArray1d  xs_fluo;
  DArray1d  xs_Compton;
  DArray1d  xs_Rayleigh;
  int   shape;
  off_struct  offdata;
  int   n_fluo;
  int   n_Compton;
  int   n_Rayleigh;
  double  p_fluo;
  double  p_Compton;
  double  p_Rayleigh;
  int     reuse_nb;
  int     reuse_intersect;
  double  reuse_ki;
  double  reuse_l0;
  double  reuse_l1;
  double  reuse_l2;
  double  reuse_l3;
  double  reuse_sigma_barn;
  DArray1d  reuse_cum_xs_fluo;
  DArray1d  reuse_cum_xs_Compton;
  DArray1d  reuse_cum_xs_Rayleigh;
  DArray1d  reuse_xs_fluo;
  DArray1d  reuse_xs_Compton;
  DArray1d  reuse_xs_Rayleigh;
}; /* _struct_Fluorescence_parameters */
typedef struct _struct_Fluorescence_parameters _class_Fluorescence_parameters;

/* Parameters for component type 'Fluorescence' */
struct _struct_Fluorescence {
  char     _name[256]; /* e.g. ROCK_absorption_sample */
  char     _type[256]; /* Fluorescence */
  long     _index; /* e.g. 383 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Fluorescence_parameters _parameters;
};
typedef struct _struct_Fluorescence _class_Fluorescence;
_class_Fluorescence _ROCK_absorption_sample_var;
#pragma acc declare create ( _ROCK_absorption_sample_var )

_class_Monitor_nD _ROCK_fluo_monitor_var;
#pragma acc declare create ( _ROCK_fluo_monitor_var )

_class_Monitor_nD _ROCK_EnergyMonitor_after_sample_var;
#pragma acc declare create ( _ROCK_EnergyMonitor_after_sample_var )

_class_PSD_monitor _ROCK_psd_monitor_var;
#pragma acc declare create ( _ROCK_psd_monitor_var )

_class_Beamstop _beamdump_398_var;
#pragma acc declare create ( _beamdump_398_var )

_class_Text _ANATOMIX_pos_var;
#pragma acc declare create ( _ANATOMIX_pos_var )

_class_Arm _ANATOMIX_var;
#pragma acc declare create ( _ANATOMIX_var )

_class_Undulator _ANATOMIX_source_var;
#pragma acc declare create ( _ANATOMIX_source_var )

_class_Monitor_nD _ANATOMIX_e_repartition_before_cc_var;
#pragma acc declare create ( _ANATOMIX_e_repartition_before_cc_var )

_class_PSD_monitor _ANATOMIX_psd_monitor_before_cc_var;
#pragma acc declare create ( _ANATOMIX_psd_monitor_before_cc_var )

_class_Bragg_crystal _ANATOMIX_bragg_crystal_var;
#pragma acc declare create ( _ANATOMIX_bragg_crystal_var )

_class_Arm _ANATOMIX_arm_var;
#pragma acc declare create ( _ANATOMIX_arm_var )

_class_Bragg_crystal _ANATOMIX_bragg_crystal_two_var;
#pragma acc declare create ( _ANATOMIX_bragg_crystal_two_var )

_class_Arm _ANATOMIX_arm_two_var;
#pragma acc declare create ( _ANATOMIX_arm_two_var )

_class_PSD_monitor _ANATOMIX_psd_after_cc_var;
#pragma acc declare create ( _ANATOMIX_psd_after_cc_var )

_class_E_monitor _ANATOMIX_e_monitor_before_sample_var;
#pragma acc declare create ( _ANATOMIX_e_monitor_before_sample_var )

_class_PSD_monitor _ANATOMIX_psd_repartition_after_cc_var;
#pragma acc declare create ( _ANATOMIX_psd_repartition_after_cc_var )

_class_Arm _ANATOMIX_sample_rotation_stage_var;
#pragma acc declare create ( _ANATOMIX_sample_rotation_stage_var )

/* component ANATOMIX_sample=Filter() [401] DECLARE */
/* Parameter definition for component type 'Filter' */
struct _struct_Filter_parameters {
  /* Component type 'Filter' setting parameters */
  MCNUM refraction;
  MCNUM fixed_delta;
  char material_datafile[16384];
  char geometry[16384];
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  MCNUM radius;
  int mu_col;
  /* Component type 'Filter' private parameters */
  int  Z;
  int  mu_c;
  double  Ar;
  double  rho;
  double  delta_prefactor;
  double  betafact;
  t_Table  table;
  int  shape;
  off_struct  offdata;
  int  filter_row;
}; /* _struct_Filter_parameters */
typedef struct _struct_Filter_parameters _class_Filter_parameters;

/* Parameters for component type 'Filter' */
struct _struct_Filter {
  char     _name[256]; /* e.g. ANATOMIX_sample */
  char     _type[256]; /* Filter */
  long     _index; /* e.g. 401 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Filter_parameters _parameters;
};
typedef struct _struct_Filter _class_Filter;
_class_Filter _ANATOMIX_sample_var;
#pragma acc declare create ( _ANATOMIX_sample_var )

_class_E_monitor _ANATOMIX_e_monitor_after_sample_var;
#pragma acc declare create ( _ANATOMIX_e_monitor_after_sample_var )

_class_PSD_monitor _ANATOMIX_psd_monitor_after_cc_var;
#pragma acc declare create ( _ANATOMIX_psd_monitor_after_cc_var )

_class_Beamstop _beamdump_416_var;
#pragma acc declare create ( _beamdump_416_var )

_class_Text _NANOSCOPIUM_pos_var;
#pragma acc declare create ( _NANOSCOPIUM_pos_var )

_class_Arm _NANOSCOPIUM_var;
#pragma acc declare create ( _NANOSCOPIUM_var )

_class_Undulator _NANO_source_var;
#pragma acc declare create ( _NANO_source_var )

_class_E_monitor _NANO_e_monitor_source_var;
#pragma acc declare create ( _NANO_e_monitor_source_var )

/* component NANO_psd_source=PSD_monitor_coh() [409] DECLARE */
/* Parameter definition for component type 'PSD_monitor_coh' */
struct _struct_PSD_monitor_coh_parameters {
  /* Component type 'PSD_monitor_coh' setting parameters */
  int nx;
  int ny;
  char filename[16384];
  MCNUM restore_xray;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM ratio;
  int centering;
  int nowritefile;
  /* Component type 'PSD_monitor_coh' private parameters */
  DArray2d  PSD_N;
  DArray2d  PSD_p2;
  DArray2d  PSD_phi_real;
  DArray2d  PSD_phi_imag;
  double  xmin;
  double  xmax;
  double  ymin;
  double  ymax;
}; /* _struct_PSD_monitor_coh_parameters */
typedef struct _struct_PSD_monitor_coh_parameters _class_PSD_monitor_coh_parameters;

/* Parameters for component type 'PSD_monitor_coh' */
struct _struct_PSD_monitor_coh {
  char     _name[256]; /* e.g. NANO_psd_source */
  char     _type[256]; /* PSD_monitor_coh */
  long     _index; /* e.g. 409 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_PSD_monitor_coh_parameters _parameters;
};
typedef struct _struct_PSD_monitor_coh _class_PSD_monitor_coh;
_class_PSD_monitor_coh _NANO_psd_source_var;
#pragma acc declare create ( _NANO_psd_source_var )

_class_Slit _NANO_slit_1_var;
#pragma acc declare create ( _NANO_slit_1_var )

_class_Arm _NANO_m1_in_var;
#pragma acc declare create ( _NANO_m1_in_var )

_class_Arm _NANO_m1_roll_var;
#pragma acc declare create ( _NANO_m1_roll_var )

_class_Mirror_curved _NANO_mirror_m1_var;
#pragma acc declare create ( _NANO_mirror_m1_var )

_class_Arm _NANO_beam_deviation_var;
#pragma acc declare create ( _NANO_beam_deviation_var )

_class_Arm _NANO_m2_in_var;
#pragma acc declare create ( _NANO_m2_in_var )

_class_Mirror_curved _NANO_mirror_m2_var;
#pragma acc declare create ( _NANO_mirror_m2_var )

_class_Arm _NANO_mirror_m2_out_var;
#pragma acc declare create ( _NANO_mirror_m2_out_var )

_class_Slit _NANO_slit_2_var;
#pragma acc declare create ( _NANO_slit_2_var )

_class_Arm _NANO_dcm_in_var;
#pragma acc declare create ( _NANO_dcm_in_var )

_class_PSD_monitor _NANO_PSD_dcm_in_var;
#pragma acc declare create ( _NANO_PSD_dcm_in_var )

_class_Arm _NANO_bragg_roll_var;
#pragma acc declare create ( _NANO_bragg_roll_var )

_class_Bragg_crystal _NANO_bragg_crystal_1_var;
#pragma acc declare create ( _NANO_bragg_crystal_1_var )

_class_Arm _NANO_dcm2_rot_var;
#pragma acc declare create ( _NANO_dcm2_rot_var )

_class_Arm _NANO_dcm_transl_var;
#pragma acc declare create ( _NANO_dcm_transl_var )

_class_Bragg_crystal _NANO_bragg_crystal_2_var;
#pragma acc declare create ( _NANO_bragg_crystal_2_var )

_class_Arm _NANO_bragg2_out_var;
#pragma acc declare create ( _NANO_bragg2_out_var )

_class_Arm _NANO_dcm_out_var;
#pragma acc declare create ( _NANO_dcm_out_var )

_class_E_monitor _NANO_e_dcm_out_var;
#pragma acc declare create ( _NANO_e_dcm_out_var )

_class_Arm _NANO_secondary_source_slits_var;
#pragma acc declare create ( _NANO_secondary_source_slits_var )

_class_PSD_monitor _NANO_psd_ss_in_var;
#pragma acc declare create ( _NANO_psd_ss_in_var )

_class_Slit _NANO_slit_3_var;
#pragma acc declare create ( _NANO_slit_3_var )

_class_PSD_monitor _NANO_psd_ss_out_var;
#pragma acc declare create ( _NANO_psd_ss_out_var )

_class_Arm _NANO_jjxray2_slits_var;
#pragma acc declare create ( _NANO_jjxray2_slits_var )

_class_Slit _NANO_slit_5_var;
#pragma acc declare create ( _NANO_slit_5_var )

_class_Arm _NANO_kb_in_var;
#pragma acc declare create ( _NANO_kb_in_var )

_class_Mirror_curved _NANO_kb_1_var;
#pragma acc declare create ( _NANO_kb_1_var )

_class_Arm _NANO_kb_beam_deviation_var;
#pragma acc declare create ( _NANO_kb_beam_deviation_var )

_class_Arm _NANO_kb1_out_var;
#pragma acc declare create ( _NANO_kb1_out_var )

_class_Mirror_curved _NANO_kb2_var;
#pragma acc declare create ( _NANO_kb2_var )

_class_Arm _NANO_kb_out_var;
#pragma acc declare create ( _NANO_kb_out_var )

_class_Slit _NANO_slit_var;
#pragma acc declare create ( _NANO_slit_var )

_class_PSD_monitor _NANO_psd_sample_stage_var;
#pragma acc declare create ( _NANO_psd_sample_stage_var )

_class_Beamstop _beamdump_456_var;
#pragma acc declare create ( _beamdump_456_var )

_class_Text _DIFFABS_pos_var;
#pragma acc declare create ( _DIFFABS_pos_var )

_class_Arm _DIFFABS_var;
#pragma acc declare create ( _DIFFABS_var )

_class_Bending_magnet _DIFFABS_BM_D13_1_var;
#pragma acc declare create ( _DIFFABS_BM_D13_1_var )

_class_Slit _DIFFABS_primary_slit_var;
#pragma acc declare create ( _DIFFABS_primary_slit_var )

_class_Arm _DIFFABS_M1_location_var;
#pragma acc declare create ( _DIFFABS_M1_location_var )

_class_Arm _DIFFABS_M1_rotated_var;
#pragma acc declare create ( _DIFFABS_M1_rotated_var )

_class_Mirror_curved _DIFFABS_M1_var;
#pragma acc declare create ( _DIFFABS_M1_var )

_class_Arm _DIFFABS_M1_out_var;
#pragma acc declare create ( _DIFFABS_M1_out_var )

_class_Slit _DIFFABS_DCM_slit_in_var;
#pragma acc declare create ( _DIFFABS_DCM_slit_in_var )

_class_Monitor_nD _DIFFABS_DCM_in_var;
#pragma acc declare create ( _DIFFABS_DCM_in_var )

_class_Monitor_nD _DIFFABS_DCM_in_div_var;
#pragma acc declare create ( _DIFFABS_DCM_in_div_var )

_class_Arm _DIFFABS_DCM_location_var;
#pragma acc declare create ( _DIFFABS_DCM_location_var )

_class_Bragg_crystal _DIFFABS_bragg_crystal_var;
#pragma acc declare create ( _DIFFABS_bragg_crystal_var )

_class_Arm _DIFFABS_arm_crystal1_var;
#pragma acc declare create ( _DIFFABS_arm_crystal1_var )

_class_Bragg_crystal _DIFFABS_bragg_crystal_two_var;
#pragma acc declare create ( _DIFFABS_bragg_crystal_two_var )

_class_Arm _DIFFABS_arm_crystal2_var;
#pragma acc declare create ( _DIFFABS_arm_crystal2_var )

_class_Monitor_nD _DIFFABS_DCM_out_var;
#pragma acc declare create ( _DIFFABS_DCM_out_var )

_class_Monitor_nD _DIFFABS_DCM_out_div_var;
#pragma acc declare create ( _DIFFABS_DCM_out_div_var )

_class_Monitor_nD _DIFFABS_DCM_out_e_var;
#pragma acc declare create ( _DIFFABS_DCM_out_e_var )

_class_Slit _DIFFABS_DCM_slit_out_var;
#pragma acc declare create ( _DIFFABS_DCM_slit_out_var )

_class_Arm _DIFFABS_M2_location_var;
#pragma acc declare create ( _DIFFABS_M2_location_var )

_class_Arm _DIFFABS_M2_rotated_var;
#pragma acc declare create ( _DIFFABS_M2_rotated_var )

_class_Mirror_curved _DIFFABS_M2_var;
#pragma acc declare create ( _DIFFABS_M2_var )

_class_Arm _DIFFABS_M2_out_var;
#pragma acc declare create ( _DIFFABS_M2_out_var )

_class_Monitor_nD _DIFFABS_sample_stage_var;
#pragma acc declare create ( _DIFFABS_sample_stage_var )

_class_FluoPowder _DIFFABS_fluo_var;
#pragma acc declare create ( _DIFFABS_fluo_var )

_class_Monitor_nD _DIFFABS_fluo_monitor_var;
#pragma acc declare create ( _DIFFABS_fluo_monitor_var )

_class_Monitor_nD _DIFFABS_det_angle_var;
#pragma acc declare create ( _DIFFABS_det_angle_var )

_class_Monitor_nD _DIFFABS_xpad_var;
#pragma acc declare create ( _DIFFABS_xpad_var )

_class_Beamstop _beamdump_487_var;
#pragma acc declare create ( _beamdump_487_var )

_class_Text _SEXTANTS_var;
#pragma acc declare create ( _SEXTANTS_var )

_class_Text _SIXS_pos_var;
#pragma acc declare create ( _SIXS_pos_var )

_class_Arm _SIXS_var;
#pragma acc declare create ( _SIXS_var )

_class_Undulator _SIXS_Source_U20_var;
#pragma acc declare create ( _SIXS_Source_U20_var )

_class_Monitor_nD _SIXS_mon_src_xy_var;
#pragma acc declare create ( _SIXS_mon_src_xy_var )

_class_Monitor_nD _SIXS_mon_src_e_var;
#pragma acc declare create ( _SIXS_mon_src_e_var )

_class_Slit _SIXS_slit_var;
#pragma acc declare create ( _SIXS_slit_var )

_class_Monitor_nD _SIXS_slit_mon_xy_var;
#pragma acc declare create ( _SIXS_slit_mon_xy_var )

_class_Arm _SIXS_DCM_location_var;
#pragma acc declare create ( _SIXS_DCM_location_var )

_class_Bragg_crystal _SIXS_dcm_xtal0_var;
#pragma acc declare create ( _SIXS_dcm_xtal0_var )

_class_Arm _SIXS_dcm0_var;
#pragma acc declare create ( _SIXS_dcm0_var )

_class_Bragg_crystal _SIXS_dcm_xtal1_var;
#pragma acc declare create ( _SIXS_dcm_xtal1_var )

_class_Arm _SIXS_dcm1_var;
#pragma acc declare create ( _SIXS_dcm1_var )

_class_Monitor_nD _SIXS_mon_dcm_e_var;
#pragma acc declare create ( _SIXS_mon_dcm_e_var )

_class_Monitor_nD _SIXS_mon_dcm_xy_var;
#pragma acc declare create ( _SIXS_mon_dcm_xy_var )

_class_Arm _SIXS_M1_location_var;
#pragma acc declare create ( _SIXS_M1_location_var )

_class_Arm _SIXS_M1_rotated_var;
#pragma acc declare create ( _SIXS_M1_rotated_var )

_class_Mirror_curved _SIXS_M1_var;
#pragma acc declare create ( _SIXS_M1_var )

_class_Arm _SIXS_M1_out_var;
#pragma acc declare create ( _SIXS_M1_out_var )

_class_Arm _SIXS_M2_location_var;
#pragma acc declare create ( _SIXS_M2_location_var )

_class_Arm _SIXS_M2_rotated_var;
#pragma acc declare create ( _SIXS_M2_rotated_var )

_class_Mirror_curved _SIXS_M2_var;
#pragma acc declare create ( _SIXS_M2_var )

_class_Arm _SIXS_M2_out_var;
#pragma acc declare create ( _SIXS_M2_out_var )

_class_Monitor_nD _SIXS_sample_stage_var;
#pragma acc declare create ( _SIXS_sample_stage_var )

_class_Single_crystal _SIXS_sx_layer_var;
#pragma acc declare create ( _SIXS_sx_layer_var )

_class_Single_crystal _SIXS_sx_bulk_var;
#pragma acc declare create ( _SIXS_sx_bulk_var )

_class_Arm _SIXS_sample_out_var;
#pragma acc declare create ( _SIXS_sample_out_var )

_class_Monitor_nD _SIXS_det4pi_var;
#pragma acc declare create ( _SIXS_det4pi_var )

_class_Monitor_nD _SIXS_detector_layer_var;
#pragma acc declare create ( _SIXS_detector_layer_var )

_class_Monitor_nD _SIXS_detector_bulk_var;
#pragma acc declare create ( _SIXS_detector_bulk_var )

_class_Beamstop _beamdump_519_var;
#pragma acc declare create ( _beamdump_519_var )

_class_Text _CASSIOPEE_pos_var;
#pragma acc declare create ( _CASSIOPEE_pos_var )

_class_Arm _CASSIOPEE_var;
#pragma acc declare create ( _CASSIOPEE_var )

_class_Undulator _CASSIOPEE_Source_HU60_var;
#pragma acc declare create ( _CASSIOPEE_Source_HU60_var )

_class_Undulator _CASSIOPEE_Source_HU256_var;
#pragma acc declare create ( _CASSIOPEE_Source_HU256_var )

_class_Arm _CASSIOPEE_M1a_location_var;
#pragma acc declare create ( _CASSIOPEE_M1a_location_var )

_class_Mirror_curved _CASSIOPEE_M1a_var;
#pragma acc declare create ( _CASSIOPEE_M1a_var )

_class_Arm _CASSIOPEE_M1a_out_var;
#pragma acc declare create ( _CASSIOPEE_M1a_out_var )

_class_Mirror_curved _CASSIOPEE_M1b_var;
#pragma acc declare create ( _CASSIOPEE_M1b_var )

_class_Mirror_curved _CASSIOPEE_M1c_var;
#pragma acc declare create ( _CASSIOPEE_M1c_var )

_class_Arm _CASSIOPEE_M1bc_out_var;
#pragma acc declare create ( _CASSIOPEE_M1bc_out_var )

_class_Monitor_nD _CASSIOPEE_PSD_M1out_var;
#pragma acc declare create ( _CASSIOPEE_PSD_M1out_var )

_class_Arm _CASSIOPEE_PG_location_var;
#pragma acc declare create ( _CASSIOPEE_PG_location_var )

_class_Grating_reflect _CASSIOPEE_PG_var;
#pragma acc declare create ( _CASSIOPEE_PG_var )

_class_Monitor_nD _CASSIOPEE_M2_rotation_axis_var;
#pragma acc declare create ( _CASSIOPEE_M2_rotation_axis_var )

_class_Mirror _CASSIOPEE_M2_var;
#pragma acc declare create ( _CASSIOPEE_M2_var )

_class_Arm _CASSIOPEE_PM_takeoff_var;
#pragma acc declare create ( _CASSIOPEE_PM_takeoff_var )

_class_Slit _CASSIOPEE_slit_var;
#pragma acc declare create ( _CASSIOPEE_slit_var )

_class_Mirror_curved _CASSIOPEE_M4_var;
#pragma acc declare create ( _CASSIOPEE_M4_var )

_class_Monitor_nD _CASSIOPEE_PSD_var;
#pragma acc declare create ( _CASSIOPEE_PSD_var )

_class_Beamstop _beamdump_540_var;
#pragma acc declare create ( _beamdump_540_var )

_class_Text _SIRIUS_pos_var;
#pragma acc declare create ( _SIRIUS_pos_var )

_class_Arm _SIRIUS_var;
#pragma acc declare create ( _SIRIUS_var )

_class_Bending_magnet _SIRIUS_source_var;
#pragma acc declare create ( _SIRIUS_source_var )

_class_Monitor_nD _SIRIUS_M1_loc_var;
#pragma acc declare create ( _SIRIUS_M1_loc_var )

_class_Arm _SIRIUS_M1_rot_var;
#pragma acc declare create ( _SIRIUS_M1_rot_var )

_class_Mirror_curved _SIRIUS_M1_var;
#pragma acc declare create ( _SIRIUS_M1_var )

_class_Arm _SIRIUS_M1_out_var;
#pragma acc declare create ( _SIRIUS_M1_out_var )

_class_Monitor_nD _SIRIUS_DCM_location_var;
#pragma acc declare create ( _SIRIUS_DCM_location_var )

_class_Bragg_crystal _SIRIUS_bragg_crystal_var;
#pragma acc declare create ( _SIRIUS_bragg_crystal_var )

_class_Arm _SIRIUS_arm_crystal1_var;
#pragma acc declare create ( _SIRIUS_arm_crystal1_var )

_class_Bragg_crystal _SIRIUS_bragg_crystal_two_var;
#pragma acc declare create ( _SIRIUS_bragg_crystal_two_var )

_class_Arm _SIRIUS_arm_crystal2_var;
#pragma acc declare create ( _SIRIUS_arm_crystal2_var )

_class_Monitor_nD _SIRIUS_DCM_out_var;
#pragma acc declare create ( _SIRIUS_DCM_out_var )

_class_Monitor_nD _SIRIUS_DCM_out_div_var;
#pragma acc declare create ( _SIRIUS_DCM_out_div_var )

_class_Monitor_nD _SIRIUS_DCM_out_e_var;
#pragma acc declare create ( _SIRIUS_DCM_out_e_var )

_class_Monitor_nD _SIRIUS_def_loc_var;
#pragma acc declare create ( _SIRIUS_def_loc_var )

_class_Arm _SIRIUS_def_rot_var;
#pragma acc declare create ( _SIRIUS_def_rot_var )

_class_Mirror _SIRIUS_def_mirror_var;
#pragma acc declare create ( _SIRIUS_def_mirror_var )

_class_Arm _SIRIUS_def_out_var;
#pragma acc declare create ( _SIRIUS_def_out_var )

_class_Monitor_nD _SIRIUS_sample_stage_var;
#pragma acc declare create ( _SIRIUS_sample_stage_var )

_class_FluoPowder _SIRIUS_fluo_var;
#pragma acc declare create ( _SIRIUS_fluo_var )

_class_Monitor_nD _SIRIUS_det_2d_var;
#pragma acc declare create ( _SIRIUS_det_2d_var )

_class_Monitor_nD _SIRIUS_det_fluo_var;
#pragma acc declare create ( _SIRIUS_det_fluo_var )

_class_Beamstop _beamdump_565_var;
#pragma acc declare create ( _beamdump_565_var )

_class_Text _LUCIA_pos_var;
#pragma acc declare create ( _LUCIA_pos_var )

_class_Arm _LUCIA_var;
#pragma acc declare create ( _LUCIA_var )

_class_Undulator _LUCIA_source_var;
#pragma acc declare create ( _LUCIA_source_var )

_class_Monitor_nD _LUCIA_mon_src_xy_var;
#pragma acc declare create ( _LUCIA_mon_src_xy_var )

_class_Monitor_nD _LUCIA_mon_src_e_var;
#pragma acc declare create ( _LUCIA_mon_src_e_var )

_class_Slit _LUCIA_slit_var;
#pragma acc declare create ( _LUCIA_slit_var )

_class_Monitor_nD _LUCIA_slit_mon_xy_var;
#pragma acc declare create ( _LUCIA_slit_mon_xy_var )

_class_Arm _LUCIA_DCM_location_var;
#pragma acc declare create ( _LUCIA_DCM_location_var )

_class_Bragg_crystal _LUCIA_dcm_xtal0_var;
#pragma acc declare create ( _LUCIA_dcm_xtal0_var )

_class_Arm _LUCIA_dcm0_var;
#pragma acc declare create ( _LUCIA_dcm0_var )

_class_Bragg_crystal _LUCIA_dcm_xtal1_var;
#pragma acc declare create ( _LUCIA_dcm_xtal1_var )

_class_Arm _LUCIA_dcm1_var;
#pragma acc declare create ( _LUCIA_dcm1_var )

_class_Monitor_nD _LUCIA_mon_dcm_e_var;
#pragma acc declare create ( _LUCIA_mon_dcm_e_var )

_class_Monitor_nD _LUCIA_mon_dcm_xy_var;
#pragma acc declare create ( _LUCIA_mon_dcm_xy_var )

_class_Slit _LUCIA_diaphragm_var;
#pragma acc declare create ( _LUCIA_diaphragm_var )

_class_Monitor_nD _LUCIA_sample_stage_var;
#pragma acc declare create ( _LUCIA_sample_stage_var )

_class_Arm _LUCIA_fluo_rotated_var;
#pragma acc declare create ( _LUCIA_fluo_rotated_var )

_class_Fluorescence _LUCIA_sample_var;
#pragma acc declare create ( _LUCIA_sample_var )

_class_Monitor_nD _LUCIA_transmission_var;
#pragma acc declare create ( _LUCIA_transmission_var )

/* component LUCIA_mon_spl_SDD=Fluo_detector() [568] DECLARE */
/* Parameter definition for component type 'Fluo_detector' */
struct _struct_Fluo_detector_parameters {
  /* Component type 'Fluo_detector' setting parameters */
  MCNUM radius;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM Emin;
  MCNUM Emax;
  MCNUM nE;
  char filename[16384];
  MCNUM restore_xray;
  MCNUM escape_ratio;
  MCNUM escape_energy;
  MCNUM pileup_ratio;
  MCNUM electronic_noise;
  MCNUM resolution_energy;
  MCNUM resolution;
  MCNUM flag_lorentzian;
  /* Component type 'Fluo_detector' private parameters */
  DArray1d  E_N;
  DArray1d  E_p;
  DArray1d  E_p2;
  DArray1d  E_N_pileup;
  DArray1d  E_p_pileup;
  DArray1d  E_p2_pileup;
  DArray1d  E_N_escape;
  DArray1d  E_p_escape;
  DArray1d  E_p2_escape;
  int       shape;
  double    K;
  double    p_sum;
  double    N_sum;
}; /* _struct_Fluo_detector_parameters */
typedef struct _struct_Fluo_detector_parameters _class_Fluo_detector_parameters;

/* Parameters for component type 'Fluo_detector' */
struct _struct_Fluo_detector {
  char     _name[256]; /* e.g. LUCIA_mon_spl_SDD */
  char     _type[256]; /* Fluo_detector */
  long     _index; /* e.g. 568 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Fluo_detector_parameters _parameters;
};
typedef struct _struct_Fluo_detector _class_Fluo_detector;
_class_Fluo_detector _LUCIA_mon_spl_SDD_var;
#pragma acc declare create ( _LUCIA_mon_spl_SDD_var )

_class_Monitor_nD _LUCIA_mon_spl_fluo_var;
#pragma acc declare create ( _LUCIA_mon_spl_fluo_var )

_class_Beamstop _beamdump_588_var;
#pragma acc declare create ( _beamdump_588_var )

/* component storage=Shape() [571] DECLARE */
/* Parameter definition for component type 'Shape' */
struct _struct_Shape_parameters {
  /* Component type 'Shape' setting parameters */
  char geometry[16384];
  MCNUM radius;
  MCNUM xwidth;
  MCNUM yheight;
  MCNUM zdepth;
  MCNUM thickness;
  MCNUM nx;
  MCNUM ny;
  MCNUM nz;
  int center;
  /* Component type 'Shape' private parameters */
  off_struct  offdata;
}; /* _struct_Shape_parameters */
typedef struct _struct_Shape_parameters _class_Shape_parameters;

/* Parameters for component type 'Shape' */
struct _struct_Shape {
  char     _name[256]; /* e.g. storage */
  char     _type[256]; /* Shape */
  long     _index; /* e.g. 571 index in TRACE list */
  Coords   _position_absolute;
  Coords   _position_relative; /* wrt PREVIOUS */
  Rotation _rotation_absolute;
  Rotation _rotation_relative; /* wrt PREVIOUS */
  int      _rotation_is_identity;
  int      _position_relative_is_zero;
  _class_Shape_parameters _parameters;
};
typedef struct _struct_Shape _class_Shape;
_class_Shape _storage_var;
#pragma acc declare create ( _storage_var )

_class_Shape _hall0_var;
#pragma acc declare create ( _hall0_var )

_class_Shape _hall1_var;
#pragma acc declare create ( _hall1_var )

_class_Arm _entrance_0_var;
#pragma acc declare create ( _entrance_0_var )

_class_Shape _entrance_1_var;
#pragma acc declare create ( _entrance_1_var )

_class_Shape _ANATOMIX_building_var;
#pragma acc declare create ( _ANATOMIX_building_var )

_class_Text _soleil_label_var;
#pragma acc declare create ( _soleil_label_var )

int mcNUMCOMP = 577;

/* User declarations from instrument definition. Can define functions. */
	  //Slit 1
	double MARS_DistanceToPrimarySlit1 = 11.340;
	double MARS_DistanceToPrimarySlit2 = 11.440;
	double MARS_PrimarySlit1Width  = 0.02;
	double MARS_PrimarySlit1Height = 0.002;
	double MARS_PrimarySlit2Width  = 0.02;
	double MARS_PrimarySlit2Height = 0.002;

	//Mirror M1
	double MARS_DistanceSourceToM1 = 12.784;
	double MARS_M12_depth = 0.06;
	double MARS_M12_length = 2.1;
	double MARS_AngleM1 = 0.0031*RAD2DEG;

	//DCM
	double MARS_DistanceSourceToDCM = 14.395;
	double MARS_DcmGap = 0.101268;
	double MARS_AngleDCM = 10.59;
	double MARS_alpha = 0;
	double MARS_DcmHoriGap = 0.09863;
	double MARS_Ts=0.04506/(2*0.1832);
	double MARS_Tz=0.04506/(2*0.9830);
	//double DiagonaleDcmGap = sqrt(MARS_Ts*MARS_Ts+MARS_Tz*MARS_Tz);

	//BeamMonitor1
	double MARS_DistanceToPrimaryBeamMonitor = 15.678;
	double MARS_PrimaryBeamMonitorWidth = 0.05;
	double MARS_PrimaryBeamMonitorHeight = 0.05;

	//Mirror M2
	double MARS_DistanceSourceToM2 = 16.826;
	double MARS_AngleM2 = 0.0031*RAD2DEG;
	double MARS_RadiusM1 = 8248;
  double MARS_RadiusM2 = 6600;

	//Slit 2
	double MARS_DistanceToSecondarySlit1 = 18.231;
	double MARS_DistanceToSecondarySlit2 = 18.315;
	double MARS_SecondarySlit1Width  = 0.03; // 3x5
	double MARS_SecondarySlit1Height = 0.05;
	double MARS_SecondarySlit2Width  = 0.005;
	double MARS_SecondarySlit2Height = 0.03;

	//BeamMonitor2
	double MARS_DistanceToSecondaryBeamMonitor = 18.588;
	double MARS_SecondaryBeamMonitorWidth = 0.5;
	double MARS_SecondaryBeamMonitorHeight = 0.5;
	
	//Sample

	double MARS_DistanceToSample = 23.06;


	//cristal analyzor
	double MARS_DistanceCentreToCristal = 0.446;
	double MARS_AngleCa = 6.2267;
	
	//slit A1
	double MARS_distanceCristalslitA1 = 0.194;



	//slit A2
	double MARS_distanceCristalslitA2 = 0.224;


	//detector
	double MARS_distanceCristaldetector = 0.224;


	/* Declarations */
	
	double MARS_M12_width=0.05;
  double MARS_calculated_angle;
  double PSICHE_dcm_gap;
  double PSICHE_dcm_scatter;
  #pragma acc declare create(PSICHE_dcm_scatter)
    double DISCO_E0;
    double DISCO_dE;
    double DISCO_grazing_angle_reflect_grating;
    //For more information on the following see the Czerny_turner instrument
    //At a later date, the Czerny-turner used in this instrument should be changed to the one used on DISCO(blazed grating, toroidal mirrors ...)
    double DISCO_number_lines_per_mm; 
    double DISCO_grazing_angle_order_grating;
    double DISCO_order;
    double DISCO_period;
    double DISCO_x_screw;
    double DISCO_theta_calculated;
    double DISCO_w_monitor_value;
    double DISCO_x_screw_var;
    double DISCO_w_monitor_error;
    double DISCO_number_events_w_monitor;  
    double PUMA_HFM_radius;
    double PUMA_DCM_gap;
    double PUMA_d_hkl;
    double PUMA_KB_VFM_radius;
    double PUMA_KB_HFM_radius;
  // Primary slit (Monochromator Ring Hutch, before the DCM)
  double CRISTAL_DistanceSourceToSlit1 = 14.0;
  double CRISTAL_Slit1Width  = 0.02;
  double CRISTAL_Slit1Height = 0.01;

  // Si(111) DCM
  double CRISTAL_DistanceSourceToDCM = 17.0;
  double CRISTAL_dcm_gap = 0.01;
  double CRISTAL_DCM_theta;

  // Mirror pair (Mirrors Hutch, horizontal deflection)
  double CRISTAL_DistanceSourceToM1 = 20.0;
  double CRISTAL_DistanceM1ToM2     = 0.5;
  double CRISTAL_M_length = 0.3;
  double CRISTAL_M_width  = 0.1;

  // Secondary slit (end of Mirrors Hutch)
  double CRISTAL_DistanceSourceToSlit2 = 22.5;
  double CRISTAL_Slit2Width  = 0.03;
  double CRISTAL_Slit2Height = 0.02;

  // Sample stage (2-circle powder diffractometer, BC Hutch)
  double CRISTAL_DistanceSourceToSample = 35.0;

  // Mythen-II curved detector, radius 720 mm
  double CRISTAL_DetectorRadius = 0.72;
  // Source: U20, 98 periods, short section (EXP-OPT-CDC-0771)
  double GALAXIES_lu = 20e-3;      // [m] undulator period
  int    GALAXIES_Nper = 98;       // number of periods
  double GALAXIES_K = 1.575;       // undulator deflection parameter (tune with E0)
  double GALAXIES_sigex  = 388e-6; // [m] e-beam H size   (short section)
  double GALAXIES_sigey  = 8.1e-6; // [m] e-beam V size
  double GALAXIES_sigepx = 14.5e-6; // [rad] e-beam H divergence
  double GALAXIES_sigepy = 4.61e-6; // [rad] e-beam V divergence

  // Front end / slits
  double GALAXIES_DistanceToAbsorber    = 10.0;
  double GALAXIES_AbsorberWidth = 2.5e-3, GALAXIES_AbsorberHeight = 2.5e-3;
  double GALAXIES_DistanceToDiaphragm    = 11.7;
  double GALAXIES_DiaphragmWidth = 1.8e-3, GALAXIES_DiaphragmHeight = 0.6e-3;
  double GALAXIES_DistanceToPrimarySlit  = 17.0;
  double GALAXIES_PrimarySlitWidth = 2.0e-3, GALAXIES_PrimarySlitHeight = 0.7e-3;

  // DCM Si(111) at 19 m
  double GALAXIES_DistanceToDCM = 19.0;
  double GALAXIES_DcmGap = 0.01;   // vertical offset between the 2 crystals [m]
  double GALAXIES_dcm_theta;        // computed in INITIALIZE

  // M1 spherical mirror at 22 m
  double GALAXIES_DistanceToM1 = 22.0;
  double GALAXIES_M1_angle = 5.0;   // [mrad] grazing angle
  double GALAXIES_M1_R = -8810.0;   // [m] spherical radius (collimating, face up)
  double GALAXIES_M1_length = 0.200, GALAXIES_M1_width = 0.02;

  // Channel-cuts (HRM) at 23.5 m
  double GALAXIES_DistanceToHRM = 23.5;

  // Toroids M2A/M2B: post-metrology values (EXP-OPT-CDC-1936)
  double GALAXIES_M2_Rt = 1335.0;   // [m] tangential radius (SESO measured)
  double GALAXIES_M2_Rs = 0.03047;  // [m] sagittal radius  (SESO measured)
  double GALAXIES_M2_angle = 4.95;  // [mrad] grazing angle after metrology
  double GALAXIES_DistanceToM2A = 24.89; // focus at 28.2 m (HAXPES/secondary slits)
  double GALAXIES_DistanceToM2B = 32.20; // focus at 35.5 m (RIXS)
  double GALAXIES_M2_length = 0.220, GALAXIES_M2_width = 0.02;

  // Secondary slits at the M2A focal plane
  double GALAXIES_DistanceToSecSlits = 28.2;

  // KB pair
  double GALAXIES_DistanceToVFM = 34.1, GALAXIES_DistanceToHFM = 34.5;
  double GALAXIES_KB_angle = 5.0;   // [mrad]
  double GALAXIES_VFM_p = 5.9, GALAXIES_VFM_q = 1.4; // from secondary slits / to sample
  double GALAXIES_HFM_p = 6.3, GALAXIES_HFM_q = 1.0;
  double GALAXIES_KB_length = 0.320, GALAXIES_KB_width = 0.02;
  double GALAXIES_vfm_radius, GALAXIES_hfm_radius; // computed in INITIALIZE (spherical approx)

  // Sample / spectrometer
  double GALAXIES_DistanceToSample = 35.5;
  double SAMBA_DCM_theta;
  double SAMBA_d_si;
  double SAMBA_M1_radius;
  double SAMBA_M2_radius;
  double SAMBA_dcm_gap;
    double PX1_calculated_angle;
    double PX2a_calculated_angle;
  double SWING_dcm_gap;
  double SWING_Lambda;
  double SWING_Ki;
  int    SWING_flag_sample_sphere;
    double ROCK_calculated_angle;
    double ROCK_Eminkev;
    double ROCK_Emaxkev;
    double ROCK_incr;
    int ROCK_n;
    int ROCK_i_h;
    int ROCK_i_k;
    int ROCK_i_l;
    double ROCK_length_first_crystal;
    double ROCK_length_second_crystal;
    double ROCK_center_first_crystal;
    double ROCK_dist_center_to_center;
    double ROCK_center_to_c_mono_angle;
    char ROCK_e_repartition_options[512];     
    double ROCK_I_err_calc; 
    double ROCK_absorption_coefficient;
    double ROCK_absorption_coefficient_error;   
    double ROCK_number_events_after_sample;       
    double ANATOMIX_calculated_angle;
    char   ANATOMIX_emonopts[128];
    double NANO_angle_dcm; // incident angle on monochromator -> depends on energy wanted
    double NANO_delta_dcm; // translation of the second crystal according to the energy selected
    char   NANO_material_coating_m2[20];
    double NANO_E1_target;  // First harmonic coresponding to the energy selected
    // double f_fresnel;  // focal length of the fresnel zone plate (depends on energy selected)
  double DIFFABS_dcm_gap;
  double SIXS_dcm_gap;
  double SIRIUS_DCM_theta;
  double SIRIUS_d_si;
  double SIRIUS_M1_radius;
  double SIRIUS_M2_radius;
  double SIRIUS_def_mirror_radius;
  double SIRIUS_dcm_gap;
  double LUCIA_dcm_gap;
  int BEAMLINE_MAX=18;
  #pragma acc declare create(BEAMLINE_MAX)
  #pragma acc update device(BEAMLINE_MAX)

#undef compcurname
#undef compcurtype
#undef compcurindex
/* end of instrument 'SOLEIL' and components DECLARE */

/* *****************************************************************************
* instrument 'SOLEIL' and components INITIALISE
***************************************************************************** */

double index_getdistance(int first_index, int second_index)
/* Calculate the distance two components from their indexes*/
{
  return coords_len(coords_sub(POS_A_COMP_INDEX(first_index), POS_A_COMP_INDEX(second_index)));
}

double getdistance(char* first_component, char* second_component)
/* Calculate the distance between two named components */
{
  int first_index = _getcomp_index(first_component);
  int second_index = _getcomp_index(second_component);
  return index_getdistance(first_index, second_index);
}

double checked_setpos_getdistance(int current_index, char* first_component, char* second_component)
/* Calculate the distance between two named components at *_setpos() time, with component index checking */
{
  int first_index = _getcomp_index(first_component);
  int second_index = _getcomp_index(second_component);
  if (first_index >= current_index || second_index >= current_index) {
    printf("setpos_getdistance can only be used with the names of components before the current one!\n");
    return 0;
  }
  return index_getdistance(first_index, second_index);
}
#define setpos_getdistance(first, second) checked_setpos_getdistance(current_setpos_index, first, second)

/* component origin=Arm() SETTING, POSITION/ROTATION */
int _origin_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_origin_setpos] component origin=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_origin_var._name, "origin", 16384);
  stracpy(_origin_var._type, "Arm", 16384);
  _origin_var._index=1;
  int current_setpos_index = 1;
  /* component origin=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(_origin_var._rotation_absolute,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_copy(_origin_var._rotation_relative, _origin_var._rotation_absolute);
    _origin_var._rotation_is_identity =  rot_test_identity(_origin_var._rotation_relative);
    _origin_var._position_absolute = coords_set(
      0, 0, 0);
    tc1 = coords_neg(_origin_var._position_absolute);
    _origin_var._position_relative = rot_apply(_origin_var._rotation_absolute, tc1);
  } /* origin=Arm() AT ROTATED */
  DEBUG_COMPONENT("origin", _origin_var._position_absolute, _origin_var._rotation_absolute);
  instrument->_position_absolute[1] = _origin_var._position_absolute;
  instrument->_position_relative[1] = _origin_var._position_relative;
    _origin_var._position_relative_is_zero =  coords_test_zero(_origin_var._position_relative);
  instrument->counter_N[1]  = instrument->counter_P[1] = instrument->counter_P2[1] = 0;
  instrument->counter_AbsorbProp[1]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0000_origin", _origin_var._position_absolute, _origin_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _origin_setpos */

/* component jumper=Arm() SETTING, POSITION/ROTATION */
int _jumper_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_jumper_setpos] component jumper=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_jumper_var._name, "jumper", 16384);
  stracpy(_jumper_var._type, "Arm", 16384);
  _jumper_var._index=2;
  int current_setpos_index = 2;
  /* component jumper=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _jumper_var._rotation_absolute);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    rot_mul(_jumper_var._rotation_absolute, tr1, _jumper_var._rotation_relative);
    _jumper_var._rotation_is_identity =  rot_test_identity(_jumper_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _jumper_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_origin_var._position_absolute, _jumper_var._position_absolute);
    _jumper_var._position_relative = rot_apply(_jumper_var._rotation_absolute, tc1);
  } /* jumper=Arm() AT ROTATED */
  DEBUG_COMPONENT("jumper", _jumper_var._position_absolute, _jumper_var._rotation_absolute);
  instrument->_position_absolute[2] = _jumper_var._position_absolute;
  instrument->_position_relative[2] = _jumper_var._position_relative;
    _jumper_var._position_relative_is_zero =  coords_test_zero(_jumper_var._position_relative);
  instrument->counter_N[2]  = instrument->counter_P[2] = instrument->counter_P2[2] = 0;
  instrument->counter_AbsorbProp[2]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0001_jumper", _jumper_var._position_absolute, _jumper_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _jumper_setpos */

/* component beamdump=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_setpos] component beamdump=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_var._name, "beamdump", 16384);
  stracpy(_beamdump_var._type, "Beamstop", 16384);
  _beamdump_var._index=3;
  int current_setpos_index = 3;
  _beamdump_var._parameters.xmin = -0.05;
  _beamdump_var._parameters.xmax = 0.05;
  _beamdump_var._parameters.ymin = -0.05;
  _beamdump_var._parameters.ymax = 0.05;
  _beamdump_var._parameters.xwidth = 0;
  _beamdump_var._parameters.yheight = 0;
  _beamdump_var._parameters.radius = 0;

  /* component beamdump=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _jumper_var._rotation_absolute, _beamdump_var._rotation_absolute);
    rot_transpose(_jumper_var._rotation_absolute, tr1);
    rot_mul(_beamdump_var._rotation_absolute, tr1, _beamdump_var._rotation_relative);
    _beamdump_var._rotation_is_identity =  rot_test_identity(_beamdump_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_jumper_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_var._position_absolute = coords_add(_jumper_var._position_absolute, tc2);
    tc1 = coords_sub(_jumper_var._position_absolute, _beamdump_var._position_absolute);
    _beamdump_var._position_relative = rot_apply(_beamdump_var._rotation_absolute, tc1);
  } /* beamdump=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump", _beamdump_var._position_absolute, _beamdump_var._rotation_absolute);
  instrument->_position_absolute[3] = _beamdump_var._position_absolute;
  instrument->_position_relative[3] = _beamdump_var._position_relative;
    _beamdump_var._position_relative_is_zero =  coords_test_zero(_beamdump_var._position_relative);
  instrument->counter_N[3]  = instrument->counter_P[3] = instrument->counter_P2[3] = 0;
  instrument->counter_AbsorbProp[3]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0002_beamdump", _beamdump_var._position_absolute, _beamdump_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0002_beamdump", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_setpos */

/* component ODE_pos=Text() SETTING, POSITION/ROTATION */
int _ODE_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ODE_pos_setpos] component ODE_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_ODE_pos_var._name, "ODE_pos", 16384);
  stracpy(_ODE_pos_var._type, "Text", 16384);
  _ODE_pos_var._index=4;
  int current_setpos_index = 4;
  if("ODE" && strlen("ODE"))
    stracpy(_ODE_pos_var._parameters.text, "ODE" ? "ODE" : "", 16384);
  else 
  _ODE_pos_var._parameters.text[0]='\0';
  _ODE_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_ODE_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _ODE_pos_var._parameters.plane[0]='\0';
  _ODE_pos_var._parameters.pen_thickness = 0.1;


  /* component ODE_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-15.112)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _ODE_pos_var._rotation_absolute);
    rot_transpose(_beamdump_var._rotation_absolute, tr1);
    rot_mul(_ODE_pos_var._rotation_absolute, tr1, _ODE_pos_var._rotation_relative);
    _ODE_pos_var._rotation_is_identity =  rot_test_identity(_ODE_pos_var._rotation_relative);
    tc1 = coords_set(
      54.392, 0, 14.688);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ODE_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_var._position_absolute, _ODE_pos_var._position_absolute);
    _ODE_pos_var._position_relative = rot_apply(_ODE_pos_var._rotation_absolute, tc1);
  } /* ODE_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("ODE_pos", _ODE_pos_var._position_absolute, _ODE_pos_var._rotation_absolute);
  instrument->_position_absolute[4] = _ODE_pos_var._position_absolute;
  instrument->_position_relative[4] = _ODE_pos_var._position_relative;
    _ODE_pos_var._position_relative_is_zero =  coords_test_zero(_ODE_pos_var._position_relative);
  instrument->counter_N[4]  = instrument->counter_P[4] = instrument->counter_P2[4] = 0;
  instrument->counter_AbsorbProp[4]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0003_ODE_pos", _ODE_pos_var._position_absolute, _ODE_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0003_ODE_pos", "text", "NONE", "ODE", "char*");
        mccomp_param_nexus(nxhandle,"0003_ODE_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0003_ODE_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0003_ODE_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ODE_pos_setpos */

/* component SMIS_pos=Text() SETTING, POSITION/ROTATION */
int _SMIS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SMIS_pos_setpos] component SMIS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_SMIS_pos_var._name, "SMIS_pos", 16384);
  stracpy(_SMIS_pos_var._type, "Text", 16384);
  _SMIS_pos_var._index=5;
  int current_setpos_index = 5;
  if("SMIS" && strlen("SMIS"))
    stracpy(_SMIS_pos_var._parameters.text, "SMIS" ? "SMIS" : "", 16384);
  else 
  _SMIS_pos_var._parameters.text[0]='\0';
  _SMIS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_SMIS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _SMIS_pos_var._parameters.plane[0]='\0';
  _SMIS_pos_var._parameters.pen_thickness = 0.1;


  /* component SMIS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-28.7)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _SMIS_pos_var._rotation_absolute);
    rot_transpose(_ODE_pos_var._rotation_absolute, tr1);
    rot_mul(_SMIS_pos_var._rotation_absolute, tr1, _SMIS_pos_var._rotation_relative);
    _SMIS_pos_var._rotation_is_identity =  rot_test_identity(_SMIS_pos_var._rotation_relative);
    tc1 = coords_set(
      49.41, 0, 27.06);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SMIS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_ODE_pos_var._position_absolute, _SMIS_pos_var._position_absolute);
    _SMIS_pos_var._position_relative = rot_apply(_SMIS_pos_var._rotation_absolute, tc1);
  } /* SMIS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("SMIS_pos", _SMIS_pos_var._position_absolute, _SMIS_pos_var._rotation_absolute);
  instrument->_position_absolute[5] = _SMIS_pos_var._position_absolute;
  instrument->_position_relative[5] = _SMIS_pos_var._position_relative;
    _SMIS_pos_var._position_relative_is_zero =  coords_test_zero(_SMIS_pos_var._position_relative);
  instrument->counter_N[5]  = instrument->counter_P[5] = instrument->counter_P2[5] = 0;
  instrument->counter_AbsorbProp[5]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0004_SMIS_pos", _SMIS_pos_var._position_absolute, _SMIS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0004_SMIS_pos", "text", "NONE", "SMIS", "char*");
        mccomp_param_nexus(nxhandle,"0004_SMIS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0004_SMIS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0004_SMIS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SMIS_pos_setpos */

/* component AILES_pos=Text() SETTING, POSITION/ROTATION */
int _AILES_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_AILES_pos_setpos] component AILES_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_AILES_pos_var._name, "AILES_pos", 16384);
  stracpy(_AILES_pos_var._type, "Text", 16384);
  _AILES_pos_var._index=6;
  int current_setpos_index = 6;
  if("AILES" && strlen("AILES"))
    stracpy(_AILES_pos_var._parameters.text, "AILES" ? "AILES" : "", 16384);
  else 
  _AILES_pos_var._parameters.text[0]='\0';
  _AILES_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_AILES_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _AILES_pos_var._parameters.plane[0]='\0';
  _AILES_pos_var._parameters.pen_thickness = 0.1;


  /* component AILES_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-51.4)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _AILES_pos_var._rotation_absolute);
    rot_transpose(_SMIS_pos_var._rotation_absolute, tr1);
    rot_mul(_AILES_pos_var._rotation_absolute, tr1, _AILES_pos_var._rotation_relative);
    _AILES_pos_var._rotation_is_identity =  rot_test_identity(_AILES_pos_var._rotation_relative);
    tc1 = coords_set(
      35.21, 0, 43.97);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _AILES_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_SMIS_pos_var._position_absolute, _AILES_pos_var._position_absolute);
    _AILES_pos_var._position_relative = rot_apply(_AILES_pos_var._rotation_absolute, tc1);
  } /* AILES_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("AILES_pos", _AILES_pos_var._position_absolute, _AILES_pos_var._rotation_absolute);
  instrument->_position_absolute[6] = _AILES_pos_var._position_absolute;
  instrument->_position_relative[6] = _AILES_pos_var._position_relative;
    _AILES_pos_var._position_relative_is_zero =  coords_test_zero(_AILES_pos_var._position_relative);
  instrument->counter_N[6]  = instrument->counter_P[6] = instrument->counter_P2[6] = 0;
  instrument->counter_AbsorbProp[6]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0005_AILES_pos", _AILES_pos_var._position_absolute, _AILES_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0005_AILES_pos", "text", "NONE", "AILES", "char*");
        mccomp_param_nexus(nxhandle,"0005_AILES_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0005_AILES_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0005_AILES_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _AILES_pos_setpos */

/* component MARS_pos=Text() SETTING, POSITION/ROTATION */
int _MARS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_pos_setpos] component MARS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_MARS_pos_var._name, "MARS_pos", 16384);
  stracpy(_MARS_pos_var._type, "Text", 16384);
  _MARS_pos_var._index=7;
  int current_setpos_index = 7;
  if("MARS" && strlen("MARS"))
    stracpy(_MARS_pos_var._parameters.text, "MARS" ? "MARS" : "", 16384);
  else 
  _MARS_pos_var._parameters.text[0]='\0';
  _MARS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_MARS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _MARS_pos_var._parameters.plane[0]='\0';
  _MARS_pos_var._parameters.pen_thickness = 0.1;


  /* component MARS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-51.5)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _MARS_pos_var._rotation_absolute);
    rot_transpose(_AILES_pos_var._rotation_absolute, tr1);
    rot_mul(_MARS_pos_var._rotation_absolute, tr1, _MARS_pos_var._rotation_relative);
    _MARS_pos_var._rotation_is_identity =  rot_test_identity(_MARS_pos_var._rotation_relative);
    tc1 = coords_set(
      35.14, 0, 44.03);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_AILES_pos_var._position_absolute, _MARS_pos_var._position_absolute);
    _MARS_pos_var._position_relative = rot_apply(_MARS_pos_var._rotation_absolute, tc1);
  } /* MARS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("MARS_pos", _MARS_pos_var._position_absolute, _MARS_pos_var._rotation_absolute);
  instrument->_position_absolute[7] = _MARS_pos_var._position_absolute;
  instrument->_position_relative[7] = _MARS_pos_var._position_relative;
    _MARS_pos_var._position_relative_is_zero =  coords_test_zero(_MARS_pos_var._position_relative);
  instrument->counter_N[7]  = instrument->counter_P[7] = instrument->counter_P2[7] = 0;
  instrument->counter_AbsorbProp[7]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0006_MARS_pos", _MARS_pos_var._position_absolute, _MARS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0006_MARS_pos", "text", "NONE", "MARS", "char*");
        mccomp_param_nexus(nxhandle,"0006_MARS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0006_MARS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0006_MARS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_pos_setpos */

/* component MARS=Arm() SETTING, POSITION/ROTATION */
int _MARS_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_setpos] component MARS=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_var._name, "MARS", 16384);
  stracpy(_MARS_var._type, "Arm", 16384);
  _MARS_var._index=8;
  int current_setpos_index = 8;
  /* component MARS=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_pos_var._rotation_absolute, _MARS_var._rotation_absolute);
    rot_transpose(_MARS_pos_var._rotation_absolute, tr1);
    rot_mul(_MARS_var._rotation_absolute, tr1, _MARS_var._rotation_relative);
    _MARS_var._rotation_is_identity =  rot_test_identity(_MARS_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_var._position_absolute = coords_add(_MARS_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_pos_var._position_absolute, _MARS_var._position_absolute);
    _MARS_var._position_relative = rot_apply(_MARS_var._rotation_absolute, tc1);
  } /* MARS=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS", _MARS_var._position_absolute, _MARS_var._rotation_absolute);
  instrument->_position_absolute[8] = _MARS_var._position_absolute;
  instrument->_position_relative[8] = _MARS_var._position_relative;
    _MARS_var._position_relative_is_zero =  coords_test_zero(_MARS_var._position_relative);
  instrument->counter_N[8]  = instrument->counter_P[8] = instrument->counter_P2[8] = 0;
  instrument->counter_AbsorbProp[8]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0007_MARS", _MARS_var._position_absolute, _MARS_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_setpos */

/* component MARS_Source=Bending_magnet() SETTING, POSITION/ROTATION */
int _MARS_Source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_Source_setpos] component MARS_Source=Bending_magnet() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");
  stracpy(_MARS_Source_var._name, "MARS_Source", 16384);
  stracpy(_MARS_Source_var._type, "Bending_magnet", 16384);
  _MARS_Source_var._index=9;
  int current_setpos_index = 9;
  _MARS_Source_var._parameters.E0 = _instrument_var._parameters.MARS_E0;
  _MARS_Source_var._parameters.dE = _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0;
  _MARS_Source_var._parameters.lambda0 = 0;
  _MARS_Source_var._parameters.dlambda = 0;
  _MARS_Source_var._parameters.phase = 0;
  _MARS_Source_var._parameters.randomphase = 1;
  _MARS_Source_var._parameters.Ee = 2.75;
  _MARS_Source_var._parameters.Ie = 0.5;
  _MARS_Source_var._parameters.B = 1.71;
  _MARS_Source_var._parameters.sigey = 25.3e-6;
  _MARS_Source_var._parameters.sigex = 79.6e-6;
  _MARS_Source_var._parameters.focus_xw = MARS_PrimarySlit1Width;
  _MARS_Source_var._parameters.focus_yh = MARS_PrimarySlit1Height;
  _MARS_Source_var._parameters.dist = MARS_DistanceToPrimarySlit1;
  _MARS_Source_var._parameters.gauss_t = 0;


  /* component MARS_Source=Bending_magnet() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_var._rotation_absolute, _MARS_Source_var._rotation_absolute);
    rot_transpose(_MARS_var._rotation_absolute, tr1);
    rot_mul(_MARS_Source_var._rotation_absolute, tr1, _MARS_Source_var._rotation_relative);
    _MARS_Source_var._rotation_is_identity =  rot_test_identity(_MARS_Source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_Source_var._position_absolute = coords_add(_MARS_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_var._position_absolute, _MARS_Source_var._position_absolute);
    _MARS_Source_var._position_relative = rot_apply(_MARS_Source_var._rotation_absolute, tc1);
  } /* MARS_Source=Bending_magnet() AT ROTATED */
  DEBUG_COMPONENT("MARS_Source", _MARS_Source_var._position_absolute, _MARS_Source_var._rotation_absolute);
  instrument->_position_absolute[9] = _MARS_Source_var._position_absolute;
  instrument->_position_relative[9] = _MARS_Source_var._position_relative;
    _MARS_Source_var._position_relative_is_zero =  coords_test_zero(_MARS_Source_var._position_relative);
  instrument->counter_N[9]  = instrument->counter_P[9] = instrument->counter_P2[9] = 0;
  instrument->counter_AbsorbProp[9]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0008_MARS_Source", _MARS_Source_var._position_absolute, _MARS_Source_var._rotation_absolute, "Bending_magnet");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "E0", "0", "_instrument_var._parameters.MARS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "dE", "0", "_instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "B", "1.6", "1.71","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "sigey", "0", "25.3e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "sigex", "0", "79.6e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "focus_xw", "0", "MARS_PrimarySlit1Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "focus_yh", "0", "MARS_PrimarySlit1Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "dist", "1", "MARS_DistanceToPrimarySlit1","MCNUM");
        mccomp_param_nexus(nxhandle,"0008_MARS_Source", "gauss_t", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_Source_setpos */

/* component MARS_displaySourceLength=Monitor_nD() SETTING, POSITION/ROTATION */
int _MARS_displaySourceLength_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_displaySourceLength_setpos] component MARS_displaySourceLength=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_MARS_displaySourceLength_var._name, "MARS_displaySourceLength", 16384);
  stracpy(_MARS_displaySourceLength_var._type, "Monitor_nD", 16384);
  _MARS_displaySourceLength_var._index=10;
  int current_setpos_index = 10;
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_displaySourceLength_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.user9[0]='\0';
  _MARS_displaySourceLength_var._parameters.xwidth = 0.2;
  _MARS_displaySourceLength_var._parameters.yheight = 0.2;
  _MARS_displaySourceLength_var._parameters.zdepth = 0;
  _MARS_displaySourceLength_var._parameters.bins = 512;
  _MARS_displaySourceLength_var._parameters.min = _instrument_var._parameters.MARS_E0 * ( 1 - _instrument_var._parameters.MARS_dEr );
  _MARS_displaySourceLength_var._parameters.max = _instrument_var._parameters.MARS_E0 * ( 1 + _instrument_var._parameters.MARS_dEr );
  _MARS_displaySourceLength_var._parameters.restore_xray = 0;
  _MARS_displaySourceLength_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_MARS_displaySourceLength_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.geometry[0]='\0';
  _MARS_displaySourceLength_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_displaySourceLength_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_displaySourceLength_var._parameters.username9[0]='\0';


  /* component MARS_displaySourceLength=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Source_var._rotation_absolute, _MARS_displaySourceLength_var._rotation_absolute);
    rot_transpose(_MARS_Source_var._rotation_absolute, tr1);
    rot_mul(_MARS_displaySourceLength_var._rotation_absolute, tr1, _MARS_displaySourceLength_var._rotation_relative);
    _MARS_displaySourceLength_var._rotation_is_identity =  rot_test_identity(_MARS_displaySourceLength_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2);
    rot_transpose(_MARS_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_displaySourceLength_var._position_absolute = coords_add(_MARS_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_Source_var._position_absolute, _MARS_displaySourceLength_var._position_absolute);
    _MARS_displaySourceLength_var._position_relative = rot_apply(_MARS_displaySourceLength_var._rotation_absolute, tc1);
  } /* MARS_displaySourceLength=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("MARS_displaySourceLength", _MARS_displaySourceLength_var._position_absolute, _MARS_displaySourceLength_var._rotation_absolute);
  instrument->_position_absolute[10] = _MARS_displaySourceLength_var._position_absolute;
  instrument->_position_relative[10] = _MARS_displaySourceLength_var._position_relative;
    _MARS_displaySourceLength_var._position_relative_is_zero =  coords_test_zero(_MARS_displaySourceLength_var._position_relative);
  instrument->counter_N[10]  = instrument->counter_P[10] = instrument->counter_P2[10] = 0;
  instrument->counter_AbsorbProp[10]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0009_MARS_displaySourceLength", _MARS_displaySourceLength_var._position_absolute, _MARS_displaySourceLength_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "xwidth", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "yheight", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "min", "-1e40", "_instrument_var._parameters.MARS_E0 * ( 1 - _instrument_var._parameters.MARS_dEr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "max", "1e40", "_instrument_var._parameters.MARS_E0 * ( 1 + _instrument_var._parameters.MARS_dEr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0009_MARS_displaySourceLength", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_displaySourceLength_setpos */

/* component MARS_displaySource=PSD_monitor() SETTING, POSITION/ROTATION */
int _MARS_displaySource_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_displaySource_setpos] component MARS_displaySource=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_MARS_displaySource_var._name, "MARS_displaySource", 16384);
  stracpy(_MARS_displaySource_var._type, "PSD_monitor", 16384);
  _MARS_displaySource_var._index=11;
  int current_setpos_index = 11;
  if("MARS_emon_psd1" && strlen("MARS_emon_psd1"))
    stracpy(_MARS_displaySource_var._parameters.filename, "MARS_emon_psd1" ? "MARS_emon_psd1" : "", 16384);
  else 
  _MARS_displaySource_var._parameters.filename[0]='\0';
  _MARS_displaySource_var._parameters.xwidth = 0.05;
  _MARS_displaySource_var._parameters.yheight = 0.05;
  _MARS_displaySource_var._parameters.radius = 0;
  _MARS_displaySource_var._parameters.restore_xray = 1;
  _MARS_displaySource_var._parameters.nowritefile = 0;
  _MARS_displaySource_var._parameters.nx = 90;
  _MARS_displaySource_var._parameters.ny = 90;
  _MARS_displaySource_var._parameters.nr = 0;


  /* component MARS_displaySource=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Source_var._rotation_absolute, _MARS_displaySource_var._rotation_absolute);
    rot_transpose(_MARS_displaySourceLength_var._rotation_absolute, tr1);
    rot_mul(_MARS_displaySource_var._rotation_absolute, tr1, _MARS_displaySource_var._rotation_relative);
    _MARS_displaySource_var._rotation_is_identity =  rot_test_identity(_MARS_displaySource_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 10);
    rot_transpose(_MARS_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_displaySource_var._position_absolute = coords_add(_MARS_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displaySourceLength_var._position_absolute, _MARS_displaySource_var._position_absolute);
    _MARS_displaySource_var._position_relative = rot_apply(_MARS_displaySource_var._rotation_absolute, tc1);
  } /* MARS_displaySource=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("MARS_displaySource", _MARS_displaySource_var._position_absolute, _MARS_displaySource_var._rotation_absolute);
  instrument->_position_absolute[11] = _MARS_displaySource_var._position_absolute;
  instrument->_position_relative[11] = _MARS_displaySource_var._position_relative;
    _MARS_displaySource_var._position_relative_is_zero =  coords_test_zero(_MARS_displaySource_var._position_relative);
  instrument->counter_N[11]  = instrument->counter_P[11] = instrument->counter_P2[11] = 0;
  instrument->counter_AbsorbProp[11]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0010_MARS_displaySource", _MARS_displaySource_var._position_absolute, _MARS_displaySource_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "filename", 0, "MARS_emon_psd1", "char*");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "yheight", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0010_MARS_displaySource", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_displaySource_setpos */

/* component MARS_slit1=Slit() SETTING, POSITION/ROTATION */
int _MARS_slit1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_slit1_setpos] component MARS_slit1=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_MARS_slit1_var._name, "MARS_slit1", 16384);
  stracpy(_MARS_slit1_var._type, "Slit", 16384);
  _MARS_slit1_var._index=12;
  int current_setpos_index = 12;
  _MARS_slit1_var._parameters.xmin = 0;
  _MARS_slit1_var._parameters.xmax = 0;
  _MARS_slit1_var._parameters.ymin = 0;
  _MARS_slit1_var._parameters.ymax = 0;
  _MARS_slit1_var._parameters.radius = 0;
  _MARS_slit1_var._parameters.xwidth = MARS_PrimarySlit1Width;
  _MARS_slit1_var._parameters.yheight = MARS_PrimarySlit1Height;
  _MARS_slit1_var._parameters.dist = 0;
  _MARS_slit1_var._parameters.focus_xw = 0;
  _MARS_slit1_var._parameters.focus_yh = 0;
  _MARS_slit1_var._parameters.focus_x0 = 0;
  _MARS_slit1_var._parameters.focus_y0 = 0;

  /* component MARS_slit1=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Source_var._rotation_absolute, _MARS_slit1_var._rotation_absolute);
    rot_transpose(_MARS_displaySource_var._rotation_absolute, tr1);
    rot_mul(_MARS_slit1_var._rotation_absolute, tr1, _MARS_slit1_var._rotation_relative);
    _MARS_slit1_var._rotation_is_identity =  rot_test_identity(_MARS_slit1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceToPrimarySlit1);
    rot_transpose(_MARS_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_slit1_var._position_absolute = coords_add(_MARS_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displaySource_var._position_absolute, _MARS_slit1_var._position_absolute);
    _MARS_slit1_var._position_relative = rot_apply(_MARS_slit1_var._rotation_absolute, tc1);
  } /* MARS_slit1=Slit() AT ROTATED */
  DEBUG_COMPONENT("MARS_slit1", _MARS_slit1_var._position_absolute, _MARS_slit1_var._rotation_absolute);
  instrument->_position_absolute[12] = _MARS_slit1_var._position_absolute;
  instrument->_position_relative[12] = _MARS_slit1_var._position_relative;
    _MARS_slit1_var._position_relative_is_zero =  coords_test_zero(_MARS_slit1_var._position_relative);
  instrument->counter_N[12]  = instrument->counter_P[12] = instrument->counter_P2[12] = 0;
  instrument->counter_AbsorbProp[12]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0011_MARS_slit1", _MARS_slit1_var._position_absolute, _MARS_slit1_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "xwidth", "0.001", "MARS_PrimarySlit1Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "yheight", "0.001", "MARS_PrimarySlit1Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0011_MARS_slit1", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_slit1_setpos */

/* component MARS_slit2=Slit() SETTING, POSITION/ROTATION */
int _MARS_slit2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_slit2_setpos] component MARS_slit2=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_MARS_slit2_var._name, "MARS_slit2", 16384);
  stracpy(_MARS_slit2_var._type, "Slit", 16384);
  _MARS_slit2_var._index=13;
  int current_setpos_index = 13;
  _MARS_slit2_var._parameters.xmin = 0;
  _MARS_slit2_var._parameters.xmax = 0;
  _MARS_slit2_var._parameters.ymin = 0;
  _MARS_slit2_var._parameters.ymax = 0;
  _MARS_slit2_var._parameters.radius = 0;
  _MARS_slit2_var._parameters.xwidth = MARS_PrimarySlit2Width;
  _MARS_slit2_var._parameters.yheight = MARS_PrimarySlit2Height;
  _MARS_slit2_var._parameters.dist = 0;
  _MARS_slit2_var._parameters.focus_xw = 0;
  _MARS_slit2_var._parameters.focus_yh = 0;
  _MARS_slit2_var._parameters.focus_x0 = 0;
  _MARS_slit2_var._parameters.focus_y0 = 0;

  /* component MARS_slit2=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Source_var._rotation_absolute, _MARS_slit2_var._rotation_absolute);
    rot_transpose(_MARS_slit1_var._rotation_absolute, tr1);
    rot_mul(_MARS_slit2_var._rotation_absolute, tr1, _MARS_slit2_var._rotation_relative);
    _MARS_slit2_var._rotation_is_identity =  rot_test_identity(_MARS_slit2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceToPrimarySlit2);
    rot_transpose(_MARS_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_slit2_var._position_absolute = coords_add(_MARS_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_slit1_var._position_absolute, _MARS_slit2_var._position_absolute);
    _MARS_slit2_var._position_relative = rot_apply(_MARS_slit2_var._rotation_absolute, tc1);
  } /* MARS_slit2=Slit() AT ROTATED */
  DEBUG_COMPONENT("MARS_slit2", _MARS_slit2_var._position_absolute, _MARS_slit2_var._rotation_absolute);
  instrument->_position_absolute[13] = _MARS_slit2_var._position_absolute;
  instrument->_position_relative[13] = _MARS_slit2_var._position_relative;
    _MARS_slit2_var._position_relative_is_zero =  coords_test_zero(_MARS_slit2_var._position_relative);
  instrument->counter_N[13]  = instrument->counter_P[13] = instrument->counter_P2[13] = 0;
  instrument->counter_AbsorbProp[13]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0012_MARS_slit2", _MARS_slit2_var._position_absolute, _MARS_slit2_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "xwidth", "0.001", "MARS_PrimarySlit2Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "yheight", "0.001", "MARS_PrimarySlit2Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0012_MARS_slit2", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_slit2_setpos */

/* component MARS_M1_arm_translation=Arm() SETTING, POSITION/ROTATION */
int _MARS_M1_arm_translation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M1_arm_translation_setpos] component MARS_M1_arm_translation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M1_arm_translation_var._name, "MARS_M1_arm_translation", 16384);
  stracpy(_MARS_M1_arm_translation_var._type, "Arm", 16384);
  _MARS_M1_arm_translation_var._index=14;
  int current_setpos_index = 14;
  /* component MARS_M1_arm_translation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Source_var._rotation_absolute, _MARS_M1_arm_translation_var._rotation_absolute);
    rot_transpose(_MARS_slit2_var._rotation_absolute, tr1);
    rot_mul(_MARS_M1_arm_translation_var._rotation_absolute, tr1, _MARS_M1_arm_translation_var._rotation_relative);
    _MARS_M1_arm_translation_var._rotation_is_identity =  rot_test_identity(_MARS_M1_arm_translation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceSourceToM1);
    rot_transpose(_MARS_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M1_arm_translation_var._position_absolute = coords_add(_MARS_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_slit2_var._position_absolute, _MARS_M1_arm_translation_var._position_absolute);
    _MARS_M1_arm_translation_var._position_relative = rot_apply(_MARS_M1_arm_translation_var._rotation_absolute, tc1);
  } /* MARS_M1_arm_translation=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M1_arm_translation", _MARS_M1_arm_translation_var._position_absolute, _MARS_M1_arm_translation_var._rotation_absolute);
  instrument->_position_absolute[14] = _MARS_M1_arm_translation_var._position_absolute;
  instrument->_position_relative[14] = _MARS_M1_arm_translation_var._position_relative;
    _MARS_M1_arm_translation_var._position_relative_is_zero =  coords_test_zero(_MARS_M1_arm_translation_var._position_relative);
  instrument->counter_N[14]  = instrument->counter_P[14] = instrument->counter_P2[14] = 0;
  instrument->counter_AbsorbProp[14]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0013_MARS_M1_arm_translation", _MARS_M1_arm_translation_var._position_absolute, _MARS_M1_arm_translation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M1_arm_translation_setpos */

/* component MARS_M1_arm_rotation_1=Arm() SETTING, POSITION/ROTATION */
int _MARS_M1_arm_rotation_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M1_arm_rotation_1_setpos] component MARS_M1_arm_rotation_1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M1_arm_rotation_1_var._name, "MARS_M1_arm_rotation_1", 16384);
  stracpy(_MARS_M1_arm_rotation_1_var._type, "Arm", 16384);
  _MARS_M1_arm_rotation_1_var._index=15;
  int current_setpos_index = 15;
  /* component MARS_M1_arm_rotation_1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _MARS_M1_arm_translation_var._rotation_absolute, _MARS_M1_arm_rotation_1_var._rotation_absolute);
    rot_transpose(_MARS_slit2_var._rotation_absolute, tr1);
    rot_mul(_MARS_M1_arm_rotation_1_var._rotation_absolute, tr1, _MARS_M1_arm_rotation_1_var._rotation_relative);
    _MARS_M1_arm_rotation_1_var._rotation_is_identity =  rot_test_identity(_MARS_M1_arm_rotation_1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_M1_arm_translation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M1_arm_rotation_1_var._position_absolute = coords_add(_MARS_M1_arm_translation_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_slit2_var._position_absolute, _MARS_M1_arm_rotation_1_var._position_absolute);
    _MARS_M1_arm_rotation_1_var._position_relative = rot_apply(_MARS_M1_arm_rotation_1_var._rotation_absolute, tc1);
  } /* MARS_M1_arm_rotation_1=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M1_arm_rotation_1", _MARS_M1_arm_rotation_1_var._position_absolute, _MARS_M1_arm_rotation_1_var._rotation_absolute);
  instrument->_position_absolute[15] = _MARS_M1_arm_rotation_1_var._position_absolute;
  instrument->_position_relative[15] = _MARS_M1_arm_rotation_1_var._position_relative;
    _MARS_M1_arm_rotation_1_var._position_relative_is_zero =  coords_test_zero(_MARS_M1_arm_rotation_1_var._position_relative);
  instrument->counter_N[15]  = instrument->counter_P[15] = instrument->counter_P2[15] = 0;
  instrument->counter_AbsorbProp[15]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0014_MARS_M1_arm_rotation_1", _MARS_M1_arm_rotation_1_var._position_absolute, _MARS_M1_arm_rotation_1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M1_arm_rotation_1_setpos */

/* component MARS_mirror_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _MARS_mirror_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_mirror_M1_setpos] component MARS_mirror_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_MARS_mirror_M1_var._name, "MARS_mirror_M1", 16384);
  stracpy(_MARS_mirror_M1_var._type, "Mirror_curved", 16384);
  _MARS_mirror_M1_var._index=16;
  int current_setpos_index = 16;
  _MARS_mirror_M1_var._parameters.radius = MARS_RadiusM1;
  _MARS_mirror_M1_var._parameters.R0 = 1;
  if(_instrument_var._parameters.MARS_reflec_material_M12 && strlen(_instrument_var._parameters.MARS_reflec_material_M12))
    stracpy(_MARS_mirror_M1_var._parameters.coating, _instrument_var._parameters.MARS_reflec_material_M12 ? _instrument_var._parameters.MARS_reflec_material_M12 : "", 16384);
  else 
  _MARS_mirror_M1_var._parameters.coating[0]='\0';
  _MARS_mirror_M1_var._parameters.zdepth = 0.2;
  _MARS_mirror_M1_var._parameters.yheight = 0.2;
  _MARS_mirror_M1_var._parameters.length = MARS_M12_length;
  _MARS_mirror_M1_var._parameters.width = MARS_M12_width;


  /* component MARS_mirror_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (MARS_AngleM1)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_M1_arm_rotation_1_var._rotation_absolute, _MARS_mirror_M1_var._rotation_absolute);
    rot_transpose(_MARS_slit2_var._rotation_absolute, tr1);
    rot_mul(_MARS_mirror_M1_var._rotation_absolute, tr1, _MARS_mirror_M1_var._rotation_relative);
    _MARS_mirror_M1_var._rotation_is_identity =  rot_test_identity(_MARS_mirror_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_M1_arm_rotation_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_mirror_M1_var._position_absolute = coords_add(_MARS_M1_arm_rotation_1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_slit2_var._position_absolute, _MARS_mirror_M1_var._position_absolute);
    _MARS_mirror_M1_var._position_relative = rot_apply(_MARS_mirror_M1_var._rotation_absolute, tc1);
  } /* MARS_mirror_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("MARS_mirror_M1", _MARS_mirror_M1_var._position_absolute, _MARS_mirror_M1_var._rotation_absolute);
  instrument->_position_absolute[16] = _MARS_mirror_M1_var._position_absolute;
  instrument->_position_relative[16] = _MARS_mirror_M1_var._position_relative;
    _MARS_mirror_M1_var._position_relative_is_zero =  coords_test_zero(_MARS_mirror_M1_var._position_relative);
  instrument->counter_N[16]  = instrument->counter_P[16] = instrument->counter_P2[16] = 0;
  instrument->counter_AbsorbProp[16]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0015_MARS_mirror_M1", _MARS_mirror_M1_var._position_absolute, _MARS_mirror_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "radius", "1", "MARS_RadiusM1","MCNUM");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "coating", "Be.txt", _instrument_var._parameters.MARS_reflec_material_M12, "char*");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "length", "0", "MARS_M12_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0015_MARS_mirror_M1", "width", "0", "MARS_M12_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_mirror_M1_setpos */

/* component MARS_M1_arm_rotation_2=Arm() SETTING, POSITION/ROTATION */
int _MARS_M1_arm_rotation_2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M1_arm_rotation_2_setpos] component MARS_M1_arm_rotation_2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M1_arm_rotation_2_var._name, "MARS_M1_arm_rotation_2", 16384);
  stracpy(_MARS_M1_arm_rotation_2_var._type, "Arm", 16384);
  _MARS_M1_arm_rotation_2_var._index=17;
  int current_setpos_index = 17;
  /* component MARS_M1_arm_rotation_2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (MARS_AngleM1)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_mirror_M1_var._rotation_absolute, _MARS_M1_arm_rotation_2_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M1_var._rotation_absolute, tr1);
    rot_mul(_MARS_M1_arm_rotation_2_var._rotation_absolute, tr1, _MARS_M1_arm_rotation_2_var._rotation_relative);
    _MARS_M1_arm_rotation_2_var._rotation_is_identity =  rot_test_identity(_MARS_M1_arm_rotation_2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_mirror_M1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M1_arm_rotation_2_var._position_absolute = coords_add(_MARS_mirror_M1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M1_var._position_absolute, _MARS_M1_arm_rotation_2_var._position_absolute);
    _MARS_M1_arm_rotation_2_var._position_relative = rot_apply(_MARS_M1_arm_rotation_2_var._rotation_absolute, tc1);
  } /* MARS_M1_arm_rotation_2=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M1_arm_rotation_2", _MARS_M1_arm_rotation_2_var._position_absolute, _MARS_M1_arm_rotation_2_var._rotation_absolute);
  instrument->_position_absolute[17] = _MARS_M1_arm_rotation_2_var._position_absolute;
  instrument->_position_relative[17] = _MARS_M1_arm_rotation_2_var._position_relative;
    _MARS_M1_arm_rotation_2_var._position_relative_is_zero =  coords_test_zero(_MARS_M1_arm_rotation_2_var._position_relative);
  instrument->counter_N[17]  = instrument->counter_P[17] = instrument->counter_P2[17] = 0;
  instrument->counter_AbsorbProp[17]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0016_MARS_M1_arm_rotation_2", _MARS_M1_arm_rotation_2_var._position_absolute, _MARS_M1_arm_rotation_2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M1_arm_rotation_2_setpos */

/* component MARS_M1_arm_rotation_2_undo=Arm() SETTING, POSITION/ROTATION */
int _MARS_M1_arm_rotation_2_undo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M1_arm_rotation_2_undo_setpos] component MARS_M1_arm_rotation_2_undo=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M1_arm_rotation_2_undo_var._name, "MARS_M1_arm_rotation_2_undo", 16384);
  stracpy(_MARS_M1_arm_rotation_2_undo_var._type, "Arm", 16384);
  _MARS_M1_arm_rotation_2_undo_var._index=18;
  int current_setpos_index = 18;
  /* component MARS_M1_arm_rotation_2_undo=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _MARS_M1_arm_rotation_2_var._rotation_absolute, _MARS_M1_arm_rotation_2_undo_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M1_var._rotation_absolute, tr1);
    rot_mul(_MARS_M1_arm_rotation_2_undo_var._rotation_absolute, tr1, _MARS_M1_arm_rotation_2_undo_var._rotation_relative);
    _MARS_M1_arm_rotation_2_undo_var._rotation_is_identity =  rot_test_identity(_MARS_M1_arm_rotation_2_undo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_M1_arm_rotation_2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M1_arm_rotation_2_undo_var._position_absolute = coords_add(_MARS_M1_arm_rotation_2_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M1_var._position_absolute, _MARS_M1_arm_rotation_2_undo_var._position_absolute);
    _MARS_M1_arm_rotation_2_undo_var._position_relative = rot_apply(_MARS_M1_arm_rotation_2_undo_var._rotation_absolute, tc1);
  } /* MARS_M1_arm_rotation_2_undo=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M1_arm_rotation_2_undo", _MARS_M1_arm_rotation_2_undo_var._position_absolute, _MARS_M1_arm_rotation_2_undo_var._rotation_absolute);
  instrument->_position_absolute[18] = _MARS_M1_arm_rotation_2_undo_var._position_absolute;
  instrument->_position_relative[18] = _MARS_M1_arm_rotation_2_undo_var._position_relative;
    _MARS_M1_arm_rotation_2_undo_var._position_relative_is_zero =  coords_test_zero(_MARS_M1_arm_rotation_2_undo_var._position_relative);
  instrument->counter_N[18]  = instrument->counter_P[18] = instrument->counter_P2[18] = 0;
  instrument->counter_AbsorbProp[18]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0017_MARS_M1_arm_rotation_2_undo", _MARS_M1_arm_rotation_2_undo_var._position_absolute, _MARS_M1_arm_rotation_2_undo_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M1_arm_rotation_2_undo_setpos */

/* component MARS_beam_arm_before_crystal=Arm() SETTING, POSITION/ROTATION */
int _MARS_beam_arm_before_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_beam_arm_before_crystal_setpos] component MARS_beam_arm_before_crystal=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_beam_arm_before_crystal_var._name, "MARS_beam_arm_before_crystal", 16384);
  stracpy(_MARS_beam_arm_before_crystal_var._type, "Arm", 16384);
  _MARS_beam_arm_before_crystal_var._index=19;
  int current_setpos_index = 19;
  /* component MARS_beam_arm_before_crystal=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_M1_arm_rotation_2_undo_var._rotation_absolute, _MARS_beam_arm_before_crystal_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M1_var._rotation_absolute, tr1);
    rot_mul(_MARS_beam_arm_before_crystal_var._rotation_absolute, tr1, _MARS_beam_arm_before_crystal_var._rotation_relative);
    _MARS_beam_arm_before_crystal_var._rotation_is_identity =  rot_test_identity(_MARS_beam_arm_before_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceSourceToDCM - MARS_DistanceSourceToM1);
    rot_transpose(_MARS_M1_arm_rotation_2_undo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_beam_arm_before_crystal_var._position_absolute = coords_add(_MARS_M1_arm_rotation_2_undo_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M1_var._position_absolute, _MARS_beam_arm_before_crystal_var._position_absolute);
    _MARS_beam_arm_before_crystal_var._position_relative = rot_apply(_MARS_beam_arm_before_crystal_var._rotation_absolute, tc1);
  } /* MARS_beam_arm_before_crystal=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_beam_arm_before_crystal", _MARS_beam_arm_before_crystal_var._position_absolute, _MARS_beam_arm_before_crystal_var._rotation_absolute);
  instrument->_position_absolute[19] = _MARS_beam_arm_before_crystal_var._position_absolute;
  instrument->_position_relative[19] = _MARS_beam_arm_before_crystal_var._position_relative;
    _MARS_beam_arm_before_crystal_var._position_relative_is_zero =  coords_test_zero(_MARS_beam_arm_before_crystal_var._position_relative);
  instrument->counter_N[19]  = instrument->counter_P[19] = instrument->counter_P2[19] = 0;
  instrument->counter_AbsorbProp[19]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0018_MARS_beam_arm_before_crystal", _MARS_beam_arm_before_crystal_var._position_absolute, _MARS_beam_arm_before_crystal_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_beam_arm_before_crystal_setpos */

/* component MARS_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _MARS_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_dcm_xtal0_setpos] component MARS_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_MARS_dcm_xtal0_var._name, "MARS_dcm_xtal0", 16384);
  stracpy(_MARS_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _MARS_dcm_xtal0_var._index=20;
  int current_setpos_index = 20;
  _MARS_dcm_xtal0_var._parameters.length = 0.04;
  _MARS_dcm_xtal0_var._parameters.width = 0.05;
  _MARS_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_MARS_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _MARS_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_MARS_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _MARS_dcm_xtal0_var._parameters.material[0]='\0';
  _MARS_dcm_xtal0_var._parameters.alpha = _instrument_var._parameters.MARS_alpha;
  _MARS_dcm_xtal0_var._parameters.R0 = 0;
  _MARS_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _MARS_dcm_xtal0_var._parameters.crystal_type = 2;
  _MARS_dcm_xtal0_var._parameters.h = 2;
  _MARS_dcm_xtal0_var._parameters.k = 2;
  _MARS_dcm_xtal0_var._parameters.l = 0;
  _MARS_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _MARS_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component MARS_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- MARS_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_beam_arm_before_crystal_var._rotation_absolute, _MARS_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M1_var._rotation_absolute, tr1);
    rot_mul(_MARS_dcm_xtal0_var._rotation_absolute, tr1, _MARS_dcm_xtal0_var._rotation_relative);
    _MARS_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_MARS_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_beam_arm_before_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_dcm_xtal0_var._position_absolute = coords_add(_MARS_beam_arm_before_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M1_var._position_absolute, _MARS_dcm_xtal0_var._position_absolute);
    _MARS_dcm_xtal0_var._position_relative = rot_apply(_MARS_dcm_xtal0_var._rotation_absolute, tc1);
  } /* MARS_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("MARS_dcm_xtal0", _MARS_dcm_xtal0_var._position_absolute, _MARS_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[20] = _MARS_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[20] = _MARS_dcm_xtal0_var._position_relative;
    _MARS_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_MARS_dcm_xtal0_var._position_relative);
  instrument->counter_N[20]  = instrument->counter_P[20] = instrument->counter_P2[20] = 0;
  instrument->counter_AbsorbProp[20]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0019_MARS_dcm_xtal0", _MARS_dcm_xtal0_var._position_absolute, _MARS_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "width", "0.02", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "alpha", "0.0", "_instrument_var._parameters.MARS_alpha","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "h", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "k", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "l", "1", "0","int");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0019_MARS_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_dcm_xtal0_setpos */

/* component MARS_dcm0=Arm() SETTING, POSITION/ROTATION */
int _MARS_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_dcm0_setpos] component MARS_dcm0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_dcm0_var._name, "MARS_dcm0", 16384);
  stracpy(_MARS_dcm0_var._type, "Arm", 16384);
  _MARS_dcm0_var._index=21;
  int current_setpos_index = 21;
  /* component MARS_dcm0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- MARS_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_dcm_xtal0_var._rotation_absolute, _MARS_dcm0_var._rotation_absolute);
    rot_transpose(_MARS_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_MARS_dcm0_var._rotation_absolute, tr1, _MARS_dcm0_var._rotation_relative);
    _MARS_dcm0_var._rotation_is_identity =  rot_test_identity(_MARS_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_dcm0_var._position_absolute = coords_add(_MARS_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_dcm_xtal0_var._position_absolute, _MARS_dcm0_var._position_absolute);
    _MARS_dcm0_var._position_relative = rot_apply(_MARS_dcm0_var._rotation_absolute, tc1);
  } /* MARS_dcm0=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_dcm0", _MARS_dcm0_var._position_absolute, _MARS_dcm0_var._rotation_absolute);
  instrument->_position_absolute[21] = _MARS_dcm0_var._position_absolute;
  instrument->_position_relative[21] = _MARS_dcm0_var._position_relative;
    _MARS_dcm0_var._position_relative_is_zero =  coords_test_zero(_MARS_dcm0_var._position_relative);
  instrument->counter_N[21]  = instrument->counter_P[21] = instrument->counter_P2[21] = 0;
  instrument->counter_AbsorbProp[21]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0020_MARS_dcm0", _MARS_dcm0_var._position_absolute, _MARS_dcm0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_dcm0_setpos */

/* component MARS_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _MARS_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_dcm_xtal1_setpos] component MARS_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_MARS_dcm_xtal1_var._name, "MARS_dcm_xtal1", 16384);
  stracpy(_MARS_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _MARS_dcm_xtal1_var._index=22;
  int current_setpos_index = 22;
  _MARS_dcm_xtal1_var._parameters.length = 0.02;
  _MARS_dcm_xtal1_var._parameters.width = 0.05;
  _MARS_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_MARS_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _MARS_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_MARS_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _MARS_dcm_xtal1_var._parameters.material[0]='\0';
  _MARS_dcm_xtal1_var._parameters.alpha = _instrument_var._parameters.MARS_alpha;
  _MARS_dcm_xtal1_var._parameters.R0 = 0;
  _MARS_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _MARS_dcm_xtal1_var._parameters.crystal_type = 2;
  _MARS_dcm_xtal1_var._parameters.h = 2;
  _MARS_dcm_xtal1_var._parameters.k = 2;
  _MARS_dcm_xtal1_var._parameters.l = 0;
  _MARS_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _MARS_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component MARS_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (MARS_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_dcm0_var._rotation_absolute, _MARS_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_MARS_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_MARS_dcm_xtal1_var._rotation_absolute, tr1, _MARS_dcm_xtal1_var._rotation_relative);
    _MARS_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_MARS_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, 20e-3, MARS_calculated_angle ? 20e-3 / tan ( MARS_calculated_angle * DEG2RAD ) : 0);
    rot_transpose(_MARS_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_dcm_xtal1_var._position_absolute = coords_add(_MARS_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_dcm_xtal0_var._position_absolute, _MARS_dcm_xtal1_var._position_absolute);
    _MARS_dcm_xtal1_var._position_relative = rot_apply(_MARS_dcm_xtal1_var._rotation_absolute, tc1);
  } /* MARS_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("MARS_dcm_xtal1", _MARS_dcm_xtal1_var._position_absolute, _MARS_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[22] = _MARS_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[22] = _MARS_dcm_xtal1_var._position_relative;
    _MARS_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_MARS_dcm_xtal1_var._position_relative);
  instrument->counter_N[22]  = instrument->counter_P[22] = instrument->counter_P2[22] = 0;
  instrument->counter_AbsorbProp[22]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0021_MARS_dcm_xtal1", _MARS_dcm_xtal1_var._position_absolute, _MARS_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "length", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "width", "0.02", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "alpha", "0.0", "_instrument_var._parameters.MARS_alpha","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "h", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "k", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "l", "1", "0","int");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0021_MARS_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_dcm_xtal1_setpos */

/* component MARS_dcm1=Arm() SETTING, POSITION/ROTATION */
int _MARS_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_dcm1_setpos] component MARS_dcm1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_dcm1_var._name, "MARS_dcm1", 16384);
  stracpy(_MARS_dcm1_var._type, "Arm", 16384);
  _MARS_dcm1_var._index=23;
  int current_setpos_index = 23;
  /* component MARS_dcm1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (MARS_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_dcm_xtal1_var._rotation_absolute, _MARS_dcm1_var._rotation_absolute);
    rot_transpose(_MARS_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_MARS_dcm1_var._rotation_absolute, tr1, _MARS_dcm1_var._rotation_relative);
    _MARS_dcm1_var._rotation_is_identity =  rot_test_identity(_MARS_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_dcm1_var._position_absolute = coords_add(_MARS_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_dcm_xtal1_var._position_absolute, _MARS_dcm1_var._position_absolute);
    _MARS_dcm1_var._position_relative = rot_apply(_MARS_dcm1_var._rotation_absolute, tc1);
  } /* MARS_dcm1=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_dcm1", _MARS_dcm1_var._position_absolute, _MARS_dcm1_var._rotation_absolute);
  instrument->_position_absolute[23] = _MARS_dcm1_var._position_absolute;
  instrument->_position_relative[23] = _MARS_dcm1_var._position_relative;
    _MARS_dcm1_var._position_relative_is_zero =  coords_test_zero(_MARS_dcm1_var._position_relative);
  instrument->counter_N[23]  = instrument->counter_P[23] = instrument->counter_P2[23] = 0;
  instrument->counter_AbsorbProp[23]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0022_MARS_dcm1", _MARS_dcm1_var._position_absolute, _MARS_dcm1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_dcm1_setpos */

/* component MARS_emon_dcm0=E_monitor() SETTING, POSITION/ROTATION */
int _MARS_emon_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_emon_dcm0_setpos] component MARS_emon_dcm0=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_MARS_emon_dcm0_var._name, "MARS_emon_dcm0", 16384);
  stracpy(_MARS_emon_dcm0_var._type, "E_monitor", 16384);
  _MARS_emon_dcm0_var._index=24;
  int current_setpos_index = 24;
  _MARS_emon_dcm0_var._parameters.nE = 101;
  if("MARS_emon_dcm0" && strlen("MARS_emon_dcm0"))
    stracpy(_MARS_emon_dcm0_var._parameters.filename, "MARS_emon_dcm0" ? "MARS_emon_dcm0" : "", 16384);
  else 
  _MARS_emon_dcm0_var._parameters.filename[0]='\0';
  _MARS_emon_dcm0_var._parameters.xwidth = MARS_PrimaryBeamMonitorWidth;
  _MARS_emon_dcm0_var._parameters.yheight = MARS_PrimaryBeamMonitorHeight;
  _MARS_emon_dcm0_var._parameters.Emin = _instrument_var._parameters.MARS_E0 - _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0;
  _MARS_emon_dcm0_var._parameters.Emax = _instrument_var._parameters.MARS_E0 + _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0;
  _MARS_emon_dcm0_var._parameters.restore_xray = 0;


  /* component MARS_emon_dcm0=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_dcm1_var._rotation_absolute, _MARS_emon_dcm0_var._rotation_absolute);
    rot_transpose(_MARS_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_MARS_emon_dcm0_var._rotation_absolute, tr1, _MARS_emon_dcm0_var._rotation_relative);
    _MARS_emon_dcm0_var._rotation_is_identity =  rot_test_identity(_MARS_emon_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceToPrimaryBeamMonitor - MARS_DistanceSourceToDCM);
    rot_transpose(_MARS_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_emon_dcm0_var._position_absolute = coords_add(_MARS_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_dcm_xtal1_var._position_absolute, _MARS_emon_dcm0_var._position_absolute);
    _MARS_emon_dcm0_var._position_relative = rot_apply(_MARS_emon_dcm0_var._rotation_absolute, tc1);
  } /* MARS_emon_dcm0=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("MARS_emon_dcm0", _MARS_emon_dcm0_var._position_absolute, _MARS_emon_dcm0_var._rotation_absolute);
  instrument->_position_absolute[24] = _MARS_emon_dcm0_var._position_absolute;
  instrument->_position_relative[24] = _MARS_emon_dcm0_var._position_relative;
    _MARS_emon_dcm0_var._position_relative_is_zero =  coords_test_zero(_MARS_emon_dcm0_var._position_relative);
  instrument->counter_N[24]  = instrument->counter_P[24] = instrument->counter_P2[24] = 0;
  instrument->counter_AbsorbProp[24]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0023_MARS_emon_dcm0", _MARS_emon_dcm0_var._position_absolute, _MARS_emon_dcm0_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "nE", "20", "101","MCNUM");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "filename", 0, "MARS_emon_dcm0", "char*");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "xwidth", "0.1", "MARS_PrimaryBeamMonitorWidth","MCNUM");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "yheight", "0.1", "MARS_PrimaryBeamMonitorHeight","MCNUM");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "Emin", "NONE", "_instrument_var._parameters.MARS_E0 - _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "Emax", "NONE", "_instrument_var._parameters.MARS_E0 + _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0023_MARS_emon_dcm0", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_emon_dcm0_setpos */

/* component MARS_displayMono=PSD_monitor() SETTING, POSITION/ROTATION */
int _MARS_displayMono_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_displayMono_setpos] component MARS_displayMono=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_MARS_displayMono_var._name, "MARS_displayMono", 16384);
  stracpy(_MARS_displayMono_var._type, "PSD_monitor", 16384);
  _MARS_displayMono_var._index=25;
  int current_setpos_index = 25;
  if("MARS_emon_psd" && strlen("MARS_emon_psd"))
    stracpy(_MARS_displayMono_var._parameters.filename, "MARS_emon_psd" ? "MARS_emon_psd" : "", 16384);
  else 
  _MARS_displayMono_var._parameters.filename[0]='\0';
  _MARS_displayMono_var._parameters.xwidth = 0.05;
  _MARS_displayMono_var._parameters.yheight = 0.05;
  _MARS_displayMono_var._parameters.radius = 0;
  _MARS_displayMono_var._parameters.restore_xray = 1;
  _MARS_displayMono_var._parameters.nowritefile = 0;
  _MARS_displayMono_var._parameters.nx = 90;
  _MARS_displayMono_var._parameters.ny = 90;
  _MARS_displayMono_var._parameters.nr = 0;


  /* component MARS_displayMono=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_emon_dcm0_var._rotation_absolute, _MARS_displayMono_var._rotation_absolute);
    rot_transpose(_MARS_emon_dcm0_var._rotation_absolute, tr1);
    rot_mul(_MARS_displayMono_var._rotation_absolute, tr1, _MARS_displayMono_var._rotation_relative);
    _MARS_displayMono_var._rotation_is_identity =  rot_test_identity(_MARS_displayMono_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_emon_dcm0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_displayMono_var._position_absolute = coords_add(_MARS_emon_dcm0_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_emon_dcm0_var._position_absolute, _MARS_displayMono_var._position_absolute);
    _MARS_displayMono_var._position_relative = rot_apply(_MARS_displayMono_var._rotation_absolute, tc1);
  } /* MARS_displayMono=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("MARS_displayMono", _MARS_displayMono_var._position_absolute, _MARS_displayMono_var._rotation_absolute);
  instrument->_position_absolute[25] = _MARS_displayMono_var._position_absolute;
  instrument->_position_relative[25] = _MARS_displayMono_var._position_relative;
    _MARS_displayMono_var._position_relative_is_zero =  coords_test_zero(_MARS_displayMono_var._position_relative);
  instrument->counter_N[25]  = instrument->counter_P[25] = instrument->counter_P2[25] = 0;
  instrument->counter_AbsorbProp[25]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0024_MARS_displayMono", _MARS_displayMono_var._position_absolute, _MARS_displayMono_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "filename", 0, "MARS_emon_psd", "char*");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "yheight", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0024_MARS_displayMono", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_displayMono_setpos */

/* component MARS_displayMonoLength=E_monitor() SETTING, POSITION/ROTATION */
int _MARS_displayMonoLength_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_displayMonoLength_setpos] component MARS_displayMonoLength=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_MARS_displayMonoLength_var._name, "MARS_displayMonoLength", 16384);
  stracpy(_MARS_displayMonoLength_var._type, "E_monitor", 16384);
  _MARS_displayMonoLength_var._index=26;
  int current_setpos_index = 26;
  _MARS_displayMonoLength_var._parameters.nE = 512;
  if("MARS_Output.E" && strlen("MARS_Output.E"))
    stracpy(_MARS_displayMonoLength_var._parameters.filename, "MARS_Output.E" ? "MARS_Output.E" : "", 16384);
  else 
  _MARS_displayMonoLength_var._parameters.filename[0]='\0';
  _MARS_displayMonoLength_var._parameters.xwidth = 0.2;
  _MARS_displayMonoLength_var._parameters.yheight = 0.2;
  _MARS_displayMonoLength_var._parameters.Emin = _instrument_var._parameters.MARS_E0 * ( 1 - _instrument_var._parameters.MARS_dEr );
  _MARS_displayMonoLength_var._parameters.Emax = _instrument_var._parameters.MARS_E0 * ( 1 + _instrument_var._parameters.MARS_dEr );
  _MARS_displayMonoLength_var._parameters.restore_xray = 0;


  /* component MARS_displayMonoLength=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_displayMono_var._rotation_absolute, _MARS_displayMonoLength_var._rotation_absolute);
    rot_transpose(_MARS_displayMono_var._rotation_absolute, tr1);
    rot_mul(_MARS_displayMonoLength_var._rotation_absolute, tr1, _MARS_displayMonoLength_var._rotation_relative);
    _MARS_displayMonoLength_var._rotation_is_identity =  rot_test_identity(_MARS_displayMonoLength_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_displayMono_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_displayMonoLength_var._position_absolute = coords_add(_MARS_displayMono_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displayMono_var._position_absolute, _MARS_displayMonoLength_var._position_absolute);
    _MARS_displayMonoLength_var._position_relative = rot_apply(_MARS_displayMonoLength_var._rotation_absolute, tc1);
  } /* MARS_displayMonoLength=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("MARS_displayMonoLength", _MARS_displayMonoLength_var._position_absolute, _MARS_displayMonoLength_var._rotation_absolute);
  instrument->_position_absolute[26] = _MARS_displayMonoLength_var._position_absolute;
  instrument->_position_relative[26] = _MARS_displayMonoLength_var._position_relative;
    _MARS_displayMonoLength_var._position_relative_is_zero =  coords_test_zero(_MARS_displayMonoLength_var._position_relative);
  instrument->counter_N[26]  = instrument->counter_P[26] = instrument->counter_P2[26] = 0;
  instrument->counter_AbsorbProp[26]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0025_MARS_displayMonoLength", _MARS_displayMonoLength_var._position_absolute, _MARS_displayMonoLength_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "nE", "20", "512","MCNUM");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "filename", 0, "MARS_Output.E", "char*");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "xwidth", "0.1", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "yheight", "0.1", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "Emin", "NONE", "_instrument_var._parameters.MARS_E0 * ( 1 - _instrument_var._parameters.MARS_dEr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "Emax", "NONE", "_instrument_var._parameters.MARS_E0 * ( 1 + _instrument_var._parameters.MARS_dEr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0025_MARS_displayMonoLength", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_displayMonoLength_setpos */

/* component MARS_M2_arm_translation=Arm() SETTING, POSITION/ROTATION */
int _MARS_M2_arm_translation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M2_arm_translation_setpos] component MARS_M2_arm_translation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M2_arm_translation_var._name, "MARS_M2_arm_translation", 16384);
  stracpy(_MARS_M2_arm_translation_var._type, "Arm", 16384);
  _MARS_M2_arm_translation_var._index=27;
  int current_setpos_index = 27;
  /* component MARS_M2_arm_translation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_displayMonoLength_var._rotation_absolute, _MARS_M2_arm_translation_var._rotation_absolute);
    rot_transpose(_MARS_displayMonoLength_var._rotation_absolute, tr1);
    rot_mul(_MARS_M2_arm_translation_var._rotation_absolute, tr1, _MARS_M2_arm_translation_var._rotation_relative);
    _MARS_M2_arm_translation_var._rotation_is_identity =  rot_test_identity(_MARS_M2_arm_translation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceSourceToM2 - MARS_DistanceToPrimaryBeamMonitor);
    rot_transpose(_MARS_displayMonoLength_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M2_arm_translation_var._position_absolute = coords_add(_MARS_displayMonoLength_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displayMonoLength_var._position_absolute, _MARS_M2_arm_translation_var._position_absolute);
    _MARS_M2_arm_translation_var._position_relative = rot_apply(_MARS_M2_arm_translation_var._rotation_absolute, tc1);
  } /* MARS_M2_arm_translation=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M2_arm_translation", _MARS_M2_arm_translation_var._position_absolute, _MARS_M2_arm_translation_var._rotation_absolute);
  instrument->_position_absolute[27] = _MARS_M2_arm_translation_var._position_absolute;
  instrument->_position_relative[27] = _MARS_M2_arm_translation_var._position_relative;
    _MARS_M2_arm_translation_var._position_relative_is_zero =  coords_test_zero(_MARS_M2_arm_translation_var._position_relative);
  instrument->counter_N[27]  = instrument->counter_P[27] = instrument->counter_P2[27] = 0;
  instrument->counter_AbsorbProp[27]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0026_MARS_M2_arm_translation", _MARS_M2_arm_translation_var._position_absolute, _MARS_M2_arm_translation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M2_arm_translation_setpos */

/* component MARS_M2_arm_rotation_1=Arm() SETTING, POSITION/ROTATION */
int _MARS_M2_arm_rotation_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M2_arm_rotation_1_setpos] component MARS_M2_arm_rotation_1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M2_arm_rotation_1_var._name, "MARS_M2_arm_rotation_1", 16384);
  stracpy(_MARS_M2_arm_rotation_1_var._type, "Arm", 16384);
  _MARS_M2_arm_rotation_1_var._index=28;
  int current_setpos_index = 28;
  /* component MARS_M2_arm_rotation_1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _MARS_M2_arm_translation_var._rotation_absolute, _MARS_M2_arm_rotation_1_var._rotation_absolute);
    rot_transpose(_MARS_displayMonoLength_var._rotation_absolute, tr1);
    rot_mul(_MARS_M2_arm_rotation_1_var._rotation_absolute, tr1, _MARS_M2_arm_rotation_1_var._rotation_relative);
    _MARS_M2_arm_rotation_1_var._rotation_is_identity =  rot_test_identity(_MARS_M2_arm_rotation_1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_M2_arm_translation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M2_arm_rotation_1_var._position_absolute = coords_add(_MARS_M2_arm_translation_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displayMonoLength_var._position_absolute, _MARS_M2_arm_rotation_1_var._position_absolute);
    _MARS_M2_arm_rotation_1_var._position_relative = rot_apply(_MARS_M2_arm_rotation_1_var._rotation_absolute, tc1);
  } /* MARS_M2_arm_rotation_1=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M2_arm_rotation_1", _MARS_M2_arm_rotation_1_var._position_absolute, _MARS_M2_arm_rotation_1_var._rotation_absolute);
  instrument->_position_absolute[28] = _MARS_M2_arm_rotation_1_var._position_absolute;
  instrument->_position_relative[28] = _MARS_M2_arm_rotation_1_var._position_relative;
    _MARS_M2_arm_rotation_1_var._position_relative_is_zero =  coords_test_zero(_MARS_M2_arm_rotation_1_var._position_relative);
  instrument->counter_N[28]  = instrument->counter_P[28] = instrument->counter_P2[28] = 0;
  instrument->counter_AbsorbProp[28]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0027_MARS_M2_arm_rotation_1", _MARS_M2_arm_rotation_1_var._position_absolute, _MARS_M2_arm_rotation_1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M2_arm_rotation_1_setpos */

/* component MARS_mirror_M2=Mirror_curved() SETTING, POSITION/ROTATION */
int _MARS_mirror_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_mirror_M2_setpos] component MARS_mirror_M2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_MARS_mirror_M2_var._name, "MARS_mirror_M2", 16384);
  stracpy(_MARS_mirror_M2_var._type, "Mirror_curved", 16384);
  _MARS_mirror_M2_var._index=29;
  int current_setpos_index = 29;
  _MARS_mirror_M2_var._parameters.radius = MARS_RadiusM2;
  _MARS_mirror_M2_var._parameters.R0 = 1;
  if(_instrument_var._parameters.MARS_reflec_material_M12 && strlen(_instrument_var._parameters.MARS_reflec_material_M12))
    stracpy(_MARS_mirror_M2_var._parameters.coating, _instrument_var._parameters.MARS_reflec_material_M12 ? _instrument_var._parameters.MARS_reflec_material_M12 : "", 16384);
  else 
  _MARS_mirror_M2_var._parameters.coating[0]='\0';
  _MARS_mirror_M2_var._parameters.zdepth = 0.2;
  _MARS_mirror_M2_var._parameters.yheight = 0.2;
  _MARS_mirror_M2_var._parameters.length = MARS_M12_length;
  _MARS_mirror_M2_var._parameters.width = MARS_M12_width;


  /* component MARS_mirror_M2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (MARS_AngleM2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_M2_arm_rotation_1_var._rotation_absolute, _MARS_mirror_M2_var._rotation_absolute);
    rot_transpose(_MARS_displayMonoLength_var._rotation_absolute, tr1);
    rot_mul(_MARS_mirror_M2_var._rotation_absolute, tr1, _MARS_mirror_M2_var._rotation_relative);
    _MARS_mirror_M2_var._rotation_is_identity =  rot_test_identity(_MARS_mirror_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_M2_arm_rotation_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_mirror_M2_var._position_absolute = coords_add(_MARS_M2_arm_rotation_1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displayMonoLength_var._position_absolute, _MARS_mirror_M2_var._position_absolute);
    _MARS_mirror_M2_var._position_relative = rot_apply(_MARS_mirror_M2_var._rotation_absolute, tc1);
  } /* MARS_mirror_M2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("MARS_mirror_M2", _MARS_mirror_M2_var._position_absolute, _MARS_mirror_M2_var._rotation_absolute);
  instrument->_position_absolute[29] = _MARS_mirror_M2_var._position_absolute;
  instrument->_position_relative[29] = _MARS_mirror_M2_var._position_relative;
    _MARS_mirror_M2_var._position_relative_is_zero =  coords_test_zero(_MARS_mirror_M2_var._position_relative);
  instrument->counter_N[29]  = instrument->counter_P[29] = instrument->counter_P2[29] = 0;
  instrument->counter_AbsorbProp[29]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0028_MARS_mirror_M2", _MARS_mirror_M2_var._position_absolute, _MARS_mirror_M2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "radius", "1", "MARS_RadiusM2","MCNUM");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "coating", "Be.txt", _instrument_var._parameters.MARS_reflec_material_M12, "char*");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "length", "0", "MARS_M12_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0028_MARS_mirror_M2", "width", "0", "MARS_M12_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_mirror_M2_setpos */

/* component MARS_M2_arm_rotation_2=Arm() SETTING, POSITION/ROTATION */
int _MARS_M2_arm_rotation_2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M2_arm_rotation_2_setpos] component MARS_M2_arm_rotation_2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M2_arm_rotation_2_var._name, "MARS_M2_arm_rotation_2", 16384);
  stracpy(_MARS_M2_arm_rotation_2_var._type, "Arm", 16384);
  _MARS_M2_arm_rotation_2_var._index=30;
  int current_setpos_index = 30;
  /* component MARS_M2_arm_rotation_2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (MARS_AngleM2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _MARS_mirror_M2_var._rotation_absolute, _MARS_M2_arm_rotation_2_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M2_var._rotation_absolute, tr1);
    rot_mul(_MARS_M2_arm_rotation_2_var._rotation_absolute, tr1, _MARS_M2_arm_rotation_2_var._rotation_relative);
    _MARS_M2_arm_rotation_2_var._rotation_is_identity =  rot_test_identity(_MARS_M2_arm_rotation_2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_mirror_M2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M2_arm_rotation_2_var._position_absolute = coords_add(_MARS_mirror_M2_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M2_var._position_absolute, _MARS_M2_arm_rotation_2_var._position_absolute);
    _MARS_M2_arm_rotation_2_var._position_relative = rot_apply(_MARS_M2_arm_rotation_2_var._rotation_absolute, tc1);
  } /* MARS_M2_arm_rotation_2=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M2_arm_rotation_2", _MARS_M2_arm_rotation_2_var._position_absolute, _MARS_M2_arm_rotation_2_var._rotation_absolute);
  instrument->_position_absolute[30] = _MARS_M2_arm_rotation_2_var._position_absolute;
  instrument->_position_relative[30] = _MARS_M2_arm_rotation_2_var._position_relative;
    _MARS_M2_arm_rotation_2_var._position_relative_is_zero =  coords_test_zero(_MARS_M2_arm_rotation_2_var._position_relative);
  instrument->counter_N[30]  = instrument->counter_P[30] = instrument->counter_P2[30] = 0;
  instrument->counter_AbsorbProp[30]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0029_MARS_M2_arm_rotation_2", _MARS_M2_arm_rotation_2_var._position_absolute, _MARS_M2_arm_rotation_2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M2_arm_rotation_2_setpos */

/* component MARS_M2_arm_rotation_2_undo=Arm() SETTING, POSITION/ROTATION */
int _MARS_M2_arm_rotation_2_undo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_M2_arm_rotation_2_undo_setpos] component MARS_M2_arm_rotation_2_undo=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_MARS_M2_arm_rotation_2_undo_var._name, "MARS_M2_arm_rotation_2_undo", 16384);
  stracpy(_MARS_M2_arm_rotation_2_undo_var._type, "Arm", 16384);
  _MARS_M2_arm_rotation_2_undo_var._index=31;
  int current_setpos_index = 31;
  /* component MARS_M2_arm_rotation_2_undo=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _MARS_M2_arm_rotation_2_var._rotation_absolute, _MARS_M2_arm_rotation_2_undo_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M2_var._rotation_absolute, tr1);
    rot_mul(_MARS_M2_arm_rotation_2_undo_var._rotation_absolute, tr1, _MARS_M2_arm_rotation_2_undo_var._rotation_relative);
    _MARS_M2_arm_rotation_2_undo_var._rotation_is_identity =  rot_test_identity(_MARS_M2_arm_rotation_2_undo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_M2_arm_rotation_2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_M2_arm_rotation_2_undo_var._position_absolute = coords_add(_MARS_M2_arm_rotation_2_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M2_var._position_absolute, _MARS_M2_arm_rotation_2_undo_var._position_absolute);
    _MARS_M2_arm_rotation_2_undo_var._position_relative = rot_apply(_MARS_M2_arm_rotation_2_undo_var._rotation_absolute, tc1);
  } /* MARS_M2_arm_rotation_2_undo=Arm() AT ROTATED */
  DEBUG_COMPONENT("MARS_M2_arm_rotation_2_undo", _MARS_M2_arm_rotation_2_undo_var._position_absolute, _MARS_M2_arm_rotation_2_undo_var._rotation_absolute);
  instrument->_position_absolute[31] = _MARS_M2_arm_rotation_2_undo_var._position_absolute;
  instrument->_position_relative[31] = _MARS_M2_arm_rotation_2_undo_var._position_relative;
    _MARS_M2_arm_rotation_2_undo_var._position_relative_is_zero =  coords_test_zero(_MARS_M2_arm_rotation_2_undo_var._position_relative);
  instrument->counter_N[31]  = instrument->counter_P[31] = instrument->counter_P2[31] = 0;
  instrument->counter_AbsorbProp[31]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0030_MARS_M2_arm_rotation_2_undo", _MARS_M2_arm_rotation_2_undo_var._position_absolute, _MARS_M2_arm_rotation_2_undo_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_M2_arm_rotation_2_undo_setpos */

/* component MARS_slitSecon1=Slit() SETTING, POSITION/ROTATION */
int _MARS_slitSecon1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_slitSecon1_setpos] component MARS_slitSecon1=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_MARS_slitSecon1_var._name, "MARS_slitSecon1", 16384);
  stracpy(_MARS_slitSecon1_var._type, "Slit", 16384);
  _MARS_slitSecon1_var._index=32;
  int current_setpos_index = 32;
  _MARS_slitSecon1_var._parameters.xmin = 0;
  _MARS_slitSecon1_var._parameters.xmax = 0;
  _MARS_slitSecon1_var._parameters.ymin = 0;
  _MARS_slitSecon1_var._parameters.ymax = 0;
  _MARS_slitSecon1_var._parameters.radius = 0;
  _MARS_slitSecon1_var._parameters.xwidth = MARS_SecondarySlit1Width;
  _MARS_slitSecon1_var._parameters.yheight = MARS_SecondarySlit1Height;
  _MARS_slitSecon1_var._parameters.dist = 0;
  _MARS_slitSecon1_var._parameters.focus_xw = 0;
  _MARS_slitSecon1_var._parameters.focus_yh = 0;
  _MARS_slitSecon1_var._parameters.focus_x0 = 0;
  _MARS_slitSecon1_var._parameters.focus_y0 = 0;

  /* component MARS_slitSecon1=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_M2_arm_rotation_2_undo_var._rotation_absolute, _MARS_slitSecon1_var._rotation_absolute);
    rot_transpose(_MARS_mirror_M2_var._rotation_absolute, tr1);
    rot_mul(_MARS_slitSecon1_var._rotation_absolute, tr1, _MARS_slitSecon1_var._rotation_relative);
    _MARS_slitSecon1_var._rotation_is_identity =  rot_test_identity(_MARS_slitSecon1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceToSecondarySlit1 - MARS_DistanceSourceToM2);
    rot_transpose(_MARS_M2_arm_rotation_2_undo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_slitSecon1_var._position_absolute = coords_add(_MARS_M2_arm_rotation_2_undo_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_mirror_M2_var._position_absolute, _MARS_slitSecon1_var._position_absolute);
    _MARS_slitSecon1_var._position_relative = rot_apply(_MARS_slitSecon1_var._rotation_absolute, tc1);
  } /* MARS_slitSecon1=Slit() AT ROTATED */
  DEBUG_COMPONENT("MARS_slitSecon1", _MARS_slitSecon1_var._position_absolute, _MARS_slitSecon1_var._rotation_absolute);
  instrument->_position_absolute[32] = _MARS_slitSecon1_var._position_absolute;
  instrument->_position_relative[32] = _MARS_slitSecon1_var._position_relative;
    _MARS_slitSecon1_var._position_relative_is_zero =  coords_test_zero(_MARS_slitSecon1_var._position_relative);
  instrument->counter_N[32]  = instrument->counter_P[32] = instrument->counter_P2[32] = 0;
  instrument->counter_AbsorbProp[32]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0031_MARS_slitSecon1", _MARS_slitSecon1_var._position_absolute, _MARS_slitSecon1_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "xwidth", "0.001", "MARS_SecondarySlit1Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "yheight", "0.001", "MARS_SecondarySlit1Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0031_MARS_slitSecon1", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_slitSecon1_setpos */

/* component MARS_slitSecon2=Slit() SETTING, POSITION/ROTATION */
int _MARS_slitSecon2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_slitSecon2_setpos] component MARS_slitSecon2=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_MARS_slitSecon2_var._name, "MARS_slitSecon2", 16384);
  stracpy(_MARS_slitSecon2_var._type, "Slit", 16384);
  _MARS_slitSecon2_var._index=33;
  int current_setpos_index = 33;
  _MARS_slitSecon2_var._parameters.xmin = 0;
  _MARS_slitSecon2_var._parameters.xmax = 0;
  _MARS_slitSecon2_var._parameters.ymin = 0;
  _MARS_slitSecon2_var._parameters.ymax = 0;
  _MARS_slitSecon2_var._parameters.radius = 0;
  _MARS_slitSecon2_var._parameters.xwidth = MARS_SecondarySlit2Width;
  _MARS_slitSecon2_var._parameters.yheight = MARS_SecondarySlit2Height;
  _MARS_slitSecon2_var._parameters.dist = 0;
  _MARS_slitSecon2_var._parameters.focus_xw = 0;
  _MARS_slitSecon2_var._parameters.focus_yh = 0;
  _MARS_slitSecon2_var._parameters.focus_x0 = 0;
  _MARS_slitSecon2_var._parameters.focus_y0 = 0;

  /* component MARS_slitSecon2=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_slitSecon1_var._rotation_absolute, _MARS_slitSecon2_var._rotation_absolute);
    rot_transpose(_MARS_slitSecon1_var._rotation_absolute, tr1);
    rot_mul(_MARS_slitSecon2_var._rotation_absolute, tr1, _MARS_slitSecon2_var._rotation_relative);
    _MARS_slitSecon2_var._rotation_is_identity =  rot_test_identity(_MARS_slitSecon2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceToSecondarySlit2 - MARS_DistanceToSecondarySlit1);
    rot_transpose(_MARS_slitSecon1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_slitSecon2_var._position_absolute = coords_add(_MARS_slitSecon1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_slitSecon1_var._position_absolute, _MARS_slitSecon2_var._position_absolute);
    _MARS_slitSecon2_var._position_relative = rot_apply(_MARS_slitSecon2_var._rotation_absolute, tc1);
  } /* MARS_slitSecon2=Slit() AT ROTATED */
  DEBUG_COMPONENT("MARS_slitSecon2", _MARS_slitSecon2_var._position_absolute, _MARS_slitSecon2_var._rotation_absolute);
  instrument->_position_absolute[33] = _MARS_slitSecon2_var._position_absolute;
  instrument->_position_relative[33] = _MARS_slitSecon2_var._position_relative;
    _MARS_slitSecon2_var._position_relative_is_zero =  coords_test_zero(_MARS_slitSecon2_var._position_relative);
  instrument->counter_N[33]  = instrument->counter_P[33] = instrument->counter_P2[33] = 0;
  instrument->counter_AbsorbProp[33]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0032_MARS_slitSecon2", _MARS_slitSecon2_var._position_absolute, _MARS_slitSecon2_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "xwidth", "0.001", "MARS_SecondarySlit2Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "yheight", "0.001", "MARS_SecondarySlit2Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0032_MARS_slitSecon2", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_slitSecon2_setpos */

/* component MARS_emon_dcm1=E_monitor() SETTING, POSITION/ROTATION */
int _MARS_emon_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_emon_dcm1_setpos] component MARS_emon_dcm1=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_MARS_emon_dcm1_var._name, "MARS_emon_dcm1", 16384);
  stracpy(_MARS_emon_dcm1_var._type, "E_monitor", 16384);
  _MARS_emon_dcm1_var._index=34;
  int current_setpos_index = 34;
  _MARS_emon_dcm1_var._parameters.nE = 101;
  if("MARS_BeamMonitor2" && strlen("MARS_BeamMonitor2"))
    stracpy(_MARS_emon_dcm1_var._parameters.filename, "MARS_BeamMonitor2" ? "MARS_BeamMonitor2" : "", 16384);
  else 
  _MARS_emon_dcm1_var._parameters.filename[0]='\0';
  _MARS_emon_dcm1_var._parameters.xwidth = MARS_SecondaryBeamMonitorWidth;
  _MARS_emon_dcm1_var._parameters.yheight = MARS_SecondaryBeamMonitorHeight;
  _MARS_emon_dcm1_var._parameters.Emin = _instrument_var._parameters.MARS_E0 - _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0;
  _MARS_emon_dcm1_var._parameters.Emax = _instrument_var._parameters.MARS_E0 + _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0;
  _MARS_emon_dcm1_var._parameters.restore_xray = 0;


  /* component MARS_emon_dcm1=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_slitSecon2_var._rotation_absolute, _MARS_emon_dcm1_var._rotation_absolute);
    rot_transpose(_MARS_slitSecon2_var._rotation_absolute, tr1);
    rot_mul(_MARS_emon_dcm1_var._rotation_absolute, tr1, _MARS_emon_dcm1_var._rotation_relative);
    _MARS_emon_dcm1_var._rotation_is_identity =  rot_test_identity(_MARS_emon_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, MARS_DistanceToSecondaryBeamMonitor - MARS_DistanceToSecondarySlit2);
    rot_transpose(_MARS_slitSecon2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_emon_dcm1_var._position_absolute = coords_add(_MARS_slitSecon2_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_slitSecon2_var._position_absolute, _MARS_emon_dcm1_var._position_absolute);
    _MARS_emon_dcm1_var._position_relative = rot_apply(_MARS_emon_dcm1_var._rotation_absolute, tc1);
  } /* MARS_emon_dcm1=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("MARS_emon_dcm1", _MARS_emon_dcm1_var._position_absolute, _MARS_emon_dcm1_var._rotation_absolute);
  instrument->_position_absolute[34] = _MARS_emon_dcm1_var._position_absolute;
  instrument->_position_relative[34] = _MARS_emon_dcm1_var._position_relative;
    _MARS_emon_dcm1_var._position_relative_is_zero =  coords_test_zero(_MARS_emon_dcm1_var._position_relative);
  instrument->counter_N[34]  = instrument->counter_P[34] = instrument->counter_P2[34] = 0;
  instrument->counter_AbsorbProp[34]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0033_MARS_emon_dcm1", _MARS_emon_dcm1_var._position_absolute, _MARS_emon_dcm1_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "nE", "20", "101","MCNUM");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "filename", 0, "MARS_BeamMonitor2", "char*");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "xwidth", "0.1", "MARS_SecondaryBeamMonitorWidth","MCNUM");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "yheight", "0.1", "MARS_SecondaryBeamMonitorHeight","MCNUM");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "Emin", "NONE", "_instrument_var._parameters.MARS_E0 - _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "Emax", "NONE", "_instrument_var._parameters.MARS_E0 + _instrument_var._parameters.MARS_dEr * _instrument_var._parameters.MARS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0033_MARS_emon_dcm1", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_emon_dcm1_setpos */

/* component MARS_displaySlit2=PSD_monitor() SETTING, POSITION/ROTATION */
int _MARS_displaySlit2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_displaySlit2_setpos] component MARS_displaySlit2=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_MARS_displaySlit2_var._name, "MARS_displaySlit2", 16384);
  stracpy(_MARS_displaySlit2_var._type, "PSD_monitor", 16384);
  _MARS_displaySlit2_var._index=35;
  int current_setpos_index = 35;
  if("MARS_emon_psd3" && strlen("MARS_emon_psd3"))
    stracpy(_MARS_displaySlit2_var._parameters.filename, "MARS_emon_psd3" ? "MARS_emon_psd3" : "", 16384);
  else 
  _MARS_displaySlit2_var._parameters.filename[0]='\0';
  _MARS_displaySlit2_var._parameters.xwidth = 0.05;
  _MARS_displaySlit2_var._parameters.yheight = 0.05;
  _MARS_displaySlit2_var._parameters.radius = 0;
  _MARS_displaySlit2_var._parameters.restore_xray = 1;
  _MARS_displaySlit2_var._parameters.nowritefile = 0;
  _MARS_displaySlit2_var._parameters.nx = 90;
  _MARS_displaySlit2_var._parameters.ny = 90;
  _MARS_displaySlit2_var._parameters.nr = 0;


  /* component MARS_displaySlit2=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_emon_dcm1_var._rotation_absolute, _MARS_displaySlit2_var._rotation_absolute);
    rot_transpose(_MARS_emon_dcm1_var._rotation_absolute, tr1);
    rot_mul(_MARS_displaySlit2_var._rotation_absolute, tr1, _MARS_displaySlit2_var._rotation_relative);
    _MARS_displaySlit2_var._rotation_is_identity =  rot_test_identity(_MARS_displaySlit2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_emon_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_displaySlit2_var._position_absolute = coords_add(_MARS_emon_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_emon_dcm1_var._position_absolute, _MARS_displaySlit2_var._position_absolute);
    _MARS_displaySlit2_var._position_relative = rot_apply(_MARS_displaySlit2_var._rotation_absolute, tc1);
  } /* MARS_displaySlit2=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("MARS_displaySlit2", _MARS_displaySlit2_var._position_absolute, _MARS_displaySlit2_var._rotation_absolute);
  instrument->_position_absolute[35] = _MARS_displaySlit2_var._position_absolute;
  instrument->_position_relative[35] = _MARS_displaySlit2_var._position_relative;
    _MARS_displaySlit2_var._position_relative_is_zero =  coords_test_zero(_MARS_displaySlit2_var._position_relative);
  instrument->counter_N[35]  = instrument->counter_P[35] = instrument->counter_P2[35] = 0;
  instrument->counter_AbsorbProp[35]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0034_MARS_displaySlit2", _MARS_displaySlit2_var._position_absolute, _MARS_displaySlit2_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "filename", 0, "MARS_emon_psd3", "char*");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "yheight", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0034_MARS_displaySlit2", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_displaySlit2_setpos */

/* component MARS_Sample=FluoPowder() SETTING, POSITION/ROTATION */
int _MARS_Sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_Sample_setpos] component MARS_Sample=FluoPowder() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");
  stracpy(_MARS_Sample_var._name, "MARS_Sample", 16384);
  stracpy(_MARS_Sample_var._type, "FluoPowder", 16384);
  _MARS_Sample_var._index=36;
  int current_setpos_index = 36;
  _MARS_Sample_var._parameters.geometry[0]='\0';
  _MARS_Sample_var._parameters.radius = 0;
  _MARS_Sample_var._parameters.thickness = 0;
  _MARS_Sample_var._parameters.xwidth = 0.005;
  _MARS_Sample_var._parameters.yheight = 0.05;
  _MARS_Sample_var._parameters.zdepth = 0.0001;
  _MARS_Sample_var._parameters.concentric = 0;
  if(_instrument_var._parameters.MARS_reflections && strlen(_instrument_var._parameters.MARS_reflections))
    stracpy(_MARS_Sample_var._parameters.material, _instrument_var._parameters.MARS_reflections ? _instrument_var._parameters.MARS_reflections : "", 16384);
  else 
  _MARS_Sample_var._parameters.material[0]='\0';
  _MARS_Sample_var._parameters.packing_factor = 0;
  _MARS_Sample_var._parameters.density = 0;
  _MARS_Sample_var._parameters.weight = 0;
  _MARS_Sample_var._parameters.p_interact = 0.99;
  _MARS_Sample_var._parameters.target_x = 0;
  _MARS_Sample_var._parameters.target_y = 0;
  _MARS_Sample_var._parameters.target_z = 1;
  _MARS_Sample_var._parameters.focus_r = 0;
  _MARS_Sample_var._parameters.focus_xw = 0;
  _MARS_Sample_var._parameters.focus_yh = 0;
  _MARS_Sample_var._parameters.focus_aw = 180;
  _MARS_Sample_var._parameters.focus_ah = asin ( 0.02 / 0.670 ) * RAD2DEG;
  _MARS_Sample_var._parameters.target_index = 0;
  _MARS_Sample_var._parameters.flag_compton = 1;
  _MARS_Sample_var._parameters.flag_rayleigh = 0;
  _MARS_Sample_var._parameters.flag_lorentzian = 0;
  _MARS_Sample_var._parameters.flag_powder = 1;
  _MARS_Sample_var._parameters.flag_kissel = 0;
  if("" && strlen(""))
    stracpy(_MARS_Sample_var._parameters.powder_refl, "" ? "" : "", 16384);
  else 
  _MARS_Sample_var._parameters.powder_refl[0]='\0';
  _MARS_Sample_var._parameters.powder_format[0] = 0;
  _MARS_Sample_var._parameters.powder_format[1] = 0;
  _MARS_Sample_var._parameters.powder_format[2] = 0;
  _MARS_Sample_var._parameters.powder_format[3] = 0;
  _MARS_Sample_var._parameters.powder_format[4] = 0;
  _MARS_Sample_var._parameters.powder_format[5] = 0;
  _MARS_Sample_var._parameters.powder_format[6] = 0;
  _MARS_Sample_var._parameters.powder_format[7] = 0;
  _MARS_Sample_var._parameters.Vc = 0;
  _MARS_Sample_var._parameters.delta_d_d = 0;
  _MARS_Sample_var._parameters.DW = 0;
  _MARS_Sample_var._parameters.d_phi = asin ( 0.02 / 0.670 ) * RAD2DEG;
  _MARS_Sample_var._parameters.nb_atoms = 1;
  _MARS_Sample_var._parameters.barns = 1;
  _MARS_Sample_var._parameters.tth_sign = 0;
  _MARS_Sample_var._parameters.order = 1;


  /* component MARS_Sample=FluoPowder() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_displaySlit2_var._rotation_absolute, _MARS_Sample_var._rotation_absolute);
    rot_transpose(_MARS_displaySlit2_var._rotation_absolute, tr1);
    rot_mul(_MARS_Sample_var._rotation_absolute, tr1, _MARS_Sample_var._rotation_relative);
    _MARS_Sample_var._rotation_is_identity =  rot_test_identity(_MARS_Sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_displaySlit2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_Sample_var._position_absolute = coords_add(_MARS_displaySlit2_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_displaySlit2_var._position_absolute, _MARS_Sample_var._position_absolute);
    _MARS_Sample_var._position_relative = rot_apply(_MARS_Sample_var._rotation_absolute, tc1);
  } /* MARS_Sample=FluoPowder() AT ROTATED */
  DEBUG_COMPONENT("MARS_Sample", _MARS_Sample_var._position_absolute, _MARS_Sample_var._rotation_absolute);
  instrument->_position_absolute[36] = _MARS_Sample_var._position_absolute;
  instrument->_position_relative[36] = _MARS_Sample_var._position_relative;
    _MARS_Sample_var._position_relative_is_zero =  coords_test_zero(_MARS_Sample_var._position_relative);
  instrument->counter_N[36]  = instrument->counter_P[36] = instrument->counter_P2[36] = 0;
  instrument->counter_AbsorbProp[36]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0035_MARS_Sample", _MARS_Sample_var._position_absolute, _MARS_Sample_var._rotation_absolute, "FluoPowder");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "xwidth", "0", "0.005","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "yheight", "0", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "zdepth", "0", "0.0001","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "material", "LaB6.cif", _instrument_var._parameters.MARS_reflections, "char*");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "p_interact", "0", "0.99","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "target_z", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "focus_aw", "0", "180","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "focus_ah", "0", "asin ( 0.02 / 0.670 ) * RAD2DEG","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "flag_rayleigh", "1", "0","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "flag_powder", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "powder_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "powder_format", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "Vc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "delta_d_d", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "DW", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "d_phi", "0", "asin ( 0.02 / 0.670 ) * RAD2DEG","MCNUM");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "nb_atoms", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "tth_sign", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0035_MARS_Sample", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_Sample_setpos */

/* component MARS_detector_diffraction=Monitor_nD() SETTING, POSITION/ROTATION */
int _MARS_detector_diffraction_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_detector_diffraction_setpos] component MARS_detector_diffraction=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_MARS_detector_diffraction_var._name, "MARS_detector_diffraction", 16384);
  stracpy(_MARS_detector_diffraction_var._type, "Monitor_nD", 16384);
  _MARS_detector_diffraction_var._index=37;
  int current_setpos_index = 37;
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_diffraction_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.user9[0]='\0';
  _MARS_detector_diffraction_var._parameters.xwidth = 0;
  _MARS_detector_diffraction_var._parameters.yheight = 0.02;
  _MARS_detector_diffraction_var._parameters.zdepth = 0;
  _MARS_detector_diffraction_var._parameters.bins = 90000;
  _MARS_detector_diffraction_var._parameters.min = 5;
  _MARS_detector_diffraction_var._parameters.max = 90;
  _MARS_detector_diffraction_var._parameters.restore_xray = 1;
  _MARS_detector_diffraction_var._parameters.radius = 0.670;
  if("abs theta" && strlen("abs theta"))
    stracpy(_MARS_detector_diffraction_var._parameters.options, "abs theta" ? "abs theta" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.geometry[0]='\0';
  _MARS_detector_diffraction_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_diffraction_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_diffraction_var._parameters.username9[0]='\0';


  /* component MARS_detector_diffraction=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Sample_var._rotation_absolute, _MARS_detector_diffraction_var._rotation_absolute);
    rot_transpose(_MARS_Sample_var._rotation_absolute, tr1);
    rot_mul(_MARS_detector_diffraction_var._rotation_absolute, tr1, _MARS_detector_diffraction_var._rotation_relative);
    _MARS_detector_diffraction_var._rotation_is_identity =  rot_test_identity(_MARS_detector_diffraction_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_Sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_detector_diffraction_var._position_absolute = coords_add(_MARS_Sample_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_Sample_var._position_absolute, _MARS_detector_diffraction_var._position_absolute);
    _MARS_detector_diffraction_var._position_relative = rot_apply(_MARS_detector_diffraction_var._rotation_absolute, tc1);
  } /* MARS_detector_diffraction=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("MARS_detector_diffraction", _MARS_detector_diffraction_var._position_absolute, _MARS_detector_diffraction_var._rotation_absolute);
  instrument->_position_absolute[37] = _MARS_detector_diffraction_var._position_absolute;
  instrument->_position_relative[37] = _MARS_detector_diffraction_var._position_relative;
    _MARS_detector_diffraction_var._position_relative_is_zero =  coords_test_zero(_MARS_detector_diffraction_var._position_relative);
  instrument->counter_N[37]  = instrument->counter_P[37] = instrument->counter_P2[37] = 0;
  instrument->counter_AbsorbProp[37]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0036_MARS_detector_diffraction", _MARS_detector_diffraction_var._position_absolute, _MARS_detector_diffraction_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "bins", "0", "90000","int");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "min", "-1e40", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "max", "1e40", "90","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "radius", "0", "0.670","MCNUM");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "options", "NULL", "abs theta", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0036_MARS_detector_diffraction", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_detector_diffraction_setpos */

/* component MARS_detector_fluo=Monitor_nD() SETTING, POSITION/ROTATION */
int _MARS_detector_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_MARS_detector_fluo_setpos] component MARS_detector_fluo=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_MARS_detector_fluo_var._name, "MARS_detector_fluo", 16384);
  stracpy(_MARS_detector_fluo_var._type, "Monitor_nD", 16384);
  _MARS_detector_fluo_var._index=38;
  int current_setpos_index = 38;
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_MARS_detector_fluo_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.user9[0]='\0';
  _MARS_detector_fluo_var._parameters.xwidth = 0;
  _MARS_detector_fluo_var._parameters.yheight = 0.02;
  _MARS_detector_fluo_var._parameters.zdepth = 0;
  _MARS_detector_fluo_var._parameters.bins = 1024;
  _MARS_detector_fluo_var._parameters.min = 0;
  _MARS_detector_fluo_var._parameters.max = _instrument_var._parameters.MARS_E0 * 1.2;
  _MARS_detector_fluo_var._parameters.restore_xray = 0;
  _MARS_detector_fluo_var._parameters.radius = 0.670;
  if("energy" && strlen("energy"))
    stracpy(_MARS_detector_fluo_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.geometry[0]='\0';
  _MARS_detector_fluo_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_MARS_detector_fluo_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _MARS_detector_fluo_var._parameters.username9[0]='\0';


  /* component MARS_detector_fluo=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_Sample_var._rotation_absolute, _MARS_detector_fluo_var._rotation_absolute);
    rot_transpose(_MARS_detector_diffraction_var._rotation_absolute, tr1);
    rot_mul(_MARS_detector_fluo_var._rotation_absolute, tr1, _MARS_detector_fluo_var._rotation_relative);
    _MARS_detector_fluo_var._rotation_is_identity =  rot_test_identity(_MARS_detector_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_Sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _MARS_detector_fluo_var._position_absolute = coords_add(_MARS_Sample_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_detector_diffraction_var._position_absolute, _MARS_detector_fluo_var._position_absolute);
    _MARS_detector_fluo_var._position_relative = rot_apply(_MARS_detector_fluo_var._rotation_absolute, tc1);
  } /* MARS_detector_fluo=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("MARS_detector_fluo", _MARS_detector_fluo_var._position_absolute, _MARS_detector_fluo_var._rotation_absolute);
  instrument->_position_absolute[38] = _MARS_detector_fluo_var._position_absolute;
  instrument->_position_relative[38] = _MARS_detector_fluo_var._position_relative;
    _MARS_detector_fluo_var._position_relative_is_zero =  coords_test_zero(_MARS_detector_fluo_var._position_relative);
  instrument->counter_N[38]  = instrument->counter_P[38] = instrument->counter_P2[38] = 0;
  instrument->counter_AbsorbProp[38]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0037_MARS_detector_fluo", _MARS_detector_fluo_var._position_absolute, _MARS_detector_fluo_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "bins", "0", "1024","int");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "min", "-1e40", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "max", "1e40", "_instrument_var._parameters.MARS_E0 * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "radius", "0", "0.670","MCNUM");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0037_MARS_detector_fluo", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _MARS_detector_fluo_setpos */

/* component beamdump_40=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_40_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_40_setpos] component beamdump_40=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_40_var._name, "beamdump_40", 16384);
  stracpy(_beamdump_40_var._type, "Beamstop", 16384);
  _beamdump_40_var._index=39;
  int current_setpos_index = 39;
  _beamdump_40_var._parameters.xmin = -0.05;
  _beamdump_40_var._parameters.xmax = 0.05;
  _beamdump_40_var._parameters.ymin = -0.05;
  _beamdump_40_var._parameters.ymax = 0.05;
  _beamdump_40_var._parameters.xwidth = 0;
  _beamdump_40_var._parameters.yheight = 0;
  _beamdump_40_var._parameters.radius = 0;

  /* component beamdump_40=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _MARS_detector_fluo_var._rotation_absolute, _beamdump_40_var._rotation_absolute);
    rot_transpose(_MARS_detector_fluo_var._rotation_absolute, tr1);
    rot_mul(_beamdump_40_var._rotation_absolute, tr1, _beamdump_40_var._rotation_relative);
    _beamdump_40_var._rotation_is_identity =  rot_test_identity(_beamdump_40_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_MARS_detector_fluo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_40_var._position_absolute = coords_add(_MARS_detector_fluo_var._position_absolute, tc2);
    tc1 = coords_sub(_MARS_detector_fluo_var._position_absolute, _beamdump_40_var._position_absolute);
    _beamdump_40_var._position_relative = rot_apply(_beamdump_40_var._rotation_absolute, tc1);
  } /* beamdump_40=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_40", _beamdump_40_var._position_absolute, _beamdump_40_var._rotation_absolute);
  instrument->_position_absolute[39] = _beamdump_40_var._position_absolute;
  instrument->_position_relative[39] = _beamdump_40_var._position_relative;
    _beamdump_40_var._position_relative_is_zero =  coords_test_zero(_beamdump_40_var._position_relative);
  instrument->counter_N[39]  = instrument->counter_P[39] = instrument->counter_P2[39] = 0;
  instrument->counter_AbsorbProp[39]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0038_beamdump_40", _beamdump_40_var._position_absolute, _beamdump_40_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0038_beamdump_40", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_40_setpos */

/* component PSICHE_pos=Text() SETTING, POSITION/ROTATION */
int _PSICHE_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_pos_setpos] component PSICHE_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_PSICHE_pos_var._name, "PSICHE_pos", 16384);
  stracpy(_PSICHE_pos_var._type, "Text", 16384);
  _PSICHE_pos_var._index=40;
  int current_setpos_index = 40;
  if("PSICHE" && strlen("PSICHE"))
    stracpy(_PSICHE_pos_var._parameters.text, "PSICHE" ? "PSICHE" : "", 16384);
  else 
  _PSICHE_pos_var._parameters.text[0]='\0';
  _PSICHE_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_PSICHE_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _PSICHE_pos_var._parameters.plane[0]='\0';
  _PSICHE_pos_var._parameters.pen_thickness = 0.1;


  /* component PSICHE_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-56.4)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _PSICHE_pos_var._rotation_absolute);
    rot_transpose(_beamdump_40_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_pos_var._rotation_absolute, tr1, _PSICHE_pos_var._rotation_relative);
    _PSICHE_pos_var._rotation_is_identity =  rot_test_identity(_PSICHE_pos_var._rotation_relative);
    tc1 = coords_set(
      31.19, 0, 46.92);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_40_var._position_absolute, _PSICHE_pos_var._position_absolute);
    _PSICHE_pos_var._position_relative = rot_apply(_PSICHE_pos_var._rotation_absolute, tc1);
  } /* PSICHE_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_pos", _PSICHE_pos_var._position_absolute, _PSICHE_pos_var._rotation_absolute);
  instrument->_position_absolute[40] = _PSICHE_pos_var._position_absolute;
  instrument->_position_relative[40] = _PSICHE_pos_var._position_relative;
    _PSICHE_pos_var._position_relative_is_zero =  coords_test_zero(_PSICHE_pos_var._position_relative);
  instrument->counter_N[40]  = instrument->counter_P[40] = instrument->counter_P2[40] = 0;
  instrument->counter_AbsorbProp[40]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0039_PSICHE_pos", _PSICHE_pos_var._position_absolute, _PSICHE_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0039_PSICHE_pos", "text", "NONE", "PSICHE", "char*");
        mccomp_param_nexus(nxhandle,"0039_PSICHE_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0039_PSICHE_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0039_PSICHE_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_pos_setpos */

/* component PSICHE=Arm() SETTING, POSITION/ROTATION */
int _PSICHE_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_setpos] component PSICHE=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PSICHE_var._name, "PSICHE", 16384);
  stracpy(_PSICHE_var._type, "Arm", 16384);
  _PSICHE_var._index=41;
  int current_setpos_index = 41;
  /* component PSICHE=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_pos_var._rotation_absolute, _PSICHE_var._rotation_absolute);
    rot_transpose(_PSICHE_pos_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_var._rotation_absolute, tr1, _PSICHE_var._rotation_relative);
    _PSICHE_var._rotation_is_identity =  rot_test_identity(_PSICHE_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_var._position_absolute = coords_add(_PSICHE_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_pos_var._position_absolute, _PSICHE_var._position_absolute);
    _PSICHE_var._position_relative = rot_apply(_PSICHE_var._rotation_absolute, tc1);
  } /* PSICHE=Arm() AT ROTATED */
  DEBUG_COMPONENT("PSICHE", _PSICHE_var._position_absolute, _PSICHE_var._rotation_absolute);
  instrument->_position_absolute[41] = _PSICHE_var._position_absolute;
  instrument->_position_relative[41] = _PSICHE_var._position_relative;
    _PSICHE_var._position_relative_is_zero =  coords_test_zero(_PSICHE_var._position_relative);
  instrument->counter_N[41]  = instrument->counter_P[41] = instrument->counter_P2[41] = 0;
  instrument->counter_AbsorbProp[41]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0040_PSICHE", _PSICHE_var._position_absolute, _PSICHE_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_setpos */

/* component PSICHE_source=Wiggler() SETTING, POSITION/ROTATION */
int _PSICHE_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_source_setpos] component PSICHE_source=Wiggler() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Wiggler.comp:107]");
  stracpy(_PSICHE_source_var._name, "PSICHE_source", 16384);
  stracpy(_PSICHE_source_var._type, "Wiggler", 16384);
  _PSICHE_source_var._index=42;
  int current_setpos_index = 42;
  _PSICHE_source_var._parameters.E0 = _instrument_var._parameters.PSICHE_E0;
  _PSICHE_source_var._parameters.dE = _instrument_var._parameters.PSICHE_dE;
  _PSICHE_source_var._parameters.lambda0 = 0;
  _PSICHE_source_var._parameters.dlambda = 0;
  _PSICHE_source_var._parameters.phase = 0;
  _PSICHE_source_var._parameters.randomphase = 1;
  _PSICHE_source_var._parameters.Ee = 2.4;
  _PSICHE_source_var._parameters.Ie = 0.5;
  _PSICHE_source_var._parameters.B = 2.1;
  _PSICHE_source_var._parameters.K = 10;
  _PSICHE_source_var._parameters.Nper = 41;
  _PSICHE_source_var._parameters.length = 38 * 50e-3;
  _PSICHE_source_var._parameters.sigey = 9.3e-6;
  _PSICHE_source_var._parameters.sigex = 215.7e-6;
  _PSICHE_source_var._parameters.focus_xw = 0;
  _PSICHE_source_var._parameters.focus_yh = 0;
  _PSICHE_source_var._parameters.dist = 1;
  _PSICHE_source_var._parameters.gauss_t = 0;
  _PSICHE_source_var._parameters.verbose = 1;
  _PSICHE_source_var._parameters.Br = 1.35;


  /* component PSICHE_source=Wiggler() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_var._rotation_absolute, _PSICHE_source_var._rotation_absolute);
    rot_transpose(_PSICHE_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_source_var._rotation_absolute, tr1, _PSICHE_source_var._rotation_relative);
    _PSICHE_source_var._rotation_is_identity =  rot_test_identity(_PSICHE_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_source_var._position_absolute = coords_add(_PSICHE_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_var._position_absolute, _PSICHE_source_var._position_absolute);
    _PSICHE_source_var._position_relative = rot_apply(_PSICHE_source_var._rotation_absolute, tc1);
  } /* PSICHE_source=Wiggler() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_source", _PSICHE_source_var._position_absolute, _PSICHE_source_var._rotation_absolute);
  instrument->_position_absolute[42] = _PSICHE_source_var._position_absolute;
  instrument->_position_relative[42] = _PSICHE_source_var._position_relative;
    _PSICHE_source_var._position_relative_is_zero =  coords_test_zero(_PSICHE_source_var._position_relative);
  instrument->counter_N[42]  = instrument->counter_P[42] = instrument->counter_P2[42] = 0;
  instrument->counter_AbsorbProp[42]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0041_PSICHE_source", _PSICHE_source_var._position_absolute, _PSICHE_source_var._rotation_absolute, "Wiggler");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "E0", "0", "_instrument_var._parameters.PSICHE_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "dE", "0", "_instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "Ee", "2.4", "2.4","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "B", "1.6", "2.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "K", "3", "10","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "Nper", "1", "41","int");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "length", "1", "38 * 50e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "sigey", "0", "9.3e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "sigex", "0", "215.7e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "gauss_t", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "verbose", "0", "1","int");
        mccomp_param_nexus(nxhandle,"0041_PSICHE_source", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_source_setpos */

/* component PSICHE_mon_src_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_src_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_src_e_setpos] component PSICHE_mon_src_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_src_e_var._name, "PSICHE_mon_src_e", 16384);
  stracpy(_PSICHE_mon_src_e_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_src_e_var._index=43;
  int current_setpos_index = 43;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.user9[0]='\0';
  _PSICHE_mon_src_e_var._parameters.xwidth = 1e-2;
  _PSICHE_mon_src_e_var._parameters.yheight = 1e-2;
  _PSICHE_mon_src_e_var._parameters.zdepth = 0;
  _PSICHE_mon_src_e_var._parameters.bins = 512;
  _PSICHE_mon_src_e_var._parameters.min = _instrument_var._parameters.PSICHE_E0 -1.1 * _instrument_var._parameters.PSICHE_dE;
  _PSICHE_mon_src_e_var._parameters.max = _instrument_var._parameters.PSICHE_E0 + 1.1 * _instrument_var._parameters.PSICHE_dE;
  _PSICHE_mon_src_e_var._parameters.restore_xray = 0;
  _PSICHE_mon_src_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_PSICHE_mon_src_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.geometry[0]='\0';
  _PSICHE_mon_src_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_e_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_src_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_source_var._rotation_absolute, _PSICHE_mon_src_e_var._rotation_absolute);
    rot_transpose(_PSICHE_source_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_src_e_var._rotation_absolute, tr1, _PSICHE_mon_src_e_var._rotation_relative);
    _PSICHE_mon_src_e_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_src_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 17.5);
    rot_transpose(_PSICHE_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_src_e_var._position_absolute = coords_add(_PSICHE_source_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_source_var._position_absolute, _PSICHE_mon_src_e_var._position_absolute);
    _PSICHE_mon_src_e_var._position_relative = rot_apply(_PSICHE_mon_src_e_var._rotation_absolute, tc1);
  } /* PSICHE_mon_src_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_src_e", _PSICHE_mon_src_e_var._position_absolute, _PSICHE_mon_src_e_var._rotation_absolute);
  instrument->_position_absolute[43] = _PSICHE_mon_src_e_var._position_absolute;
  instrument->_position_relative[43] = _PSICHE_mon_src_e_var._position_relative;
    _PSICHE_mon_src_e_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_src_e_var._position_relative);
  instrument->counter_N[43]  = instrument->counter_P[43] = instrument->counter_P2[43] = 0;
  instrument->counter_AbsorbProp[43]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0042_PSICHE_mon_src_e", _PSICHE_mon_src_e_var._position_absolute, _PSICHE_mon_src_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "min", "-1e40", "_instrument_var._parameters.PSICHE_E0 -1.1 * _instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "max", "1e40", "_instrument_var._parameters.PSICHE_E0 + 1.1 * _instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0042_PSICHE_mon_src_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_src_e_setpos */

/* component PSICHE_mon_src_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_src_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_src_xy_setpos] component PSICHE_mon_src_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_src_xy_var._name, "PSICHE_mon_src_xy", 16384);
  stracpy(_PSICHE_mon_src_xy_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_src_xy_var._index=44;
  int current_setpos_index = 44;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_src_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.user9[0]='\0';
  _PSICHE_mon_src_xy_var._parameters.xwidth = 1e-2;
  _PSICHE_mon_src_xy_var._parameters.yheight = 1e-2;
  _PSICHE_mon_src_xy_var._parameters.zdepth = 0;
  _PSICHE_mon_src_xy_var._parameters.bins = 128;
  _PSICHE_mon_src_xy_var._parameters.min = -1e40;
  _PSICHE_mon_src_xy_var._parameters.max = 1e40;
  _PSICHE_mon_src_xy_var._parameters.restore_xray = 0;
  _PSICHE_mon_src_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.geometry[0]='\0';
  _PSICHE_mon_src_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_src_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_src_xy_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_src_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_mon_src_e_var._rotation_absolute, _PSICHE_mon_src_xy_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_src_e_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_src_xy_var._rotation_absolute, tr1, _PSICHE_mon_src_xy_var._rotation_relative);
    _PSICHE_mon_src_xy_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_src_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_mon_src_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_src_xy_var._position_absolute = coords_add(_PSICHE_mon_src_e_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_src_e_var._position_absolute, _PSICHE_mon_src_xy_var._position_absolute);
    _PSICHE_mon_src_xy_var._position_relative = rot_apply(_PSICHE_mon_src_xy_var._rotation_absolute, tc1);
  } /* PSICHE_mon_src_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_src_xy", _PSICHE_mon_src_xy_var._position_absolute, _PSICHE_mon_src_xy_var._rotation_absolute);
  instrument->_position_absolute[44] = _PSICHE_mon_src_xy_var._position_absolute;
  instrument->_position_relative[44] = _PSICHE_mon_src_xy_var._position_relative;
    _PSICHE_mon_src_xy_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_src_xy_var._position_relative);
  instrument->counter_N[44]  = instrument->counter_P[44] = instrument->counter_P2[44] = 0;
  instrument->counter_AbsorbProp[44]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0043_PSICHE_mon_src_xy", _PSICHE_mon_src_xy_var._position_absolute, _PSICHE_mon_src_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0043_PSICHE_mon_src_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_src_xy_setpos */

/* component PSICHE_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _PSICHE_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_DCM_location_setpos] component PSICHE_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PSICHE_DCM_location_var._name, "PSICHE_DCM_location", 16384);
  stracpy(_PSICHE_DCM_location_var._type, "Arm", 16384);
  _PSICHE_DCM_location_var._index=45;
  int current_setpos_index = 45;
  /* component PSICHE_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_source_var._rotation_absolute, _PSICHE_DCM_location_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_DCM_location_var._rotation_absolute, tr1, _PSICHE_DCM_location_var._rotation_relative);
    _PSICHE_DCM_location_var._rotation_is_identity =  rot_test_identity(_PSICHE_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 20.5);
    rot_transpose(_PSICHE_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_DCM_location_var._position_absolute = coords_add(_PSICHE_source_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_src_xy_var._position_absolute, _PSICHE_DCM_location_var._position_absolute);
    _PSICHE_DCM_location_var._position_relative = rot_apply(_PSICHE_DCM_location_var._rotation_absolute, tc1);
  } /* PSICHE_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_DCM_location", _PSICHE_DCM_location_var._position_absolute, _PSICHE_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[45] = _PSICHE_DCM_location_var._position_absolute;
  instrument->_position_relative[45] = _PSICHE_DCM_location_var._position_relative;
    _PSICHE_DCM_location_var._position_relative_is_zero =  coords_test_zero(_PSICHE_DCM_location_var._position_relative);
  instrument->counter_N[45]  = instrument->counter_P[45] = instrument->counter_P2[45] = 0;
  instrument->counter_AbsorbProp[45]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0044_PSICHE_DCM_location", _PSICHE_DCM_location_var._position_absolute, _PSICHE_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_DCM_location_setpos */

/* component PSICHE_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PSICHE_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_dcm_xtal0_setpos] component PSICHE_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PSICHE_dcm_xtal0_var._name, "PSICHE_dcm_xtal0", 16384);
  stracpy(_PSICHE_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _PSICHE_dcm_xtal0_var._index=46;
  int current_setpos_index = 46;
  _PSICHE_dcm_xtal0_var._parameters.length = 0.04;
  _PSICHE_dcm_xtal0_var._parameters.width = 0.04;
  _PSICHE_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PSICHE_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PSICHE_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PSICHE_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PSICHE_dcm_xtal0_var._parameters.material[0]='\0';
  _PSICHE_dcm_xtal0_var._parameters.alpha = 0.0;
  _PSICHE_dcm_xtal0_var._parameters.R0 = 0;
  _PSICHE_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _PSICHE_dcm_xtal0_var._parameters.crystal_type = 1;
  _PSICHE_dcm_xtal0_var._parameters.h = 1;
  _PSICHE_dcm_xtal0_var._parameters.k = 1;
  _PSICHE_dcm_xtal0_var._parameters.l = 1;
  _PSICHE_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _PSICHE_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component PSICHE_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.PSICHE_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_DCM_location_var._rotation_absolute, _PSICHE_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_dcm_xtal0_var._rotation_absolute, tr1, _PSICHE_dcm_xtal0_var._rotation_relative);
    _PSICHE_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_PSICHE_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_dcm_xtal0_var._position_absolute = coords_add(_PSICHE_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_src_xy_var._position_absolute, _PSICHE_dcm_xtal0_var._position_absolute);
    _PSICHE_dcm_xtal0_var._position_relative = rot_apply(_PSICHE_dcm_xtal0_var._rotation_absolute, tc1);
  } /* PSICHE_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_dcm_xtal0", _PSICHE_dcm_xtal0_var._position_absolute, _PSICHE_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[46] = _PSICHE_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[46] = _PSICHE_dcm_xtal0_var._position_relative;
    _PSICHE_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_PSICHE_dcm_xtal0_var._position_relative);
  instrument->counter_N[46]  = instrument->counter_P[46] = instrument->counter_P2[46] = 0;
  instrument->counter_AbsorbProp[46]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", _PSICHE_dcm_xtal0_var._position_absolute, _PSICHE_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0045_PSICHE_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_dcm_xtal0_setpos */

/* component PSICHE_dcm0=Arm() SETTING, POSITION/ROTATION */
int _PSICHE_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_dcm0_setpos] component PSICHE_dcm0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PSICHE_dcm0_var._name, "PSICHE_dcm0", 16384);
  stracpy(_PSICHE_dcm0_var._type, "Arm", 16384);
  _PSICHE_dcm0_var._index=47;
  int current_setpos_index = 47;
  /* component PSICHE_dcm0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.PSICHE_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_dcm_xtal0_var._rotation_absolute, _PSICHE_dcm0_var._rotation_absolute);
    rot_transpose(_PSICHE_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_dcm0_var._rotation_absolute, tr1, _PSICHE_dcm0_var._rotation_relative);
    _PSICHE_dcm0_var._rotation_is_identity =  rot_test_identity(_PSICHE_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_dcm0_var._position_absolute = coords_add(_PSICHE_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_dcm_xtal0_var._position_absolute, _PSICHE_dcm0_var._position_absolute);
    _PSICHE_dcm0_var._position_relative = rot_apply(_PSICHE_dcm0_var._rotation_absolute, tc1);
  } /* PSICHE_dcm0=Arm() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_dcm0", _PSICHE_dcm0_var._position_absolute, _PSICHE_dcm0_var._rotation_absolute);
  instrument->_position_absolute[47] = _PSICHE_dcm0_var._position_absolute;
  instrument->_position_relative[47] = _PSICHE_dcm0_var._position_relative;
    _PSICHE_dcm0_var._position_relative_is_zero =  coords_test_zero(_PSICHE_dcm0_var._position_relative);
  instrument->counter_N[47]  = instrument->counter_P[47] = instrument->counter_P2[47] = 0;
  instrument->counter_AbsorbProp[47]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0046_PSICHE_dcm0", _PSICHE_dcm0_var._position_absolute, _PSICHE_dcm0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_dcm0_setpos */

/* component PSICHE_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PSICHE_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_dcm_xtal1_setpos] component PSICHE_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PSICHE_dcm_xtal1_var._name, "PSICHE_dcm_xtal1", 16384);
  stracpy(_PSICHE_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _PSICHE_dcm_xtal1_var._index=48;
  int current_setpos_index = 48;
  _PSICHE_dcm_xtal1_var._parameters.length = 0.04;
  _PSICHE_dcm_xtal1_var._parameters.width = 0.04;
  _PSICHE_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PSICHE_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PSICHE_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PSICHE_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PSICHE_dcm_xtal1_var._parameters.material[0]='\0';
  _PSICHE_dcm_xtal1_var._parameters.alpha = 0.0;
  _PSICHE_dcm_xtal1_var._parameters.R0 = 0;
  _PSICHE_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _PSICHE_dcm_xtal1_var._parameters.crystal_type = 1;
  _PSICHE_dcm_xtal1_var._parameters.h = 1;
  _PSICHE_dcm_xtal1_var._parameters.k = 1;
  _PSICHE_dcm_xtal1_var._parameters.l = 1;
  _PSICHE_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _PSICHE_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component PSICHE_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PSICHE_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_dcm0_var._rotation_absolute, _PSICHE_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_PSICHE_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_dcm_xtal1_var._rotation_absolute, tr1, _PSICHE_dcm_xtal1_var._rotation_relative);
    _PSICHE_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_PSICHE_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, PSICHE_dcm_gap, _instrument_var._parameters.PSICHE_dcm_theta ? PSICHE_dcm_gap / tan ( _instrument_var._parameters.PSICHE_dcm_theta * DEG2RAD ) : 0);
    rot_transpose(_PSICHE_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_dcm_xtal1_var._position_absolute = coords_add(_PSICHE_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_dcm_xtal0_var._position_absolute, _PSICHE_dcm_xtal1_var._position_absolute);
    _PSICHE_dcm_xtal1_var._position_relative = rot_apply(_PSICHE_dcm_xtal1_var._rotation_absolute, tc1);
  } /* PSICHE_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_dcm_xtal1", _PSICHE_dcm_xtal1_var._position_absolute, _PSICHE_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[48] = _PSICHE_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[48] = _PSICHE_dcm_xtal1_var._position_relative;
    _PSICHE_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_PSICHE_dcm_xtal1_var._position_relative);
  instrument->counter_N[48]  = instrument->counter_P[48] = instrument->counter_P2[48] = 0;
  instrument->counter_AbsorbProp[48]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", _PSICHE_dcm_xtal1_var._position_absolute, _PSICHE_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0047_PSICHE_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_dcm_xtal1_setpos */

/* component PSICHE_dcm1=Arm() SETTING, POSITION/ROTATION */
int _PSICHE_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_dcm1_setpos] component PSICHE_dcm1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PSICHE_dcm1_var._name, "PSICHE_dcm1", 16384);
  stracpy(_PSICHE_dcm1_var._type, "Arm", 16384);
  _PSICHE_dcm1_var._index=49;
  int current_setpos_index = 49;
  /* component PSICHE_dcm1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PSICHE_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_dcm_xtal1_var._rotation_absolute, _PSICHE_dcm1_var._rotation_absolute);
    rot_transpose(_PSICHE_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_dcm1_var._rotation_absolute, tr1, _PSICHE_dcm1_var._rotation_relative);
    _PSICHE_dcm1_var._rotation_is_identity =  rot_test_identity(_PSICHE_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_dcm1_var._position_absolute = coords_add(_PSICHE_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_dcm_xtal1_var._position_absolute, _PSICHE_dcm1_var._position_absolute);
    _PSICHE_dcm1_var._position_relative = rot_apply(_PSICHE_dcm1_var._rotation_absolute, tc1);
  } /* PSICHE_dcm1=Arm() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_dcm1", _PSICHE_dcm1_var._position_absolute, _PSICHE_dcm1_var._rotation_absolute);
  instrument->_position_absolute[49] = _PSICHE_dcm1_var._position_absolute;
  instrument->_position_relative[49] = _PSICHE_dcm1_var._position_relative;
    _PSICHE_dcm1_var._position_relative_is_zero =  coords_test_zero(_PSICHE_dcm1_var._position_relative);
  instrument->counter_N[49]  = instrument->counter_P[49] = instrument->counter_P2[49] = 0;
  instrument->counter_AbsorbProp[49]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0048_PSICHE_dcm1", _PSICHE_dcm1_var._position_absolute, _PSICHE_dcm1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_dcm1_setpos */

/* component PSICHE_mon_dcm_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_dcm_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_dcm_e_setpos] component PSICHE_mon_dcm_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_dcm_e_var._name, "PSICHE_mon_dcm_e", 16384);
  stracpy(_PSICHE_mon_dcm_e_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_dcm_e_var._index=50;
  int current_setpos_index = 50;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.user9[0]='\0';
  _PSICHE_mon_dcm_e_var._parameters.xwidth = 1e-2;
  _PSICHE_mon_dcm_e_var._parameters.yheight = 1e-2;
  _PSICHE_mon_dcm_e_var._parameters.zdepth = 0;
  _PSICHE_mon_dcm_e_var._parameters.bins = 512;
  _PSICHE_mon_dcm_e_var._parameters.min = _instrument_var._parameters.PSICHE_E0 -1.1 * _instrument_var._parameters.PSICHE_dE;
  _PSICHE_mon_dcm_e_var._parameters.max = _instrument_var._parameters.PSICHE_E0 + 1.1 * _instrument_var._parameters.PSICHE_dE;
  _PSICHE_mon_dcm_e_var._parameters.restore_xray = 0;
  _PSICHE_mon_dcm_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.geometry[0]='\0';
  _PSICHE_mon_dcm_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_e_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_dcm_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_dcm1_var._rotation_absolute, _PSICHE_mon_dcm_e_var._rotation_absolute);
    rot_transpose(_PSICHE_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_dcm_e_var._rotation_absolute, tr1, _PSICHE_mon_dcm_e_var._rotation_relative);
    _PSICHE_mon_dcm_e_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_dcm_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_PSICHE_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_dcm_e_var._position_absolute = coords_add(_PSICHE_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_dcm_xtal1_var._position_absolute, _PSICHE_mon_dcm_e_var._position_absolute);
    _PSICHE_mon_dcm_e_var._position_relative = rot_apply(_PSICHE_mon_dcm_e_var._rotation_absolute, tc1);
  } /* PSICHE_mon_dcm_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_dcm_e", _PSICHE_mon_dcm_e_var._position_absolute, _PSICHE_mon_dcm_e_var._rotation_absolute);
  instrument->_position_absolute[50] = _PSICHE_mon_dcm_e_var._position_absolute;
  instrument->_position_relative[50] = _PSICHE_mon_dcm_e_var._position_relative;
    _PSICHE_mon_dcm_e_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_dcm_e_var._position_relative);
  instrument->counter_N[50]  = instrument->counter_P[50] = instrument->counter_P2[50] = 0;
  instrument->counter_AbsorbProp[50]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", _PSICHE_mon_dcm_e_var._position_absolute, _PSICHE_mon_dcm_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "min", "-1e40", "_instrument_var._parameters.PSICHE_E0 -1.1 * _instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "max", "1e40", "_instrument_var._parameters.PSICHE_E0 + 1.1 * _instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0049_PSICHE_mon_dcm_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_dcm_e_setpos */

/* component PSICHE_mon_dcm_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_dcm_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_dcm_xy_setpos] component PSICHE_mon_dcm_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_dcm_xy_var._name, "PSICHE_mon_dcm_xy", 16384);
  stracpy(_PSICHE_mon_dcm_xy_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_dcm_xy_var._index=51;
  int current_setpos_index = 51;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.user9[0]='\0';
  _PSICHE_mon_dcm_xy_var._parameters.xwidth = 1e-2;
  _PSICHE_mon_dcm_xy_var._parameters.yheight = 1e-2;
  _PSICHE_mon_dcm_xy_var._parameters.zdepth = 0;
  _PSICHE_mon_dcm_xy_var._parameters.bins = 128;
  _PSICHE_mon_dcm_xy_var._parameters.min = -1e40;
  _PSICHE_mon_dcm_xy_var._parameters.max = 1e40;
  _PSICHE_mon_dcm_xy_var._parameters.restore_xray = 0;
  _PSICHE_mon_dcm_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.geometry[0]='\0';
  _PSICHE_mon_dcm_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_dcm_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_dcm_xy_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_dcm_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_mon_dcm_e_var._rotation_absolute, _PSICHE_mon_dcm_xy_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_dcm_e_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_dcm_xy_var._rotation_absolute, tr1, _PSICHE_mon_dcm_xy_var._rotation_relative);
    _PSICHE_mon_dcm_xy_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_dcm_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_dcm_xy_var._position_absolute = coords_add(_PSICHE_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_dcm_e_var._position_absolute, _PSICHE_mon_dcm_xy_var._position_absolute);
    _PSICHE_mon_dcm_xy_var._position_relative = rot_apply(_PSICHE_mon_dcm_xy_var._rotation_absolute, tc1);
  } /* PSICHE_mon_dcm_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_dcm_xy", _PSICHE_mon_dcm_xy_var._position_absolute, _PSICHE_mon_dcm_xy_var._rotation_absolute);
  instrument->_position_absolute[51] = _PSICHE_mon_dcm_xy_var._position_absolute;
  instrument->_position_relative[51] = _PSICHE_mon_dcm_xy_var._position_relative;
    _PSICHE_mon_dcm_xy_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_dcm_xy_var._position_relative);
  instrument->counter_N[51]  = instrument->counter_P[51] = instrument->counter_P2[51] = 0;
  instrument->counter_AbsorbProp[51]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", _PSICHE_mon_dcm_xy_var._position_absolute, _PSICHE_mon_dcm_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0050_PSICHE_mon_dcm_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_dcm_xy_setpos */

/* component PSICHE_slit=Slit() SETTING, POSITION/ROTATION */
int _PSICHE_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_slit_setpos] component PSICHE_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PSICHE_slit_var._name, "PSICHE_slit", 16384);
  stracpy(_PSICHE_slit_var._type, "Slit", 16384);
  _PSICHE_slit_var._index=52;
  int current_setpos_index = 52;
  _PSICHE_slit_var._parameters.xmin = 0;
  _PSICHE_slit_var._parameters.xmax = 0;
  _PSICHE_slit_var._parameters.ymin = 0;
  _PSICHE_slit_var._parameters.ymax = 0;
  _PSICHE_slit_var._parameters.radius = 0;
  _PSICHE_slit_var._parameters.xwidth = 17e-3;
  _PSICHE_slit_var._parameters.yheight = 6e-3;
  _PSICHE_slit_var._parameters.dist = 0;
  _PSICHE_slit_var._parameters.focus_xw = 0;
  _PSICHE_slit_var._parameters.focus_yh = 0;
  _PSICHE_slit_var._parameters.focus_x0 = 0;
  _PSICHE_slit_var._parameters.focus_y0 = 0;

  /* component PSICHE_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_mon_dcm_xy_var._rotation_absolute, _PSICHE_slit_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_slit_var._rotation_absolute, tr1, _PSICHE_slit_var._rotation_relative);
    _PSICHE_slit_var._rotation_is_identity =  rot_test_identity(_PSICHE_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_mon_dcm_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_slit_var._position_absolute = coords_add(_PSICHE_mon_dcm_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_dcm_xy_var._position_absolute, _PSICHE_slit_var._position_absolute);
    _PSICHE_slit_var._position_relative = rot_apply(_PSICHE_slit_var._rotation_absolute, tc1);
  } /* PSICHE_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_slit", _PSICHE_slit_var._position_absolute, _PSICHE_slit_var._rotation_absolute);
  instrument->_position_absolute[52] = _PSICHE_slit_var._position_absolute;
  instrument->_position_relative[52] = _PSICHE_slit_var._position_relative;
    _PSICHE_slit_var._position_relative_is_zero =  coords_test_zero(_PSICHE_slit_var._position_relative);
  instrument->counter_N[52]  = instrument->counter_P[52] = instrument->counter_P2[52] = 0;
  instrument->counter_AbsorbProp[52]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0051_PSICHE_slit", _PSICHE_slit_var._position_absolute, _PSICHE_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "xwidth", "0.001", "17e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "yheight", "0.001", "6e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0051_PSICHE_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_slit_setpos */

/* component PSICHE_sample_stage=Arm() SETTING, POSITION/ROTATION */
int _PSICHE_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_sample_stage_setpos] component PSICHE_sample_stage=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PSICHE_sample_stage_var._name, "PSICHE_sample_stage", 16384);
  stracpy(_PSICHE_sample_stage_var._type, "Arm", 16384);
  _PSICHE_sample_stage_var._index=53;
  int current_setpos_index = 53;
  /* component PSICHE_sample_stage=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_slit_var._rotation_absolute, _PSICHE_sample_stage_var._rotation_absolute);
    rot_transpose(_PSICHE_slit_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_sample_stage_var._rotation_absolute, tr1, _PSICHE_sample_stage_var._rotation_relative);
    _PSICHE_sample_stage_var._rotation_is_identity =  rot_test_identity(_PSICHE_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_PSICHE_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_sample_stage_var._position_absolute = coords_add(_PSICHE_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_slit_var._position_absolute, _PSICHE_sample_stage_var._position_absolute);
    _PSICHE_sample_stage_var._position_relative = rot_apply(_PSICHE_sample_stage_var._rotation_absolute, tc1);
  } /* PSICHE_sample_stage=Arm() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_sample_stage", _PSICHE_sample_stage_var._position_absolute, _PSICHE_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[53] = _PSICHE_sample_stage_var._position_absolute;
  instrument->_position_relative[53] = _PSICHE_sample_stage_var._position_relative;
    _PSICHE_sample_stage_var._position_relative_is_zero =  coords_test_zero(_PSICHE_sample_stage_var._position_relative);
  instrument->counter_N[53]  = instrument->counter_P[53] = instrument->counter_P2[53] = 0;
  instrument->counter_AbsorbProp[53]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0052_PSICHE_sample_stage", _PSICHE_sample_stage_var._position_absolute, _PSICHE_sample_stage_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_sample_stage_setpos */

/* component PSICHE_sample=FluoPowder() SETTING, POSITION/ROTATION */
int _PSICHE_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_sample_setpos] component PSICHE_sample=FluoPowder() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");
  stracpy(_PSICHE_sample_var._name, "PSICHE_sample", 16384);
  stracpy(_PSICHE_sample_var._type, "FluoPowder", 16384);
  _PSICHE_sample_var._index=54;
  int current_setpos_index = 54;
  if(_instrument_var._parameters.PSICHE_sample_geometry && strlen(_instrument_var._parameters.PSICHE_sample_geometry))
    stracpy(_PSICHE_sample_var._parameters.geometry, _instrument_var._parameters.PSICHE_sample_geometry ? _instrument_var._parameters.PSICHE_sample_geometry : "", 16384);
  else 
  _PSICHE_sample_var._parameters.geometry[0]='\0';
  _PSICHE_sample_var._parameters.radius = 0;
  _PSICHE_sample_var._parameters.thickness = 0;
  _PSICHE_sample_var._parameters.xwidth = 20e-3;
  _PSICHE_sample_var._parameters.yheight = 10e-3;
  _PSICHE_sample_var._parameters.zdepth = 1e-3;
  _PSICHE_sample_var._parameters.concentric = 0;
  if(_instrument_var._parameters.PSICHE_sample_material && strlen(_instrument_var._parameters.PSICHE_sample_material))
    stracpy(_PSICHE_sample_var._parameters.material, _instrument_var._parameters.PSICHE_sample_material ? _instrument_var._parameters.PSICHE_sample_material : "", 16384);
  else 
  _PSICHE_sample_var._parameters.material[0]='\0';
  _PSICHE_sample_var._parameters.packing_factor = 0;
  _PSICHE_sample_var._parameters.density = 0;
  _PSICHE_sample_var._parameters.weight = 0;
  _PSICHE_sample_var._parameters.p_interact = 0.8;
  _PSICHE_sample_var._parameters.target_x = 0;
  _PSICHE_sample_var._parameters.target_y = 0;
  _PSICHE_sample_var._parameters.target_z = 0;
  _PSICHE_sample_var._parameters.focus_r = 0;
  _PSICHE_sample_var._parameters.focus_xw = 0;
  _PSICHE_sample_var._parameters.focus_yh = 0;
  _PSICHE_sample_var._parameters.focus_aw = 90;
  _PSICHE_sample_var._parameters.focus_ah = 5;
  _PSICHE_sample_var._parameters.target_index = 3;
  _PSICHE_sample_var._parameters.flag_compton = 1;
  _PSICHE_sample_var._parameters.flag_rayleigh = 1;
  _PSICHE_sample_var._parameters.flag_lorentzian = 0;
  _PSICHE_sample_var._parameters.flag_powder = 1;
  _PSICHE_sample_var._parameters.flag_kissel = 0;
  if("" && strlen(""))
    stracpy(_PSICHE_sample_var._parameters.powder_refl, "" ? "" : "", 16384);
  else 
  _PSICHE_sample_var._parameters.powder_refl[0]='\0';
  _PSICHE_sample_var._parameters.powder_format[0] = 0;
  _PSICHE_sample_var._parameters.powder_format[1] = 0;
  _PSICHE_sample_var._parameters.powder_format[2] = 0;
  _PSICHE_sample_var._parameters.powder_format[3] = 0;
  _PSICHE_sample_var._parameters.powder_format[4] = 0;
  _PSICHE_sample_var._parameters.powder_format[5] = 0;
  _PSICHE_sample_var._parameters.powder_format[6] = 0;
  _PSICHE_sample_var._parameters.powder_format[7] = 0;
  _PSICHE_sample_var._parameters.Vc = 0;
  _PSICHE_sample_var._parameters.delta_d_d = 0;
  _PSICHE_sample_var._parameters.DW = 0;
  _PSICHE_sample_var._parameters.d_phi = asin ( 0.01 / 0.1 ) * RAD2DEG;
  _PSICHE_sample_var._parameters.nb_atoms = 1;
  _PSICHE_sample_var._parameters.barns = 1;
  _PSICHE_sample_var._parameters.tth_sign = 0;
  _PSICHE_sample_var._parameters.order = 1;


  /* component PSICHE_sample=FluoPowder() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.PSICHE_sample_theta)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_sample_stage_var._rotation_absolute, _PSICHE_sample_var._rotation_absolute);
    rot_transpose(_PSICHE_slit_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_sample_var._rotation_absolute, tr1, _PSICHE_sample_var._rotation_relative);
    _PSICHE_sample_var._rotation_is_identity =  rot_test_identity(_PSICHE_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_sample_var._position_absolute = coords_add(_PSICHE_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_slit_var._position_absolute, _PSICHE_sample_var._position_absolute);
    _PSICHE_sample_var._position_relative = rot_apply(_PSICHE_sample_var._rotation_absolute, tc1);
  } /* PSICHE_sample=FluoPowder() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_sample", _PSICHE_sample_var._position_absolute, _PSICHE_sample_var._rotation_absolute);
  instrument->_position_absolute[54] = _PSICHE_sample_var._position_absolute;
  instrument->_position_relative[54] = _PSICHE_sample_var._position_relative;
    _PSICHE_sample_var._position_relative_is_zero =  coords_test_zero(_PSICHE_sample_var._position_relative);
  instrument->counter_N[54]  = instrument->counter_P[54] = instrument->counter_P2[54] = 0;
  instrument->counter_AbsorbProp[54]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0053_PSICHE_sample", _PSICHE_sample_var._position_absolute, _PSICHE_sample_var._rotation_absolute, "FluoPowder");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "geometry", 0, _instrument_var._parameters.PSICHE_sample_geometry, "char*");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "xwidth", "0", "20e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "yheight", "0", "10e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "zdepth", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "material", "LaB6.cif", _instrument_var._parameters.PSICHE_sample_material, "char*");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "p_interact", "0", "0.8","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "target_z", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "focus_aw", "0", "90","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "focus_ah", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "target_index", "0", "3","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "flag_powder", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "powder_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "powder_format", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "Vc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "delta_d_d", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "DW", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "d_phi", "0", "asin ( 0.01 / 0.1 ) * RAD2DEG","MCNUM");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "nb_atoms", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "tth_sign", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0053_PSICHE_sample", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_sample_setpos */

/* component PSICHE_fluo_holder=Arm() SETTING, POSITION/ROTATION */
int _PSICHE_fluo_holder_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_fluo_holder_setpos] component PSICHE_fluo_holder=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PSICHE_fluo_holder_var._name, "PSICHE_fluo_holder", 16384);
  stracpy(_PSICHE_fluo_holder_var._type, "Arm", 16384);
  _PSICHE_fluo_holder_var._index=55;
  int current_setpos_index = 55;
  /* component PSICHE_fluo_holder=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (30)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_sample_stage_var._rotation_absolute, _PSICHE_fluo_holder_var._rotation_absolute);
    rot_transpose(_PSICHE_sample_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_fluo_holder_var._rotation_absolute, tr1, _PSICHE_fluo_holder_var._rotation_relative);
    _PSICHE_fluo_holder_var._rotation_is_identity =  rot_test_identity(_PSICHE_fluo_holder_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_fluo_holder_var._position_absolute = coords_add(_PSICHE_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_sample_var._position_absolute, _PSICHE_fluo_holder_var._position_absolute);
    _PSICHE_fluo_holder_var._position_relative = rot_apply(_PSICHE_fluo_holder_var._rotation_absolute, tc1);
  } /* PSICHE_fluo_holder=Arm() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_fluo_holder", _PSICHE_fluo_holder_var._position_absolute, _PSICHE_fluo_holder_var._rotation_absolute);
  instrument->_position_absolute[55] = _PSICHE_fluo_holder_var._position_absolute;
  instrument->_position_relative[55] = _PSICHE_fluo_holder_var._position_relative;
    _PSICHE_fluo_holder_var._position_relative_is_zero =  coords_test_zero(_PSICHE_fluo_holder_var._position_relative);
  instrument->counter_N[55]  = instrument->counter_P[55] = instrument->counter_P2[55] = 0;
  instrument->counter_AbsorbProp[55]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0054_PSICHE_fluo_holder", _PSICHE_fluo_holder_var._position_absolute, _PSICHE_fluo_holder_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_fluo_holder_setpos */

/* component PSICHE_mon_spl_fluo=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_spl_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_spl_fluo_setpos] component PSICHE_mon_spl_fluo=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_spl_fluo_var._name, "PSICHE_mon_spl_fluo", 16384);
  stracpy(_PSICHE_mon_spl_fluo_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_spl_fluo_var._index=56;
  int current_setpos_index = 56;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.user9[0]='\0';
  _PSICHE_mon_spl_fluo_var._parameters.xwidth = 0.01;
  _PSICHE_mon_spl_fluo_var._parameters.yheight = 0.01;
  _PSICHE_mon_spl_fluo_var._parameters.zdepth = 0;
  _PSICHE_mon_spl_fluo_var._parameters.bins = 1000;
  _PSICHE_mon_spl_fluo_var._parameters.min = 0;
  _PSICHE_mon_spl_fluo_var._parameters.max = _instrument_var._parameters.PSICHE_E0 + _instrument_var._parameters.PSICHE_dE * 1.05;
  _PSICHE_mon_spl_fluo_var._parameters.restore_xray = 0;
  _PSICHE_mon_spl_fluo_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.geometry[0]='\0';
  _PSICHE_mon_spl_fluo_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_fluo_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_fluo_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_spl_fluo=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_fluo_holder_var._rotation_absolute, _PSICHE_mon_spl_fluo_var._rotation_absolute);
    rot_transpose(_PSICHE_sample_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_spl_fluo_var._rotation_absolute, tr1, _PSICHE_mon_spl_fluo_var._rotation_relative);
    _PSICHE_mon_spl_fluo_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_spl_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_PSICHE_fluo_holder_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_spl_fluo_var._position_absolute = coords_add(_PSICHE_fluo_holder_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_sample_var._position_absolute, _PSICHE_mon_spl_fluo_var._position_absolute);
    _PSICHE_mon_spl_fluo_var._position_relative = rot_apply(_PSICHE_mon_spl_fluo_var._rotation_absolute, tc1);
  } /* PSICHE_mon_spl_fluo=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_spl_fluo", _PSICHE_mon_spl_fluo_var._position_absolute, _PSICHE_mon_spl_fluo_var._rotation_absolute);
  instrument->_position_absolute[56] = _PSICHE_mon_spl_fluo_var._position_absolute;
  instrument->_position_relative[56] = _PSICHE_mon_spl_fluo_var._position_relative;
    _PSICHE_mon_spl_fluo_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_spl_fluo_var._position_relative);
  instrument->counter_N[56]  = instrument->counter_P[56] = instrument->counter_P2[56] = 0;
  instrument->counter_AbsorbProp[56]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", _PSICHE_mon_spl_fluo_var._position_absolute, _PSICHE_mon_spl_fluo_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "bins", "0", "1000","int");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "min", "-1e40", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "max", "1e40", "_instrument_var._parameters.PSICHE_E0 + _instrument_var._parameters.PSICHE_dE * 1.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0055_PSICHE_mon_spl_fluo", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_spl_fluo_setpos */

/* component PSICHE_mon_spl_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_spl_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_spl_e_setpos] component PSICHE_mon_spl_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_spl_e_var._name, "PSICHE_mon_spl_e", 16384);
  stracpy(_PSICHE_mon_spl_e_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_spl_e_var._index=57;
  int current_setpos_index = 57;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.user9[0]='\0';
  _PSICHE_mon_spl_e_var._parameters.xwidth = 1e-2;
  _PSICHE_mon_spl_e_var._parameters.yheight = 1e-2;
  _PSICHE_mon_spl_e_var._parameters.zdepth = 0;
  _PSICHE_mon_spl_e_var._parameters.bins = 512;
  _PSICHE_mon_spl_e_var._parameters.min = _instrument_var._parameters.PSICHE_E0 -1.1 * _instrument_var._parameters.PSICHE_dE;
  _PSICHE_mon_spl_e_var._parameters.max = _instrument_var._parameters.PSICHE_E0 + 1.1 * _instrument_var._parameters.PSICHE_dE;
  _PSICHE_mon_spl_e_var._parameters.restore_xray = 0;
  _PSICHE_mon_spl_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.geometry[0]='\0';
  _PSICHE_mon_spl_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_e_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_spl_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_sample_stage_var._rotation_absolute, _PSICHE_mon_spl_e_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_spl_fluo_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_spl_e_var._rotation_absolute, tr1, _PSICHE_mon_spl_e_var._rotation_relative);
    _PSICHE_mon_spl_e_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_spl_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_PSICHE_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_spl_e_var._position_absolute = coords_add(_PSICHE_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_spl_fluo_var._position_absolute, _PSICHE_mon_spl_e_var._position_absolute);
    _PSICHE_mon_spl_e_var._position_relative = rot_apply(_PSICHE_mon_spl_e_var._rotation_absolute, tc1);
  } /* PSICHE_mon_spl_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_spl_e", _PSICHE_mon_spl_e_var._position_absolute, _PSICHE_mon_spl_e_var._rotation_absolute);
  instrument->_position_absolute[57] = _PSICHE_mon_spl_e_var._position_absolute;
  instrument->_position_relative[57] = _PSICHE_mon_spl_e_var._position_relative;
    _PSICHE_mon_spl_e_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_spl_e_var._position_relative);
  instrument->counter_N[57]  = instrument->counter_P[57] = instrument->counter_P2[57] = 0;
  instrument->counter_AbsorbProp[57]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0056_PSICHE_mon_spl_e", _PSICHE_mon_spl_e_var._position_absolute, _PSICHE_mon_spl_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "min", "-1e40", "_instrument_var._parameters.PSICHE_E0 -1.1 * _instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "max", "1e40", "_instrument_var._parameters.PSICHE_E0 + 1.1 * _instrument_var._parameters.PSICHE_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0056_PSICHE_mon_spl_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_spl_e_setpos */

/* component PSICHE_mon_spl_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _PSICHE_mon_spl_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PSICHE_mon_spl_xy_setpos] component PSICHE_mon_spl_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PSICHE_mon_spl_xy_var._name, "PSICHE_mon_spl_xy", 16384);
  stracpy(_PSICHE_mon_spl_xy_var._type, "Monitor_nD", 16384);
  _PSICHE_mon_spl_xy_var._index=58;
  int current_setpos_index = 58;
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.user9[0]='\0';
  _PSICHE_mon_spl_xy_var._parameters.xwidth = 1e-2;
  _PSICHE_mon_spl_xy_var._parameters.yheight = 1e-2;
  _PSICHE_mon_spl_xy_var._parameters.zdepth = 0;
  _PSICHE_mon_spl_xy_var._parameters.bins = 128;
  _PSICHE_mon_spl_xy_var._parameters.min = -1e40;
  _PSICHE_mon_spl_xy_var._parameters.max = 1e40;
  _PSICHE_mon_spl_xy_var._parameters.restore_xray = 0;
  _PSICHE_mon_spl_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.geometry[0]='\0';
  _PSICHE_mon_spl_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PSICHE_mon_spl_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PSICHE_mon_spl_xy_var._parameters.username9[0]='\0';


  /* component PSICHE_mon_spl_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_mon_spl_e_var._rotation_absolute, _PSICHE_mon_spl_xy_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_spl_e_var._rotation_absolute, tr1);
    rot_mul(_PSICHE_mon_spl_xy_var._rotation_absolute, tr1, _PSICHE_mon_spl_xy_var._rotation_relative);
    _PSICHE_mon_spl_xy_var._rotation_is_identity =  rot_test_identity(_PSICHE_mon_spl_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_mon_spl_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PSICHE_mon_spl_xy_var._position_absolute = coords_add(_PSICHE_mon_spl_e_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_spl_e_var._position_absolute, _PSICHE_mon_spl_xy_var._position_absolute);
    _PSICHE_mon_spl_xy_var._position_relative = rot_apply(_PSICHE_mon_spl_xy_var._rotation_absolute, tc1);
  } /* PSICHE_mon_spl_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PSICHE_mon_spl_xy", _PSICHE_mon_spl_xy_var._position_absolute, _PSICHE_mon_spl_xy_var._rotation_absolute);
  instrument->_position_absolute[58] = _PSICHE_mon_spl_xy_var._position_absolute;
  instrument->_position_relative[58] = _PSICHE_mon_spl_xy_var._position_relative;
    _PSICHE_mon_spl_xy_var._position_relative_is_zero =  coords_test_zero(_PSICHE_mon_spl_xy_var._position_relative);
  instrument->counter_N[58]  = instrument->counter_P[58] = instrument->counter_P2[58] = 0;
  instrument->counter_AbsorbProp[58]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", _PSICHE_mon_spl_xy_var._position_absolute, _PSICHE_mon_spl_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0057_PSICHE_mon_spl_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PSICHE_mon_spl_xy_setpos */

/* component beamdump_61=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_61_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_61_setpos] component beamdump_61=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_61_var._name, "beamdump_61", 16384);
  stracpy(_beamdump_61_var._type, "Beamstop", 16384);
  _beamdump_61_var._index=59;
  int current_setpos_index = 59;
  _beamdump_61_var._parameters.xmin = -0.05;
  _beamdump_61_var._parameters.xmax = 0.05;
  _beamdump_61_var._parameters.ymin = -0.05;
  _beamdump_61_var._parameters.ymax = 0.05;
  _beamdump_61_var._parameters.xwidth = 0;
  _beamdump_61_var._parameters.yheight = 0;
  _beamdump_61_var._parameters.radius = 0;

  /* component beamdump_61=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PSICHE_mon_spl_xy_var._rotation_absolute, _beamdump_61_var._rotation_absolute);
    rot_transpose(_PSICHE_mon_spl_xy_var._rotation_absolute, tr1);
    rot_mul(_beamdump_61_var._rotation_absolute, tr1, _beamdump_61_var._rotation_relative);
    _beamdump_61_var._rotation_is_identity =  rot_test_identity(_beamdump_61_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PSICHE_mon_spl_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_61_var._position_absolute = coords_add(_PSICHE_mon_spl_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PSICHE_mon_spl_xy_var._position_absolute, _beamdump_61_var._position_absolute);
    _beamdump_61_var._position_relative = rot_apply(_beamdump_61_var._rotation_absolute, tc1);
  } /* beamdump_61=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_61", _beamdump_61_var._position_absolute, _beamdump_61_var._rotation_absolute);
  instrument->_position_absolute[59] = _beamdump_61_var._position_absolute;
  instrument->_position_relative[59] = _beamdump_61_var._position_relative;
    _beamdump_61_var._position_relative_is_zero =  coords_test_zero(_beamdump_61_var._position_relative);
  instrument->counter_N[59]  = instrument->counter_P[59] = instrument->counter_P2[59] = 0;
  instrument->counter_AbsorbProp[59]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0058_beamdump_61", _beamdump_61_var._position_absolute, _beamdump_61_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0058_beamdump_61", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_61_setpos */

/* component PLEIADES_pos=Text() SETTING, POSITION/ROTATION */
int _PLEIADES_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PLEIADES_pos_setpos] component PLEIADES_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_PLEIADES_pos_var._name, "PLEIADES_pos", 16384);
  stracpy(_PLEIADES_pos_var._type, "Text", 16384);
  _PLEIADES_pos_var._index=60;
  int current_setpos_index = 60;
  if("PLEIADES" && strlen("PLEIADES"))
    stracpy(_PLEIADES_pos_var._parameters.text, "PLEIADES" ? "PLEIADES" : "", 16384);
  else 
  _PLEIADES_pos_var._parameters.text[0]='\0';
  _PLEIADES_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_PLEIADES_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _PLEIADES_pos_var._parameters.plane[0]='\0';
  _PLEIADES_pos_var._parameters.pen_thickness = 0.1;


  /* component PLEIADES_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-65.736)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _PLEIADES_pos_var._rotation_absolute);
    rot_transpose(_beamdump_61_var._rotation_absolute, tr1);
    rot_mul(_PLEIADES_pos_var._rotation_absolute, tr1, _PLEIADES_pos_var._rotation_relative);
    _PLEIADES_pos_var._rotation_is_identity =  rot_test_identity(_PLEIADES_pos_var._rotation_relative);
    tc1 = coords_set(
      23.15, 0, 51.36);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PLEIADES_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_61_var._position_absolute, _PLEIADES_pos_var._position_absolute);
    _PLEIADES_pos_var._position_relative = rot_apply(_PLEIADES_pos_var._rotation_absolute, tc1);
  } /* PLEIADES_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("PLEIADES_pos", _PLEIADES_pos_var._position_absolute, _PLEIADES_pos_var._rotation_absolute);
  instrument->_position_absolute[60] = _PLEIADES_pos_var._position_absolute;
  instrument->_position_relative[60] = _PLEIADES_pos_var._position_relative;
    _PLEIADES_pos_var._position_relative_is_zero =  coords_test_zero(_PLEIADES_pos_var._position_relative);
  instrument->counter_N[60]  = instrument->counter_P[60] = instrument->counter_P2[60] = 0;
  instrument->counter_AbsorbProp[60]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0059_PLEIADES_pos", _PLEIADES_pos_var._position_absolute, _PLEIADES_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0059_PLEIADES_pos", "text", "NONE", "PLEIADES", "char*");
        mccomp_param_nexus(nxhandle,"0059_PLEIADES_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0059_PLEIADES_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0059_PLEIADES_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PLEIADES_pos_setpos */

/* component DISCO_pos=Text() SETTING, POSITION/ROTATION */
int _DISCO_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_pos_setpos] component DISCO_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_DISCO_pos_var._name, "DISCO_pos", 16384);
  stracpy(_DISCO_pos_var._type, "Text", 16384);
  _DISCO_pos_var._index=61;
  int current_setpos_index = 61;
  if("DISCO" && strlen("DISCO"))
    stracpy(_DISCO_pos_var._parameters.text, "DISCO" ? "DISCO" : "", 16384);
  else 
  _DISCO_pos_var._parameters.text[0]='\0';
  _DISCO_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_DISCO_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _DISCO_pos_var._parameters.plane[0]='\0';
  _DISCO_pos_var._parameters.pen_thickness = 0.1;


  /* component DISCO_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-79.749)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _DISCO_pos_var._rotation_absolute);
    rot_transpose(_PLEIADES_pos_var._rotation_absolute, tr1);
    rot_mul(_DISCO_pos_var._rotation_absolute, tr1, _DISCO_pos_var._rotation_relative);
    _DISCO_pos_var._rotation_is_identity =  rot_test_identity(_DISCO_pos_var._rotation_relative);
    tc1 = coords_set(
      10.03, 0, 55.44);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_PLEIADES_pos_var._position_absolute, _DISCO_pos_var._position_absolute);
    _DISCO_pos_var._position_relative = rot_apply(_DISCO_pos_var._rotation_absolute, tc1);
  } /* DISCO_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("DISCO_pos", _DISCO_pos_var._position_absolute, _DISCO_pos_var._rotation_absolute);
  instrument->_position_absolute[61] = _DISCO_pos_var._position_absolute;
  instrument->_position_relative[61] = _DISCO_pos_var._position_relative;
    _DISCO_pos_var._position_relative_is_zero =  coords_test_zero(_DISCO_pos_var._position_relative);
  instrument->counter_N[61]  = instrument->counter_P[61] = instrument->counter_P2[61] = 0;
  instrument->counter_AbsorbProp[61]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0060_DISCO_pos", _DISCO_pos_var._position_absolute, _DISCO_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0060_DISCO_pos", "text", "NONE", "DISCO", "char*");
        mccomp_param_nexus(nxhandle,"0060_DISCO_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0060_DISCO_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0060_DISCO_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_pos_setpos */

/* component DISCO=Arm() SETTING, POSITION/ROTATION */
int _DISCO_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_setpos] component DISCO=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_var._name, "DISCO", 16384);
  stracpy(_DISCO_var._type, "Arm", 16384);
  _DISCO_var._index=62;
  int current_setpos_index = 62;
  /* component DISCO=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_pos_var._rotation_absolute, _DISCO_var._rotation_absolute);
    rot_transpose(_DISCO_pos_var._rotation_absolute, tr1);
    rot_mul(_DISCO_var._rotation_absolute, tr1, _DISCO_var._rotation_relative);
    _DISCO_var._rotation_is_identity =  rot_test_identity(_DISCO_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_var._position_absolute = coords_add(_DISCO_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_pos_var._position_absolute, _DISCO_var._position_absolute);
    _DISCO_var._position_relative = rot_apply(_DISCO_var._rotation_absolute, tc1);
  } /* DISCO=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO", _DISCO_var._position_absolute, _DISCO_var._rotation_absolute);
  instrument->_position_absolute[62] = _DISCO_var._position_absolute;
  instrument->_position_relative[62] = _DISCO_var._position_relative;
    _DISCO_var._position_relative_is_zero =  coords_test_zero(_DISCO_var._position_relative);
  instrument->counter_N[62]  = instrument->counter_P[62] = instrument->counter_P2[62] = 0;
  instrument->counter_AbsorbProp[62]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0061_DISCO", _DISCO_var._position_absolute, _DISCO_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_setpos */

/* component DISCO_Source=Bending_magnet() SETTING, POSITION/ROTATION */
int _DISCO_Source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Source_setpos] component DISCO_Source=Bending_magnet() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");
  stracpy(_DISCO_Source_var._name, "DISCO_Source", 16384);
  stracpy(_DISCO_Source_var._type, "Bending_magnet", 16384);
  _DISCO_Source_var._index=63;
  int current_setpos_index = 63;
  _DISCO_Source_var._parameters.E0 = DISCO_E0;
  _DISCO_Source_var._parameters.dE = DISCO_dE;
  _DISCO_Source_var._parameters.lambda0 = 0;
  _DISCO_Source_var._parameters.dlambda = 0;
  _DISCO_Source_var._parameters.phase = 0;
  _DISCO_Source_var._parameters.randomphase = 1;
  _DISCO_Source_var._parameters.Ee = 2.75;
  _DISCO_Source_var._parameters.Ie = 0.5;
  _DISCO_Source_var._parameters.B = 1.72;
  _DISCO_Source_var._parameters.sigey = 18.4e-6;
  _DISCO_Source_var._parameters.sigex = 45.5e-6;
  _DISCO_Source_var._parameters.focus_xw = 0;
  _DISCO_Source_var._parameters.focus_yh = 0;
  _DISCO_Source_var._parameters.dist = 1;
  _DISCO_Source_var._parameters.gauss_t = 0;


  /* component DISCO_Source=Bending_magnet() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_var._rotation_absolute, _DISCO_Source_var._rotation_absolute);
    rot_transpose(_DISCO_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Source_var._rotation_absolute, tr1, _DISCO_Source_var._rotation_relative);
    _DISCO_Source_var._rotation_is_identity =  rot_test_identity(_DISCO_Source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Source_var._position_absolute = coords_add(_DISCO_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_var._position_absolute, _DISCO_Source_var._position_absolute);
    _DISCO_Source_var._position_relative = rot_apply(_DISCO_Source_var._rotation_absolute, tc1);
  } /* DISCO_Source=Bending_magnet() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Source", _DISCO_Source_var._position_absolute, _DISCO_Source_var._rotation_absolute);
  instrument->_position_absolute[63] = _DISCO_Source_var._position_absolute;
  instrument->_position_relative[63] = _DISCO_Source_var._position_relative;
    _DISCO_Source_var._position_relative_is_zero =  coords_test_zero(_DISCO_Source_var._position_relative);
  instrument->counter_N[63]  = instrument->counter_P[63] = instrument->counter_P2[63] = 0;
  instrument->counter_AbsorbProp[63]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0062_DISCO_Source", _DISCO_Source_var._position_absolute, _DISCO_Source_var._rotation_absolute, "Bending_magnet");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "E0", "0", "DISCO_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "dE", "0", "DISCO_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "B", "1.6", "1.72","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "sigey", "0", "18.4e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "sigex", "0", "45.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0062_DISCO_Source", "gauss_t", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Source_setpos */

/* component DISCO_ColdFinger=Mask() SETTING, POSITION/ROTATION */
int _DISCO_ColdFinger_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_ColdFinger_setpos] component DISCO_ColdFinger=Mask() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mask.comp:87]");
  stracpy(_DISCO_ColdFinger_var._name, "DISCO_ColdFinger", 16384);
  stracpy(_DISCO_ColdFinger_var._type, "Mask", 16384);
  _DISCO_ColdFinger_var._index=64;
  int current_setpos_index = 64;
  _DISCO_ColdFinger_var._parameters.xwidth = 0.3;
  _DISCO_ColdFinger_var._parameters.yheight = 7.5e-3;
  if("coldfinger.mask" && strlen("coldfinger.mask"))
    stracpy(_DISCO_ColdFinger_var._parameters.mask, "coldfinger.mask" ? "coldfinger.mask" : "", 16384);
  else 
  _DISCO_ColdFinger_var._parameters.mask[0]='\0';
  _DISCO_ColdFinger_var._parameters.invert = 0;
  _DISCO_ColdFinger_var._parameters.virtual = 0;


  /* component DISCO_ColdFinger=Mask() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Source_var._rotation_absolute, _DISCO_ColdFinger_var._rotation_absolute);
    rot_transpose(_DISCO_Source_var._rotation_absolute, tr1);
    rot_mul(_DISCO_ColdFinger_var._rotation_absolute, tr1, _DISCO_ColdFinger_var._rotation_relative);
    _DISCO_ColdFinger_var._rotation_is_identity =  rot_test_identity(_DISCO_ColdFinger_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 4.975);
    rot_transpose(_DISCO_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_ColdFinger_var._position_absolute = coords_add(_DISCO_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_Source_var._position_absolute, _DISCO_ColdFinger_var._position_absolute);
    _DISCO_ColdFinger_var._position_relative = rot_apply(_DISCO_ColdFinger_var._rotation_absolute, tc1);
  } /* DISCO_ColdFinger=Mask() AT ROTATED */
  DEBUG_COMPONENT("DISCO_ColdFinger", _DISCO_ColdFinger_var._position_absolute, _DISCO_ColdFinger_var._rotation_absolute);
  instrument->_position_absolute[64] = _DISCO_ColdFinger_var._position_absolute;
  instrument->_position_relative[64] = _DISCO_ColdFinger_var._position_relative;
    _DISCO_ColdFinger_var._position_relative_is_zero =  coords_test_zero(_DISCO_ColdFinger_var._position_relative);
  instrument->counter_N[64]  = instrument->counter_P[64] = instrument->counter_P2[64] = 0;
  instrument->counter_AbsorbProp[64]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0063_DISCO_ColdFinger", _DISCO_ColdFinger_var._position_absolute, _DISCO_ColdFinger_var._rotation_absolute, "Mask");
        mccomp_param_nexus(nxhandle,"0063_DISCO_ColdFinger", "xwidth", "0.1", "0.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0063_DISCO_ColdFinger", "yheight", "0.1", "7.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0063_DISCO_ColdFinger", "mask", "Test_Mask_input_file.mask", "coldfinger.mask", "char*");
        mccomp_param_nexus(nxhandle,"0063_DISCO_ColdFinger", "invert", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0063_DISCO_ColdFinger", "virtual", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_ColdFinger_setpos */

/* component DISCO_M1_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_location_setpos] component DISCO_M1_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_location_var._name, "DISCO_M1_location", 16384);
  stracpy(_DISCO_M1_location_var._type, "Arm", 16384);
  _DISCO_M1_location_var._index=65;
  int current_setpos_index = 65;
  /* component DISCO_M1_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Source_var._rotation_absolute, _DISCO_M1_location_var._rotation_absolute);
    rot_transpose(_DISCO_ColdFinger_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_location_var._rotation_absolute, tr1, _DISCO_M1_location_var._rotation_relative);
    _DISCO_M1_location_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 5.800);
    rot_transpose(_DISCO_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_location_var._position_absolute = coords_add(_DISCO_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_ColdFinger_var._position_absolute, _DISCO_M1_location_var._position_absolute);
    _DISCO_M1_location_var._position_relative = rot_apply(_DISCO_M1_location_var._rotation_absolute, tc1);
  } /* DISCO_M1_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_location", _DISCO_M1_location_var._position_absolute, _DISCO_M1_location_var._rotation_absolute);
  instrument->_position_absolute[65] = _DISCO_M1_location_var._position_absolute;
  instrument->_position_relative[65] = _DISCO_M1_location_var._position_relative;
    _DISCO_M1_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_location_var._position_relative);
  instrument->counter_N[65]  = instrument->counter_P[65] = instrument->counter_P2[65] = 0;
  instrument->counter_AbsorbProp[65]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0064_DISCO_M1_location", _DISCO_M1_location_var._position_absolute, _DISCO_M1_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_location_setpos */

/* component DISCO_M1_rotated=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_rotated_setpos] component DISCO_M1_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_rotated_var._name, "DISCO_M1_rotated", 16384);
  stracpy(_DISCO_M1_rotated_var._type, "Arm", 16384);
  _DISCO_M1_rotated_var._index=66;
  int current_setpos_index = 66;
  /* component DISCO_M1_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_location_var._rotation_absolute, _DISCO_M1_rotated_var._rotation_absolute);
    rot_transpose(_DISCO_ColdFinger_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_rotated_var._rotation_absolute, tr1, _DISCO_M1_rotated_var._rotation_relative);
    _DISCO_M1_rotated_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_rotated_var._position_absolute = coords_add(_DISCO_M1_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_ColdFinger_var._position_absolute, _DISCO_M1_rotated_var._position_absolute);
    _DISCO_M1_rotated_var._position_relative = rot_apply(_DISCO_M1_rotated_var._rotation_absolute, tc1);
  } /* DISCO_M1_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_rotated", _DISCO_M1_rotated_var._position_absolute, _DISCO_M1_rotated_var._rotation_absolute);
  instrument->_position_absolute[66] = _DISCO_M1_rotated_var._position_absolute;
  instrument->_position_relative[66] = _DISCO_M1_rotated_var._position_relative;
    _DISCO_M1_rotated_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_rotated_var._position_relative);
  instrument->counter_N[66]  = instrument->counter_P[66] = instrument->counter_P2[66] = 0;
  instrument->counter_AbsorbProp[66]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0065_DISCO_M1_rotated", _DISCO_M1_rotated_var._position_absolute, _DISCO_M1_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_rotated_setpos */

/* component DISCO_M1_x=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_x_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_x_setpos] component DISCO_M1_x=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_x_var._name, "DISCO_M1_x", 16384);
  stracpy(_DISCO_M1_x_var._type, "Arm", 16384);
  _DISCO_M1_x_var._index=67;
  int current_setpos_index = 67;
  /* component DISCO_M1_x=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_rotated_var._rotation_absolute, _DISCO_M1_x_var._rotation_absolute);
    rot_transpose(_DISCO_ColdFinger_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_x_var._rotation_absolute, tr1, _DISCO_M1_x_var._rotation_relative);
    _DISCO_M1_x_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_x_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_x_var._position_absolute = coords_add(_DISCO_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_ColdFinger_var._position_absolute, _DISCO_M1_x_var._position_absolute);
    _DISCO_M1_x_var._position_relative = rot_apply(_DISCO_M1_x_var._rotation_absolute, tc1);
  } /* DISCO_M1_x=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_x", _DISCO_M1_x_var._position_absolute, _DISCO_M1_x_var._rotation_absolute);
  instrument->_position_absolute[67] = _DISCO_M1_x_var._position_absolute;
  instrument->_position_relative[67] = _DISCO_M1_x_var._position_relative;
    _DISCO_M1_x_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_x_var._position_relative);
  instrument->counter_N[67]  = instrument->counter_P[67] = instrument->counter_P2[67] = 0;
  instrument->counter_AbsorbProp[67]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0066_DISCO_M1_x", _DISCO_M1_x_var._position_absolute, _DISCO_M1_x_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_x_setpos */

/* component DISCO_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _DISCO_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_setpos] component DISCO_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_DISCO_M1_var._name, "DISCO_M1", 16384);
  stracpy(_DISCO_M1_var._type, "Mirror_curved", 16384);
  _DISCO_M1_var._index=68;
  int current_setpos_index = 68;
  _DISCO_M1_var._parameters.radius = -75;
  _DISCO_M1_var._parameters.R0 = 1;
  if("Si_disco.dat" && strlen("Si_disco.dat"))
    stracpy(_DISCO_M1_var._parameters.coating, "Si_disco.dat" ? "Si_disco.dat" : "", 16384);
  else 
  _DISCO_M1_var._parameters.coating[0]='\0';
  _DISCO_M1_var._parameters.zdepth = 0.2;
  _DISCO_M1_var._parameters.yheight = 0.2;
  _DISCO_M1_var._parameters.length = 0.26;
  _DISCO_M1_var._parameters.width = 0.19;


  /* component DISCO_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_x_var._rotation_absolute, _DISCO_M1_var._rotation_absolute);
    rot_transpose(_DISCO_ColdFinger_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_var._rotation_absolute, tr1, _DISCO_M1_var._rotation_relative);
    _DISCO_M1_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_x_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_var._position_absolute = coords_add(_DISCO_M1_x_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_ColdFinger_var._position_absolute, _DISCO_M1_var._position_absolute);
    _DISCO_M1_var._position_relative = rot_apply(_DISCO_M1_var._rotation_absolute, tc1);
  } /* DISCO_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1", _DISCO_M1_var._position_absolute, _DISCO_M1_var._rotation_absolute);
  instrument->_position_absolute[68] = _DISCO_M1_var._position_absolute;
  instrument->_position_relative[68] = _DISCO_M1_var._position_relative;
    _DISCO_M1_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_var._position_relative);
  instrument->counter_N[68]  = instrument->counter_P[68] = instrument->counter_P2[68] = 0;
  instrument->counter_AbsorbProp[68]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0067_DISCO_M1", _DISCO_M1_var._position_absolute, _DISCO_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "radius", "1", "-75","MCNUM");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "coating", "Be.txt", "Si_disco.dat", "char*");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "length", "0", "0.26","MCNUM");
        mccomp_param_nexus(nxhandle,"0067_DISCO_M1", "width", "0", "0.19","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_setpos */

/* component DISCO_M1_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_takeoff_setpos] component DISCO_M1_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_takeoff_var._name, "DISCO_M1_takeoff", 16384);
  stracpy(_DISCO_M1_takeoff_var._type, "Arm", 16384);
  _DISCO_M1_takeoff_var._index=69;
  int current_setpos_index = 69;
  /* component DISCO_M1_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_var._rotation_absolute, _DISCO_M1_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_takeoff_var._rotation_absolute, tr1, _DISCO_M1_takeoff_var._rotation_relative);
    _DISCO_M1_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_takeoff_var._position_absolute = coords_add(_DISCO_M1_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M1_takeoff_var._position_absolute);
    _DISCO_M1_takeoff_var._position_relative = rot_apply(_DISCO_M1_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M1_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_takeoff", _DISCO_M1_takeoff_var._position_absolute, _DISCO_M1_takeoff_var._rotation_absolute);
  instrument->_position_absolute[69] = _DISCO_M1_takeoff_var._position_absolute;
  instrument->_position_relative[69] = _DISCO_M1_takeoff_var._position_relative;
    _DISCO_M1_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_takeoff_var._position_relative);
  instrument->counter_N[69]  = instrument->counter_P[69] = instrument->counter_P2[69] = 0;
  instrument->counter_AbsorbProp[69]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0068_DISCO_M1_takeoff", _DISCO_M1_takeoff_var._position_absolute, _DISCO_M1_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_takeoff_setpos */

/* component DISCO_M1_x_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_x_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_x_takeoff_setpos] component DISCO_M1_x_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_x_takeoff_var._name, "DISCO_M1_x_takeoff", 16384);
  stracpy(_DISCO_M1_x_takeoff_var._type, "Arm", 16384);
  _DISCO_M1_x_takeoff_var._index=70;
  int current_setpos_index = 70;
  /* component DISCO_M1_x_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_takeoff_var._rotation_absolute, _DISCO_M1_x_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_x_takeoff_var._rotation_absolute, tr1, _DISCO_M1_x_takeoff_var._rotation_relative);
    _DISCO_M1_x_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_x_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_x_takeoff_var._position_absolute = coords_add(_DISCO_M1_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M1_x_takeoff_var._position_absolute);
    _DISCO_M1_x_takeoff_var._position_relative = rot_apply(_DISCO_M1_x_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M1_x_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_x_takeoff", _DISCO_M1_x_takeoff_var._position_absolute, _DISCO_M1_x_takeoff_var._rotation_absolute);
  instrument->_position_absolute[70] = _DISCO_M1_x_takeoff_var._position_absolute;
  instrument->_position_relative[70] = _DISCO_M1_x_takeoff_var._position_relative;
    _DISCO_M1_x_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_x_takeoff_var._position_relative);
  instrument->counter_N[70]  = instrument->counter_P[70] = instrument->counter_P2[70] = 0;
  instrument->counter_AbsorbProp[70]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0069_DISCO_M1_x_takeoff", _DISCO_M1_x_takeoff_var._position_absolute, _DISCO_M1_x_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_x_takeoff_setpos */

/* component DISCO_M2_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M2_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_location_setpos] component DISCO_M2_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M2_location_var._name, "DISCO_M2_location", 16384);
  stracpy(_DISCO_M2_location_var._type, "Arm", 16384);
  _DISCO_M2_location_var._index=71;
  int current_setpos_index = 71;
  /* component DISCO_M2_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_x_takeoff_var._rotation_absolute, _DISCO_M2_location_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_location_var._rotation_absolute, tr1, _DISCO_M2_location_var._rotation_relative);
    _DISCO_M2_location_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_DISCO_M1_x_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_location_var._position_absolute = coords_add(_DISCO_M1_x_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M2_location_var._position_absolute);
    _DISCO_M2_location_var._position_relative = rot_apply(_DISCO_M2_location_var._rotation_absolute, tc1);
  } /* DISCO_M2_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2_location", _DISCO_M2_location_var._position_absolute, _DISCO_M2_location_var._rotation_absolute);
  instrument->_position_absolute[71] = _DISCO_M2_location_var._position_absolute;
  instrument->_position_relative[71] = _DISCO_M2_location_var._position_relative;
    _DISCO_M2_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_location_var._position_relative);
  instrument->counter_N[71]  = instrument->counter_P[71] = instrument->counter_P2[71] = 0;
  instrument->counter_AbsorbProp[71]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0070_DISCO_M2_location", _DISCO_M2_location_var._position_absolute, _DISCO_M2_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_location_setpos */

/* component DISCO_M2_rotated_x=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M2_rotated_x_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_rotated_x_setpos] component DISCO_M2_rotated_x=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M2_rotated_x_var._name, "DISCO_M2_rotated_x", 16384);
  stracpy(_DISCO_M2_rotated_x_var._type, "Arm", 16384);
  _DISCO_M2_rotated_x_var._index=72;
  int current_setpos_index = 72;
  /* component DISCO_M2_rotated_x=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_var._rotation_absolute, _DISCO_M2_rotated_x_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_rotated_x_var._rotation_absolute, tr1, _DISCO_M2_rotated_x_var._rotation_relative);
    _DISCO_M2_rotated_x_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_rotated_x_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M2_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_rotated_x_var._position_absolute = coords_add(_DISCO_M2_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M2_rotated_x_var._position_absolute);
    _DISCO_M2_rotated_x_var._position_relative = rot_apply(_DISCO_M2_rotated_x_var._rotation_absolute, tc1);
  } /* DISCO_M2_rotated_x=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2_rotated_x", _DISCO_M2_rotated_x_var._position_absolute, _DISCO_M2_rotated_x_var._rotation_absolute);
  instrument->_position_absolute[72] = _DISCO_M2_rotated_x_var._position_absolute;
  instrument->_position_relative[72] = _DISCO_M2_rotated_x_var._position_relative;
    _DISCO_M2_rotated_x_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_rotated_x_var._position_relative);
  instrument->counter_N[72]  = instrument->counter_P[72] = instrument->counter_P2[72] = 0;
  instrument->counter_AbsorbProp[72]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0071_DISCO_M2_rotated_x", _DISCO_M2_rotated_x_var._position_absolute, _DISCO_M2_rotated_x_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_rotated_x_setpos */

/* component DISCO_M2_rotated=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M2_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_rotated_setpos] component DISCO_M2_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M2_rotated_var._name, "DISCO_M2_rotated", 16384);
  stracpy(_DISCO_M2_rotated_var._type, "Arm", 16384);
  _DISCO_M2_rotated_var._index=73;
  int current_setpos_index = 73;
  /* component DISCO_M2_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M2_rotated_x_var._rotation_absolute, _DISCO_M2_rotated_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_rotated_var._rotation_absolute, tr1, _DISCO_M2_rotated_var._rotation_relative);
    _DISCO_M2_rotated_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M2_rotated_x_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_rotated_var._position_absolute = coords_add(_DISCO_M2_rotated_x_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M2_rotated_var._position_absolute);
    _DISCO_M2_rotated_var._position_relative = rot_apply(_DISCO_M2_rotated_var._rotation_absolute, tc1);
  } /* DISCO_M2_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2_rotated", _DISCO_M2_rotated_var._position_absolute, _DISCO_M2_rotated_var._rotation_absolute);
  instrument->_position_absolute[73] = _DISCO_M2_rotated_var._position_absolute;
  instrument->_position_relative[73] = _DISCO_M2_rotated_var._position_relative;
    _DISCO_M2_rotated_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_rotated_var._position_relative);
  instrument->counter_N[73]  = instrument->counter_P[73] = instrument->counter_P2[73] = 0;
  instrument->counter_AbsorbProp[73]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0072_DISCO_M2_rotated", _DISCO_M2_rotated_var._position_absolute, _DISCO_M2_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_rotated_setpos */

/* component DISCO_M2_other_side=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M2_other_side_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_other_side_setpos] component DISCO_M2_other_side=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M2_other_side_var._name, "DISCO_M2_other_side", 16384);
  stracpy(_DISCO_M2_other_side_var._type, "Arm", 16384);
  _DISCO_M2_other_side_var._index=74;
  int current_setpos_index = 74;
  /* component DISCO_M2_other_side=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (180)*DEG2RAD);
    rot_mul(tr1, _DISCO_M2_rotated_var._rotation_absolute, _DISCO_M2_other_side_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_other_side_var._rotation_absolute, tr1, _DISCO_M2_other_side_var._rotation_relative);
    _DISCO_M2_other_side_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_other_side_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_other_side_var._position_absolute = coords_add(_DISCO_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M2_other_side_var._position_absolute);
    _DISCO_M2_other_side_var._position_relative = rot_apply(_DISCO_M2_other_side_var._rotation_absolute, tc1);
  } /* DISCO_M2_other_side=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2_other_side", _DISCO_M2_other_side_var._position_absolute, _DISCO_M2_other_side_var._rotation_absolute);
  instrument->_position_absolute[74] = _DISCO_M2_other_side_var._position_absolute;
  instrument->_position_relative[74] = _DISCO_M2_other_side_var._position_relative;
    _DISCO_M2_other_side_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_other_side_var._position_relative);
  instrument->counter_N[74]  = instrument->counter_P[74] = instrument->counter_P2[74] = 0;
  instrument->counter_AbsorbProp[74]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0073_DISCO_M2_other_side", _DISCO_M2_other_side_var._position_absolute, _DISCO_M2_other_side_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_other_side_setpos */

/* component DISCO_M2=Mirror_toroid_pothole() SETTING, POSITION/ROTATION */
int _DISCO_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_setpos] component DISCO_M2=Mirror_toroid_pothole() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:64]");
  stracpy(_DISCO_M2_var._name, "DISCO_M2", 16384);
  stracpy(_DISCO_M2_var._type, "Mirror_toroid_pothole", 16384);
  _DISCO_M2_var._index=75;
  int current_setpos_index = 75;
  _DISCO_M2_var._parameters.zdepth = 0.19;
  _DISCO_M2_var._parameters.xwidth = 0.26;
  _DISCO_M2_var._parameters.radius = 2.56;
  _DISCO_M2_var._parameters.radius_o = 21.04;
  _DISCO_M2_var._parameters.R0 = 0;
  if("Si_disco.dat" && strlen("Si_disco.dat"))
    stracpy(_DISCO_M2_var._parameters.coating, "Si_disco.dat" ? "Si_disco.dat" : "", 16384);
  else 
  _DISCO_M2_var._parameters.coating[0]='\0';


  /* component DISCO_M2=Mirror_toroid_pothole() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M2_other_side_var._rotation_absolute, _DISCO_M2_var._rotation_absolute);
    rot_transpose(_DISCO_M1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_var._rotation_absolute, tr1, _DISCO_M2_var._rotation_relative);
    _DISCO_M2_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M2_other_side_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_var._position_absolute = coords_add(_DISCO_M2_other_side_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M1_var._position_absolute, _DISCO_M2_var._position_absolute);
    _DISCO_M2_var._position_relative = rot_apply(_DISCO_M2_var._rotation_absolute, tc1);
  } /* DISCO_M2=Mirror_toroid_pothole() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2", _DISCO_M2_var._position_absolute, _DISCO_M2_var._rotation_absolute);
  instrument->_position_absolute[75] = _DISCO_M2_var._position_absolute;
  instrument->_position_relative[75] = _DISCO_M2_var._position_relative;
    _DISCO_M2_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_var._position_relative);
  instrument->counter_N[75]  = instrument->counter_P[75] = instrument->counter_P2[75] = 0;
  instrument->counter_AbsorbProp[75]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0074_DISCO_M2", _DISCO_M2_var._position_absolute, _DISCO_M2_var._rotation_absolute, "Mirror_toroid_pothole");
        mccomp_param_nexus(nxhandle,"0074_DISCO_M2", "zdepth", "0.1", "0.19","MCNUM");
        mccomp_param_nexus(nxhandle,"0074_DISCO_M2", "xwidth", "0.01", "0.26","MCNUM");
        mccomp_param_nexus(nxhandle,"0074_DISCO_M2", "radius", "NONE", "2.56","MCNUM");
        mccomp_param_nexus(nxhandle,"0074_DISCO_M2", "radius_o", "NONE", "21.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0074_DISCO_M2", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0074_DISCO_M2", "coating", "", "Si_disco.dat", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_setpos */

/* component DISCO_M2_other_side_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M2_other_side_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_other_side_back_setpos] component DISCO_M2_other_side_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M2_other_side_back_var._name, "DISCO_M2_other_side_back", 16384);
  stracpy(_DISCO_M2_other_side_back_var._type, "Arm", 16384);
  _DISCO_M2_other_side_back_var._index=76;
  int current_setpos_index = 76;
  /* component DISCO_M2_other_side_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-180)*DEG2RAD);
    rot_mul(tr1, _DISCO_M2_var._rotation_absolute, _DISCO_M2_other_side_back_var._rotation_absolute);
    rot_transpose(_DISCO_M2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_other_side_back_var._rotation_absolute, tr1, _DISCO_M2_other_side_back_var._rotation_relative);
    _DISCO_M2_other_side_back_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_other_side_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_other_side_back_var._position_absolute = coords_add(_DISCO_M2_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M2_var._position_absolute, _DISCO_M2_other_side_back_var._position_absolute);
    _DISCO_M2_other_side_back_var._position_relative = rot_apply(_DISCO_M2_other_side_back_var._rotation_absolute, tc1);
  } /* DISCO_M2_other_side_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2_other_side_back", _DISCO_M2_other_side_back_var._position_absolute, _DISCO_M2_other_side_back_var._rotation_absolute);
  instrument->_position_absolute[76] = _DISCO_M2_other_side_back_var._position_absolute;
  instrument->_position_relative[76] = _DISCO_M2_other_side_back_var._position_relative;
    _DISCO_M2_other_side_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_other_side_back_var._position_relative);
  instrument->counter_N[76]  = instrument->counter_P[76] = instrument->counter_P2[76] = 0;
  instrument->counter_AbsorbProp[76]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0075_DISCO_M2_other_side_back", _DISCO_M2_other_side_back_var._position_absolute, _DISCO_M2_other_side_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_other_side_back_setpos */

/* component DISCO_M2_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M2_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M2_takeoff_setpos] component DISCO_M2_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M2_takeoff_var._name, "DISCO_M2_takeoff", 16384);
  stracpy(_DISCO_M2_takeoff_var._type, "Arm", 16384);
  _DISCO_M2_takeoff_var._index=77;
  int current_setpos_index = 77;
  /* component DISCO_M2_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M2_other_side_back_var._rotation_absolute, _DISCO_M2_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M2_takeoff_var._rotation_absolute, tr1, _DISCO_M2_takeoff_var._rotation_relative);
    _DISCO_M2_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M2_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M2_other_side_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M2_takeoff_var._position_absolute = coords_add(_DISCO_M2_other_side_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M2_var._position_absolute, _DISCO_M2_takeoff_var._position_absolute);
    _DISCO_M2_takeoff_var._position_relative = rot_apply(_DISCO_M2_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M2_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M2_takeoff", _DISCO_M2_takeoff_var._position_absolute, _DISCO_M2_takeoff_var._rotation_absolute);
  instrument->_position_absolute[77] = _DISCO_M2_takeoff_var._position_absolute;
  instrument->_position_relative[77] = _DISCO_M2_takeoff_var._position_relative;
    _DISCO_M2_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M2_takeoff_var._position_relative);
  instrument->counter_N[77]  = instrument->counter_P[77] = instrument->counter_P2[77] = 0;
  instrument->counter_AbsorbProp[77]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0076_DISCO_M2_takeoff", _DISCO_M2_takeoff_var._position_absolute, _DISCO_M2_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M2_takeoff_setpos */

/* component DISCO_HFP_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_HFP_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_HFP_location_setpos] component DISCO_HFP_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_HFP_location_var._name, "DISCO_HFP_location", 16384);
  stracpy(_DISCO_HFP_location_var._type, "Arm", 16384);
  _DISCO_HFP_location_var._index=78;
  int current_setpos_index = 78;
  /* component DISCO_HFP_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M2_takeoff_var._rotation_absolute, _DISCO_HFP_location_var._rotation_absolute);
    rot_transpose(_DISCO_M2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_HFP_location_var._rotation_absolute, tr1, _DISCO_HFP_location_var._rotation_relative);
    _DISCO_HFP_location_var._rotation_is_identity =  rot_test_identity(_DISCO_HFP_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 8);
    rot_transpose(_DISCO_M2_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_HFP_location_var._position_absolute = coords_add(_DISCO_M2_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M2_var._position_absolute, _DISCO_HFP_location_var._position_absolute);
    _DISCO_HFP_location_var._position_relative = rot_apply(_DISCO_HFP_location_var._rotation_absolute, tc1);
  } /* DISCO_HFP_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_HFP_location", _DISCO_HFP_location_var._position_absolute, _DISCO_HFP_location_var._rotation_absolute);
  instrument->_position_absolute[78] = _DISCO_HFP_location_var._position_absolute;
  instrument->_position_relative[78] = _DISCO_HFP_location_var._position_relative;
    _DISCO_HFP_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_HFP_location_var._position_relative);
  instrument->counter_N[78]  = instrument->counter_P[78] = instrument->counter_P2[78] = 0;
  instrument->counter_AbsorbProp[78]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0077_DISCO_HFP_location", _DISCO_HFP_location_var._position_absolute, _DISCO_HFP_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_HFP_location_setpos */

/* component DISCO_HFP=PSD_monitor() SETTING, POSITION/ROTATION */
int _DISCO_HFP_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_HFP_setpos] component DISCO_HFP=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_DISCO_HFP_var._name, "DISCO_HFP", 16384);
  stracpy(_DISCO_HFP_var._type, "PSD_monitor", 16384);
  _DISCO_HFP_var._index=79;
  int current_setpos_index = 79;
  if("DISCO_HFP_image.dat" && strlen("DISCO_HFP_image.dat"))
    stracpy(_DISCO_HFP_var._parameters.filename, "DISCO_HFP_image.dat" ? "DISCO_HFP_image.dat" : "", 16384);
  else 
  _DISCO_HFP_var._parameters.filename[0]='\0';
  _DISCO_HFP_var._parameters.xwidth = 0.08;
  _DISCO_HFP_var._parameters.yheight = 0.04;
  _DISCO_HFP_var._parameters.radius = 0;
  _DISCO_HFP_var._parameters.restore_xray = 1;
  _DISCO_HFP_var._parameters.nowritefile = 0;
  _DISCO_HFP_var._parameters.nx = 100;
  _DISCO_HFP_var._parameters.ny = 100;
  _DISCO_HFP_var._parameters.nr = 0;


  /* component DISCO_HFP=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_HFP_location_var._rotation_absolute, _DISCO_HFP_var._rotation_absolute);
    rot_transpose(_DISCO_M2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_HFP_var._rotation_absolute, tr1, _DISCO_HFP_var._rotation_relative);
    _DISCO_HFP_var._rotation_is_identity =  rot_test_identity(_DISCO_HFP_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.DISCO_HFP_shift);
    rot_transpose(_DISCO_HFP_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_HFP_var._position_absolute = coords_add(_DISCO_HFP_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M2_var._position_absolute, _DISCO_HFP_var._position_absolute);
    _DISCO_HFP_var._position_relative = rot_apply(_DISCO_HFP_var._rotation_absolute, tc1);
  } /* DISCO_HFP=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("DISCO_HFP", _DISCO_HFP_var._position_absolute, _DISCO_HFP_var._rotation_absolute);
  instrument->_position_absolute[79] = _DISCO_HFP_var._position_absolute;
  instrument->_position_relative[79] = _DISCO_HFP_var._position_relative;
    _DISCO_HFP_var._position_relative_is_zero =  coords_test_zero(_DISCO_HFP_var._position_relative);
  instrument->counter_N[79]  = instrument->counter_P[79] = instrument->counter_P2[79] = 0;
  instrument->counter_AbsorbProp[79]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0078_DISCO_HFP", _DISCO_HFP_var._position_absolute, _DISCO_HFP_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "filename", 0, "DISCO_HFP_image.dat", "char*");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "xwidth", "0.05", "0.08","MCNUM");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "yheight", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0078_DISCO_HFP", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_HFP_setpos */

/* component DISCO_M3_arm=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M3_arm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M3_arm_setpos] component DISCO_M3_arm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M3_arm_var._name, "DISCO_M3_arm", 16384);
  stracpy(_DISCO_M3_arm_var._type, "Arm", 16384);
  _DISCO_M3_arm_var._index=80;
  int current_setpos_index = 80;
  /* component DISCO_M3_arm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_HFP_location_var._rotation_absolute, _DISCO_M3_arm_var._rotation_absolute);
    rot_transpose(_DISCO_HFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M3_arm_var._rotation_absolute, tr1, _DISCO_M3_arm_var._rotation_relative);
    _DISCO_M3_arm_var._rotation_is_identity =  rot_test_identity(_DISCO_M3_arm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2.6);
    rot_transpose(_DISCO_HFP_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M3_arm_var._position_absolute = coords_add(_DISCO_HFP_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_HFP_var._position_absolute, _DISCO_M3_arm_var._position_absolute);
    _DISCO_M3_arm_var._position_relative = rot_apply(_DISCO_M3_arm_var._rotation_absolute, tc1);
  } /* DISCO_M3_arm=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M3_arm", _DISCO_M3_arm_var._position_absolute, _DISCO_M3_arm_var._rotation_absolute);
  instrument->_position_absolute[80] = _DISCO_M3_arm_var._position_absolute;
  instrument->_position_relative[80] = _DISCO_M3_arm_var._position_relative;
    _DISCO_M3_arm_var._position_relative_is_zero =  coords_test_zero(_DISCO_M3_arm_var._position_relative);
  instrument->counter_N[80]  = instrument->counter_P[80] = instrument->counter_P2[80] = 0;
  instrument->counter_AbsorbProp[80]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0079_DISCO_M3_arm", _DISCO_M3_arm_var._position_absolute, _DISCO_M3_arm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M3_arm_setpos */

/* component DISCO_M3=Mirror_curved() SETTING, POSITION/ROTATION */
int _DISCO_M3_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M3_setpos] component DISCO_M3=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_DISCO_M3_var._name, "DISCO_M3", 16384);
  stracpy(_DISCO_M3_var._type, "Mirror_curved", 16384);
  _DISCO_M3_var._index=81;
  int current_setpos_index = 81;
  _DISCO_M3_var._parameters.radius = 9.93;
  _DISCO_M3_var._parameters.R0 = 1;
  if("Si_disco.dat" && strlen("Si_disco.dat"))
    stracpy(_DISCO_M3_var._parameters.coating, "Si_disco.dat" ? "Si_disco.dat" : "", 16384);
  else 
  _DISCO_M3_var._parameters.coating[0]='\0';
  _DISCO_M3_var._parameters.zdepth = 0.2;
  _DISCO_M3_var._parameters.yheight = 0.2;
  _DISCO_M3_var._parameters.length = 240e-3;
  _DISCO_M3_var._parameters.width = 30e-3;


  /* component DISCO_M3=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M3_arm_var._rotation_absolute, _DISCO_M3_var._rotation_absolute);
    rot_transpose(_DISCO_HFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M3_var._rotation_absolute, tr1, _DISCO_M3_var._rotation_relative);
    _DISCO_M3_var._rotation_is_identity =  rot_test_identity(_DISCO_M3_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M3_arm_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M3_var._position_absolute = coords_add(_DISCO_M3_arm_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_HFP_var._position_absolute, _DISCO_M3_var._position_absolute);
    _DISCO_M3_var._position_relative = rot_apply(_DISCO_M3_var._rotation_absolute, tc1);
  } /* DISCO_M3=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M3", _DISCO_M3_var._position_absolute, _DISCO_M3_var._rotation_absolute);
  instrument->_position_absolute[81] = _DISCO_M3_var._position_absolute;
  instrument->_position_relative[81] = _DISCO_M3_var._position_relative;
    _DISCO_M3_var._position_relative_is_zero =  coords_test_zero(_DISCO_M3_var._position_relative);
  instrument->counter_N[81]  = instrument->counter_P[81] = instrument->counter_P2[81] = 0;
  instrument->counter_AbsorbProp[81]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0080_DISCO_M3", _DISCO_M3_var._position_absolute, _DISCO_M3_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "radius", "1", "9.93","MCNUM");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "coating", "Be.txt", "Si_disco.dat", "char*");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "length", "0", "240e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0080_DISCO_M3", "width", "0", "30e-3","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M3_setpos */

/* component DISCO_M3_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M3_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M3_takeoff_setpos] component DISCO_M3_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M3_takeoff_var._name, "DISCO_M3_takeoff", 16384);
  stracpy(_DISCO_M3_takeoff_var._type, "Arm", 16384);
  _DISCO_M3_takeoff_var._index=82;
  int current_setpos_index = 82;
  /* component DISCO_M3_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M3_var._rotation_absolute, _DISCO_M3_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M3_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M3_takeoff_var._rotation_absolute, tr1, _DISCO_M3_takeoff_var._rotation_relative);
    _DISCO_M3_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M3_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M3_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M3_takeoff_var._position_absolute = coords_add(_DISCO_M3_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M3_var._position_absolute, _DISCO_M3_takeoff_var._position_absolute);
    _DISCO_M3_takeoff_var._position_relative = rot_apply(_DISCO_M3_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M3_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M3_takeoff", _DISCO_M3_takeoff_var._position_absolute, _DISCO_M3_takeoff_var._rotation_absolute);
  instrument->_position_absolute[82] = _DISCO_M3_takeoff_var._position_absolute;
  instrument->_position_relative[82] = _DISCO_M3_takeoff_var._position_relative;
    _DISCO_M3_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M3_takeoff_var._position_relative);
  instrument->counter_N[82]  = instrument->counter_P[82] = instrument->counter_P2[82] = 0;
  instrument->counter_AbsorbProp[82]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0081_DISCO_M3_takeoff", _DISCO_M3_takeoff_var._position_absolute, _DISCO_M3_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M3_takeoff_setpos */

/* component DISCO_M3_yz=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M3_yz_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M3_yz_setpos] component DISCO_M3_yz=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M3_yz_var._name, "DISCO_M3_yz", 16384);
  stracpy(_DISCO_M3_yz_var._type, "Arm", 16384);
  _DISCO_M3_yz_var._index=83;
  int current_setpos_index = 83;
  /* component DISCO_M3_yz=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M3_takeoff_var._rotation_absolute, _DISCO_M3_yz_var._rotation_absolute);
    rot_transpose(_DISCO_M3_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M3_yz_var._rotation_absolute, tr1, _DISCO_M3_yz_var._rotation_relative);
    _DISCO_M3_yz_var._rotation_is_identity =  rot_test_identity(_DISCO_M3_yz_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M3_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M3_yz_var._position_absolute = coords_add(_DISCO_M3_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M3_var._position_absolute, _DISCO_M3_yz_var._position_absolute);
    _DISCO_M3_yz_var._position_relative = rot_apply(_DISCO_M3_yz_var._rotation_absolute, tc1);
  } /* DISCO_M3_yz=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M3_yz", _DISCO_M3_yz_var._position_absolute, _DISCO_M3_yz_var._rotation_absolute);
  instrument->_position_absolute[83] = _DISCO_M3_yz_var._position_absolute;
  instrument->_position_relative[83] = _DISCO_M3_yz_var._position_relative;
    _DISCO_M3_yz_var._position_relative_is_zero =  coords_test_zero(_DISCO_M3_yz_var._position_relative);
  instrument->counter_N[83]  = instrument->counter_P[83] = instrument->counter_P2[83] = 0;
  instrument->counter_AbsorbProp[83]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0082_DISCO_M3_yz", _DISCO_M3_yz_var._position_absolute, _DISCO_M3_yz_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M3_yz_setpos */

/* component DISCO_M4_yz=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M4_yz_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M4_yz_setpos] component DISCO_M4_yz=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M4_yz_var._name, "DISCO_M4_yz", 16384);
  stracpy(_DISCO_M4_yz_var._type, "Arm", 16384);
  _DISCO_M4_yz_var._index=84;
  int current_setpos_index = 84;
  /* component DISCO_M4_yz=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M3_yz_var._rotation_absolute, _DISCO_M4_yz_var._rotation_absolute);
    rot_transpose(_DISCO_M3_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M4_yz_var._rotation_absolute, tr1, _DISCO_M4_yz_var._rotation_relative);
    _DISCO_M4_yz_var._rotation_is_identity =  rot_test_identity(_DISCO_M4_yz_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_DISCO_M3_yz_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M4_yz_var._position_absolute = coords_add(_DISCO_M3_yz_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M3_var._position_absolute, _DISCO_M4_yz_var._position_absolute);
    _DISCO_M4_yz_var._position_relative = rot_apply(_DISCO_M4_yz_var._rotation_absolute, tc1);
  } /* DISCO_M4_yz=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M4_yz", _DISCO_M4_yz_var._position_absolute, _DISCO_M4_yz_var._rotation_absolute);
  instrument->_position_absolute[84] = _DISCO_M4_yz_var._position_absolute;
  instrument->_position_relative[84] = _DISCO_M4_yz_var._position_relative;
    _DISCO_M4_yz_var._position_relative_is_zero =  coords_test_zero(_DISCO_M4_yz_var._position_relative);
  instrument->counter_N[84]  = instrument->counter_P[84] = instrument->counter_P2[84] = 0;
  instrument->counter_AbsorbProp[84]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0083_DISCO_M4_yz", _DISCO_M4_yz_var._position_absolute, _DISCO_M4_yz_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M4_yz_setpos */

/* component DISCO_M4=Mirror() SETTING, POSITION/ROTATION */
int _DISCO_M4_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M4_setpos] component DISCO_M4=Mirror() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:69]");
  stracpy(_DISCO_M4_var._name, "DISCO_M4", 16384);
  stracpy(_DISCO_M4_var._type, "Mirror", 16384);
  _DISCO_M4_var._index=85;
  int current_setpos_index = 85;
  _DISCO_M4_var._parameters.zdepth = 240e-3;
  _DISCO_M4_var._parameters.xwidth = 30e-3;
  _DISCO_M4_var._parameters.yheight = 0;
  if("Si_disco.dat" && strlen("Si_disco.dat"))
    stracpy(_DISCO_M4_var._parameters.coating, "Si_disco.dat" ? "Si_disco.dat" : "", 16384);
  else 
  _DISCO_M4_var._parameters.coating[0]='\0';
  _DISCO_M4_var._parameters.R0 = 0;
  if("" && strlen(""))
    stracpy(_DISCO_M4_var._parameters.geometry, "" ? "" : "", 16384);
  else 
  _DISCO_M4_var._parameters.geometry[0]='\0';


  /* component DISCO_M4=Mirror() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M4_yz_var._rotation_absolute, _DISCO_M4_var._rotation_absolute);
    rot_transpose(_DISCO_M3_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M4_var._rotation_absolute, tr1, _DISCO_M4_var._rotation_relative);
    _DISCO_M4_var._rotation_is_identity =  rot_test_identity(_DISCO_M4_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M4_yz_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M4_var._position_absolute = coords_add(_DISCO_M4_yz_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M3_var._position_absolute, _DISCO_M4_var._position_absolute);
    _DISCO_M4_var._position_relative = rot_apply(_DISCO_M4_var._rotation_absolute, tc1);
  } /* DISCO_M4=Mirror() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M4", _DISCO_M4_var._position_absolute, _DISCO_M4_var._rotation_absolute);
  instrument->_position_absolute[85] = _DISCO_M4_var._position_absolute;
  instrument->_position_relative[85] = _DISCO_M4_var._position_relative;
    _DISCO_M4_var._position_relative_is_zero =  coords_test_zero(_DISCO_M4_var._position_relative);
  instrument->counter_N[85]  = instrument->counter_P[85] = instrument->counter_P2[85] = 0;
  instrument->counter_AbsorbProp[85]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0084_DISCO_M4", _DISCO_M4_var._position_absolute, _DISCO_M4_var._rotation_absolute, "Mirror");
        mccomp_param_nexus(nxhandle,"0084_DISCO_M4", "zdepth", "0.1", "240e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0084_DISCO_M4", "xwidth", "0.01", "30e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0084_DISCO_M4", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0084_DISCO_M4", "coating", "", "Si_disco.dat", "char*");
        mccomp_param_nexus(nxhandle,"0084_DISCO_M4", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0084_DISCO_M4", "geometry", "", "", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M4_setpos */

/* component DISCO_M4_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M4_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M4_takeoff_setpos] component DISCO_M4_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M4_takeoff_var._name, "DISCO_M4_takeoff", 16384);
  stracpy(_DISCO_M4_takeoff_var._type, "Arm", 16384);
  _DISCO_M4_takeoff_var._index=86;
  int current_setpos_index = 86;
  /* component DISCO_M4_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M4_var._rotation_absolute, _DISCO_M4_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M4_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M4_takeoff_var._rotation_absolute, tr1, _DISCO_M4_takeoff_var._rotation_relative);
    _DISCO_M4_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M4_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M4_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M4_takeoff_var._position_absolute = coords_add(_DISCO_M4_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M4_var._position_absolute, _DISCO_M4_takeoff_var._position_absolute);
    _DISCO_M4_takeoff_var._position_relative = rot_apply(_DISCO_M4_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M4_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M4_takeoff", _DISCO_M4_takeoff_var._position_absolute, _DISCO_M4_takeoff_var._rotation_absolute);
  instrument->_position_absolute[86] = _DISCO_M4_takeoff_var._position_absolute;
  instrument->_position_relative[86] = _DISCO_M4_takeoff_var._position_relative;
    _DISCO_M4_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M4_takeoff_var._position_relative);
  instrument->counter_N[86]  = instrument->counter_P[86] = instrument->counter_P2[86] = 0;
  instrument->counter_AbsorbProp[86]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0085_DISCO_M4_takeoff", _DISCO_M4_takeoff_var._position_absolute, _DISCO_M4_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M4_takeoff_setpos */

/* component DISCO_M4_arm_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M4_arm_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M4_arm_back_setpos] component DISCO_M4_arm_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M4_arm_back_var._name, "DISCO_M4_arm_back", 16384);
  stracpy(_DISCO_M4_arm_back_var._type, "Arm", 16384);
  _DISCO_M4_arm_back_var._index=87;
  int current_setpos_index = 87;
  /* component DISCO_M4_arm_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M4_takeoff_var._rotation_absolute, _DISCO_M4_arm_back_var._rotation_absolute);
    rot_transpose(_DISCO_M4_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M4_arm_back_var._rotation_absolute, tr1, _DISCO_M4_arm_back_var._rotation_relative);
    _DISCO_M4_arm_back_var._rotation_is_identity =  rot_test_identity(_DISCO_M4_arm_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M4_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M4_arm_back_var._position_absolute = coords_add(_DISCO_M4_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M4_var._position_absolute, _DISCO_M4_arm_back_var._position_absolute);
    _DISCO_M4_arm_back_var._position_relative = rot_apply(_DISCO_M4_arm_back_var._rotation_absolute, tc1);
  } /* DISCO_M4_arm_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M4_arm_back", _DISCO_M4_arm_back_var._position_absolute, _DISCO_M4_arm_back_var._rotation_absolute);
  instrument->_position_absolute[87] = _DISCO_M4_arm_back_var._position_absolute;
  instrument->_position_relative[87] = _DISCO_M4_arm_back_var._position_relative;
    _DISCO_M4_arm_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_M4_arm_back_var._position_relative);
  instrument->counter_N[87]  = instrument->counter_P[87] = instrument->counter_P2[87] = 0;
  instrument->counter_AbsorbProp[87]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0086_DISCO_M4_arm_back", _DISCO_M4_arm_back_var._position_absolute, _DISCO_M4_arm_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M4_arm_back_setpos */

/* component DISCO_VFP_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_VFP_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_VFP_location_setpos] component DISCO_VFP_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_VFP_location_var._name, "DISCO_VFP_location", 16384);
  stracpy(_DISCO_VFP_location_var._type, "Arm", 16384);
  _DISCO_VFP_location_var._index=88;
  int current_setpos_index = 88;
  /* component DISCO_VFP_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M4_arm_back_var._rotation_absolute, _DISCO_VFP_location_var._rotation_absolute);
    rot_transpose(_DISCO_M4_var._rotation_absolute, tr1);
    rot_mul(_DISCO_VFP_location_var._rotation_absolute, tr1, _DISCO_VFP_location_var._rotation_relative);
    _DISCO_VFP_location_var._rotation_is_identity =  rot_test_identity(_DISCO_VFP_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.67);
    rot_transpose(_DISCO_M4_arm_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_VFP_location_var._position_absolute = coords_add(_DISCO_M4_arm_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M4_var._position_absolute, _DISCO_VFP_location_var._position_absolute);
    _DISCO_VFP_location_var._position_relative = rot_apply(_DISCO_VFP_location_var._rotation_absolute, tc1);
  } /* DISCO_VFP_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_VFP_location", _DISCO_VFP_location_var._position_absolute, _DISCO_VFP_location_var._rotation_absolute);
  instrument->_position_absolute[88] = _DISCO_VFP_location_var._position_absolute;
  instrument->_position_relative[88] = _DISCO_VFP_location_var._position_relative;
    _DISCO_VFP_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_VFP_location_var._position_relative);
  instrument->counter_N[88]  = instrument->counter_P[88] = instrument->counter_P2[88] = 0;
  instrument->counter_AbsorbProp[88]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0087_DISCO_VFP_location", _DISCO_VFP_location_var._position_absolute, _DISCO_VFP_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_VFP_location_setpos */

/* component DISCO_VFP=PSD_monitor() SETTING, POSITION/ROTATION */
int _DISCO_VFP_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_VFP_setpos] component DISCO_VFP=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_DISCO_VFP_var._name, "DISCO_VFP", 16384);
  stracpy(_DISCO_VFP_var._type, "PSD_monitor", 16384);
  _DISCO_VFP_var._index=89;
  int current_setpos_index = 89;
  if("DISCO_VFP_image.dat" && strlen("DISCO_VFP_image.dat"))
    stracpy(_DISCO_VFP_var._parameters.filename, "DISCO_VFP_image.dat" ? "DISCO_VFP_image.dat" : "", 16384);
  else 
  _DISCO_VFP_var._parameters.filename[0]='\0';
  _DISCO_VFP_var._parameters.xwidth = 0.02;
  _DISCO_VFP_var._parameters.yheight = 0.04;
  _DISCO_VFP_var._parameters.radius = 0;
  _DISCO_VFP_var._parameters.restore_xray = 1;
  _DISCO_VFP_var._parameters.nowritefile = 0;
  _DISCO_VFP_var._parameters.nx = 100;
  _DISCO_VFP_var._parameters.ny = 100;
  _DISCO_VFP_var._parameters.nr = 0;


  /* component DISCO_VFP=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_VFP_location_var._rotation_absolute, _DISCO_VFP_var._rotation_absolute);
    rot_transpose(_DISCO_M4_var._rotation_absolute, tr1);
    rot_mul(_DISCO_VFP_var._rotation_absolute, tr1, _DISCO_VFP_var._rotation_relative);
    _DISCO_VFP_var._rotation_is_identity =  rot_test_identity(_DISCO_VFP_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.DISCO_VFP_shift);
    rot_transpose(_DISCO_VFP_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_VFP_var._position_absolute = coords_add(_DISCO_VFP_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M4_var._position_absolute, _DISCO_VFP_var._position_absolute);
    _DISCO_VFP_var._position_relative = rot_apply(_DISCO_VFP_var._rotation_absolute, tc1);
  } /* DISCO_VFP=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("DISCO_VFP", _DISCO_VFP_var._position_absolute, _DISCO_VFP_var._rotation_absolute);
  instrument->_position_absolute[89] = _DISCO_VFP_var._position_absolute;
  instrument->_position_relative[89] = _DISCO_VFP_var._position_relative;
    _DISCO_VFP_var._position_relative_is_zero =  coords_test_zero(_DISCO_VFP_var._position_relative);
  instrument->counter_N[89]  = instrument->counter_P[89] = instrument->counter_P2[89] = 0;
  instrument->counter_AbsorbProp[89]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0088_DISCO_VFP", _DISCO_VFP_var._position_absolute, _DISCO_VFP_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "filename", 0, "DISCO_VFP_image.dat", "char*");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "xwidth", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "yheight", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0088_DISCO_VFP", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_VFP_setpos */

/* component DISCO_M51_position=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M51_position_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M51_position_setpos] component DISCO_M51_position=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M51_position_var._name, "DISCO_M51_position", 16384);
  stracpy(_DISCO_M51_position_var._type, "Arm", 16384);
  _DISCO_M51_position_var._index=90;
  int current_setpos_index = 90;
  /* component DISCO_M51_position=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_VFP_location_var._rotation_absolute, _DISCO_M51_position_var._rotation_absolute);
    rot_transpose(_DISCO_VFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M51_position_var._rotation_absolute, tr1, _DISCO_M51_position_var._rotation_relative);
    _DISCO_M51_position_var._rotation_is_identity =  rot_test_identity(_DISCO_M51_position_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.48);
    rot_transpose(_DISCO_VFP_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M51_position_var._position_absolute = coords_add(_DISCO_VFP_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_VFP_var._position_absolute, _DISCO_M51_position_var._position_absolute);
    _DISCO_M51_position_var._position_relative = rot_apply(_DISCO_M51_position_var._rotation_absolute, tc1);
  } /* DISCO_M51_position=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M51_position", _DISCO_M51_position_var._position_absolute, _DISCO_M51_position_var._rotation_absolute);
  instrument->_position_absolute[90] = _DISCO_M51_position_var._position_absolute;
  instrument->_position_relative[90] = _DISCO_M51_position_var._position_relative;
    _DISCO_M51_position_var._position_relative_is_zero =  coords_test_zero(_DISCO_M51_position_var._position_relative);
  instrument->counter_N[90]  = instrument->counter_P[90] = instrument->counter_P2[90] = 0;
  instrument->counter_AbsorbProp[90]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0089_DISCO_M51_position", _DISCO_M51_position_var._position_absolute, _DISCO_M51_position_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M51_position_setpos */

/* component DISCO_M51_rotation=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M51_rotation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M51_rotation_setpos] component DISCO_M51_rotation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M51_rotation_var._name, "DISCO_M51_rotation", 16384);
  stracpy(_DISCO_M51_rotation_var._type, "Arm", 16384);
  _DISCO_M51_rotation_var._index=91;
  int current_setpos_index = 91;
  /* component DISCO_M51_rotation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M51_position_var._rotation_absolute, _DISCO_M51_rotation_var._rotation_absolute);
    rot_transpose(_DISCO_VFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M51_rotation_var._rotation_absolute, tr1, _DISCO_M51_rotation_var._rotation_relative);
    _DISCO_M51_rotation_var._rotation_is_identity =  rot_test_identity(_DISCO_M51_rotation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M51_position_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M51_rotation_var._position_absolute = coords_add(_DISCO_M51_position_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_VFP_var._position_absolute, _DISCO_M51_rotation_var._position_absolute);
    _DISCO_M51_rotation_var._position_relative = rot_apply(_DISCO_M51_rotation_var._rotation_absolute, tc1);
  } /* DISCO_M51_rotation=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M51_rotation", _DISCO_M51_rotation_var._position_absolute, _DISCO_M51_rotation_var._rotation_absolute);
  instrument->_position_absolute[91] = _DISCO_M51_rotation_var._position_absolute;
  instrument->_position_relative[91] = _DISCO_M51_rotation_var._position_relative;
    _DISCO_M51_rotation_var._position_relative_is_zero =  coords_test_zero(_DISCO_M51_rotation_var._position_relative);
  instrument->counter_N[91]  = instrument->counter_P[91] = instrument->counter_P2[91] = 0;
  instrument->counter_AbsorbProp[91]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0090_DISCO_M51_rotation", _DISCO_M51_rotation_var._position_absolute, _DISCO_M51_rotation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M51_rotation_setpos */

/* component DISCO_M51=Mirror_elliptic() SETTING, POSITION/ROTATION */
int _DISCO_M51_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M51_setpos] component DISCO_M51=Mirror_elliptic() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_elliptic.comp:71]");
  stracpy(_DISCO_M51_var._name, "DISCO_M51", 16384);
  stracpy(_DISCO_M51_var._type, "Mirror_elliptic", 16384);
  _DISCO_M51_var._index=92;
  int current_setpos_index = 92;
  _DISCO_M51_var._parameters.x_a = 35;
  _DISCO_M51_var._parameters.y_b = 35;
  _DISCO_M51_var._parameters.z_c = 35;
  _DISCO_M51_var._parameters.zdepth = 0.2;
  _DISCO_M51_var._parameters.xwidth = 0.2;
  _DISCO_M51_var._parameters.R0 = 1;
  if("Si_disco.dat" && strlen("Si_disco.dat"))
    stracpy(_DISCO_M51_var._parameters.coating, "Si_disco.dat" ? "Si_disco.dat" : "", 16384);
  else 
  _DISCO_M51_var._parameters.coating[0]='\0';
  _DISCO_M51_var._parameters.length = 40e-3;
  _DISCO_M51_var._parameters.width = 20e-3;
  _DISCO_M51_var._parameters.radius = 0;


  /* component DISCO_M51=Mirror_elliptic() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M51_rotation_var._rotation_absolute, _DISCO_M51_var._rotation_absolute);
    rot_transpose(_DISCO_VFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M51_var._rotation_absolute, tr1, _DISCO_M51_var._rotation_relative);
    _DISCO_M51_var._rotation_is_identity =  rot_test_identity(_DISCO_M51_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M51_rotation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M51_var._position_absolute = coords_add(_DISCO_M51_rotation_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_VFP_var._position_absolute, _DISCO_M51_var._position_absolute);
    _DISCO_M51_var._position_relative = rot_apply(_DISCO_M51_var._rotation_absolute, tc1);
  } /* DISCO_M51=Mirror_elliptic() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M51", _DISCO_M51_var._position_absolute, _DISCO_M51_var._rotation_absolute);
  instrument->_position_absolute[92] = _DISCO_M51_var._position_absolute;
  instrument->_position_relative[92] = _DISCO_M51_var._position_relative;
    _DISCO_M51_var._position_relative_is_zero =  coords_test_zero(_DISCO_M51_var._position_relative);
  instrument->counter_N[92]  = instrument->counter_P[92] = instrument->counter_P2[92] = 0;
  instrument->counter_AbsorbProp[92]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0091_DISCO_M51", _DISCO_M51_var._position_absolute, _DISCO_M51_var._rotation_absolute, "Mirror_elliptic");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "x_a", "0", "35","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "y_b", "1.0", "35","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "z_c", "1.0", "35","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "xwidth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "coating", "Be.txt", "Si_disco.dat", "char*");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "length", "0", "40e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "width", "0", "20e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0091_DISCO_M51", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M51_setpos */

/* component DISCO_arm=Arm() SETTING, POSITION/ROTATION */
int _DISCO_arm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_arm_setpos] component DISCO_arm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_arm_var._name, "DISCO_arm", 16384);
  stracpy(_DISCO_arm_var._type, "Arm", 16384);
  _DISCO_arm_var._index=93;
  int current_setpos_index = 93;
  /* component DISCO_arm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M51_var._rotation_absolute, _DISCO_arm_var._rotation_absolute);
    rot_transpose(_DISCO_M51_var._rotation_absolute, tr1);
    rot_mul(_DISCO_arm_var._rotation_absolute, tr1, _DISCO_arm_var._rotation_relative);
    _DISCO_arm_var._rotation_is_identity =  rot_test_identity(_DISCO_arm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M51_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_arm_var._position_absolute = coords_add(_DISCO_M51_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M51_var._position_absolute, _DISCO_arm_var._position_absolute);
    _DISCO_arm_var._position_relative = rot_apply(_DISCO_arm_var._rotation_absolute, tc1);
  } /* DISCO_arm=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_arm", _DISCO_arm_var._position_absolute, _DISCO_arm_var._rotation_absolute);
  instrument->_position_absolute[93] = _DISCO_arm_var._position_absolute;
  instrument->_position_relative[93] = _DISCO_arm_var._position_relative;
    _DISCO_arm_var._position_relative_is_zero =  coords_test_zero(_DISCO_arm_var._position_relative);
  instrument->counter_N[93]  = instrument->counter_P[93] = instrument->counter_P2[93] = 0;
  instrument->counter_AbsorbProp[93]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0092_DISCO_arm", _DISCO_arm_var._position_absolute, _DISCO_arm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_arm_setpos */

/* component DISCO_M51_arm_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M51_arm_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M51_arm_back_setpos] component DISCO_M51_arm_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M51_arm_back_var._name, "DISCO_M51_arm_back", 16384);
  stracpy(_DISCO_M51_arm_back_var._type, "Arm", 16384);
  _DISCO_M51_arm_back_var._index=94;
  int current_setpos_index = 94;
  /* component DISCO_M51_arm_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DISCO_arm_var._rotation_absolute, _DISCO_M51_arm_back_var._rotation_absolute);
    rot_transpose(_DISCO_M51_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M51_arm_back_var._rotation_absolute, tr1, _DISCO_M51_arm_back_var._rotation_relative);
    _DISCO_M51_arm_back_var._rotation_is_identity =  rot_test_identity(_DISCO_M51_arm_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_arm_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M51_arm_back_var._position_absolute = coords_add(_DISCO_arm_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M51_var._position_absolute, _DISCO_M51_arm_back_var._position_absolute);
    _DISCO_M51_arm_back_var._position_relative = rot_apply(_DISCO_M51_arm_back_var._rotation_absolute, tc1);
  } /* DISCO_M51_arm_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M51_arm_back", _DISCO_M51_arm_back_var._position_absolute, _DISCO_M51_arm_back_var._rotation_absolute);
  instrument->_position_absolute[94] = _DISCO_M51_arm_back_var._position_absolute;
  instrument->_position_relative[94] = _DISCO_M51_arm_back_var._position_relative;
    _DISCO_M51_arm_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_M51_arm_back_var._position_relative);
  instrument->counter_N[94]  = instrument->counter_P[94] = instrument->counter_P2[94] = 0;
  instrument->counter_AbsorbProp[94]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0093_DISCO_M51_arm_back", _DISCO_M51_arm_back_var._position_absolute, _DISCO_M51_arm_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M51_arm_back_setpos */

/* component DISCO_M52_position=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M52_position_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M52_position_setpos] component DISCO_M52_position=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M52_position_var._name, "DISCO_M52_position", 16384);
  stracpy(_DISCO_M52_position_var._type, "Arm", 16384);
  _DISCO_M52_position_var._index=95;
  int current_setpos_index = 95;
  /* component DISCO_M52_position=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M51_arm_back_var._rotation_absolute, _DISCO_M52_position_var._rotation_absolute);
    rot_transpose(_DISCO_M51_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M52_position_var._rotation_absolute, tr1, _DISCO_M52_position_var._rotation_relative);
    _DISCO_M52_position_var._rotation_is_identity =  rot_test_identity(_DISCO_M52_position_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.8);
    rot_transpose(_DISCO_M51_arm_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M52_position_var._position_absolute = coords_add(_DISCO_M51_arm_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M51_var._position_absolute, _DISCO_M52_position_var._position_absolute);
    _DISCO_M52_position_var._position_relative = rot_apply(_DISCO_M52_position_var._rotation_absolute, tc1);
  } /* DISCO_M52_position=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M52_position", _DISCO_M52_position_var._position_absolute, _DISCO_M52_position_var._rotation_absolute);
  instrument->_position_absolute[95] = _DISCO_M52_position_var._position_absolute;
  instrument->_position_relative[95] = _DISCO_M52_position_var._position_relative;
    _DISCO_M52_position_var._position_relative_is_zero =  coords_test_zero(_DISCO_M52_position_var._position_relative);
  instrument->counter_N[95]  = instrument->counter_P[95] = instrument->counter_P2[95] = 0;
  instrument->counter_AbsorbProp[95]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0094_DISCO_M52_position", _DISCO_M52_position_var._position_absolute, _DISCO_M52_position_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M52_position_setpos */

/* component DISCO_M52_x=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M52_x_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M52_x_setpos] component DISCO_M52_x=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M52_x_var._name, "DISCO_M52_x", 16384);
  stracpy(_DISCO_M52_x_var._type, "Arm", 16384);
  _DISCO_M52_x_var._index=96;
  int current_setpos_index = 96;
  /* component DISCO_M52_x=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M52_position_var._rotation_absolute, _DISCO_M52_x_var._rotation_absolute);
    rot_transpose(_DISCO_M51_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M52_x_var._rotation_absolute, tr1, _DISCO_M52_x_var._rotation_relative);
    _DISCO_M52_x_var._rotation_is_identity =  rot_test_identity(_DISCO_M52_x_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M52_position_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M52_x_var._position_absolute = coords_add(_DISCO_M52_position_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M51_var._position_absolute, _DISCO_M52_x_var._position_absolute);
    _DISCO_M52_x_var._position_relative = rot_apply(_DISCO_M52_x_var._rotation_absolute, tc1);
  } /* DISCO_M52_x=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M52_x", _DISCO_M52_x_var._position_absolute, _DISCO_M52_x_var._rotation_absolute);
  instrument->_position_absolute[96] = _DISCO_M52_x_var._position_absolute;
  instrument->_position_relative[96] = _DISCO_M52_x_var._position_relative;
    _DISCO_M52_x_var._position_relative_is_zero =  coords_test_zero(_DISCO_M52_x_var._position_relative);
  instrument->counter_N[96]  = instrument->counter_P[96] = instrument->counter_P2[96] = 0;
  instrument->counter_AbsorbProp[96]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0095_DISCO_M52_x", _DISCO_M52_x_var._position_absolute, _DISCO_M52_x_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M52_x_setpos */

/* component DISCO_M52=Mirror_curved() SETTING, POSITION/ROTATION */
int _DISCO_M52_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M52_setpos] component DISCO_M52=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_DISCO_M52_var._name, "DISCO_M52", 16384);
  stracpy(_DISCO_M52_var._type, "Mirror_curved", 16384);
  _DISCO_M52_var._index=97;
  int current_setpos_index = 97;
  _DISCO_M52_var._parameters.radius = 2;
  _DISCO_M52_var._parameters.R0 = 1;
  if("AlMgF2_disco.dat" && strlen("AlMgF2_disco.dat"))
    stracpy(_DISCO_M52_var._parameters.coating, "AlMgF2_disco.dat" ? "AlMgF2_disco.dat" : "", 16384);
  else 
  _DISCO_M52_var._parameters.coating[0]='\0';
  _DISCO_M52_var._parameters.zdepth = 0.2;
  _DISCO_M52_var._parameters.yheight = 0.2;
  _DISCO_M52_var._parameters.length = 20e-3;
  _DISCO_M52_var._parameters.width = 40e-3;


  /* component DISCO_M52=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-20.65)*DEG2RAD);
    rot_mul(tr1, _DISCO_M52_x_var._rotation_absolute, _DISCO_M52_var._rotation_absolute);
    rot_transpose(_DISCO_M51_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M52_var._rotation_absolute, tr1, _DISCO_M52_var._rotation_relative);
    _DISCO_M52_var._rotation_is_identity =  rot_test_identity(_DISCO_M52_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M52_x_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M52_var._position_absolute = coords_add(_DISCO_M52_x_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M51_var._position_absolute, _DISCO_M52_var._position_absolute);
    _DISCO_M52_var._position_relative = rot_apply(_DISCO_M52_var._rotation_absolute, tc1);
  } /* DISCO_M52=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M52", _DISCO_M52_var._position_absolute, _DISCO_M52_var._rotation_absolute);
  instrument->_position_absolute[97] = _DISCO_M52_var._position_absolute;
  instrument->_position_relative[97] = _DISCO_M52_var._position_relative;
    _DISCO_M52_var._position_relative_is_zero =  coords_test_zero(_DISCO_M52_var._position_relative);
  instrument->counter_N[97]  = instrument->counter_P[97] = instrument->counter_P2[97] = 0;
  instrument->counter_AbsorbProp[97]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0096_DISCO_M52", _DISCO_M52_var._position_absolute, _DISCO_M52_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "radius", "1", "2","MCNUM");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "coating", "Be.txt", "AlMgF2_disco.dat", "char*");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "length", "0", "20e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0096_DISCO_M52", "width", "0", "40e-3","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M52_setpos */

/* component DISCO_M52_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M52_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M52_takeoff_setpos] component DISCO_M52_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M52_takeoff_var._name, "DISCO_M52_takeoff", 16384);
  stracpy(_DISCO_M52_takeoff_var._type, "Arm", 16384);
  _DISCO_M52_takeoff_var._index=98;
  int current_setpos_index = 98;
  /* component DISCO_M52_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-20.65)*DEG2RAD);
    rot_mul(tr1, _DISCO_M52_var._rotation_absolute, _DISCO_M52_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M52_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M52_takeoff_var._rotation_absolute, tr1, _DISCO_M52_takeoff_var._rotation_relative);
    _DISCO_M52_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M52_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M52_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M52_takeoff_var._position_absolute = coords_add(_DISCO_M52_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M52_var._position_absolute, _DISCO_M52_takeoff_var._position_absolute);
    _DISCO_M52_takeoff_var._position_relative = rot_apply(_DISCO_M52_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M52_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M52_takeoff", _DISCO_M52_takeoff_var._position_absolute, _DISCO_M52_takeoff_var._rotation_absolute);
  instrument->_position_absolute[98] = _DISCO_M52_takeoff_var._position_absolute;
  instrument->_position_relative[98] = _DISCO_M52_takeoff_var._position_relative;
    _DISCO_M52_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M52_takeoff_var._position_relative);
  instrument->counter_N[98]  = instrument->counter_P[98] = instrument->counter_P2[98] = 0;
  instrument->counter_AbsorbProp[98]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0097_DISCO_M52_takeoff", _DISCO_M52_takeoff_var._position_absolute, _DISCO_M52_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M52_takeoff_setpos */

/* component DISCO_M52_x_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M52_x_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M52_x_takeoff_setpos] component DISCO_M52_x_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M52_x_takeoff_var._name, "DISCO_M52_x_takeoff", 16384);
  stracpy(_DISCO_M52_x_takeoff_var._type, "Arm", 16384);
  _DISCO_M52_x_takeoff_var._index=99;
  int current_setpos_index = 99;
  /* component DISCO_M52_x_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M52_takeoff_var._rotation_absolute, _DISCO_M52_x_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M52_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M52_x_takeoff_var._rotation_absolute, tr1, _DISCO_M52_x_takeoff_var._rotation_relative);
    _DISCO_M52_x_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M52_x_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M52_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M52_x_takeoff_var._position_absolute = coords_add(_DISCO_M52_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M52_var._position_absolute, _DISCO_M52_x_takeoff_var._position_absolute);
    _DISCO_M52_x_takeoff_var._position_relative = rot_apply(_DISCO_M52_x_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M52_x_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M52_x_takeoff", _DISCO_M52_x_takeoff_var._position_absolute, _DISCO_M52_x_takeoff_var._rotation_absolute);
  instrument->_position_absolute[99] = _DISCO_M52_x_takeoff_var._position_absolute;
  instrument->_position_relative[99] = _DISCO_M52_x_takeoff_var._position_relative;
    _DISCO_M52_x_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M52_x_takeoff_var._position_relative);
  instrument->counter_N[99]  = instrument->counter_P[99] = instrument->counter_P2[99] = 0;
  instrument->counter_AbsorbProp[99]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0098_DISCO_M52_x_takeoff", _DISCO_M52_x_takeoff_var._position_absolute, _DISCO_M52_x_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M52_x_takeoff_setpos */

/* component DISCO_second_HFP_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_second_HFP_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_second_HFP_location_setpos] component DISCO_second_HFP_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_second_HFP_location_var._name, "DISCO_second_HFP_location", 16384);
  stracpy(_DISCO_second_HFP_location_var._type, "Arm", 16384);
  _DISCO_second_HFP_location_var._index=100;
  int current_setpos_index = 100;
  /* component DISCO_second_HFP_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M52_x_takeoff_var._rotation_absolute, _DISCO_second_HFP_location_var._rotation_absolute);
    rot_transpose(_DISCO_M52_var._rotation_absolute, tr1);
    rot_mul(_DISCO_second_HFP_location_var._rotation_absolute, tr1, _DISCO_second_HFP_location_var._rotation_relative);
    _DISCO_second_HFP_location_var._rotation_is_identity =  rot_test_identity(_DISCO_second_HFP_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 4.96);
    rot_transpose(_DISCO_M52_x_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_second_HFP_location_var._position_absolute = coords_add(_DISCO_M52_x_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M52_var._position_absolute, _DISCO_second_HFP_location_var._position_absolute);
    _DISCO_second_HFP_location_var._position_relative = rot_apply(_DISCO_second_HFP_location_var._rotation_absolute, tc1);
  } /* DISCO_second_HFP_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_second_HFP_location", _DISCO_second_HFP_location_var._position_absolute, _DISCO_second_HFP_location_var._rotation_absolute);
  instrument->_position_absolute[100] = _DISCO_second_HFP_location_var._position_absolute;
  instrument->_position_relative[100] = _DISCO_second_HFP_location_var._position_relative;
    _DISCO_second_HFP_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_second_HFP_location_var._position_relative);
  instrument->counter_N[100]  = instrument->counter_P[100] = instrument->counter_P2[100] = 0;
  instrument->counter_AbsorbProp[100]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0099_DISCO_second_HFP_location", _DISCO_second_HFP_location_var._position_absolute, _DISCO_second_HFP_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_second_HFP_location_setpos */

/* component DISCO_second_HFP=PSD_monitor() SETTING, POSITION/ROTATION */
int _DISCO_second_HFP_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_second_HFP_setpos] component DISCO_second_HFP=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_DISCO_second_HFP_var._name, "DISCO_second_HFP", 16384);
  stracpy(_DISCO_second_HFP_var._type, "PSD_monitor", 16384);
  _DISCO_second_HFP_var._index=101;
  int current_setpos_index = 101;
  if("DISCO_second_HFP_image.dat" && strlen("DISCO_second_HFP_image.dat"))
    stracpy(_DISCO_second_HFP_var._parameters.filename, "DISCO_second_HFP_image.dat" ? "DISCO_second_HFP_image.dat" : "", 16384);
  else 
  _DISCO_second_HFP_var._parameters.filename[0]='\0';
  _DISCO_second_HFP_var._parameters.xwidth = 0.8;
  _DISCO_second_HFP_var._parameters.yheight = 0.08;
  _DISCO_second_HFP_var._parameters.radius = 0;
  _DISCO_second_HFP_var._parameters.restore_xray = 1;
  _DISCO_second_HFP_var._parameters.nowritefile = 0;
  _DISCO_second_HFP_var._parameters.nx = 100;
  _DISCO_second_HFP_var._parameters.ny = 100;
  _DISCO_second_HFP_var._parameters.nr = 0;


  /* component DISCO_second_HFP=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_second_HFP_location_var._rotation_absolute, _DISCO_second_HFP_var._rotation_absolute);
    rot_transpose(_DISCO_M52_var._rotation_absolute, tr1);
    rot_mul(_DISCO_second_HFP_var._rotation_absolute, tr1, _DISCO_second_HFP_var._rotation_relative);
    _DISCO_second_HFP_var._rotation_is_identity =  rot_test_identity(_DISCO_second_HFP_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.DISCO_second_HFP_shift);
    rot_transpose(_DISCO_second_HFP_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_second_HFP_var._position_absolute = coords_add(_DISCO_second_HFP_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M52_var._position_absolute, _DISCO_second_HFP_var._position_absolute);
    _DISCO_second_HFP_var._position_relative = rot_apply(_DISCO_second_HFP_var._rotation_absolute, tc1);
  } /* DISCO_second_HFP=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("DISCO_second_HFP", _DISCO_second_HFP_var._position_absolute, _DISCO_second_HFP_var._rotation_absolute);
  instrument->_position_absolute[101] = _DISCO_second_HFP_var._position_absolute;
  instrument->_position_relative[101] = _DISCO_second_HFP_var._position_relative;
    _DISCO_second_HFP_var._position_relative_is_zero =  coords_test_zero(_DISCO_second_HFP_var._position_relative);
  instrument->counter_N[101]  = instrument->counter_P[101] = instrument->counter_P2[101] = 0;
  instrument->counter_AbsorbProp[101]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0100_DISCO_second_HFP", _DISCO_second_HFP_var._position_absolute, _DISCO_second_HFP_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "filename", 0, "DISCO_second_HFP_image.dat", "char*");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "xwidth", "0.05", "0.8","MCNUM");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "yheight", "0.05", "0.08","MCNUM");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0100_DISCO_second_HFP", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_second_HFP_setpos */

/* component DISCO_M53_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M53_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M53_location_setpos] component DISCO_M53_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M53_location_var._name, "DISCO_M53_location", 16384);
  stracpy(_DISCO_M53_location_var._type, "Arm", 16384);
  _DISCO_M53_location_var._index=102;
  int current_setpos_index = 102;
  /* component DISCO_M53_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M52_x_takeoff_var._rotation_absolute, _DISCO_M53_location_var._rotation_absolute);
    rot_transpose(_DISCO_second_HFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M53_location_var._rotation_absolute, tr1, _DISCO_M53_location_var._rotation_relative);
    _DISCO_M53_location_var._rotation_is_identity =  rot_test_identity(_DISCO_M53_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 23.75);
    rot_transpose(_DISCO_M52_x_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M53_location_var._position_absolute = coords_add(_DISCO_M52_x_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_second_HFP_var._position_absolute, _DISCO_M53_location_var._position_absolute);
    _DISCO_M53_location_var._position_relative = rot_apply(_DISCO_M53_location_var._rotation_absolute, tc1);
  } /* DISCO_M53_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M53_location", _DISCO_M53_location_var._position_absolute, _DISCO_M53_location_var._rotation_absolute);
  instrument->_position_absolute[102] = _DISCO_M53_location_var._position_absolute;
  instrument->_position_relative[102] = _DISCO_M53_location_var._position_relative;
    _DISCO_M53_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_M53_location_var._position_relative);
  instrument->counter_N[102]  = instrument->counter_P[102] = instrument->counter_P2[102] = 0;
  instrument->counter_AbsorbProp[102]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0101_DISCO_M53_location", _DISCO_M53_location_var._position_absolute, _DISCO_M53_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M53_location_setpos */

/* component DISCO_M53_rotated=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M53_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M53_rotated_setpos] component DISCO_M53_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M53_rotated_var._name, "DISCO_M53_rotated", 16384);
  stracpy(_DISCO_M53_rotated_var._type, "Arm", 16384);
  _DISCO_M53_rotated_var._index=103;
  int current_setpos_index = 103;
  /* component DISCO_M53_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M53_location_var._rotation_absolute, _DISCO_M53_rotated_var._rotation_absolute);
    rot_transpose(_DISCO_second_HFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M53_rotated_var._rotation_absolute, tr1, _DISCO_M53_rotated_var._rotation_relative);
    _DISCO_M53_rotated_var._rotation_is_identity =  rot_test_identity(_DISCO_M53_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M53_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M53_rotated_var._position_absolute = coords_add(_DISCO_M53_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_second_HFP_var._position_absolute, _DISCO_M53_rotated_var._position_absolute);
    _DISCO_M53_rotated_var._position_relative = rot_apply(_DISCO_M53_rotated_var._rotation_absolute, tc1);
  } /* DISCO_M53_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M53_rotated", _DISCO_M53_rotated_var._position_absolute, _DISCO_M53_rotated_var._rotation_absolute);
  instrument->_position_absolute[103] = _DISCO_M53_rotated_var._position_absolute;
  instrument->_position_relative[103] = _DISCO_M53_rotated_var._position_relative;
    _DISCO_M53_rotated_var._position_relative_is_zero =  coords_test_zero(_DISCO_M53_rotated_var._position_relative);
  instrument->counter_N[103]  = instrument->counter_P[103] = instrument->counter_P2[103] = 0;
  instrument->counter_AbsorbProp[103]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0102_DISCO_M53_rotated", _DISCO_M53_rotated_var._position_absolute, _DISCO_M53_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M53_rotated_setpos */

/* component DISCO_M53=Mirror_toroid_pothole() SETTING, POSITION/ROTATION */
int _DISCO_M53_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M53_setpos] component DISCO_M53=Mirror_toroid_pothole() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:64]");
  stracpy(_DISCO_M53_var._name, "DISCO_M53", 16384);
  stracpy(_DISCO_M53_var._type, "Mirror_toroid_pothole", 16384);
  _DISCO_M53_var._index=104;
  int current_setpos_index = 104;
  _DISCO_M53_var._parameters.zdepth = 130e-3;
  _DISCO_M53_var._parameters.xwidth = 50e-3;
  _DISCO_M53_var._parameters.radius = 0.714;
  _DISCO_M53_var._parameters.radius_o = 4.75;
  _DISCO_M53_var._parameters.R0 = 0;
  if("AlMgF2_disco.dat" && strlen("AlMgF2_disco.dat"))
    stracpy(_DISCO_M53_var._parameters.coating, "AlMgF2_disco.dat" ? "AlMgF2_disco.dat" : "", 16384);
  else 
  _DISCO_M53_var._parameters.coating[0]='\0';


  /* component DISCO_M53=Mirror_toroid_pothole() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M53_rotated_var._rotation_absolute, _DISCO_M53_var._rotation_absolute);
    rot_transpose(_DISCO_second_HFP_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M53_var._rotation_absolute, tr1, _DISCO_M53_var._rotation_relative);
    _DISCO_M53_var._rotation_is_identity =  rot_test_identity(_DISCO_M53_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M53_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M53_var._position_absolute = coords_add(_DISCO_M53_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_second_HFP_var._position_absolute, _DISCO_M53_var._position_absolute);
    _DISCO_M53_var._position_relative = rot_apply(_DISCO_M53_var._rotation_absolute, tc1);
  } /* DISCO_M53=Mirror_toroid_pothole() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M53", _DISCO_M53_var._position_absolute, _DISCO_M53_var._rotation_absolute);
  instrument->_position_absolute[104] = _DISCO_M53_var._position_absolute;
  instrument->_position_relative[104] = _DISCO_M53_var._position_relative;
    _DISCO_M53_var._position_relative_is_zero =  coords_test_zero(_DISCO_M53_var._position_relative);
  instrument->counter_N[104]  = instrument->counter_P[104] = instrument->counter_P2[104] = 0;
  instrument->counter_AbsorbProp[104]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0103_DISCO_M53", _DISCO_M53_var._position_absolute, _DISCO_M53_var._rotation_absolute, "Mirror_toroid_pothole");
        mccomp_param_nexus(nxhandle,"0103_DISCO_M53", "zdepth", "0.1", "130e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0103_DISCO_M53", "xwidth", "0.01", "50e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0103_DISCO_M53", "radius", "NONE", "0.714","MCNUM");
        mccomp_param_nexus(nxhandle,"0103_DISCO_M53", "radius_o", "NONE", "4.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0103_DISCO_M53", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0103_DISCO_M53", "coating", "", "AlMgF2_disco.dat", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M53_setpos */

/* component DISCO_M53_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M53_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M53_takeoff_setpos] component DISCO_M53_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M53_takeoff_var._name, "DISCO_M53_takeoff", 16384);
  stracpy(_DISCO_M53_takeoff_var._type, "Arm", 16384);
  _DISCO_M53_takeoff_var._index=105;
  int current_setpos_index = 105;
  /* component DISCO_M53_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M53_var._rotation_absolute, _DISCO_M53_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M53_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M53_takeoff_var._rotation_absolute, tr1, _DISCO_M53_takeoff_var._rotation_relative);
    _DISCO_M53_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M53_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M53_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M53_takeoff_var._position_absolute = coords_add(_DISCO_M53_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M53_var._position_absolute, _DISCO_M53_takeoff_var._position_absolute);
    _DISCO_M53_takeoff_var._position_relative = rot_apply(_DISCO_M53_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M53_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M53_takeoff", _DISCO_M53_takeoff_var._position_absolute, _DISCO_M53_takeoff_var._rotation_absolute);
  instrument->_position_absolute[105] = _DISCO_M53_takeoff_var._position_absolute;
  instrument->_position_relative[105] = _DISCO_M53_takeoff_var._position_relative;
    _DISCO_M53_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M53_takeoff_var._position_relative);
  instrument->counter_N[105]  = instrument->counter_P[105] = instrument->counter_P2[105] = 0;
  instrument->counter_AbsorbProp[105]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0104_DISCO_M53_takeoff", _DISCO_M53_takeoff_var._position_absolute, _DISCO_M53_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M53_takeoff_setpos */

/* component DISCO_M54_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M54_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M54_location_setpos] component DISCO_M54_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M54_location_var._name, "DISCO_M54_location", 16384);
  stracpy(_DISCO_M54_location_var._type, "Arm", 16384);
  _DISCO_M54_location_var._index=106;
  int current_setpos_index = 106;
  /* component DISCO_M54_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M53_takeoff_var._rotation_absolute, _DISCO_M54_location_var._rotation_absolute);
    rot_transpose(_DISCO_M53_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M54_location_var._rotation_absolute, tr1, _DISCO_M54_location_var._rotation_relative);
    _DISCO_M54_location_var._rotation_is_identity =  rot_test_identity(_DISCO_M54_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.25);
    rot_transpose(_DISCO_M53_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M54_location_var._position_absolute = coords_add(_DISCO_M53_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M53_var._position_absolute, _DISCO_M54_location_var._position_absolute);
    _DISCO_M54_location_var._position_relative = rot_apply(_DISCO_M54_location_var._rotation_absolute, tc1);
  } /* DISCO_M54_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M54_location", _DISCO_M54_location_var._position_absolute, _DISCO_M54_location_var._rotation_absolute);
  instrument->_position_absolute[106] = _DISCO_M54_location_var._position_absolute;
  instrument->_position_relative[106] = _DISCO_M54_location_var._position_relative;
    _DISCO_M54_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_M54_location_var._position_relative);
  instrument->counter_N[106]  = instrument->counter_P[106] = instrument->counter_P2[106] = 0;
  instrument->counter_AbsorbProp[106]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0105_DISCO_M54_location", _DISCO_M54_location_var._position_absolute, _DISCO_M54_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M54_location_setpos */

/* component DISCO_M54_rotated=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M54_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M54_rotated_setpos] component DISCO_M54_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M54_rotated_var._name, "DISCO_M54_rotated", 16384);
  stracpy(_DISCO_M54_rotated_var._type, "Arm", 16384);
  _DISCO_M54_rotated_var._index=107;
  int current_setpos_index = 107;
  /* component DISCO_M54_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (180)*DEG2RAD);
    rot_mul(tr1, _DISCO_M54_location_var._rotation_absolute, _DISCO_M54_rotated_var._rotation_absolute);
    rot_transpose(_DISCO_M53_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M54_rotated_var._rotation_absolute, tr1, _DISCO_M54_rotated_var._rotation_relative);
    _DISCO_M54_rotated_var._rotation_is_identity =  rot_test_identity(_DISCO_M54_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M54_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M54_rotated_var._position_absolute = coords_add(_DISCO_M54_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M53_var._position_absolute, _DISCO_M54_rotated_var._position_absolute);
    _DISCO_M54_rotated_var._position_relative = rot_apply(_DISCO_M54_rotated_var._rotation_absolute, tc1);
  } /* DISCO_M54_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M54_rotated", _DISCO_M54_rotated_var._position_absolute, _DISCO_M54_rotated_var._rotation_absolute);
  instrument->_position_absolute[107] = _DISCO_M54_rotated_var._position_absolute;
  instrument->_position_relative[107] = _DISCO_M54_rotated_var._position_relative;
    _DISCO_M54_rotated_var._position_relative_is_zero =  coords_test_zero(_DISCO_M54_rotated_var._position_relative);
  instrument->counter_N[107]  = instrument->counter_P[107] = instrument->counter_P2[107] = 0;
  instrument->counter_AbsorbProp[107]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0106_DISCO_M54_rotated", _DISCO_M54_rotated_var._position_absolute, _DISCO_M54_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M54_rotated_setpos */

/* component DISCO_M54=Mirror_toroid_pothole() SETTING, POSITION/ROTATION */
int _DISCO_M54_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M54_setpos] component DISCO_M54=Mirror_toroid_pothole() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:64]");
  stracpy(_DISCO_M54_var._name, "DISCO_M54", 16384);
  stracpy(_DISCO_M54_var._type, "Mirror_toroid_pothole", 16384);
  _DISCO_M54_var._index=108;
  int current_setpos_index = 108;
  _DISCO_M54_var._parameters.zdepth = 110e-3;
  _DISCO_M54_var._parameters.xwidth = 50e-3;
  _DISCO_M54_var._parameters.radius = 1.12;
  _DISCO_M54_var._parameters.radius_o = 7.8;
  _DISCO_M54_var._parameters.R0 = 0;
  if("AlMgF2_disco.dat" && strlen("AlMgF2_disco.dat"))
    stracpy(_DISCO_M54_var._parameters.coating, "AlMgF2_disco.dat" ? "AlMgF2_disco.dat" : "", 16384);
  else 
  _DISCO_M54_var._parameters.coating[0]='\0';


  /* component DISCO_M54=Mirror_toroid_pothole() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M54_rotated_var._rotation_absolute, _DISCO_M54_var._rotation_absolute);
    rot_transpose(_DISCO_M53_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M54_var._rotation_absolute, tr1, _DISCO_M54_var._rotation_relative);
    _DISCO_M54_var._rotation_is_identity =  rot_test_identity(_DISCO_M54_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M54_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M54_var._position_absolute = coords_add(_DISCO_M54_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M53_var._position_absolute, _DISCO_M54_var._position_absolute);
    _DISCO_M54_var._position_relative = rot_apply(_DISCO_M54_var._rotation_absolute, tc1);
  } /* DISCO_M54=Mirror_toroid_pothole() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M54", _DISCO_M54_var._position_absolute, _DISCO_M54_var._rotation_absolute);
  instrument->_position_absolute[108] = _DISCO_M54_var._position_absolute;
  instrument->_position_relative[108] = _DISCO_M54_var._position_relative;
    _DISCO_M54_var._position_relative_is_zero =  coords_test_zero(_DISCO_M54_var._position_relative);
  instrument->counter_N[108]  = instrument->counter_P[108] = instrument->counter_P2[108] = 0;
  instrument->counter_AbsorbProp[108]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0107_DISCO_M54", _DISCO_M54_var._position_absolute, _DISCO_M54_var._rotation_absolute, "Mirror_toroid_pothole");
        mccomp_param_nexus(nxhandle,"0107_DISCO_M54", "zdepth", "0.1", "110e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0107_DISCO_M54", "xwidth", "0.01", "50e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0107_DISCO_M54", "radius", "NONE", "1.12","MCNUM");
        mccomp_param_nexus(nxhandle,"0107_DISCO_M54", "radius_o", "NONE", "7.8","MCNUM");
        mccomp_param_nexus(nxhandle,"0107_DISCO_M54", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0107_DISCO_M54", "coating", "", "AlMgF2_disco.dat", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M54_setpos */

/* component DISCO_M54_takeoff=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M54_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M54_takeoff_setpos] component DISCO_M54_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M54_takeoff_var._name, "DISCO_M54_takeoff", 16384);
  stracpy(_DISCO_M54_takeoff_var._type, "Arm", 16384);
  _DISCO_M54_takeoff_var._index=109;
  int current_setpos_index = 109;
  /* component DISCO_M54_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DISCO_grazing_angle_one)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M54_var._rotation_absolute, _DISCO_M54_takeoff_var._rotation_absolute);
    rot_transpose(_DISCO_M54_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M54_takeoff_var._rotation_absolute, tr1, _DISCO_M54_takeoff_var._rotation_relative);
    _DISCO_M54_takeoff_var._rotation_is_identity =  rot_test_identity(_DISCO_M54_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M54_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M54_takeoff_var._position_absolute = coords_add(_DISCO_M54_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M54_var._position_absolute, _DISCO_M54_takeoff_var._position_absolute);
    _DISCO_M54_takeoff_var._position_relative = rot_apply(_DISCO_M54_takeoff_var._rotation_absolute, tc1);
  } /* DISCO_M54_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M54_takeoff", _DISCO_M54_takeoff_var._position_absolute, _DISCO_M54_takeoff_var._rotation_absolute);
  instrument->_position_absolute[109] = _DISCO_M54_takeoff_var._position_absolute;
  instrument->_position_relative[109] = _DISCO_M54_takeoff_var._position_relative;
    _DISCO_M54_takeoff_var._position_relative_is_zero =  coords_test_zero(_DISCO_M54_takeoff_var._position_relative);
  instrument->counter_N[109]  = instrument->counter_P[109] = instrument->counter_P2[109] = 0;
  instrument->counter_AbsorbProp[109]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0108_DISCO_M54_takeoff", _DISCO_M54_takeoff_var._position_absolute, _DISCO_M54_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M54_takeoff_setpos */

/* component DISCO_Mtoroids_arm_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Mtoroids_arm_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Mtoroids_arm_back_setpos] component DISCO_Mtoroids_arm_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Mtoroids_arm_back_var._name, "DISCO_Mtoroids_arm_back", 16384);
  stracpy(_DISCO_Mtoroids_arm_back_var._type, "Arm", 16384);
  _DISCO_Mtoroids_arm_back_var._index=110;
  int current_setpos_index = 110;
  /* component DISCO_Mtoroids_arm_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-180 -90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M54_takeoff_var._rotation_absolute, _DISCO_Mtoroids_arm_back_var._rotation_absolute);
    rot_transpose(_DISCO_M54_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Mtoroids_arm_back_var._rotation_absolute, tr1, _DISCO_Mtoroids_arm_back_var._rotation_relative);
    _DISCO_Mtoroids_arm_back_var._rotation_is_identity =  rot_test_identity(_DISCO_Mtoroids_arm_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M54_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Mtoroids_arm_back_var._position_absolute = coords_add(_DISCO_M54_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M54_var._position_absolute, _DISCO_Mtoroids_arm_back_var._position_absolute);
    _DISCO_Mtoroids_arm_back_var._position_relative = rot_apply(_DISCO_Mtoroids_arm_back_var._rotation_absolute, tc1);
  } /* DISCO_Mtoroids_arm_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Mtoroids_arm_back", _DISCO_Mtoroids_arm_back_var._position_absolute, _DISCO_Mtoroids_arm_back_var._rotation_absolute);
  instrument->_position_absolute[110] = _DISCO_Mtoroids_arm_back_var._position_absolute;
  instrument->_position_relative[110] = _DISCO_Mtoroids_arm_back_var._position_relative;
    _DISCO_Mtoroids_arm_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_Mtoroids_arm_back_var._position_relative);
  instrument->counter_N[110]  = instrument->counter_P[110] = instrument->counter_P2[110] = 0;
  instrument->counter_AbsorbProp[110]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0109_DISCO_Mtoroids_arm_back", _DISCO_Mtoroids_arm_back_var._position_absolute, _DISCO_Mtoroids_arm_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Mtoroids_arm_back_setpos */

/* component DISCO_M1_position=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_position_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_position_setpos] component DISCO_M1_position=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_position_var._name, "DISCO_M1_position", 16384);
  stracpy(_DISCO_M1_position_var._type, "Arm", 16384);
  _DISCO_M1_position_var._index=111;
  int current_setpos_index = 111;
  /* component DISCO_M1_position=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Mtoroids_arm_back_var._rotation_absolute, _DISCO_M1_position_var._rotation_absolute);
    rot_transpose(_DISCO_M54_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_position_var._rotation_absolute, tr1, _DISCO_M1_position_var._rotation_relative);
    _DISCO_M1_position_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_position_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.3);
    rot_transpose(_DISCO_Mtoroids_arm_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_position_var._position_absolute = coords_add(_DISCO_Mtoroids_arm_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M54_var._position_absolute, _DISCO_M1_position_var._position_absolute);
    _DISCO_M1_position_var._position_relative = rot_apply(_DISCO_M1_position_var._rotation_absolute, tc1);
  } /* DISCO_M1_position=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_position", _DISCO_M1_position_var._position_absolute, _DISCO_M1_position_var._rotation_absolute);
  instrument->_position_absolute[111] = _DISCO_M1_position_var._position_absolute;
  instrument->_position_relative[111] = _DISCO_M1_position_var._position_relative;
    _DISCO_M1_position_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_position_var._position_relative);
  instrument->counter_N[111]  = instrument->counter_P[111] = instrument->counter_P2[111] = 0;
  instrument->counter_AbsorbProp[111]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0110_DISCO_M1_position", _DISCO_M1_position_var._position_absolute, _DISCO_M1_position_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_position_setpos */

/* component DISCO_M1_rotation=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_rotation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_rotation_setpos] component DISCO_M1_rotation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_rotation_var._name, "DISCO_M1_rotation", 16384);
  stracpy(_DISCO_M1_rotation_var._type, "Arm", 16384);
  _DISCO_M1_rotation_var._index=112;
  int current_setpos_index = 112;
  /* component DISCO_M1_rotation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_position_var._rotation_absolute, _DISCO_M1_rotation_var._rotation_absolute);
    rot_transpose(_DISCO_M54_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_rotation_var._rotation_absolute, tr1, _DISCO_M1_rotation_var._rotation_relative);
    _DISCO_M1_rotation_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_rotation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_position_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_rotation_var._position_absolute = coords_add(_DISCO_M1_position_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M54_var._position_absolute, _DISCO_M1_rotation_var._position_absolute);
    _DISCO_M1_rotation_var._position_relative = rot_apply(_DISCO_M1_rotation_var._rotation_absolute, tc1);
  } /* DISCO_M1_rotation=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_rotation", _DISCO_M1_rotation_var._position_absolute, _DISCO_M1_rotation_var._rotation_absolute);
  instrument->_position_absolute[112] = _DISCO_M1_rotation_var._position_absolute;
  instrument->_position_relative[112] = _DISCO_M1_rotation_var._position_relative;
    _DISCO_M1_rotation_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_rotation_var._position_relative);
  instrument->counter_N[112]  = instrument->counter_P[112] = instrument->counter_P2[112] = 0;
  instrument->counter_AbsorbProp[112]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0111_DISCO_M1_rotation", _DISCO_M1_rotation_var._position_absolute, _DISCO_M1_rotation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_rotation_setpos */

/* component DISCO_mirror_m1=Mirror_elliptic() SETTING, POSITION/ROTATION */
int _DISCO_mirror_m1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_mirror_m1_setpos] component DISCO_mirror_m1=Mirror_elliptic() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_elliptic.comp:71]");
  stracpy(_DISCO_mirror_m1_var._name, "DISCO_mirror_m1", 16384);
  stracpy(_DISCO_mirror_m1_var._type, "Mirror_elliptic", 16384);
  _DISCO_mirror_m1_var._index=113;
  int current_setpos_index = 113;
  _DISCO_mirror_m1_var._parameters.x_a = 1.025;
  _DISCO_mirror_m1_var._parameters.y_b = 1.025;
  _DISCO_mirror_m1_var._parameters.z_c = 1.025;
  _DISCO_mirror_m1_var._parameters.zdepth = 0.2;
  _DISCO_mirror_m1_var._parameters.xwidth = 0.2;
  _DISCO_mirror_m1_var._parameters.R0 = 1;
  if("Be.txt" && strlen("Be.txt"))
    stracpy(_DISCO_mirror_m1_var._parameters.coating, "Be.txt" ? "Be.txt" : "", 16384);
  else 
  _DISCO_mirror_m1_var._parameters.coating[0]='\0';
  _DISCO_mirror_m1_var._parameters.length = 150e-3;
  _DISCO_mirror_m1_var._parameters.width = 150e-3;
  _DISCO_mirror_m1_var._parameters.radius = 0;


  /* component DISCO_mirror_m1=Mirror_elliptic() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ( 90 -4.5 ))*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_rotation_var._rotation_absolute, _DISCO_mirror_m1_var._rotation_absolute);
    rot_transpose(_DISCO_M54_var._rotation_absolute, tr1);
    rot_mul(_DISCO_mirror_m1_var._rotation_absolute, tr1, _DISCO_mirror_m1_var._rotation_relative);
    _DISCO_mirror_m1_var._rotation_is_identity =  rot_test_identity(_DISCO_mirror_m1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M1_rotation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_mirror_m1_var._position_absolute = coords_add(_DISCO_M1_rotation_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_M54_var._position_absolute, _DISCO_mirror_m1_var._position_absolute);
    _DISCO_mirror_m1_var._position_relative = rot_apply(_DISCO_mirror_m1_var._rotation_absolute, tc1);
  } /* DISCO_mirror_m1=Mirror_elliptic() AT ROTATED */
  DEBUG_COMPONENT("DISCO_mirror_m1", _DISCO_mirror_m1_var._position_absolute, _DISCO_mirror_m1_var._rotation_absolute);
  instrument->_position_absolute[113] = _DISCO_mirror_m1_var._position_absolute;
  instrument->_position_relative[113] = _DISCO_mirror_m1_var._position_relative;
    _DISCO_mirror_m1_var._position_relative_is_zero =  coords_test_zero(_DISCO_mirror_m1_var._position_relative);
  instrument->counter_N[113]  = instrument->counter_P[113] = instrument->counter_P2[113] = 0;
  instrument->counter_AbsorbProp[113]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0112_DISCO_mirror_m1", _DISCO_mirror_m1_var._position_absolute, _DISCO_mirror_m1_var._rotation_absolute, "Mirror_elliptic");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "x_a", "0", "1.025","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "y_b", "1.0", "1.025","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "z_c", "1.0", "1.025","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "xwidth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "coating", "Be.txt", "Be.txt", "char*");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "length", "0", "150e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "width", "0", "150e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0112_DISCO_mirror_m1", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_mirror_m1_setpos */

/* component DISCO_armm=Arm() SETTING, POSITION/ROTATION */
int _DISCO_armm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_armm_setpos] component DISCO_armm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_armm_var._name, "DISCO_armm", 16384);
  stracpy(_DISCO_armm_var._type, "Arm", 16384);
  _DISCO_armm_var._index=114;
  int current_setpos_index = 114;
  /* component DISCO_armm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ( 90 -4.5 ))*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_mirror_m1_var._rotation_absolute, _DISCO_armm_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_armm_var._rotation_absolute, tr1, _DISCO_armm_var._rotation_relative);
    _DISCO_armm_var._rotation_is_identity =  rot_test_identity(_DISCO_armm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_armm_var._position_absolute = coords_add(_DISCO_mirror_m1_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_armm_var._position_absolute);
    _DISCO_armm_var._position_relative = rot_apply(_DISCO_armm_var._rotation_absolute, tc1);
  } /* DISCO_armm=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_armm", _DISCO_armm_var._position_absolute, _DISCO_armm_var._rotation_absolute);
  instrument->_position_absolute[114] = _DISCO_armm_var._position_absolute;
  instrument->_position_relative[114] = _DISCO_armm_var._position_relative;
    _DISCO_armm_var._position_relative_is_zero =  coords_test_zero(_DISCO_armm_var._position_relative);
  instrument->counter_N[114]  = instrument->counter_P[114] = instrument->counter_P2[114] = 0;
  instrument->counter_AbsorbProp[114]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0113_DISCO_armm", _DISCO_armm_var._position_absolute, _DISCO_armm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_armm_setpos */

/* component DISCO_M1_arm_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M1_arm_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M1_arm_back_setpos] component DISCO_M1_arm_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M1_arm_back_var._name, "DISCO_M1_arm_back", 16384);
  stracpy(_DISCO_M1_arm_back_var._type, "Arm", 16384);
  _DISCO_M1_arm_back_var._index=115;
  int current_setpos_index = 115;
  /* component DISCO_M1_arm_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _DISCO_armm_var._rotation_absolute, _DISCO_M1_arm_back_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M1_arm_back_var._rotation_absolute, tr1, _DISCO_M1_arm_back_var._rotation_relative);
    _DISCO_M1_arm_back_var._rotation_is_identity =  rot_test_identity(_DISCO_M1_arm_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_armm_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M1_arm_back_var._position_absolute = coords_add(_DISCO_armm_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_M1_arm_back_var._position_absolute);
    _DISCO_M1_arm_back_var._position_relative = rot_apply(_DISCO_M1_arm_back_var._rotation_absolute, tc1);
  } /* DISCO_M1_arm_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M1_arm_back", _DISCO_M1_arm_back_var._position_absolute, _DISCO_M1_arm_back_var._rotation_absolute);
  instrument->_position_absolute[115] = _DISCO_M1_arm_back_var._position_absolute;
  instrument->_position_relative[115] = _DISCO_M1_arm_back_var._position_relative;
    _DISCO_M1_arm_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_M1_arm_back_var._position_relative);
  instrument->counter_N[115]  = instrument->counter_P[115] = instrument->counter_P2[115] = 0;
  instrument->counter_AbsorbProp[115]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0114_DISCO_M1_arm_back", _DISCO_M1_arm_back_var._position_absolute, _DISCO_M1_arm_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M1_arm_back_setpos */

/* component DISCO_Grating_position=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_position_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_position_setpos] component DISCO_Grating_position=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_position_var._name, "DISCO_Grating_position", 16384);
  stracpy(_DISCO_Grating_position_var._type, "Arm", 16384);
  _DISCO_Grating_position_var._index=116;
  int current_setpos_index = 116;
  /* component DISCO_Grating_position=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M1_arm_back_var._rotation_absolute, _DISCO_Grating_position_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_position_var._rotation_absolute, tr1, _DISCO_Grating_position_var._rotation_relative);
    _DISCO_Grating_position_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_position_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 834.35e-3);
    rot_transpose(_DISCO_M1_arm_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_position_var._position_absolute = coords_add(_DISCO_M1_arm_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_Grating_position_var._position_absolute);
    _DISCO_Grating_position_var._position_relative = rot_apply(_DISCO_Grating_position_var._rotation_absolute, tc1);
  } /* DISCO_Grating_position=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_position", _DISCO_Grating_position_var._position_absolute, _DISCO_Grating_position_var._rotation_absolute);
  instrument->_position_absolute[116] = _DISCO_Grating_position_var._position_absolute;
  instrument->_position_relative[116] = _DISCO_Grating_position_var._position_relative;
    _DISCO_Grating_position_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_position_var._position_relative);
  instrument->counter_N[116]  = instrument->counter_P[116] = instrument->counter_P2[116] = 0;
  instrument->counter_AbsorbProp[116]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0115_DISCO_Grating_position", _DISCO_Grating_position_var._position_absolute, _DISCO_Grating_position_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_position_setpos */

/* component DISCO_Grating_rotation=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_rotation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_rotation_setpos] component DISCO_Grating_rotation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_rotation_var._name, "DISCO_Grating_rotation", 16384);
  stracpy(_DISCO_Grating_rotation_var._type, "Arm", 16384);
  _DISCO_Grating_rotation_var._index=117;
  int current_setpos_index = 117;
  /* component DISCO_Grating_rotation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_position_var._rotation_absolute, _DISCO_Grating_rotation_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_rotation_var._rotation_absolute, tr1, _DISCO_Grating_rotation_var._rotation_relative);
    _DISCO_Grating_rotation_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_rotation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_position_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_rotation_var._position_absolute = coords_add(_DISCO_Grating_position_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_Grating_rotation_var._position_absolute);
    _DISCO_Grating_rotation_var._position_relative = rot_apply(_DISCO_Grating_rotation_var._rotation_absolute, tc1);
  } /* DISCO_Grating_rotation=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_rotation", _DISCO_Grating_rotation_var._position_absolute, _DISCO_Grating_rotation_var._rotation_absolute);
  instrument->_position_absolute[117] = _DISCO_Grating_rotation_var._position_absolute;
  instrument->_position_relative[117] = _DISCO_Grating_rotation_var._position_relative;
    _DISCO_Grating_rotation_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_rotation_var._position_relative);
  instrument->counter_N[117]  = instrument->counter_P[117] = instrument->counter_P2[117] = 0;
  instrument->counter_AbsorbProp[117]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0116_DISCO_Grating_rotation", _DISCO_Grating_rotation_var._position_absolute, _DISCO_Grating_rotation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_rotation_setpos */

/* component DISCO_Grating_rotation_lines_grating=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_rotation_lines_grating_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_rotation_lines_grating_setpos] component DISCO_Grating_rotation_lines_grating=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_rotation_lines_grating_var._name, "DISCO_Grating_rotation_lines_grating", 16384);
  stracpy(_DISCO_Grating_rotation_lines_grating_var._type, "Arm", 16384);
  _DISCO_Grating_rotation_lines_grating_var._index=118;
  int current_setpos_index = 118;
  /* component DISCO_Grating_rotation_lines_grating=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-90)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_rotation_var._rotation_absolute, _DISCO_Grating_rotation_lines_grating_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_rotation_lines_grating_var._rotation_absolute, tr1, _DISCO_Grating_rotation_lines_grating_var._rotation_relative);
    _DISCO_Grating_rotation_lines_grating_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_rotation_lines_grating_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_rotation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_rotation_lines_grating_var._position_absolute = coords_add(_DISCO_Grating_rotation_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_Grating_rotation_lines_grating_var._position_absolute);
    _DISCO_Grating_rotation_lines_grating_var._position_relative = rot_apply(_DISCO_Grating_rotation_lines_grating_var._rotation_absolute, tc1);
  } /* DISCO_Grating_rotation_lines_grating=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_rotation_lines_grating", _DISCO_Grating_rotation_lines_grating_var._position_absolute, _DISCO_Grating_rotation_lines_grating_var._rotation_absolute);
  instrument->_position_absolute[118] = _DISCO_Grating_rotation_lines_grating_var._position_absolute;
  instrument->_position_relative[118] = _DISCO_Grating_rotation_lines_grating_var._position_relative;
    _DISCO_Grating_rotation_lines_grating_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_rotation_lines_grating_var._position_relative);
  instrument->counter_N[118]  = instrument->counter_P[118] = instrument->counter_P2[118] = 0;
  instrument->counter_AbsorbProp[118]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0117_DISCO_Grating_rotation_lines_grating", _DISCO_Grating_rotation_lines_grating_var._position_absolute, _DISCO_Grating_rotation_lines_grating_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_rotation_lines_grating_setpos */

/* component DISCO_Grating_rotation_nine_degrees=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_rotation_nine_degrees_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_rotation_nine_degrees_setpos] component DISCO_Grating_rotation_nine_degrees=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_rotation_nine_degrees_var._name, "DISCO_Grating_rotation_nine_degrees", 16384);
  stracpy(_DISCO_Grating_rotation_nine_degrees_var._type, "Arm", 16384);
  _DISCO_Grating_rotation_nine_degrees_var._index=119;
  int current_setpos_index = 119;
  /* component DISCO_Grating_rotation_nine_degrees=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-9)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_rotation_lines_grating_var._rotation_absolute, _DISCO_Grating_rotation_nine_degrees_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_rotation_nine_degrees_var._rotation_absolute, tr1, _DISCO_Grating_rotation_nine_degrees_var._rotation_relative);
    _DISCO_Grating_rotation_nine_degrees_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_rotation_nine_degrees_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_rotation_lines_grating_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_rotation_nine_degrees_var._position_absolute = coords_add(_DISCO_Grating_rotation_lines_grating_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_Grating_rotation_nine_degrees_var._position_absolute);
    _DISCO_Grating_rotation_nine_degrees_var._position_relative = rot_apply(_DISCO_Grating_rotation_nine_degrees_var._rotation_absolute, tc1);
  } /* DISCO_Grating_rotation_nine_degrees=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_rotation_nine_degrees", _DISCO_Grating_rotation_nine_degrees_var._position_absolute, _DISCO_Grating_rotation_nine_degrees_var._rotation_absolute);
  instrument->_position_absolute[119] = _DISCO_Grating_rotation_nine_degrees_var._position_absolute;
  instrument->_position_relative[119] = _DISCO_Grating_rotation_nine_degrees_var._position_relative;
    _DISCO_Grating_rotation_nine_degrees_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_rotation_nine_degrees_var._position_relative);
  instrument->counter_N[119]  = instrument->counter_P[119] = instrument->counter_P2[119] = 0;
  instrument->counter_AbsorbProp[119]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0118_DISCO_Grating_rotation_nine_degrees", _DISCO_Grating_rotation_nine_degrees_var._position_absolute, _DISCO_Grating_rotation_nine_degrees_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_rotation_nine_degrees_setpos */

/* component DISCO_reflective_grating=Grating_reflect() SETTING, POSITION/ROTATION */
int _DISCO_reflective_grating_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_reflective_grating_setpos] component DISCO_reflective_grating=Grating_reflect() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Grating_reflect.comp:79]");
  stracpy(_DISCO_reflective_grating_var._name, "DISCO_reflective_grating", 16384);
  stracpy(_DISCO_reflective_grating_var._type, "Grating_reflect", 16384);
  _DISCO_reflective_grating_var._index=120;
  int current_setpos_index = 120;
  _DISCO_reflective_grating_var._parameters.d_phi = 1;
  _DISCO_reflective_grating_var._parameters.R0 = 1;
  _DISCO_reflective_grating_var._parameters.rho_l = DISCO_number_lines_per_mm;
  _DISCO_reflective_grating_var._parameters.order = DISCO_order;
  _DISCO_reflective_grating_var._parameters.phi0 = 0;
  _DISCO_reflective_grating_var._parameters.zdepth = 102e-3;
  _DISCO_reflective_grating_var._parameters.xwidth = 102e-3;
  _DISCO_reflective_grating_var._parameters.verbose = 0;


  /* component DISCO_reflective_grating=Grating_reflect() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (DISCO_theta_calculated)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_rotation_nine_degrees_var._rotation_absolute, _DISCO_reflective_grating_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_DISCO_reflective_grating_var._rotation_absolute, tr1, _DISCO_reflective_grating_var._rotation_relative);
    _DISCO_reflective_grating_var._rotation_is_identity =  rot_test_identity(_DISCO_reflective_grating_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_rotation_nine_degrees_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_reflective_grating_var._position_absolute = coords_add(_DISCO_Grating_rotation_nine_degrees_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m1_var._position_absolute, _DISCO_reflective_grating_var._position_absolute);
    _DISCO_reflective_grating_var._position_relative = rot_apply(_DISCO_reflective_grating_var._rotation_absolute, tc1);
  } /* DISCO_reflective_grating=Grating_reflect() AT ROTATED */
  DEBUG_COMPONENT("DISCO_reflective_grating", _DISCO_reflective_grating_var._position_absolute, _DISCO_reflective_grating_var._rotation_absolute);
  instrument->_position_absolute[120] = _DISCO_reflective_grating_var._position_absolute;
  instrument->_position_relative[120] = _DISCO_reflective_grating_var._position_relative;
    _DISCO_reflective_grating_var._position_relative_is_zero =  coords_test_zero(_DISCO_reflective_grating_var._position_relative);
  instrument->counter_N[120]  = instrument->counter_P[120] = instrument->counter_P2[120] = 0;
  instrument->counter_AbsorbProp[120]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0119_DISCO_reflective_grating", _DISCO_reflective_grating_var._position_absolute, _DISCO_reflective_grating_var._rotation_absolute, "Grating_reflect");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "d_phi", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "rho_l", "800", "DISCO_number_lines_per_mm","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "order", "0", "DISCO_order","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "phi0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "zdepth", "0.015", "102e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "xwidth", "0.136", "102e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0119_DISCO_reflective_grating", "verbose", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_reflective_grating_setpos */

/* component DISCO_Grating_rotation_lines_grating_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_rotation_lines_grating_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_rotation_lines_grating_back_setpos] component DISCO_Grating_rotation_lines_grating_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_rotation_lines_grating_back_var._name, "DISCO_Grating_rotation_lines_grating_back", 16384);
  stracpy(_DISCO_Grating_rotation_lines_grating_back_var._type, "Arm", 16384);
  _DISCO_Grating_rotation_lines_grating_back_var._index=121;
  int current_setpos_index = 121;
  /* component DISCO_Grating_rotation_lines_grating_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (90)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_reflective_grating_var._rotation_absolute, _DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute, tr1, _DISCO_Grating_rotation_lines_grating_back_var._rotation_relative);
    _DISCO_Grating_rotation_lines_grating_back_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_rotation_lines_grating_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_rotation_lines_grating_back_var._position_absolute = coords_add(_DISCO_reflective_grating_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_Grating_rotation_lines_grating_back_var._position_absolute);
    _DISCO_Grating_rotation_lines_grating_back_var._position_relative = rot_apply(_DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute, tc1);
  } /* DISCO_Grating_rotation_lines_grating_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_rotation_lines_grating_back", _DISCO_Grating_rotation_lines_grating_back_var._position_absolute, _DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute);
  instrument->_position_absolute[121] = _DISCO_Grating_rotation_lines_grating_back_var._position_absolute;
  instrument->_position_relative[121] = _DISCO_Grating_rotation_lines_grating_back_var._position_relative;
    _DISCO_Grating_rotation_lines_grating_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_rotation_lines_grating_back_var._position_relative);
  instrument->counter_N[121]  = instrument->counter_P[121] = instrument->counter_P2[121] = 0;
  instrument->counter_AbsorbProp[121]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0120_DISCO_Grating_rotation_lines_grating_back", _DISCO_Grating_rotation_lines_grating_back_var._position_absolute, _DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_rotation_lines_grating_back_setpos */

/* component DISCO_Grating_arm_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_arm_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_arm_back_setpos] component DISCO_Grating_arm_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_arm_back_var._name, "DISCO_Grating_arm_back", 16384);
  stracpy(_DISCO_Grating_arm_back_var._type, "Arm", 16384);
  _DISCO_Grating_arm_back_var._index=122;
  int current_setpos_index = 122;
  /* component DISCO_Grating_arm_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute, _DISCO_Grating_arm_back_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_arm_back_var._rotation_absolute, tr1, _DISCO_Grating_arm_back_var._rotation_relative);
    _DISCO_Grating_arm_back_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_arm_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_rotation_lines_grating_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_arm_back_var._position_absolute = coords_add(_DISCO_Grating_rotation_lines_grating_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_Grating_arm_back_var._position_absolute);
    _DISCO_Grating_arm_back_var._position_relative = rot_apply(_DISCO_Grating_arm_back_var._rotation_absolute, tc1);
  } /* DISCO_Grating_arm_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_arm_back", _DISCO_Grating_arm_back_var._position_absolute, _DISCO_Grating_arm_back_var._rotation_absolute);
  instrument->_position_absolute[122] = _DISCO_Grating_arm_back_var._position_absolute;
  instrument->_position_relative[122] = _DISCO_Grating_arm_back_var._position_relative;
    _DISCO_Grating_arm_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_arm_back_var._position_relative);
  instrument->counter_N[122]  = instrument->counter_P[122] = instrument->counter_P2[122] = 0;
  instrument->counter_AbsorbProp[122]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0121_DISCO_Grating_arm_back", _DISCO_Grating_arm_back_var._position_absolute, _DISCO_Grating_arm_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_arm_back_setpos */

/* component DISCO_Grating_arm_back_2=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_arm_back_2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_arm_back_2_setpos] component DISCO_Grating_arm_back_2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_arm_back_2_var._name, "DISCO_Grating_arm_back_2", 16384);
  stracpy(_DISCO_Grating_arm_back_2_var._type, "Arm", 16384);
  _DISCO_Grating_arm_back_2_var._index=123;
  int current_setpos_index = 123;
  /* component DISCO_Grating_arm_back_2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (180)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_arm_back_var._rotation_absolute, _DISCO_Grating_arm_back_2_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_arm_back_2_var._rotation_absolute, tr1, _DISCO_Grating_arm_back_2_var._rotation_relative);
    _DISCO_Grating_arm_back_2_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_arm_back_2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_arm_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_arm_back_2_var._position_absolute = coords_add(_DISCO_Grating_arm_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_Grating_arm_back_2_var._position_absolute);
    _DISCO_Grating_arm_back_2_var._position_relative = rot_apply(_DISCO_Grating_arm_back_2_var._rotation_absolute, tc1);
  } /* DISCO_Grating_arm_back_2=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_arm_back_2", _DISCO_Grating_arm_back_2_var._position_absolute, _DISCO_Grating_arm_back_2_var._rotation_absolute);
  instrument->_position_absolute[123] = _DISCO_Grating_arm_back_2_var._position_absolute;
  instrument->_position_relative[123] = _DISCO_Grating_arm_back_2_var._position_relative;
    _DISCO_Grating_arm_back_2_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_arm_back_2_var._position_relative);
  instrument->counter_N[123]  = instrument->counter_P[123] = instrument->counter_P2[123] = 0;
  instrument->counter_AbsorbProp[123]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0122_DISCO_Grating_arm_back_2", _DISCO_Grating_arm_back_2_var._position_absolute, _DISCO_Grating_arm_back_2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_arm_back_2_setpos */

/* component DISCO_Grating_arm_back_3=Arm() SETTING, POSITION/ROTATION */
int _DISCO_Grating_arm_back_3_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_Grating_arm_back_3_setpos] component DISCO_Grating_arm_back_3=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_Grating_arm_back_3_var._name, "DISCO_Grating_arm_back_3", 16384);
  stracpy(_DISCO_Grating_arm_back_3_var._type, "Arm", 16384);
  _DISCO_Grating_arm_back_3_var._index=124;
  int current_setpos_index = 124;
  /* component DISCO_Grating_arm_back_3=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- DISCO_theta_calculated -9)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_arm_back_2_var._rotation_absolute, _DISCO_Grating_arm_back_3_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_Grating_arm_back_3_var._rotation_absolute, tr1, _DISCO_Grating_arm_back_3_var._rotation_relative);
    _DISCO_Grating_arm_back_3_var._rotation_is_identity =  rot_test_identity(_DISCO_Grating_arm_back_3_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_Grating_arm_back_2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_Grating_arm_back_3_var._position_absolute = coords_add(_DISCO_Grating_arm_back_2_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_Grating_arm_back_3_var._position_absolute);
    _DISCO_Grating_arm_back_3_var._position_relative = rot_apply(_DISCO_Grating_arm_back_3_var._rotation_absolute, tc1);
  } /* DISCO_Grating_arm_back_3=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_Grating_arm_back_3", _DISCO_Grating_arm_back_3_var._position_absolute, _DISCO_Grating_arm_back_3_var._rotation_absolute);
  instrument->_position_absolute[124] = _DISCO_Grating_arm_back_3_var._position_absolute;
  instrument->_position_relative[124] = _DISCO_Grating_arm_back_3_var._position_relative;
    _DISCO_Grating_arm_back_3_var._position_relative_is_zero =  coords_test_zero(_DISCO_Grating_arm_back_3_var._position_relative);
  instrument->counter_N[124]  = instrument->counter_P[124] = instrument->counter_P2[124] = 0;
  instrument->counter_AbsorbProp[124]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0123_DISCO_Grating_arm_back_3", _DISCO_Grating_arm_back_3_var._position_absolute, _DISCO_Grating_arm_back_3_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_Grating_arm_back_3_setpos */

/* component DISCO_M22_location=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M22_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M22_location_setpos] component DISCO_M22_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M22_location_var._name, "DISCO_M22_location", 16384);
  stracpy(_DISCO_M22_location_var._type, "Arm", 16384);
  _DISCO_M22_location_var._index=125;
  int current_setpos_index = 125;
  /* component DISCO_M22_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_Grating_arm_back_3_var._rotation_absolute, _DISCO_M22_location_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M22_location_var._rotation_absolute, tr1, _DISCO_M22_location_var._rotation_relative);
    _DISCO_M22_location_var._rotation_is_identity =  rot_test_identity(_DISCO_M22_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 749.1e-3);
    rot_transpose(_DISCO_Grating_arm_back_3_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M22_location_var._position_absolute = coords_add(_DISCO_Grating_arm_back_3_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_M22_location_var._position_absolute);
    _DISCO_M22_location_var._position_relative = rot_apply(_DISCO_M22_location_var._rotation_absolute, tc1);
  } /* DISCO_M22_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M22_location", _DISCO_M22_location_var._position_absolute, _DISCO_M22_location_var._rotation_absolute);
  instrument->_position_absolute[125] = _DISCO_M22_location_var._position_absolute;
  instrument->_position_relative[125] = _DISCO_M22_location_var._position_relative;
    _DISCO_M22_location_var._position_relative_is_zero =  coords_test_zero(_DISCO_M22_location_var._position_relative);
  instrument->counter_N[125]  = instrument->counter_P[125] = instrument->counter_P2[125] = 0;
  instrument->counter_AbsorbProp[125]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0124_DISCO_M22_location", _DISCO_M22_location_var._position_absolute, _DISCO_M22_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M22_location_setpos */

/* component DISCO_M22_rotated=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M22_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M22_rotated_setpos] component DISCO_M22_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M22_rotated_var._name, "DISCO_M22_rotated", 16384);
  stracpy(_DISCO_M22_rotated_var._type, "Arm", 16384);
  _DISCO_M22_rotated_var._index=126;
  int current_setpos_index = 126;
  /* component DISCO_M22_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DISCO_M22_location_var._rotation_absolute, _DISCO_M22_rotated_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M22_rotated_var._rotation_absolute, tr1, _DISCO_M22_rotated_var._rotation_relative);
    _DISCO_M22_rotated_var._rotation_is_identity =  rot_test_identity(_DISCO_M22_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M22_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M22_rotated_var._position_absolute = coords_add(_DISCO_M22_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_M22_rotated_var._position_absolute);
    _DISCO_M22_rotated_var._position_relative = rot_apply(_DISCO_M22_rotated_var._rotation_absolute, tc1);
  } /* DISCO_M22_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M22_rotated", _DISCO_M22_rotated_var._position_absolute, _DISCO_M22_rotated_var._rotation_absolute);
  instrument->_position_absolute[126] = _DISCO_M22_rotated_var._position_absolute;
  instrument->_position_relative[126] = _DISCO_M22_rotated_var._position_relative;
    _DISCO_M22_rotated_var._position_relative_is_zero =  coords_test_zero(_DISCO_M22_rotated_var._position_relative);
  instrument->counter_N[126]  = instrument->counter_P[126] = instrument->counter_P2[126] = 0;
  instrument->counter_AbsorbProp[126]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0125_DISCO_M22_rotated", _DISCO_M22_rotated_var._position_absolute, _DISCO_M22_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M22_rotated_setpos */

/* component DISCO_mirror_m2=Mirror_elliptic() SETTING, POSITION/ROTATION */
int _DISCO_mirror_m2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_mirror_m2_setpos] component DISCO_mirror_m2=Mirror_elliptic() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_elliptic.comp:71]");
  stracpy(_DISCO_mirror_m2_var._name, "DISCO_mirror_m2", 16384);
  stracpy(_DISCO_mirror_m2_var._type, "Mirror_elliptic", 16384);
  _DISCO_mirror_m2_var._index=127;
  int current_setpos_index = 127;
  _DISCO_mirror_m2_var._parameters.x_a = 0.925;
  _DISCO_mirror_m2_var._parameters.y_b = 0.925;
  _DISCO_mirror_m2_var._parameters.z_c = 0.925;
  _DISCO_mirror_m2_var._parameters.zdepth = 0.2;
  _DISCO_mirror_m2_var._parameters.xwidth = 0.2;
  _DISCO_mirror_m2_var._parameters.R0 = 1;
  if("Be.txt" && strlen("Be.txt"))
    stracpy(_DISCO_mirror_m2_var._parameters.coating, "Be.txt" ? "Be.txt" : "", 16384);
  else 
  _DISCO_mirror_m2_var._parameters.coating[0]='\0';
  _DISCO_mirror_m2_var._parameters.length = 150e-3;
  _DISCO_mirror_m2_var._parameters.width = 150e-3;
  _DISCO_mirror_m2_var._parameters.radius = 0;


  /* component DISCO_mirror_m2=Mirror_elliptic() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ( 90 -5 ))*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M22_rotated_var._rotation_absolute, _DISCO_mirror_m2_var._rotation_absolute);
    rot_transpose(_DISCO_reflective_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_mirror_m2_var._rotation_absolute, tr1, _DISCO_mirror_m2_var._rotation_relative);
    _DISCO_mirror_m2_var._rotation_is_identity =  rot_test_identity(_DISCO_mirror_m2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_M22_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_mirror_m2_var._position_absolute = coords_add(_DISCO_M22_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_reflective_grating_var._position_absolute, _DISCO_mirror_m2_var._position_absolute);
    _DISCO_mirror_m2_var._position_relative = rot_apply(_DISCO_mirror_m2_var._rotation_absolute, tc1);
  } /* DISCO_mirror_m2=Mirror_elliptic() AT ROTATED */
  DEBUG_COMPONENT("DISCO_mirror_m2", _DISCO_mirror_m2_var._position_absolute, _DISCO_mirror_m2_var._rotation_absolute);
  instrument->_position_absolute[127] = _DISCO_mirror_m2_var._position_absolute;
  instrument->_position_relative[127] = _DISCO_mirror_m2_var._position_relative;
    _DISCO_mirror_m2_var._position_relative_is_zero =  coords_test_zero(_DISCO_mirror_m2_var._position_relative);
  instrument->counter_N[127]  = instrument->counter_P[127] = instrument->counter_P2[127] = 0;
  instrument->counter_AbsorbProp[127]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0126_DISCO_mirror_m2", _DISCO_mirror_m2_var._position_absolute, _DISCO_mirror_m2_var._rotation_absolute, "Mirror_elliptic");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "x_a", "0", "0.925","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "y_b", "1.0", "0.925","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "z_c", "1.0", "0.925","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "xwidth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "coating", "Be.txt", "Be.txt", "char*");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "length", "0", "150e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "width", "0", "150e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0126_DISCO_mirror_m2", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_mirror_m2_setpos */

/* component DISCO_arm2=Arm() SETTING, POSITION/ROTATION */
int _DISCO_arm2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_arm2_setpos] component DISCO_arm2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_arm2_var._name, "DISCO_arm2", 16384);
  stracpy(_DISCO_arm2_var._type, "Arm", 16384);
  _DISCO_arm2_var._index=128;
  int current_setpos_index = 128;
  /* component DISCO_arm2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ( 90 -5 ))*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_mirror_m2_var._rotation_absolute, _DISCO_arm2_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_arm2_var._rotation_absolute, tr1, _DISCO_arm2_var._rotation_relative);
    _DISCO_arm2_var._rotation_is_identity =  rot_test_identity(_DISCO_arm2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_mirror_m2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_arm2_var._position_absolute = coords_add(_DISCO_mirror_m2_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m2_var._position_absolute, _DISCO_arm2_var._position_absolute);
    _DISCO_arm2_var._position_relative = rot_apply(_DISCO_arm2_var._rotation_absolute, tc1);
  } /* DISCO_arm2=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_arm2", _DISCO_arm2_var._position_absolute, _DISCO_arm2_var._rotation_absolute);
  instrument->_position_absolute[128] = _DISCO_arm2_var._position_absolute;
  instrument->_position_relative[128] = _DISCO_arm2_var._position_relative;
    _DISCO_arm2_var._position_relative_is_zero =  coords_test_zero(_DISCO_arm2_var._position_relative);
  instrument->counter_N[128]  = instrument->counter_P[128] = instrument->counter_P2[128] = 0;
  instrument->counter_AbsorbProp[128]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0127_DISCO_arm2", _DISCO_arm2_var._position_absolute, _DISCO_arm2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_arm2_setpos */

/* component DISCO_M44_arm_back=Arm() SETTING, POSITION/ROTATION */
int _DISCO_M44_arm_back_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_M44_arm_back_setpos] component DISCO_M44_arm_back=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_M44_arm_back_var._name, "DISCO_M44_arm_back", 16384);
  stracpy(_DISCO_M44_arm_back_var._type, "Arm", 16384);
  _DISCO_M44_arm_back_var._index=129;
  int current_setpos_index = 129;
  /* component DISCO_M44_arm_back=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _DISCO_arm2_var._rotation_absolute, _DISCO_M44_arm_back_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_M44_arm_back_var._rotation_absolute, tr1, _DISCO_M44_arm_back_var._rotation_relative);
    _DISCO_M44_arm_back_var._rotation_is_identity =  rot_test_identity(_DISCO_M44_arm_back_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_arm2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_M44_arm_back_var._position_absolute = coords_add(_DISCO_arm2_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m2_var._position_absolute, _DISCO_M44_arm_back_var._position_absolute);
    _DISCO_M44_arm_back_var._position_relative = rot_apply(_DISCO_M44_arm_back_var._rotation_absolute, tc1);
  } /* DISCO_M44_arm_back=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_M44_arm_back", _DISCO_M44_arm_back_var._position_absolute, _DISCO_M44_arm_back_var._rotation_absolute);
  instrument->_position_absolute[129] = _DISCO_M44_arm_back_var._position_absolute;
  instrument->_position_relative[129] = _DISCO_M44_arm_back_var._position_relative;
    _DISCO_M44_arm_back_var._position_relative_is_zero =  coords_test_zero(_DISCO_M44_arm_back_var._position_relative);
  instrument->counter_N[129]  = instrument->counter_P[129] = instrument->counter_P2[129] = 0;
  instrument->counter_AbsorbProp[129]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0128_DISCO_M44_arm_back", _DISCO_M44_arm_back_var._position_absolute, _DISCO_M44_arm_back_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_M44_arm_back_setpos */

/* component DISCO_arm3=Arm() SETTING, POSITION/ROTATION */
int _DISCO_arm3_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_arm3_setpos] component DISCO_arm3=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DISCO_arm3_var._name, "DISCO_arm3", 16384);
  stracpy(_DISCO_arm3_var._type, "Arm", 16384);
  _DISCO_arm3_var._index=130;
  int current_setpos_index = 130;
  /* component DISCO_arm3=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DISCO_M44_arm_back_var._rotation_absolute, _DISCO_arm3_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_arm3_var._rotation_absolute, tr1, _DISCO_arm3_var._rotation_relative);
    _DISCO_arm3_var._rotation_is_identity =  rot_test_identity(_DISCO_arm3_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 760.33e-3);
    rot_transpose(_DISCO_M44_arm_back_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_arm3_var._position_absolute = coords_add(_DISCO_M44_arm_back_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m2_var._position_absolute, _DISCO_arm3_var._position_absolute);
    _DISCO_arm3_var._position_relative = rot_apply(_DISCO_arm3_var._rotation_absolute, tc1);
  } /* DISCO_arm3=Arm() AT ROTATED */
  DEBUG_COMPONENT("DISCO_arm3", _DISCO_arm3_var._position_absolute, _DISCO_arm3_var._rotation_absolute);
  instrument->_position_absolute[130] = _DISCO_arm3_var._position_absolute;
  instrument->_position_relative[130] = _DISCO_arm3_var._position_relative;
    _DISCO_arm3_var._position_relative_is_zero =  coords_test_zero(_DISCO_arm3_var._position_relative);
  instrument->counter_N[130]  = instrument->counter_P[130] = instrument->counter_P2[130] = 0;
  instrument->counter_AbsorbProp[130]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0129_DISCO_arm3", _DISCO_arm3_var._position_absolute, _DISCO_arm3_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_arm3_setpos */

/* component DISCO_psd_before_slit=PSD_monitor() SETTING, POSITION/ROTATION */
int _DISCO_psd_before_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_psd_before_slit_setpos] component DISCO_psd_before_slit=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_DISCO_psd_before_slit_var._name, "DISCO_psd_before_slit", 16384);
  stracpy(_DISCO_psd_before_slit_var._type, "PSD_monitor", 16384);
  _DISCO_psd_before_slit_var._index=131;
  int current_setpos_index = 131;
  if("DISCO_psd_before_slit.dat" && strlen("DISCO_psd_before_slit.dat"))
    stracpy(_DISCO_psd_before_slit_var._parameters.filename, "DISCO_psd_before_slit.dat" ? "DISCO_psd_before_slit.dat" : "", 16384);
  else 
  _DISCO_psd_before_slit_var._parameters.filename[0]='\0';
  _DISCO_psd_before_slit_var._parameters.xwidth = 130e-3;
  _DISCO_psd_before_slit_var._parameters.yheight = 130e-3;
  _DISCO_psd_before_slit_var._parameters.radius = 0;
  _DISCO_psd_before_slit_var._parameters.restore_xray = 1;
  _DISCO_psd_before_slit_var._parameters.nowritefile = 0;
  _DISCO_psd_before_slit_var._parameters.nx = 100;
  _DISCO_psd_before_slit_var._parameters.ny = 100;
  _DISCO_psd_before_slit_var._parameters.nr = 0;


  /* component DISCO_psd_before_slit=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_arm3_var._rotation_absolute, _DISCO_psd_before_slit_var._rotation_absolute);
    rot_transpose(_DISCO_mirror_m2_var._rotation_absolute, tr1);
    rot_mul(_DISCO_psd_before_slit_var._rotation_absolute, tr1, _DISCO_psd_before_slit_var._rotation_relative);
    _DISCO_psd_before_slit_var._rotation_is_identity =  rot_test_identity(_DISCO_psd_before_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_arm3_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_psd_before_slit_var._position_absolute = coords_add(_DISCO_arm3_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_mirror_m2_var._position_absolute, _DISCO_psd_before_slit_var._position_absolute);
    _DISCO_psd_before_slit_var._position_relative = rot_apply(_DISCO_psd_before_slit_var._rotation_absolute, tc1);
  } /* DISCO_psd_before_slit=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("DISCO_psd_before_slit", _DISCO_psd_before_slit_var._position_absolute, _DISCO_psd_before_slit_var._rotation_absolute);
  instrument->_position_absolute[131] = _DISCO_psd_before_slit_var._position_absolute;
  instrument->_position_relative[131] = _DISCO_psd_before_slit_var._position_relative;
    _DISCO_psd_before_slit_var._position_relative_is_zero =  coords_test_zero(_DISCO_psd_before_slit_var._position_relative);
  instrument->counter_N[131]  = instrument->counter_P[131] = instrument->counter_P2[131] = 0;
  instrument->counter_AbsorbProp[131]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0130_DISCO_psd_before_slit", _DISCO_psd_before_slit_var._position_absolute, _DISCO_psd_before_slit_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "filename", 0, "DISCO_psd_before_slit.dat", "char*");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "xwidth", "0.05", "130e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "yheight", "0.05", "130e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0130_DISCO_psd_before_slit", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_psd_before_slit_setpos */

/* component DISCO_slit=Slit() SETTING, POSITION/ROTATION */
int _DISCO_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_slit_setpos] component DISCO_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_DISCO_slit_var._name, "DISCO_slit", 16384);
  stracpy(_DISCO_slit_var._type, "Slit", 16384);
  _DISCO_slit_var._index=132;
  int current_setpos_index = 132;
  _DISCO_slit_var._parameters.xmin = 0;
  _DISCO_slit_var._parameters.xmax = 0;
  _DISCO_slit_var._parameters.ymin = 0;
  _DISCO_slit_var._parameters.ymax = 0;
  _DISCO_slit_var._parameters.radius = 0;
  _DISCO_slit_var._parameters.xwidth = 13.5e-6;
  _DISCO_slit_var._parameters.yheight = 0.01;
  _DISCO_slit_var._parameters.dist = 0;
  _DISCO_slit_var._parameters.focus_xw = 0;
  _DISCO_slit_var._parameters.focus_yh = 0;
  _DISCO_slit_var._parameters.focus_x0 = 0;
  _DISCO_slit_var._parameters.focus_y0 = 0;

  /* component DISCO_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_psd_before_slit_var._rotation_absolute, _DISCO_slit_var._rotation_absolute);
    rot_transpose(_DISCO_psd_before_slit_var._rotation_absolute, tr1);
    rot_mul(_DISCO_slit_var._rotation_absolute, tr1, _DISCO_slit_var._rotation_relative);
    _DISCO_slit_var._rotation_is_identity =  rot_test_identity(_DISCO_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_psd_before_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_slit_var._position_absolute = coords_add(_DISCO_psd_before_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_psd_before_slit_var._position_absolute, _DISCO_slit_var._position_absolute);
    _DISCO_slit_var._position_relative = rot_apply(_DISCO_slit_var._rotation_absolute, tc1);
  } /* DISCO_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("DISCO_slit", _DISCO_slit_var._position_absolute, _DISCO_slit_var._rotation_absolute);
  instrument->_position_absolute[132] = _DISCO_slit_var._position_absolute;
  instrument->_position_relative[132] = _DISCO_slit_var._position_relative;
    _DISCO_slit_var._position_relative_is_zero =  coords_test_zero(_DISCO_slit_var._position_relative);
  instrument->counter_N[132]  = instrument->counter_P[132] = instrument->counter_P2[132] = 0;
  instrument->counter_AbsorbProp[132]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0131_DISCO_slit", _DISCO_slit_var._position_absolute, _DISCO_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "xwidth", "0.001", "13.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0131_DISCO_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_slit_setpos */

/* component DISCO_psd_monitor=PSD_monitor() SETTING, POSITION/ROTATION */
int _DISCO_psd_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_psd_monitor_setpos] component DISCO_psd_monitor=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_DISCO_psd_monitor_var._name, "DISCO_psd_monitor", 16384);
  stracpy(_DISCO_psd_monitor_var._type, "PSD_monitor", 16384);
  _DISCO_psd_monitor_var._index=133;
  int current_setpos_index = 133;
  if("DISCO_psd" && strlen("DISCO_psd"))
    stracpy(_DISCO_psd_monitor_var._parameters.filename, "DISCO_psd" ? "DISCO_psd" : "", 16384);
  else 
  _DISCO_psd_monitor_var._parameters.filename[0]='\0';
  _DISCO_psd_monitor_var._parameters.xwidth = 0.002;
  _DISCO_psd_monitor_var._parameters.yheight = 0.02;
  _DISCO_psd_monitor_var._parameters.radius = 0;
  _DISCO_psd_monitor_var._parameters.restore_xray = 1;
  _DISCO_psd_monitor_var._parameters.nowritefile = 0;
  _DISCO_psd_monitor_var._parameters.nx = 100;
  _DISCO_psd_monitor_var._parameters.ny = 100;
  _DISCO_psd_monitor_var._parameters.nr = 0;


  /* component DISCO_psd_monitor=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_slit_var._rotation_absolute, _DISCO_psd_monitor_var._rotation_absolute);
    rot_transpose(_DISCO_slit_var._rotation_absolute, tr1);
    rot_mul(_DISCO_psd_monitor_var._rotation_absolute, tr1, _DISCO_psd_monitor_var._rotation_relative);
    _DISCO_psd_monitor_var._rotation_is_identity =  rot_test_identity(_DISCO_psd_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 10e-3);
    rot_transpose(_DISCO_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_psd_monitor_var._position_absolute = coords_add(_DISCO_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_slit_var._position_absolute, _DISCO_psd_monitor_var._position_absolute);
    _DISCO_psd_monitor_var._position_relative = rot_apply(_DISCO_psd_monitor_var._rotation_absolute, tc1);
  } /* DISCO_psd_monitor=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("DISCO_psd_monitor", _DISCO_psd_monitor_var._position_absolute, _DISCO_psd_monitor_var._rotation_absolute);
  instrument->_position_absolute[133] = _DISCO_psd_monitor_var._position_absolute;
  instrument->_position_relative[133] = _DISCO_psd_monitor_var._position_relative;
    _DISCO_psd_monitor_var._position_relative_is_zero =  coords_test_zero(_DISCO_psd_monitor_var._position_relative);
  instrument->counter_N[133]  = instrument->counter_P[133] = instrument->counter_P2[133] = 0;
  instrument->counter_AbsorbProp[133]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0132_DISCO_psd_monitor", _DISCO_psd_monitor_var._position_absolute, _DISCO_psd_monitor_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "filename", 0, "DISCO_psd", "char*");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "xwidth", "0.05", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "yheight", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0132_DISCO_psd_monitor", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_psd_monitor_setpos */

/* component DISCO_psd_giant_after_grating=PSD_monitor() SETTING, POSITION/ROTATION */
int _DISCO_psd_giant_after_grating_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_psd_giant_after_grating_setpos] component DISCO_psd_giant_after_grating=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_DISCO_psd_giant_after_grating_var._name, "DISCO_psd_giant_after_grating", 16384);
  stracpy(_DISCO_psd_giant_after_grating_var._type, "PSD_monitor", 16384);
  _DISCO_psd_giant_after_grating_var._index=134;
  int current_setpos_index = 134;
  if("DISCO_psd_giant_after_grating" && strlen("DISCO_psd_giant_after_grating"))
    stracpy(_DISCO_psd_giant_after_grating_var._parameters.filename, "DISCO_psd_giant_after_grating" ? "DISCO_psd_giant_after_grating" : "", 16384);
  else 
  _DISCO_psd_giant_after_grating_var._parameters.filename[0]='\0';
  _DISCO_psd_giant_after_grating_var._parameters.xwidth = 2e-3;
  _DISCO_psd_giant_after_grating_var._parameters.yheight = 1e-2;
  _DISCO_psd_giant_after_grating_var._parameters.radius = 0;
  _DISCO_psd_giant_after_grating_var._parameters.restore_xray = 1;
  _DISCO_psd_giant_after_grating_var._parameters.nowritefile = 0;
  _DISCO_psd_giant_after_grating_var._parameters.nx = 2001;
  _DISCO_psd_giant_after_grating_var._parameters.ny = 1;
  _DISCO_psd_giant_after_grating_var._parameters.nr = 0;


  /* component DISCO_psd_giant_after_grating=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_psd_monitor_var._rotation_absolute, _DISCO_psd_giant_after_grating_var._rotation_absolute);
    rot_transpose(_DISCO_psd_monitor_var._rotation_absolute, tr1);
    rot_mul(_DISCO_psd_giant_after_grating_var._rotation_absolute, tr1, _DISCO_psd_giant_after_grating_var._rotation_relative);
    _DISCO_psd_giant_after_grating_var._rotation_is_identity =  rot_test_identity(_DISCO_psd_giant_after_grating_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_psd_monitor_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_psd_giant_after_grating_var._position_absolute = coords_add(_DISCO_psd_monitor_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_psd_monitor_var._position_absolute, _DISCO_psd_giant_after_grating_var._position_absolute);
    _DISCO_psd_giant_after_grating_var._position_relative = rot_apply(_DISCO_psd_giant_after_grating_var._rotation_absolute, tc1);
  } /* DISCO_psd_giant_after_grating=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("DISCO_psd_giant_after_grating", _DISCO_psd_giant_after_grating_var._position_absolute, _DISCO_psd_giant_after_grating_var._rotation_absolute);
  instrument->_position_absolute[134] = _DISCO_psd_giant_after_grating_var._position_absolute;
  instrument->_position_relative[134] = _DISCO_psd_giant_after_grating_var._position_relative;
    _DISCO_psd_giant_after_grating_var._position_relative_is_zero =  coords_test_zero(_DISCO_psd_giant_after_grating_var._position_relative);
  instrument->counter_N[134]  = instrument->counter_P[134] = instrument->counter_P2[134] = 0;
  instrument->counter_AbsorbProp[134]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", _DISCO_psd_giant_after_grating_var._position_absolute, _DISCO_psd_giant_after_grating_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "filename", 0, "DISCO_psd_giant_after_grating", "char*");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "xwidth", "0.05", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "yheight", "0.05", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "nx", "90", "2001","int");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "ny", "90", "1","int");
        mccomp_param_nexus(nxhandle,"0133_DISCO_psd_giant_after_grating", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_psd_giant_after_grating_setpos */

/* component DISCO_e_monitor=Monitor_nD() SETTING, POSITION/ROTATION */
int _DISCO_e_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_e_monitor_setpos] component DISCO_e_monitor=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DISCO_e_monitor_var._name, "DISCO_e_monitor", 16384);
  stracpy(_DISCO_e_monitor_var._type, "Monitor_nD", 16384);
  _DISCO_e_monitor_var._index=135;
  int current_setpos_index = 135;
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_e_monitor_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.user9[0]='\0';
  _DISCO_e_monitor_var._parameters.xwidth = 2e-3;
  _DISCO_e_monitor_var._parameters.yheight = 1e-2;
  _DISCO_e_monitor_var._parameters.zdepth = 0;
  _DISCO_e_monitor_var._parameters.bins = 0;
  _DISCO_e_monitor_var._parameters.min = -1e40;
  _DISCO_e_monitor_var._parameters.max = 1e40;
  _DISCO_e_monitor_var._parameters.restore_xray = 1;
  _DISCO_e_monitor_var._parameters.radius = 0;
  if("energy  bins=500 limits=[0 0.007],  x  bins=500" && strlen("energy  bins=500 limits=[0 0.007],  x  bins=500"))
    stracpy(_DISCO_e_monitor_var._parameters.options, "energy  bins=500 limits=[0 0.007],  x  bins=500" ? "energy  bins=500 limits=[0 0.007],  x  bins=500" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.options[0]='\0';
  if("DISCO_e_monitor" && strlen("DISCO_e_monitor"))
    stracpy(_DISCO_e_monitor_var._parameters.filename, "DISCO_e_monitor" ? "DISCO_e_monitor" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.geometry[0]='\0';
  _DISCO_e_monitor_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_e_monitor_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_e_monitor_var._parameters.username9[0]='\0';


  /* component DISCO_e_monitor=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_psd_giant_after_grating_var._rotation_absolute, _DISCO_e_monitor_var._rotation_absolute);
    rot_transpose(_DISCO_psd_giant_after_grating_var._rotation_absolute, tr1);
    rot_mul(_DISCO_e_monitor_var._rotation_absolute, tr1, _DISCO_e_monitor_var._rotation_relative);
    _DISCO_e_monitor_var._rotation_is_identity =  rot_test_identity(_DISCO_e_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_psd_giant_after_grating_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_e_monitor_var._position_absolute = coords_add(_DISCO_psd_giant_after_grating_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_psd_giant_after_grating_var._position_absolute, _DISCO_e_monitor_var._position_absolute);
    _DISCO_e_monitor_var._position_relative = rot_apply(_DISCO_e_monitor_var._rotation_absolute, tc1);
  } /* DISCO_e_monitor=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DISCO_e_monitor", _DISCO_e_monitor_var._position_absolute, _DISCO_e_monitor_var._rotation_absolute);
  instrument->_position_absolute[135] = _DISCO_e_monitor_var._position_absolute;
  instrument->_position_relative[135] = _DISCO_e_monitor_var._position_relative;
    _DISCO_e_monitor_var._position_relative_is_zero =  coords_test_zero(_DISCO_e_monitor_var._position_relative);
  instrument->counter_N[135]  = instrument->counter_P[135] = instrument->counter_P2[135] = 0;
  instrument->counter_AbsorbProp[135]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0134_DISCO_e_monitor", _DISCO_e_monitor_var._position_absolute, _DISCO_e_monitor_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "options", "NULL", "energy  bins=500 limits=[0 0.007],  x  bins=500", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "filename", "NULL", "DISCO_e_monitor", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0134_DISCO_e_monitor", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_e_monitor_setpos */

/* component DISCO_w_monitor=Monitor_nD() SETTING, POSITION/ROTATION */
int _DISCO_w_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DISCO_w_monitor_setpos] component DISCO_w_monitor=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DISCO_w_monitor_var._name, "DISCO_w_monitor", 16384);
  stracpy(_DISCO_w_monitor_var._type, "Monitor_nD", 16384);
  _DISCO_w_monitor_var._index=136;
  int current_setpos_index = 136;
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DISCO_w_monitor_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.user9[0]='\0';
  _DISCO_w_monitor_var._parameters.xwidth = 2e-3;
  _DISCO_w_monitor_var._parameters.yheight = 1e-2;
  _DISCO_w_monitor_var._parameters.zdepth = 0;
  _DISCO_w_monitor_var._parameters.bins = 0;
  _DISCO_w_monitor_var._parameters.min = -1e40;
  _DISCO_w_monitor_var._parameters.max = 1e40;
  _DISCO_w_monitor_var._parameters.restore_xray = 1;
  _DISCO_w_monitor_var._parameters.radius = 0;
  if("wavelength  bins=500 limits=[1980 11000],  x  bins=500" && strlen("wavelength  bins=500 limits=[1980 11000],  x  bins=500"))
    stracpy(_DISCO_w_monitor_var._parameters.options, "wavelength  bins=500 limits=[1980 11000],  x  bins=500" ? "wavelength  bins=500 limits=[1980 11000],  x  bins=500" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.options[0]='\0';
  if("DISCO_w_monitor" && strlen("DISCO_w_monitor"))
    stracpy(_DISCO_w_monitor_var._parameters.filename, "DISCO_w_monitor" ? "DISCO_w_monitor" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.geometry[0]='\0';
  _DISCO_w_monitor_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DISCO_w_monitor_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DISCO_w_monitor_var._parameters.username9[0]='\0';


  /* component DISCO_w_monitor=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_e_monitor_var._rotation_absolute, _DISCO_w_monitor_var._rotation_absolute);
    rot_transpose(_DISCO_e_monitor_var._rotation_absolute, tr1);
    rot_mul(_DISCO_w_monitor_var._rotation_absolute, tr1, _DISCO_w_monitor_var._rotation_relative);
    _DISCO_w_monitor_var._rotation_is_identity =  rot_test_identity(_DISCO_w_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_e_monitor_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DISCO_w_monitor_var._position_absolute = coords_add(_DISCO_e_monitor_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_e_monitor_var._position_absolute, _DISCO_w_monitor_var._position_absolute);
    _DISCO_w_monitor_var._position_relative = rot_apply(_DISCO_w_monitor_var._rotation_absolute, tc1);
  } /* DISCO_w_monitor=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DISCO_w_monitor", _DISCO_w_monitor_var._position_absolute, _DISCO_w_monitor_var._rotation_absolute);
  instrument->_position_absolute[136] = _DISCO_w_monitor_var._position_absolute;
  instrument->_position_relative[136] = _DISCO_w_monitor_var._position_relative;
    _DISCO_w_monitor_var._position_relative_is_zero =  coords_test_zero(_DISCO_w_monitor_var._position_relative);
  instrument->counter_N[136]  = instrument->counter_P[136] = instrument->counter_P2[136] = 0;
  instrument->counter_AbsorbProp[136]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0135_DISCO_w_monitor", _DISCO_w_monitor_var._position_absolute, _DISCO_w_monitor_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "options", "NULL", "wavelength  bins=500 limits=[1980 11000],  x  bins=500", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "filename", "NULL", "DISCO_w_monitor", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0135_DISCO_w_monitor", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DISCO_w_monitor_setpos */

/* component beamdump_140=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_140_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_140_setpos] component beamdump_140=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_140_var._name, "beamdump_140", 16384);
  stracpy(_beamdump_140_var._type, "Beamstop", 16384);
  _beamdump_140_var._index=137;
  int current_setpos_index = 137;
  _beamdump_140_var._parameters.xmin = -0.05;
  _beamdump_140_var._parameters.xmax = 0.05;
  _beamdump_140_var._parameters.ymin = -0.05;
  _beamdump_140_var._parameters.ymax = 0.05;
  _beamdump_140_var._parameters.xwidth = 0;
  _beamdump_140_var._parameters.yheight = 0;
  _beamdump_140_var._parameters.radius = 0;

  /* component beamdump_140=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DISCO_w_monitor_var._rotation_absolute, _beamdump_140_var._rotation_absolute);
    rot_transpose(_DISCO_w_monitor_var._rotation_absolute, tr1);
    rot_mul(_beamdump_140_var._rotation_absolute, tr1, _beamdump_140_var._rotation_relative);
    _beamdump_140_var._rotation_is_identity =  rot_test_identity(_beamdump_140_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DISCO_w_monitor_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_140_var._position_absolute = coords_add(_DISCO_w_monitor_var._position_absolute, tc2);
    tc1 = coords_sub(_DISCO_w_monitor_var._position_absolute, _beamdump_140_var._position_absolute);
    _beamdump_140_var._position_relative = rot_apply(_beamdump_140_var._rotation_absolute, tc1);
  } /* beamdump_140=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_140", _beamdump_140_var._position_absolute, _beamdump_140_var._rotation_absolute);
  instrument->_position_absolute[137] = _beamdump_140_var._position_absolute;
  instrument->_position_relative[137] = _beamdump_140_var._position_relative;
    _beamdump_140_var._position_relative_is_zero =  coords_test_zero(_beamdump_140_var._position_relative);
  instrument->counter_N[137]  = instrument->counter_P[137] = instrument->counter_P2[137] = 0;
  instrument->counter_AbsorbProp[137]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0136_beamdump_140", _beamdump_140_var._position_absolute, _beamdump_140_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0136_beamdump_140", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_140_setpos */

/* component DESIRS_pos=Text() SETTING, POSITION/ROTATION */
int _DESIRS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DESIRS_pos_setpos] component DESIRS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_DESIRS_pos_var._name, "DESIRS_pos", 16384);
  stracpy(_DESIRS_pos_var._type, "Text", 16384);
  _DESIRS_pos_var._index=138;
  int current_setpos_index = 138;
  if("DESIRS" && strlen("DESIRS"))
    stracpy(_DESIRS_pos_var._parameters.text, "DESIRS" ? "DESIRS" : "", 16384);
  else 
  _DESIRS_pos_var._parameters.text[0]='\0';
  _DESIRS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_DESIRS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _DESIRS_pos_var._parameters.plane[0]='\0';
  _DESIRS_pos_var._parameters.pen_thickness = 0.1;


  /* component DESIRS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-90.02)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _DESIRS_pos_var._rotation_absolute);
    rot_transpose(_beamdump_140_var._rotation_absolute, tr1);
    rot_mul(_DESIRS_pos_var._rotation_absolute, tr1, _DESIRS_pos_var._rotation_relative);
    _DESIRS_pos_var._rotation_is_identity =  rot_test_identity(_DESIRS_pos_var._rotation_relative);
    tc1 = coords_set(
      -0.02, 0, 56.34);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DESIRS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_140_var._position_absolute, _DESIRS_pos_var._position_absolute);
    _DESIRS_pos_var._position_relative = rot_apply(_DESIRS_pos_var._rotation_absolute, tc1);
  } /* DESIRS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("DESIRS_pos", _DESIRS_pos_var._position_absolute, _DESIRS_pos_var._rotation_absolute);
  instrument->_position_absolute[138] = _DESIRS_pos_var._position_absolute;
  instrument->_position_relative[138] = _DESIRS_pos_var._position_relative;
    _DESIRS_pos_var._position_relative_is_zero =  coords_test_zero(_DESIRS_pos_var._position_relative);
  instrument->counter_N[138]  = instrument->counter_P[138] = instrument->counter_P2[138] = 0;
  instrument->counter_AbsorbProp[138]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0137_DESIRS_pos", _DESIRS_pos_var._position_absolute, _DESIRS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0137_DESIRS_pos", "text", "NONE", "DESIRS", "char*");
        mccomp_param_nexus(nxhandle,"0137_DESIRS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0137_DESIRS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0137_DESIRS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DESIRS_pos_setpos */

/* component METRO_pos=Text() SETTING, POSITION/ROTATION */
int _METRO_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_METRO_pos_setpos] component METRO_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_METRO_pos_var._name, "METRO_pos", 16384);
  stracpy(_METRO_pos_var._type, "Text", 16384);
  _METRO_pos_var._index=139;
  int current_setpos_index = 139;
  if("METROLOGIE" && strlen("METROLOGIE"))
    stracpy(_METRO_pos_var._parameters.text, "METROLOGIE" ? "METROLOGIE" : "", 16384);
  else 
  _METRO_pos_var._parameters.text[0]='\0';
  _METRO_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_METRO_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _METRO_pos_var._parameters.plane[0]='\0';
  _METRO_pos_var._parameters.pen_thickness = 0.1;


  /* component METRO_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-105.142)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _METRO_pos_var._rotation_absolute);
    rot_transpose(_DESIRS_pos_var._rotation_absolute, tr1);
    rot_mul(_METRO_pos_var._rotation_absolute, tr1, _METRO_pos_var._rotation_relative);
    _METRO_pos_var._rotation_is_identity =  rot_test_identity(_METRO_pos_var._rotation_relative);
    tc1 = coords_set(
      -14.71, 0, 54.38);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _METRO_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_DESIRS_pos_var._position_absolute, _METRO_pos_var._position_absolute);
    _METRO_pos_var._position_relative = rot_apply(_METRO_pos_var._rotation_absolute, tc1);
  } /* METRO_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("METRO_pos", _METRO_pos_var._position_absolute, _METRO_pos_var._rotation_absolute);
  instrument->_position_absolute[139] = _METRO_pos_var._position_absolute;
  instrument->_position_relative[139] = _METRO_pos_var._position_relative;
    _METRO_pos_var._position_relative_is_zero =  coords_test_zero(_METRO_pos_var._position_relative);
  instrument->counter_N[139]  = instrument->counter_P[139] = instrument->counter_P2[139] = 0;
  instrument->counter_AbsorbProp[139]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0138_METRO_pos", _METRO_pos_var._position_absolute, _METRO_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0138_METRO_pos", "text", "NONE", "METROLOGIE", "char*");
        mccomp_param_nexus(nxhandle,"0138_METRO_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0138_METRO_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0138_METRO_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _METRO_pos_setpos */

/* component PUMA_pos=Text() SETTING, POSITION/ROTATION */
int _PUMA_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_pos_setpos] component PUMA_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_PUMA_pos_var._name, "PUMA_pos", 16384);
  stracpy(_PUMA_pos_var._type, "Text", 16384);
  _PUMA_pos_var._index=140;
  int current_setpos_index = 140;
  if("PUMA" && strlen("PUMA"))
    stracpy(_PUMA_pos_var._parameters.text, "PUMA" ? "PUMA" : "", 16384);
  else 
  _PUMA_pos_var._parameters.text[0]='\0';
  _PUMA_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_PUMA_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _PUMA_pos_var._parameters.plane[0]='\0';
  _PUMA_pos_var._parameters.pen_thickness = 0.1;


  /* component PUMA_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-112.424)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _PUMA_pos_var._rotation_absolute);
    rot_transpose(_METRO_pos_var._rotation_absolute, tr1);
    rot_mul(_PUMA_pos_var._rotation_absolute, tr1, _PUMA_pos_var._rotation_relative);
    _PUMA_pos_var._rotation_is_identity =  rot_test_identity(_PUMA_pos_var._rotation_relative);
    tc1 = coords_set(
      -21.49, 0, 52.08);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_METRO_pos_var._position_absolute, _PUMA_pos_var._position_absolute);
    _PUMA_pos_var._position_relative = rot_apply(_PUMA_pos_var._rotation_absolute, tc1);
  } /* PUMA_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("PUMA_pos", _PUMA_pos_var._position_absolute, _PUMA_pos_var._rotation_absolute);
  instrument->_position_absolute[140] = _PUMA_pos_var._position_absolute;
  instrument->_position_relative[140] = _PUMA_pos_var._position_relative;
    _PUMA_pos_var._position_relative_is_zero =  coords_test_zero(_PUMA_pos_var._position_relative);
  instrument->counter_N[140]  = instrument->counter_P[140] = instrument->counter_P2[140] = 0;
  instrument->counter_AbsorbProp[140]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0139_PUMA_pos", _PUMA_pos_var._position_absolute, _PUMA_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0139_PUMA_pos", "text", "NONE", "PUMA", "char*");
        mccomp_param_nexus(nxhandle,"0139_PUMA_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0139_PUMA_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0139_PUMA_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_pos_setpos */

/* component PUMA=Arm() SETTING, POSITION/ROTATION */
int _PUMA_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_setpos] component PUMA=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_var._name, "PUMA", 16384);
  stracpy(_PUMA_var._type, "Arm", 16384);
  _PUMA_var._index=141;
  int current_setpos_index = 141;
  /* component PUMA=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_pos_var._rotation_absolute, _PUMA_var._rotation_absolute);
    rot_transpose(_PUMA_pos_var._rotation_absolute, tr1);
    rot_mul(_PUMA_var._rotation_absolute, tr1, _PUMA_var._rotation_relative);
    _PUMA_var._rotation_is_identity =  rot_test_identity(_PUMA_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_var._position_absolute = coords_add(_PUMA_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_pos_var._position_absolute, _PUMA_var._position_absolute);
    _PUMA_var._position_relative = rot_apply(_PUMA_var._rotation_absolute, tc1);
  } /* PUMA=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA", _PUMA_var._position_absolute, _PUMA_var._rotation_absolute);
  instrument->_position_absolute[141] = _PUMA_var._position_absolute;
  instrument->_position_relative[141] = _PUMA_var._position_relative;
    _PUMA_var._position_relative_is_zero =  coords_test_zero(_PUMA_var._position_relative);
  instrument->counter_N[141]  = instrument->counter_P[141] = instrument->counter_P2[141] = 0;
  instrument->counter_AbsorbProp[141]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0140_PUMA", _PUMA_var._position_absolute, _PUMA_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_setpos */

/* component PUMA_Source=Wiggler() SETTING, POSITION/ROTATION */
int _PUMA_Source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_Source_setpos] component PUMA_Source=Wiggler() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Wiggler.comp:107]");
  stracpy(_PUMA_Source_var._name, "PUMA_Source", 16384);
  stracpy(_PUMA_Source_var._type, "Wiggler", 16384);
  _PUMA_Source_var._index=142;
  int current_setpos_index = 142;
  _PUMA_Source_var._parameters.E0 = _instrument_var._parameters.PUMA_E0;
  _PUMA_Source_var._parameters.dE = _instrument_var._parameters.PUMA_dE;
  _PUMA_Source_var._parameters.lambda0 = 0;
  _PUMA_Source_var._parameters.dlambda = 0;
  _PUMA_Source_var._parameters.phase = 0;
  _PUMA_Source_var._parameters.randomphase = 1;
  _PUMA_Source_var._parameters.Ee = 2.75;
  _PUMA_Source_var._parameters.Ie = 0.5;
  _PUMA_Source_var._parameters.B = 1.8;
  _PUMA_Source_var._parameters.K = 1.37;
  _PUMA_Source_var._parameters.Nper = 20;
  _PUMA_Source_var._parameters.length = 0.1642;
  _PUMA_Source_var._parameters.sigey = 8.5e-6;
  _PUMA_Source_var._parameters.sigex = 206.5e-6;
  _PUMA_Source_var._parameters.focus_xw = 1.5e-3;
  _PUMA_Source_var._parameters.focus_yh = 3e-3;
  _PUMA_Source_var._parameters.dist = 19.4292;
  _PUMA_Source_var._parameters.gauss_t = 0;
  _PUMA_Source_var._parameters.verbose = 0;
  _PUMA_Source_var._parameters.Br = 1.35;


  /* component PUMA_Source=Wiggler() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_var._rotation_absolute, _PUMA_Source_var._rotation_absolute);
    rot_transpose(_PUMA_var._rotation_absolute, tr1);
    rot_mul(_PUMA_Source_var._rotation_absolute, tr1, _PUMA_Source_var._rotation_relative);
    _PUMA_Source_var._rotation_is_identity =  rot_test_identity(_PUMA_Source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_Source_var._position_absolute = coords_add(_PUMA_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_var._position_absolute, _PUMA_Source_var._position_absolute);
    _PUMA_Source_var._position_relative = rot_apply(_PUMA_Source_var._rotation_absolute, tc1);
  } /* PUMA_Source=Wiggler() AT ROTATED */
  DEBUG_COMPONENT("PUMA_Source", _PUMA_Source_var._position_absolute, _PUMA_Source_var._rotation_absolute);
  instrument->_position_absolute[142] = _PUMA_Source_var._position_absolute;
  instrument->_position_relative[142] = _PUMA_Source_var._position_relative;
    _PUMA_Source_var._position_relative_is_zero =  coords_test_zero(_PUMA_Source_var._position_relative);
  instrument->counter_N[142]  = instrument->counter_P[142] = instrument->counter_P2[142] = 0;
  instrument->counter_AbsorbProp[142]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0141_PUMA_Source", _PUMA_Source_var._position_absolute, _PUMA_Source_var._rotation_absolute, "Wiggler");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "E0", "0", "_instrument_var._parameters.PUMA_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "dE", "0", "_instrument_var._parameters.PUMA_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "B", "1.6", "1.8","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "K", "3", "1.37","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "Nper", "1", "20","int");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "length", "1", "0.1642","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "sigey", "0", "8.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "sigex", "0", "206.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "focus_xw", "0", "1.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "focus_yh", "0", "3e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "dist", "1", "19.4292","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "gauss_t", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0141_PUMA_Source", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_Source_setpos */

/* component PUMA_slit1=Slit() SETTING, POSITION/ROTATION */
int _PUMA_slit1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_slit1_setpos] component PUMA_slit1=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PUMA_slit1_var._name, "PUMA_slit1", 16384);
  stracpy(_PUMA_slit1_var._type, "Slit", 16384);
  _PUMA_slit1_var._index=143;
  int current_setpos_index = 143;
  _PUMA_slit1_var._parameters.xmin = 0;
  _PUMA_slit1_var._parameters.xmax = 0;
  _PUMA_slit1_var._parameters.ymin = 0;
  _PUMA_slit1_var._parameters.ymax = 0;
  _PUMA_slit1_var._parameters.radius = 0;
  _PUMA_slit1_var._parameters.xwidth = 0.02;
  _PUMA_slit1_var._parameters.yheight = 3e-3;
  _PUMA_slit1_var._parameters.dist = 0;
  _PUMA_slit1_var._parameters.focus_xw = 0;
  _PUMA_slit1_var._parameters.focus_yh = 0;
  _PUMA_slit1_var._parameters.focus_x0 = 0;
  _PUMA_slit1_var._parameters.focus_y0 = 0;

  /* component PUMA_slit1=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_Source_var._rotation_absolute, _PUMA_slit1_var._rotation_absolute);
    rot_transpose(_PUMA_Source_var._rotation_absolute, tr1);
    rot_mul(_PUMA_slit1_var._rotation_absolute, tr1, _PUMA_slit1_var._rotation_relative);
    _PUMA_slit1_var._rotation_is_identity =  rot_test_identity(_PUMA_slit1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 19.4292);
    rot_transpose(_PUMA_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_slit1_var._position_absolute = coords_add(_PUMA_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_Source_var._position_absolute, _PUMA_slit1_var._position_absolute);
    _PUMA_slit1_var._position_relative = rot_apply(_PUMA_slit1_var._rotation_absolute, tc1);
  } /* PUMA_slit1=Slit() AT ROTATED */
  DEBUG_COMPONENT("PUMA_slit1", _PUMA_slit1_var._position_absolute, _PUMA_slit1_var._rotation_absolute);
  instrument->_position_absolute[143] = _PUMA_slit1_var._position_absolute;
  instrument->_position_relative[143] = _PUMA_slit1_var._position_relative;
    _PUMA_slit1_var._position_relative_is_zero =  coords_test_zero(_PUMA_slit1_var._position_relative);
  instrument->counter_N[143]  = instrument->counter_P[143] = instrument->counter_P2[143] = 0;
  instrument->counter_AbsorbProp[143]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0142_PUMA_slit1", _PUMA_slit1_var._position_absolute, _PUMA_slit1_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "xwidth", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "yheight", "0.001", "3e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0142_PUMA_slit1", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_slit1_setpos */

/* component PUMA_slit2=Slit() SETTING, POSITION/ROTATION */
int _PUMA_slit2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_slit2_setpos] component PUMA_slit2=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PUMA_slit2_var._name, "PUMA_slit2", 16384);
  stracpy(_PUMA_slit2_var._type, "Slit", 16384);
  _PUMA_slit2_var._index=144;
  int current_setpos_index = 144;
  _PUMA_slit2_var._parameters.xmin = 0;
  _PUMA_slit2_var._parameters.xmax = 0;
  _PUMA_slit2_var._parameters.ymin = 0;
  _PUMA_slit2_var._parameters.ymax = 0;
  _PUMA_slit2_var._parameters.radius = 0;
  _PUMA_slit2_var._parameters.xwidth = 1.5e-3;
  _PUMA_slit2_var._parameters.yheight = 0.01;
  _PUMA_slit2_var._parameters.dist = 0;
  _PUMA_slit2_var._parameters.focus_xw = 0;
  _PUMA_slit2_var._parameters.focus_yh = 0;
  _PUMA_slit2_var._parameters.focus_x0 = 0;
  _PUMA_slit2_var._parameters.focus_y0 = 0;

  /* component PUMA_slit2=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_slit1_var._rotation_absolute, _PUMA_slit2_var._rotation_absolute);
    rot_transpose(_PUMA_slit1_var._rotation_absolute, tr1);
    rot_mul(_PUMA_slit2_var._rotation_absolute, tr1, _PUMA_slit2_var._rotation_relative);
    _PUMA_slit2_var._rotation_is_identity =  rot_test_identity(_PUMA_slit2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 19.433 -19.4292 ));
    rot_transpose(_PUMA_slit1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_slit2_var._position_absolute = coords_add(_PUMA_slit1_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_slit1_var._position_absolute, _PUMA_slit2_var._position_absolute);
    _PUMA_slit2_var._position_relative = rot_apply(_PUMA_slit2_var._rotation_absolute, tc1);
  } /* PUMA_slit2=Slit() AT ROTATED */
  DEBUG_COMPONENT("PUMA_slit2", _PUMA_slit2_var._position_absolute, _PUMA_slit2_var._rotation_absolute);
  instrument->_position_absolute[144] = _PUMA_slit2_var._position_absolute;
  instrument->_position_relative[144] = _PUMA_slit2_var._position_relative;
    _PUMA_slit2_var._position_relative_is_zero =  coords_test_zero(_PUMA_slit2_var._position_relative);
  instrument->counter_N[144]  = instrument->counter_P[144] = instrument->counter_P2[144] = 0;
  instrument->counter_AbsorbProp[144]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0143_PUMA_slit2", _PUMA_slit2_var._position_absolute, _PUMA_slit2_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "xwidth", "0.001", "1.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0143_PUMA_slit2", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_slit2_setpos */

/* component PUMA_mon_src_e=E_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_src_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_src_e_setpos] component PUMA_mon_src_e=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_PUMA_mon_src_e_var._name, "PUMA_mon_src_e", 16384);
  stracpy(_PUMA_mon_src_e_var._type, "E_monitor", 16384);
  _PUMA_mon_src_e_var._index=145;
  int current_setpos_index = 145;
  _PUMA_mon_src_e_var._parameters.nE = 100;
  _PUMA_mon_src_e_var._parameters.filename[0]='\0';
  _PUMA_mon_src_e_var._parameters.xwidth = 0.1;
  _PUMA_mon_src_e_var._parameters.yheight = 0.1;
  _PUMA_mon_src_e_var._parameters.Emin = 4;
  _PUMA_mon_src_e_var._parameters.Emax = 60;
  _PUMA_mon_src_e_var._parameters.restore_xray = 1;


  /* component PUMA_mon_src_e=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_slit2_var._rotation_absolute, _PUMA_mon_src_e_var._rotation_absolute);
    rot_transpose(_PUMA_slit2_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_src_e_var._rotation_absolute, tr1, _PUMA_mon_src_e_var._rotation_relative);
    _PUMA_mon_src_e_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_src_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_slit2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_src_e_var._position_absolute = coords_add(_PUMA_slit2_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_slit2_var._position_absolute, _PUMA_mon_src_e_var._position_absolute);
    _PUMA_mon_src_e_var._position_relative = rot_apply(_PUMA_mon_src_e_var._rotation_absolute, tc1);
  } /* PUMA_mon_src_e=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_src_e", _PUMA_mon_src_e_var._position_absolute, _PUMA_mon_src_e_var._rotation_absolute);
  instrument->_position_absolute[145] = _PUMA_mon_src_e_var._position_absolute;
  instrument->_position_relative[145] = _PUMA_mon_src_e_var._position_relative;
    _PUMA_mon_src_e_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_src_e_var._position_relative);
  instrument->counter_N[145]  = instrument->counter_P[145] = instrument->counter_P2[145] = 0;
  instrument->counter_AbsorbProp[145]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0144_PUMA_mon_src_e", _PUMA_mon_src_e_var._position_absolute, _PUMA_mon_src_e_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "nE", "20", "100","MCNUM");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "Emin", "NONE", "4","MCNUM");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "Emax", "NONE", "60","MCNUM");
        mccomp_param_nexus(nxhandle,"0144_PUMA_mon_src_e", "restore_xray", "0", "1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_src_e_setpos */

/* component PUMA_mon_src_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_src_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_src_xy_setpos] component PUMA_mon_src_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_src_xy_var._name, "PUMA_mon_src_xy", 16384);
  stracpy(_PUMA_mon_src_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_src_xy_var._index=146;
  int current_setpos_index = 146;
  _PUMA_mon_src_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_src_xy_var._parameters.xwidth = 0.02;
  _PUMA_mon_src_xy_var._parameters.yheight = 0.01;
  _PUMA_mon_src_xy_var._parameters.radius = 0;
  _PUMA_mon_src_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_src_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_src_xy_var._parameters.nx = 100;
  _PUMA_mon_src_xy_var._parameters.ny = 100;
  _PUMA_mon_src_xy_var._parameters.nr = 0;


  /* component PUMA_mon_src_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_src_e_var._rotation_absolute, _PUMA_mon_src_xy_var._rotation_absolute);
    rot_transpose(_PUMA_mon_src_e_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_src_xy_var._rotation_absolute, tr1, _PUMA_mon_src_xy_var._rotation_relative);
    _PUMA_mon_src_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_src_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_mon_src_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_src_xy_var._position_absolute = coords_add(_PUMA_mon_src_e_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_src_e_var._position_absolute, _PUMA_mon_src_xy_var._position_absolute);
    _PUMA_mon_src_xy_var._position_relative = rot_apply(_PUMA_mon_src_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_src_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_src_xy", _PUMA_mon_src_xy_var._position_absolute, _PUMA_mon_src_xy_var._rotation_absolute);
  instrument->_position_absolute[146] = _PUMA_mon_src_xy_var._position_absolute;
  instrument->_position_relative[146] = _PUMA_mon_src_xy_var._position_relative;
    _PUMA_mon_src_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_src_xy_var._position_relative);
  instrument->counter_N[146]  = instrument->counter_P[146] = instrument->counter_P2[146] = 0;
  instrument->counter_AbsorbProp[146]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0145_PUMA_mon_src_xy", _PUMA_mon_src_xy_var._position_absolute, _PUMA_mon_src_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "xwidth", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0145_PUMA_mon_src_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_src_xy_setpos */

/* component PUMA_HFM_location=Arm() SETTING, POSITION/ROTATION */
int _PUMA_HFM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_HFM_location_setpos] component PUMA_HFM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_HFM_location_var._name, "PUMA_HFM_location", 16384);
  stracpy(_PUMA_HFM_location_var._type, "Arm", 16384);
  _PUMA_HFM_location_var._index=147;
  int current_setpos_index = 147;
  /* component PUMA_HFM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_src_xy_var._rotation_absolute, _PUMA_HFM_location_var._rotation_absolute);
    rot_transpose(_PUMA_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_HFM_location_var._rotation_absolute, tr1, _PUMA_HFM_location_var._rotation_relative);
    _PUMA_HFM_location_var._rotation_is_identity =  rot_test_identity(_PUMA_HFM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 21 - 19.433 ));
    rot_transpose(_PUMA_mon_src_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_HFM_location_var._position_absolute = coords_add(_PUMA_mon_src_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_src_xy_var._position_absolute, _PUMA_HFM_location_var._position_absolute);
    _PUMA_HFM_location_var._position_relative = rot_apply(_PUMA_HFM_location_var._rotation_absolute, tc1);
  } /* PUMA_HFM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_HFM_location", _PUMA_HFM_location_var._position_absolute, _PUMA_HFM_location_var._rotation_absolute);
  instrument->_position_absolute[147] = _PUMA_HFM_location_var._position_absolute;
  instrument->_position_relative[147] = _PUMA_HFM_location_var._position_relative;
    _PUMA_HFM_location_var._position_relative_is_zero =  coords_test_zero(_PUMA_HFM_location_var._position_relative);
  instrument->counter_N[147]  = instrument->counter_P[147] = instrument->counter_P2[147] = 0;
  instrument->counter_AbsorbProp[147]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0146_PUMA_HFM_location", _PUMA_HFM_location_var._position_absolute, _PUMA_HFM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_HFM_location_setpos */

/* component PUMA_HFM_rotated=Arm() SETTING, POSITION/ROTATION */
int _PUMA_HFM_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_HFM_rotated_setpos] component PUMA_HFM_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_HFM_rotated_var._name, "PUMA_HFM_rotated", 16384);
  stracpy(_PUMA_HFM_rotated_var._type, "Arm", 16384);
  _PUMA_HFM_rotated_var._index=148;
  int current_setpos_index = 148;
  /* component PUMA_HFM_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.PUMA_HFM_angle / 2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_HFM_location_var._rotation_absolute, _PUMA_HFM_rotated_var._rotation_absolute);
    rot_transpose(_PUMA_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_HFM_rotated_var._rotation_absolute, tr1, _PUMA_HFM_rotated_var._rotation_relative);
    _PUMA_HFM_rotated_var._rotation_is_identity =  rot_test_identity(_PUMA_HFM_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_HFM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_HFM_rotated_var._position_absolute = coords_add(_PUMA_HFM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_src_xy_var._position_absolute, _PUMA_HFM_rotated_var._position_absolute);
    _PUMA_HFM_rotated_var._position_relative = rot_apply(_PUMA_HFM_rotated_var._rotation_absolute, tc1);
  } /* PUMA_HFM_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_HFM_rotated", _PUMA_HFM_rotated_var._position_absolute, _PUMA_HFM_rotated_var._rotation_absolute);
  instrument->_position_absolute[148] = _PUMA_HFM_rotated_var._position_absolute;
  instrument->_position_relative[148] = _PUMA_HFM_rotated_var._position_relative;
    _PUMA_HFM_rotated_var._position_relative_is_zero =  coords_test_zero(_PUMA_HFM_rotated_var._position_relative);
  instrument->counter_N[148]  = instrument->counter_P[148] = instrument->counter_P2[148] = 0;
  instrument->counter_AbsorbProp[148]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0147_PUMA_HFM_rotated", _PUMA_HFM_rotated_var._position_absolute, _PUMA_HFM_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_HFM_rotated_setpos */

/* component PUMA_mirror_HFM=Mirror_curved() SETTING, POSITION/ROTATION */
int _PUMA_mirror_HFM_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mirror_HFM_setpos] component PUMA_mirror_HFM=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PUMA_mirror_HFM_var._name, "PUMA_mirror_HFM", 16384);
  stracpy(_PUMA_mirror_HFM_var._type, "Mirror_curved", 16384);
  _PUMA_mirror_HFM_var._index=149;
  int current_setpos_index = 149;
  _PUMA_mirror_HFM_var._parameters.radius = PUMA_HFM_radius;
  _PUMA_mirror_HFM_var._parameters.R0 = 1;
  if("Ir.txt" && strlen("Ir.txt"))
    stracpy(_PUMA_mirror_HFM_var._parameters.coating, "Ir.txt" ? "Ir.txt" : "", 16384);
  else 
  _PUMA_mirror_HFM_var._parameters.coating[0]='\0';
  _PUMA_mirror_HFM_var._parameters.zdepth = 0.2;
  _PUMA_mirror_HFM_var._parameters.yheight = 0.2;
  _PUMA_mirror_HFM_var._parameters.length = 1.1;
  _PUMA_mirror_HFM_var._parameters.width = 0.01;


  /* component PUMA_mirror_HFM=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_HFM_rotated_var._rotation_absolute, _PUMA_mirror_HFM_var._rotation_absolute);
    rot_transpose(_PUMA_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mirror_HFM_var._rotation_absolute, tr1, _PUMA_mirror_HFM_var._rotation_relative);
    _PUMA_mirror_HFM_var._rotation_is_identity =  rot_test_identity(_PUMA_mirror_HFM_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_HFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mirror_HFM_var._position_absolute = coords_add(_PUMA_HFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_src_xy_var._position_absolute, _PUMA_mirror_HFM_var._position_absolute);
    _PUMA_mirror_HFM_var._position_relative = rot_apply(_PUMA_mirror_HFM_var._rotation_absolute, tc1);
  } /* PUMA_mirror_HFM=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mirror_HFM", _PUMA_mirror_HFM_var._position_absolute, _PUMA_mirror_HFM_var._rotation_absolute);
  instrument->_position_absolute[149] = _PUMA_mirror_HFM_var._position_absolute;
  instrument->_position_relative[149] = _PUMA_mirror_HFM_var._position_relative;
    _PUMA_mirror_HFM_var._position_relative_is_zero =  coords_test_zero(_PUMA_mirror_HFM_var._position_relative);
  instrument->counter_N[149]  = instrument->counter_P[149] = instrument->counter_P2[149] = 0;
  instrument->counter_AbsorbProp[149]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0148_PUMA_mirror_HFM", _PUMA_mirror_HFM_var._position_absolute, _PUMA_mirror_HFM_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "radius", "1", "PUMA_HFM_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "coating", "Be.txt", "Ir.txt", "char*");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "length", "0", "1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0148_PUMA_mirror_HFM", "width", "0", "0.01","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mirror_HFM_setpos */

/* component PUMA_HFM_out=Arm() SETTING, POSITION/ROTATION */
int _PUMA_HFM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_HFM_out_setpos] component PUMA_HFM_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_HFM_out_var._name, "PUMA_HFM_out", 16384);
  stracpy(_PUMA_HFM_out_var._type, "Arm", 16384);
  _PUMA_HFM_out_var._index=150;
  int current_setpos_index = 150;
  /* component PUMA_HFM_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.PUMA_HFM_angle / 2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_HFM_rotated_var._rotation_absolute, _PUMA_HFM_out_var._rotation_absolute);
    rot_transpose(_PUMA_mirror_HFM_var._rotation_absolute, tr1);
    rot_mul(_PUMA_HFM_out_var._rotation_absolute, tr1, _PUMA_HFM_out_var._rotation_relative);
    _PUMA_HFM_out_var._rotation_is_identity =  rot_test_identity(_PUMA_HFM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_HFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_HFM_out_var._position_absolute = coords_add(_PUMA_HFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mirror_HFM_var._position_absolute, _PUMA_HFM_out_var._position_absolute);
    _PUMA_HFM_out_var._position_relative = rot_apply(_PUMA_HFM_out_var._rotation_absolute, tc1);
  } /* PUMA_HFM_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_HFM_out", _PUMA_HFM_out_var._position_absolute, _PUMA_HFM_out_var._rotation_absolute);
  instrument->_position_absolute[150] = _PUMA_HFM_out_var._position_absolute;
  instrument->_position_relative[150] = _PUMA_HFM_out_var._position_relative;
    _PUMA_HFM_out_var._position_relative_is_zero =  coords_test_zero(_PUMA_HFM_out_var._position_relative);
  instrument->counter_N[150]  = instrument->counter_P[150] = instrument->counter_P2[150] = 0;
  instrument->counter_AbsorbProp[150]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0149_PUMA_HFM_out", _PUMA_HFM_out_var._position_absolute, _PUMA_HFM_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_HFM_out_setpos */

/* component PUMA_mon_HFM_out_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_HFM_out_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_HFM_out_xy_setpos] component PUMA_mon_HFM_out_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_HFM_out_xy_var._name, "PUMA_mon_HFM_out_xy", 16384);
  stracpy(_PUMA_mon_HFM_out_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_HFM_out_xy_var._index=151;
  int current_setpos_index = 151;
  if("PUMA_Position_after_HFM_fixed_mirror" && strlen("PUMA_Position_after_HFM_fixed_mirror"))
    stracpy(_PUMA_mon_HFM_out_xy_var._parameters.filename, "PUMA_Position_after_HFM_fixed_mirror" ? "PUMA_Position_after_HFM_fixed_mirror" : "", 16384);
  else 
  _PUMA_mon_HFM_out_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_HFM_out_xy_var._parameters.xwidth = 0.02;
  _PUMA_mon_HFM_out_xy_var._parameters.yheight = 0.01;
  _PUMA_mon_HFM_out_xy_var._parameters.radius = 0;
  _PUMA_mon_HFM_out_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_HFM_out_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_HFM_out_xy_var._parameters.nx = 100;
  _PUMA_mon_HFM_out_xy_var._parameters.ny = 100;
  _PUMA_mon_HFM_out_xy_var._parameters.nr = 0;


  /* component PUMA_mon_HFM_out_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_HFM_out_var._rotation_absolute, _PUMA_mon_HFM_out_xy_var._rotation_absolute);
    rot_transpose(_PUMA_mirror_HFM_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_HFM_out_xy_var._rotation_absolute, tr1, _PUMA_mon_HFM_out_xy_var._rotation_relative);
    _PUMA_mon_HFM_out_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_HFM_out_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_HFM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_HFM_out_xy_var._position_absolute = coords_add(_PUMA_HFM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mirror_HFM_var._position_absolute, _PUMA_mon_HFM_out_xy_var._position_absolute);
    _PUMA_mon_HFM_out_xy_var._position_relative = rot_apply(_PUMA_mon_HFM_out_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_HFM_out_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_HFM_out_xy", _PUMA_mon_HFM_out_xy_var._position_absolute, _PUMA_mon_HFM_out_xy_var._rotation_absolute);
  instrument->_position_absolute[151] = _PUMA_mon_HFM_out_xy_var._position_absolute;
  instrument->_position_relative[151] = _PUMA_mon_HFM_out_xy_var._position_relative;
    _PUMA_mon_HFM_out_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_HFM_out_xy_var._position_relative);
  instrument->counter_N[151]  = instrument->counter_P[151] = instrument->counter_P2[151] = 0;
  instrument->counter_AbsorbProp[151]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", _PUMA_mon_HFM_out_xy_var._position_absolute, _PUMA_mon_HFM_out_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "filename", 0, "PUMA_Position_after_HFM_fixed_mirror", "char*");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "xwidth", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0150_PUMA_mon_HFM_out_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_HFM_out_xy_setpos */

/* component PUMA_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _PUMA_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_DCM_location_setpos] component PUMA_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_DCM_location_var._name, "PUMA_DCM_location", 16384);
  stracpy(_PUMA_DCM_location_var._type, "Arm", 16384);
  _PUMA_DCM_location_var._index=152;
  int current_setpos_index = 152;
  /* component PUMA_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_HFM_out_xy_var._rotation_absolute, _PUMA_DCM_location_var._rotation_absolute);
    rot_transpose(_PUMA_mon_HFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_DCM_location_var._rotation_absolute, tr1, _PUMA_DCM_location_var._rotation_relative);
    _PUMA_DCM_location_var._rotation_is_identity =  rot_test_identity(_PUMA_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 22.5 - 21);
    rot_transpose(_PUMA_mon_HFM_out_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_DCM_location_var._position_absolute = coords_add(_PUMA_mon_HFM_out_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_HFM_out_xy_var._position_absolute, _PUMA_DCM_location_var._position_absolute);
    _PUMA_DCM_location_var._position_relative = rot_apply(_PUMA_DCM_location_var._rotation_absolute, tc1);
  } /* PUMA_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_DCM_location", _PUMA_DCM_location_var._position_absolute, _PUMA_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[152] = _PUMA_DCM_location_var._position_absolute;
  instrument->_position_relative[152] = _PUMA_DCM_location_var._position_relative;
    _PUMA_DCM_location_var._position_relative_is_zero =  coords_test_zero(_PUMA_DCM_location_var._position_relative);
  instrument->counter_N[152]  = instrument->counter_P[152] = instrument->counter_P2[152] = 0;
  instrument->counter_AbsorbProp[152]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0151_PUMA_DCM_location", _PUMA_DCM_location_var._position_absolute, _PUMA_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_DCM_location_setpos */

/* component PUMA_DCM_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PUMA_DCM_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_DCM_xtal1_setpos] component PUMA_DCM_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PUMA_DCM_xtal1_var._name, "PUMA_DCM_xtal1", 16384);
  stracpy(_PUMA_DCM_xtal1_var._type, "Bragg_crystal", 16384);
  _PUMA_DCM_xtal1_var._index=153;
  int current_setpos_index = 153;
  _PUMA_DCM_xtal1_var._parameters.length = 0.09;
  _PUMA_DCM_xtal1_var._parameters.width = 0.025;
  _PUMA_DCM_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PUMA_DCM_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PUMA_DCM_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PUMA_DCM_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PUMA_DCM_xtal1_var._parameters.material[0]='\0';
  _PUMA_DCM_xtal1_var._parameters.alpha = 0.0;
  _PUMA_DCM_xtal1_var._parameters.R0 = 0;
  _PUMA_DCM_xtal1_var._parameters.debye_waller_B = 0.4632;
  _PUMA_DCM_xtal1_var._parameters.crystal_type = 1;
  _PUMA_DCM_xtal1_var._parameters.h = _instrument_var._parameters.PUMA_h;
  _PUMA_DCM_xtal1_var._parameters.k = _instrument_var._parameters.PUMA_k;
  _PUMA_DCM_xtal1_var._parameters.l = _instrument_var._parameters.PUMA_l;
  _PUMA_DCM_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _PUMA_DCM_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component PUMA_DCM_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.PUMA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_DCM_location_var._rotation_absolute, _PUMA_DCM_xtal1_var._rotation_absolute);
    rot_transpose(_PUMA_mon_HFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_DCM_xtal1_var._rotation_absolute, tr1, _PUMA_DCM_xtal1_var._rotation_relative);
    _PUMA_DCM_xtal1_var._rotation_is_identity =  rot_test_identity(_PUMA_DCM_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_DCM_xtal1_var._position_absolute = coords_add(_PUMA_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_HFM_out_xy_var._position_absolute, _PUMA_DCM_xtal1_var._position_absolute);
    _PUMA_DCM_xtal1_var._position_relative = rot_apply(_PUMA_DCM_xtal1_var._rotation_absolute, tc1);
  } /* PUMA_DCM_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PUMA_DCM_xtal1", _PUMA_DCM_xtal1_var._position_absolute, _PUMA_DCM_xtal1_var._rotation_absolute);
  instrument->_position_absolute[153] = _PUMA_DCM_xtal1_var._position_absolute;
  instrument->_position_relative[153] = _PUMA_DCM_xtal1_var._position_relative;
    _PUMA_DCM_xtal1_var._position_relative_is_zero =  coords_test_zero(_PUMA_DCM_xtal1_var._position_relative);
  instrument->counter_N[153]  = instrument->counter_P[153] = instrument->counter_P2[153] = 0;
  instrument->counter_AbsorbProp[153]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0152_PUMA_DCM_xtal1", _PUMA_DCM_xtal1_var._position_absolute, _PUMA_DCM_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "length", "0.05", "0.09","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "width", "0.02", "0.025","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "h", "1", "_instrument_var._parameters.PUMA_h","int");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "k", "1", "_instrument_var._parameters.PUMA_k","int");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "l", "1", "_instrument_var._parameters.PUMA_l","int");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0152_PUMA_DCM_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_DCM_xtal1_setpos */

/* component PUMA_DCM_xtal1_out=Arm() SETTING, POSITION/ROTATION */
int _PUMA_DCM_xtal1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_DCM_xtal1_out_setpos] component PUMA_DCM_xtal1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_DCM_xtal1_out_var._name, "PUMA_DCM_xtal1_out", 16384);
  stracpy(_PUMA_DCM_xtal1_out_var._type, "Arm", 16384);
  _PUMA_DCM_xtal1_out_var._index=154;
  int current_setpos_index = 154;
  /* component PUMA_DCM_xtal1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.PUMA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_DCM_xtal1_var._rotation_absolute, _PUMA_DCM_xtal1_out_var._rotation_absolute);
    rot_transpose(_PUMA_DCM_xtal1_var._rotation_absolute, tr1);
    rot_mul(_PUMA_DCM_xtal1_out_var._rotation_absolute, tr1, _PUMA_DCM_xtal1_out_var._rotation_relative);
    _PUMA_DCM_xtal1_out_var._rotation_is_identity =  rot_test_identity(_PUMA_DCM_xtal1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_DCM_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_DCM_xtal1_out_var._position_absolute = coords_add(_PUMA_DCM_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_DCM_xtal1_var._position_absolute, _PUMA_DCM_xtal1_out_var._position_absolute);
    _PUMA_DCM_xtal1_out_var._position_relative = rot_apply(_PUMA_DCM_xtal1_out_var._rotation_absolute, tc1);
  } /* PUMA_DCM_xtal1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_DCM_xtal1_out", _PUMA_DCM_xtal1_out_var._position_absolute, _PUMA_DCM_xtal1_out_var._rotation_absolute);
  instrument->_position_absolute[154] = _PUMA_DCM_xtal1_out_var._position_absolute;
  instrument->_position_relative[154] = _PUMA_DCM_xtal1_out_var._position_relative;
    _PUMA_DCM_xtal1_out_var._position_relative_is_zero =  coords_test_zero(_PUMA_DCM_xtal1_out_var._position_relative);
  instrument->counter_N[154]  = instrument->counter_P[154] = instrument->counter_P2[154] = 0;
  instrument->counter_AbsorbProp[154]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0153_PUMA_DCM_xtal1_out", _PUMA_DCM_xtal1_out_var._position_absolute, _PUMA_DCM_xtal1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_DCM_xtal1_out_setpos */

/* component PUMA_mon_DCM_xtal1_only_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_DCM_xtal1_only_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_DCM_xtal1_only_xy_setpos] component PUMA_mon_DCM_xtal1_only_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_DCM_xtal1_only_xy_var._name, "PUMA_mon_DCM_xtal1_only_xy", 16384);
  stracpy(_PUMA_mon_DCM_xtal1_only_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_DCM_xtal1_only_xy_var._index=155;
  int current_setpos_index = 155;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.xwidth = 0.02;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.yheight = 0.01;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.radius = 0;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.nx = 100;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.ny = 100;
  _PUMA_mon_DCM_xtal1_only_xy_var._parameters.nr = 0;


  /* component PUMA_mon_DCM_xtal1_only_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_DCM_xtal1_out_var._rotation_absolute, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute);
    rot_transpose(_PUMA_DCM_xtal1_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute, tr1, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_relative);
    _PUMA_mon_DCM_xtal1_only_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_DCM_xtal1_only_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.01);
    rot_transpose(_PUMA_DCM_xtal1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_DCM_xtal1_only_xy_var._position_absolute = coords_add(_PUMA_DCM_xtal1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_DCM_xtal1_var._position_absolute, _PUMA_mon_DCM_xtal1_only_xy_var._position_absolute);
    _PUMA_mon_DCM_xtal1_only_xy_var._position_relative = rot_apply(_PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_DCM_xtal1_only_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_DCM_xtal1_only_xy", _PUMA_mon_DCM_xtal1_only_xy_var._position_absolute, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute);
  instrument->_position_absolute[155] = _PUMA_mon_DCM_xtal1_only_xy_var._position_absolute;
  instrument->_position_relative[155] = _PUMA_mon_DCM_xtal1_only_xy_var._position_relative;
    _PUMA_mon_DCM_xtal1_only_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_DCM_xtal1_only_xy_var._position_relative);
  instrument->counter_N[155]  = instrument->counter_P[155] = instrument->counter_P2[155] = 0;
  instrument->counter_AbsorbProp[155]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", _PUMA_mon_DCM_xtal1_only_xy_var._position_absolute, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "xwidth", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0154_PUMA_mon_DCM_xtal1_only_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_DCM_xtal1_only_xy_setpos */

/* component PUMA_DCM_xtal2=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PUMA_DCM_xtal2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_DCM_xtal2_setpos] component PUMA_DCM_xtal2=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PUMA_DCM_xtal2_var._name, "PUMA_DCM_xtal2", 16384);
  stracpy(_PUMA_DCM_xtal2_var._type, "Bragg_crystal", 16384);
  _PUMA_DCM_xtal2_var._index=156;
  int current_setpos_index = 156;
  _PUMA_DCM_xtal2_var._parameters.length = 0.09;
  _PUMA_DCM_xtal2_var._parameters.width = 0.025;
  _PUMA_DCM_xtal2_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PUMA_DCM_xtal2_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PUMA_DCM_xtal2_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PUMA_DCM_xtal2_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PUMA_DCM_xtal2_var._parameters.material[0]='\0';
  _PUMA_DCM_xtal2_var._parameters.alpha = 0.0;
  _PUMA_DCM_xtal2_var._parameters.R0 = 0;
  _PUMA_DCM_xtal2_var._parameters.debye_waller_B = 0.4632;
  _PUMA_DCM_xtal2_var._parameters.crystal_type = 1;
  _PUMA_DCM_xtal2_var._parameters.h = _instrument_var._parameters.PUMA_h;
  _PUMA_DCM_xtal2_var._parameters.k = _instrument_var._parameters.PUMA_k;
  _PUMA_DCM_xtal2_var._parameters.l = _instrument_var._parameters.PUMA_l;
  _PUMA_DCM_xtal2_var._parameters.structure_factor_scale_r = 0.0;
  _PUMA_DCM_xtal2_var._parameters.structure_factor_scale_i = 0.0;


  /* component PUMA_DCM_xtal2=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PUMA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute, _PUMA_DCM_xtal2_var._rotation_absolute);
    rot_transpose(_PUMA_mon_DCM_xtal1_only_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_DCM_xtal2_var._rotation_absolute, tr1, _PUMA_DCM_xtal2_var._rotation_relative);
    _PUMA_DCM_xtal2_var._rotation_is_identity =  rot_test_identity(_PUMA_DCM_xtal2_var._rotation_relative);
    tc1 = coords_set(
      0, PUMA_DCM_gap, _instrument_var._parameters.PUMA_DCM_theta ? PUMA_DCM_gap / tan ( _instrument_var._parameters.PUMA_DCM_theta * DEG2RAD ) : 0);
    rot_transpose(_PUMA_DCM_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_DCM_xtal2_var._position_absolute = coords_add(_PUMA_DCM_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_DCM_xtal1_only_xy_var._position_absolute, _PUMA_DCM_xtal2_var._position_absolute);
    _PUMA_DCM_xtal2_var._position_relative = rot_apply(_PUMA_DCM_xtal2_var._rotation_absolute, tc1);
  } /* PUMA_DCM_xtal2=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PUMA_DCM_xtal2", _PUMA_DCM_xtal2_var._position_absolute, _PUMA_DCM_xtal2_var._rotation_absolute);
  instrument->_position_absolute[156] = _PUMA_DCM_xtal2_var._position_absolute;
  instrument->_position_relative[156] = _PUMA_DCM_xtal2_var._position_relative;
    _PUMA_DCM_xtal2_var._position_relative_is_zero =  coords_test_zero(_PUMA_DCM_xtal2_var._position_relative);
  instrument->counter_N[156]  = instrument->counter_P[156] = instrument->counter_P2[156] = 0;
  instrument->counter_AbsorbProp[156]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0155_PUMA_DCM_xtal2", _PUMA_DCM_xtal2_var._position_absolute, _PUMA_DCM_xtal2_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "length", "0.05", "0.09","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "width", "0.02", "0.025","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "h", "1", "_instrument_var._parameters.PUMA_h","int");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "k", "1", "_instrument_var._parameters.PUMA_k","int");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "l", "1", "_instrument_var._parameters.PUMA_l","int");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0155_PUMA_DCM_xtal2", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_DCM_xtal2_setpos */

/* component PUMA_DCM_xtal2_out=Arm() SETTING, POSITION/ROTATION */
int _PUMA_DCM_xtal2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_DCM_xtal2_out_setpos] component PUMA_DCM_xtal2_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_DCM_xtal2_out_var._name, "PUMA_DCM_xtal2_out", 16384);
  stracpy(_PUMA_DCM_xtal2_out_var._type, "Arm", 16384);
  _PUMA_DCM_xtal2_out_var._index=157;
  int current_setpos_index = 157;
  /* component PUMA_DCM_xtal2_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PUMA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_DCM_xtal2_var._rotation_absolute, _PUMA_DCM_xtal2_out_var._rotation_absolute);
    rot_transpose(_PUMA_DCM_xtal2_var._rotation_absolute, tr1);
    rot_mul(_PUMA_DCM_xtal2_out_var._rotation_absolute, tr1, _PUMA_DCM_xtal2_out_var._rotation_relative);
    _PUMA_DCM_xtal2_out_var._rotation_is_identity =  rot_test_identity(_PUMA_DCM_xtal2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_DCM_xtal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_DCM_xtal2_out_var._position_absolute = coords_add(_PUMA_DCM_xtal2_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_DCM_xtal2_var._position_absolute, _PUMA_DCM_xtal2_out_var._position_absolute);
    _PUMA_DCM_xtal2_out_var._position_relative = rot_apply(_PUMA_DCM_xtal2_out_var._rotation_absolute, tc1);
  } /* PUMA_DCM_xtal2_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_DCM_xtal2_out", _PUMA_DCM_xtal2_out_var._position_absolute, _PUMA_DCM_xtal2_out_var._rotation_absolute);
  instrument->_position_absolute[157] = _PUMA_DCM_xtal2_out_var._position_absolute;
  instrument->_position_relative[157] = _PUMA_DCM_xtal2_out_var._position_relative;
    _PUMA_DCM_xtal2_out_var._position_relative_is_zero =  coords_test_zero(_PUMA_DCM_xtal2_out_var._position_relative);
  instrument->counter_N[157]  = instrument->counter_P[157] = instrument->counter_P2[157] = 0;
  instrument->counter_AbsorbProp[157]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0156_PUMA_DCM_xtal2_out", _PUMA_DCM_xtal2_out_var._position_absolute, _PUMA_DCM_xtal2_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_DCM_xtal2_out_setpos */

/* component PUMA_mon_DCM_out_e=E_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_DCM_out_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_DCM_out_e_setpos] component PUMA_mon_DCM_out_e=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_PUMA_mon_DCM_out_e_var._name, "PUMA_mon_DCM_out_e", 16384);
  stracpy(_PUMA_mon_DCM_out_e_var._type, "E_monitor", 16384);
  _PUMA_mon_DCM_out_e_var._index=158;
  int current_setpos_index = 158;
  _PUMA_mon_DCM_out_e_var._parameters.nE = 100;
  _PUMA_mon_DCM_out_e_var._parameters.filename[0]='\0';
  _PUMA_mon_DCM_out_e_var._parameters.xwidth = 0.1;
  _PUMA_mon_DCM_out_e_var._parameters.yheight = 0.1;
  _PUMA_mon_DCM_out_e_var._parameters.Emin = 4;
  _PUMA_mon_DCM_out_e_var._parameters.Emax = 60;
  _PUMA_mon_DCM_out_e_var._parameters.restore_xray = 1;


  /* component PUMA_mon_DCM_out_e=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_DCM_xtal2_out_var._rotation_absolute, _PUMA_mon_DCM_out_e_var._rotation_absolute);
    rot_transpose(_PUMA_DCM_xtal2_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_DCM_out_e_var._rotation_absolute, tr1, _PUMA_mon_DCM_out_e_var._rotation_relative);
    _PUMA_mon_DCM_out_e_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_DCM_out_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_PUMA_DCM_xtal2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_DCM_out_e_var._position_absolute = coords_add(_PUMA_DCM_xtal2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_DCM_xtal2_var._position_absolute, _PUMA_mon_DCM_out_e_var._position_absolute);
    _PUMA_mon_DCM_out_e_var._position_relative = rot_apply(_PUMA_mon_DCM_out_e_var._rotation_absolute, tc1);
  } /* PUMA_mon_DCM_out_e=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_DCM_out_e", _PUMA_mon_DCM_out_e_var._position_absolute, _PUMA_mon_DCM_out_e_var._rotation_absolute);
  instrument->_position_absolute[158] = _PUMA_mon_DCM_out_e_var._position_absolute;
  instrument->_position_relative[158] = _PUMA_mon_DCM_out_e_var._position_relative;
    _PUMA_mon_DCM_out_e_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_DCM_out_e_var._position_relative);
  instrument->counter_N[158]  = instrument->counter_P[158] = instrument->counter_P2[158] = 0;
  instrument->counter_AbsorbProp[158]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", _PUMA_mon_DCM_out_e_var._position_absolute, _PUMA_mon_DCM_out_e_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "nE", "20", "100","MCNUM");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "Emin", "NONE", "4","MCNUM");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "Emax", "NONE", "60","MCNUM");
        mccomp_param_nexus(nxhandle,"0157_PUMA_mon_DCM_out_e", "restore_xray", "0", "1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_DCM_out_e_setpos */

/* component PUMA_mon_DCM_out_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_DCM_out_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_DCM_out_xy_setpos] component PUMA_mon_DCM_out_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_DCM_out_xy_var._name, "PUMA_mon_DCM_out_xy", 16384);
  stracpy(_PUMA_mon_DCM_out_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_DCM_out_xy_var._index=159;
  int current_setpos_index = 159;
  if("PUMA_Position_after_Mono_DCM" && strlen("PUMA_Position_after_Mono_DCM"))
    stracpy(_PUMA_mon_DCM_out_xy_var._parameters.filename, "PUMA_Position_after_Mono_DCM" ? "PUMA_Position_after_Mono_DCM" : "", 16384);
  else 
  _PUMA_mon_DCM_out_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_DCM_out_xy_var._parameters.xwidth = 0.07;
  _PUMA_mon_DCM_out_xy_var._parameters.yheight = 0.05;
  _PUMA_mon_DCM_out_xy_var._parameters.radius = 0;
  _PUMA_mon_DCM_out_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_DCM_out_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_DCM_out_xy_var._parameters.nx = 100;
  _PUMA_mon_DCM_out_xy_var._parameters.ny = 100;
  _PUMA_mon_DCM_out_xy_var._parameters.nr = 0;


  /* component PUMA_mon_DCM_out_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_DCM_out_e_var._rotation_absolute, _PUMA_mon_DCM_out_xy_var._rotation_absolute);
    rot_transpose(_PUMA_mon_DCM_out_e_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_DCM_out_xy_var._rotation_absolute, tr1, _PUMA_mon_DCM_out_xy_var._rotation_relative);
    _PUMA_mon_DCM_out_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_DCM_out_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_mon_DCM_out_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_DCM_out_xy_var._position_absolute = coords_add(_PUMA_mon_DCM_out_e_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_DCM_out_e_var._position_absolute, _PUMA_mon_DCM_out_xy_var._position_absolute);
    _PUMA_mon_DCM_out_xy_var._position_relative = rot_apply(_PUMA_mon_DCM_out_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_DCM_out_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_DCM_out_xy", _PUMA_mon_DCM_out_xy_var._position_absolute, _PUMA_mon_DCM_out_xy_var._rotation_absolute);
  instrument->_position_absolute[159] = _PUMA_mon_DCM_out_xy_var._position_absolute;
  instrument->_position_relative[159] = _PUMA_mon_DCM_out_xy_var._position_relative;
    _PUMA_mon_DCM_out_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_DCM_out_xy_var._position_relative);
  instrument->counter_N[159]  = instrument->counter_P[159] = instrument->counter_P2[159] = 0;
  instrument->counter_AbsorbProp[159]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", _PUMA_mon_DCM_out_xy_var._position_absolute, _PUMA_mon_DCM_out_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "filename", 0, "PUMA_Position_after_Mono_DCM", "char*");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "xwidth", "0.05", "0.07","MCNUM");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "yheight", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0158_PUMA_mon_DCM_out_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_DCM_out_xy_setpos */

/* component PUMA_slit3=Slit() SETTING, POSITION/ROTATION */
int _PUMA_slit3_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_slit3_setpos] component PUMA_slit3=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PUMA_slit3_var._name, "PUMA_slit3", 16384);
  stracpy(_PUMA_slit3_var._type, "Slit", 16384);
  _PUMA_slit3_var._index=160;
  int current_setpos_index = 160;
  _PUMA_slit3_var._parameters.xmin = 0;
  _PUMA_slit3_var._parameters.xmax = 0;
  _PUMA_slit3_var._parameters.ymin = 0;
  _PUMA_slit3_var._parameters.ymax = 0;
  _PUMA_slit3_var._parameters.radius = 0;
  _PUMA_slit3_var._parameters.xwidth = 0.02;
  _PUMA_slit3_var._parameters.yheight = 3e-3;
  _PUMA_slit3_var._parameters.dist = 0;
  _PUMA_slit3_var._parameters.focus_xw = 0;
  _PUMA_slit3_var._parameters.focus_yh = 0;
  _PUMA_slit3_var._parameters.focus_x0 = 0;
  _PUMA_slit3_var._parameters.focus_y0 = 0;

  /* component PUMA_slit3=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_DCM_out_xy_var._rotation_absolute, _PUMA_slit3_var._rotation_absolute);
    rot_transpose(_PUMA_mon_DCM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_slit3_var._rotation_absolute, tr1, _PUMA_slit3_var._rotation_relative);
    _PUMA_slit3_var._rotation_is_identity =  rot_test_identity(_PUMA_slit3_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 23.535 - 22.5 ));
    rot_transpose(_PUMA_mon_DCM_out_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_slit3_var._position_absolute = coords_add(_PUMA_mon_DCM_out_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_DCM_out_xy_var._position_absolute, _PUMA_slit3_var._position_absolute);
    _PUMA_slit3_var._position_relative = rot_apply(_PUMA_slit3_var._rotation_absolute, tc1);
  } /* PUMA_slit3=Slit() AT ROTATED */
  DEBUG_COMPONENT("PUMA_slit3", _PUMA_slit3_var._position_absolute, _PUMA_slit3_var._rotation_absolute);
  instrument->_position_absolute[160] = _PUMA_slit3_var._position_absolute;
  instrument->_position_relative[160] = _PUMA_slit3_var._position_relative;
    _PUMA_slit3_var._position_relative_is_zero =  coords_test_zero(_PUMA_slit3_var._position_relative);
  instrument->counter_N[160]  = instrument->counter_P[160] = instrument->counter_P2[160] = 0;
  instrument->counter_AbsorbProp[160]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0159_PUMA_slit3", _PUMA_slit3_var._position_absolute, _PUMA_slit3_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "xwidth", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "yheight", "0.001", "3e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0159_PUMA_slit3", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_slit3_setpos */

/* component PUMA_slit4=Slit() SETTING, POSITION/ROTATION */
int _PUMA_slit4_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_slit4_setpos] component PUMA_slit4=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PUMA_slit4_var._name, "PUMA_slit4", 16384);
  stracpy(_PUMA_slit4_var._type, "Slit", 16384);
  _PUMA_slit4_var._index=161;
  int current_setpos_index = 161;
  _PUMA_slit4_var._parameters.xmin = 0;
  _PUMA_slit4_var._parameters.xmax = 0;
  _PUMA_slit4_var._parameters.ymin = 0;
  _PUMA_slit4_var._parameters.ymax = 0;
  _PUMA_slit4_var._parameters.radius = 0;
  _PUMA_slit4_var._parameters.xwidth = 1.5e-3;
  _PUMA_slit4_var._parameters.yheight = 0.01;
  _PUMA_slit4_var._parameters.dist = 0;
  _PUMA_slit4_var._parameters.focus_xw = 0;
  _PUMA_slit4_var._parameters.focus_yh = 0;
  _PUMA_slit4_var._parameters.focus_x0 = 0;
  _PUMA_slit4_var._parameters.focus_y0 = 0;

  /* component PUMA_slit4=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_slit3_var._rotation_absolute, _PUMA_slit4_var._rotation_absolute);
    rot_transpose(_PUMA_slit3_var._rotation_absolute, tr1);
    rot_mul(_PUMA_slit4_var._rotation_absolute, tr1, _PUMA_slit4_var._rotation_relative);
    _PUMA_slit4_var._rotation_is_identity =  rot_test_identity(_PUMA_slit4_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 23.658 - 23.535 ));
    rot_transpose(_PUMA_slit3_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_slit4_var._position_absolute = coords_add(_PUMA_slit3_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_slit3_var._position_absolute, _PUMA_slit4_var._position_absolute);
    _PUMA_slit4_var._position_relative = rot_apply(_PUMA_slit4_var._rotation_absolute, tc1);
  } /* PUMA_slit4=Slit() AT ROTATED */
  DEBUG_COMPONENT("PUMA_slit4", _PUMA_slit4_var._position_absolute, _PUMA_slit4_var._rotation_absolute);
  instrument->_position_absolute[161] = _PUMA_slit4_var._position_absolute;
  instrument->_position_relative[161] = _PUMA_slit4_var._position_relative;
    _PUMA_slit4_var._position_relative_is_zero =  coords_test_zero(_PUMA_slit4_var._position_relative);
  instrument->counter_N[161]  = instrument->counter_P[161] = instrument->counter_P2[161] = 0;
  instrument->counter_AbsorbProp[161]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0160_PUMA_slit4", _PUMA_slit4_var._position_absolute, _PUMA_slit4_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "xwidth", "0.001", "1.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0160_PUMA_slit4", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_slit4_setpos */

/* component PUMA_slit5=Slit() SETTING, POSITION/ROTATION */
int _PUMA_slit5_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_slit5_setpos] component PUMA_slit5=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PUMA_slit5_var._name, "PUMA_slit5", 16384);
  stracpy(_PUMA_slit5_var._type, "Slit", 16384);
  _PUMA_slit5_var._index=162;
  int current_setpos_index = 162;
  _PUMA_slit5_var._parameters.xmin = 0;
  _PUMA_slit5_var._parameters.xmax = 0;
  _PUMA_slit5_var._parameters.ymin = 0;
  _PUMA_slit5_var._parameters.ymax = 0;
  _PUMA_slit5_var._parameters.radius = 0;
  _PUMA_slit5_var._parameters.xwidth = 1.5e-3;
  _PUMA_slit5_var._parameters.yheight = 3e-3;
  _PUMA_slit5_var._parameters.dist = 0;
  _PUMA_slit5_var._parameters.focus_xw = 0;
  _PUMA_slit5_var._parameters.focus_yh = 0;
  _PUMA_slit5_var._parameters.focus_x0 = 0;
  _PUMA_slit5_var._parameters.focus_y0 = 0;

  /* component PUMA_slit5=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_slit4_var._rotation_absolute, _PUMA_slit5_var._rotation_absolute);
    rot_transpose(_PUMA_slit4_var._rotation_absolute, tr1);
    rot_mul(_PUMA_slit5_var._rotation_absolute, tr1, _PUMA_slit5_var._rotation_relative);
    _PUMA_slit5_var._rotation_is_identity =  rot_test_identity(_PUMA_slit5_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 40 - 23.658 ));
    rot_transpose(_PUMA_slit4_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_slit5_var._position_absolute = coords_add(_PUMA_slit4_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_slit4_var._position_absolute, _PUMA_slit5_var._position_absolute);
    _PUMA_slit5_var._position_relative = rot_apply(_PUMA_slit5_var._rotation_absolute, tc1);
  } /* PUMA_slit5=Slit() AT ROTATED */
  DEBUG_COMPONENT("PUMA_slit5", _PUMA_slit5_var._position_absolute, _PUMA_slit5_var._rotation_absolute);
  instrument->_position_absolute[162] = _PUMA_slit5_var._position_absolute;
  instrument->_position_relative[162] = _PUMA_slit5_var._position_relative;
    _PUMA_slit5_var._position_relative_is_zero =  coords_test_zero(_PUMA_slit5_var._position_relative);
  instrument->counter_N[162]  = instrument->counter_P[162] = instrument->counter_P2[162] = 0;
  instrument->counter_AbsorbProp[162]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0161_PUMA_slit5", _PUMA_slit5_var._position_absolute, _PUMA_slit5_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "xwidth", "0.001", "1.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "yheight", "0.001", "3e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0161_PUMA_slit5", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_slit5_setpos */

/* component PUMA_KB_VFM_location=Arm() SETTING, POSITION/ROTATION */
int _PUMA_KB_VFM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_KB_VFM_location_setpos] component PUMA_KB_VFM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_KB_VFM_location_var._name, "PUMA_KB_VFM_location", 16384);
  stracpy(_PUMA_KB_VFM_location_var._type, "Arm", 16384);
  _PUMA_KB_VFM_location_var._index=163;
  int current_setpos_index = 163;
  /* component PUMA_KB_VFM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_slit5_var._rotation_absolute, _PUMA_KB_VFM_location_var._rotation_absolute);
    rot_transpose(_PUMA_slit5_var._rotation_absolute, tr1);
    rot_mul(_PUMA_KB_VFM_location_var._rotation_absolute, tr1, _PUMA_KB_VFM_location_var._rotation_relative);
    _PUMA_KB_VFM_location_var._rotation_is_identity =  rot_test_identity(_PUMA_KB_VFM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 62.515 - 40 ));
    rot_transpose(_PUMA_slit5_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_KB_VFM_location_var._position_absolute = coords_add(_PUMA_slit5_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_slit5_var._position_absolute, _PUMA_KB_VFM_location_var._position_absolute);
    _PUMA_KB_VFM_location_var._position_relative = rot_apply(_PUMA_KB_VFM_location_var._rotation_absolute, tc1);
  } /* PUMA_KB_VFM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_KB_VFM_location", _PUMA_KB_VFM_location_var._position_absolute, _PUMA_KB_VFM_location_var._rotation_absolute);
  instrument->_position_absolute[163] = _PUMA_KB_VFM_location_var._position_absolute;
  instrument->_position_relative[163] = _PUMA_KB_VFM_location_var._position_relative;
    _PUMA_KB_VFM_location_var._position_relative_is_zero =  coords_test_zero(_PUMA_KB_VFM_location_var._position_relative);
  instrument->counter_N[163]  = instrument->counter_P[163] = instrument->counter_P2[163] = 0;
  instrument->counter_AbsorbProp[163]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0162_PUMA_KB_VFM_location", _PUMA_KB_VFM_location_var._position_absolute, _PUMA_KB_VFM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_KB_VFM_location_setpos */

/* component PUMA_mon_KB_in_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_KB_in_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_KB_in_xy_setpos] component PUMA_mon_KB_in_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_KB_in_xy_var._name, "PUMA_mon_KB_in_xy", 16384);
  stracpy(_PUMA_mon_KB_in_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_KB_in_xy_var._index=164;
  int current_setpos_index = 164;
  _PUMA_mon_KB_in_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_KB_in_xy_var._parameters.xwidth = 0.05;
  _PUMA_mon_KB_in_xy_var._parameters.yheight = 0.03;
  _PUMA_mon_KB_in_xy_var._parameters.radius = 0;
  _PUMA_mon_KB_in_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_KB_in_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_KB_in_xy_var._parameters.nx = 100;
  _PUMA_mon_KB_in_xy_var._parameters.ny = 100;
  _PUMA_mon_KB_in_xy_var._parameters.nr = 0;


  /* component PUMA_mon_KB_in_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_VFM_location_var._rotation_absolute, _PUMA_mon_KB_in_xy_var._rotation_absolute);
    rot_transpose(_PUMA_slit5_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_KB_in_xy_var._rotation_absolute, tr1, _PUMA_mon_KB_in_xy_var._rotation_relative);
    _PUMA_mon_KB_in_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_KB_in_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_VFM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_KB_in_xy_var._position_absolute = coords_add(_PUMA_KB_VFM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_slit5_var._position_absolute, _PUMA_mon_KB_in_xy_var._position_absolute);
    _PUMA_mon_KB_in_xy_var._position_relative = rot_apply(_PUMA_mon_KB_in_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_KB_in_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_KB_in_xy", _PUMA_mon_KB_in_xy_var._position_absolute, _PUMA_mon_KB_in_xy_var._rotation_absolute);
  instrument->_position_absolute[164] = _PUMA_mon_KB_in_xy_var._position_absolute;
  instrument->_position_relative[164] = _PUMA_mon_KB_in_xy_var._position_relative;
    _PUMA_mon_KB_in_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_KB_in_xy_var._position_relative);
  instrument->counter_N[164]  = instrument->counter_P[164] = instrument->counter_P2[164] = 0;
  instrument->counter_AbsorbProp[164]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", _PUMA_mon_KB_in_xy_var._position_absolute, _PUMA_mon_KB_in_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "yheight", "0.05", "0.03","MCNUM");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0163_PUMA_mon_KB_in_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_KB_in_xy_setpos */

/* component PUMA_KB_VFM_rotated=Arm() SETTING, POSITION/ROTATION */
int _PUMA_KB_VFM_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_KB_VFM_rotated_setpos] component PUMA_KB_VFM_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_KB_VFM_rotated_var._name, "PUMA_KB_VFM_rotated", 16384);
  stracpy(_PUMA_KB_VFM_rotated_var._type, "Arm", 16384);
  _PUMA_KB_VFM_rotated_var._index=165;
  int current_setpos_index = 165;
  /* component PUMA_KB_VFM_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PUMA_KB_angle / 2)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_VFM_location_var._rotation_absolute, _PUMA_KB_VFM_rotated_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_in_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_KB_VFM_rotated_var._rotation_absolute, tr1, _PUMA_KB_VFM_rotated_var._rotation_relative);
    _PUMA_KB_VFM_rotated_var._rotation_is_identity =  rot_test_identity(_PUMA_KB_VFM_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_VFM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_KB_VFM_rotated_var._position_absolute = coords_add(_PUMA_KB_VFM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_in_xy_var._position_absolute, _PUMA_KB_VFM_rotated_var._position_absolute);
    _PUMA_KB_VFM_rotated_var._position_relative = rot_apply(_PUMA_KB_VFM_rotated_var._rotation_absolute, tc1);
  } /* PUMA_KB_VFM_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_KB_VFM_rotated", _PUMA_KB_VFM_rotated_var._position_absolute, _PUMA_KB_VFM_rotated_var._rotation_absolute);
  instrument->_position_absolute[165] = _PUMA_KB_VFM_rotated_var._position_absolute;
  instrument->_position_relative[165] = _PUMA_KB_VFM_rotated_var._position_relative;
    _PUMA_KB_VFM_rotated_var._position_relative_is_zero =  coords_test_zero(_PUMA_KB_VFM_rotated_var._position_relative);
  instrument->counter_N[165]  = instrument->counter_P[165] = instrument->counter_P2[165] = 0;
  instrument->counter_AbsorbProp[165]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0164_PUMA_KB_VFM_rotated", _PUMA_KB_VFM_rotated_var._position_absolute, _PUMA_KB_VFM_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_KB_VFM_rotated_setpos */

/* component PUMA_mirror_KB_VFM=Mirror_curved() SETTING, POSITION/ROTATION */
int _PUMA_mirror_KB_VFM_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mirror_KB_VFM_setpos] component PUMA_mirror_KB_VFM=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PUMA_mirror_KB_VFM_var._name, "PUMA_mirror_KB_VFM", 16384);
  stracpy(_PUMA_mirror_KB_VFM_var._type, "Mirror_curved", 16384);
  _PUMA_mirror_KB_VFM_var._index=166;
  int current_setpos_index = 166;
  _PUMA_mirror_KB_VFM_var._parameters.radius = PUMA_KB_VFM_radius;
  _PUMA_mirror_KB_VFM_var._parameters.R0 = 1;
  if(_instrument_var._parameters.PUMA_KB_coating && strlen(_instrument_var._parameters.PUMA_KB_coating))
    stracpy(_PUMA_mirror_KB_VFM_var._parameters.coating, _instrument_var._parameters.PUMA_KB_coating ? _instrument_var._parameters.PUMA_KB_coating : "", 16384);
  else 
  _PUMA_mirror_KB_VFM_var._parameters.coating[0]='\0';
  _PUMA_mirror_KB_VFM_var._parameters.zdepth = 0.2;
  _PUMA_mirror_KB_VFM_var._parameters.yheight = 0.2;
  _PUMA_mirror_KB_VFM_var._parameters.length = 0.3;
  _PUMA_mirror_KB_VFM_var._parameters.width = 0.04;


  /* component PUMA_mirror_KB_VFM=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_VFM_rotated_var._rotation_absolute, _PUMA_mirror_KB_VFM_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_in_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mirror_KB_VFM_var._rotation_absolute, tr1, _PUMA_mirror_KB_VFM_var._rotation_relative);
    _PUMA_mirror_KB_VFM_var._rotation_is_identity =  rot_test_identity(_PUMA_mirror_KB_VFM_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_VFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mirror_KB_VFM_var._position_absolute = coords_add(_PUMA_KB_VFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_in_xy_var._position_absolute, _PUMA_mirror_KB_VFM_var._position_absolute);
    _PUMA_mirror_KB_VFM_var._position_relative = rot_apply(_PUMA_mirror_KB_VFM_var._rotation_absolute, tc1);
  } /* PUMA_mirror_KB_VFM=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mirror_KB_VFM", _PUMA_mirror_KB_VFM_var._position_absolute, _PUMA_mirror_KB_VFM_var._rotation_absolute);
  instrument->_position_absolute[166] = _PUMA_mirror_KB_VFM_var._position_absolute;
  instrument->_position_relative[166] = _PUMA_mirror_KB_VFM_var._position_relative;
    _PUMA_mirror_KB_VFM_var._position_relative_is_zero =  coords_test_zero(_PUMA_mirror_KB_VFM_var._position_relative);
  instrument->counter_N[166]  = instrument->counter_P[166] = instrument->counter_P2[166] = 0;
  instrument->counter_AbsorbProp[166]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", _PUMA_mirror_KB_VFM_var._position_absolute, _PUMA_mirror_KB_VFM_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "radius", "1", "PUMA_KB_VFM_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "coating", "Be.txt", _instrument_var._parameters.PUMA_KB_coating, "char*");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "length", "0", "0.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0165_PUMA_mirror_KB_VFM", "width", "0", "0.04","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mirror_KB_VFM_setpos */

/* component PUMA_KB_VFM_out=Arm() SETTING, POSITION/ROTATION */
int _PUMA_KB_VFM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_KB_VFM_out_setpos] component PUMA_KB_VFM_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_KB_VFM_out_var._name, "PUMA_KB_VFM_out", 16384);
  stracpy(_PUMA_KB_VFM_out_var._type, "Arm", 16384);
  _PUMA_KB_VFM_out_var._index=167;
  int current_setpos_index = 167;
  /* component PUMA_KB_VFM_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PUMA_KB_angle / 2)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_VFM_rotated_var._rotation_absolute, _PUMA_KB_VFM_out_var._rotation_absolute);
    rot_transpose(_PUMA_mirror_KB_VFM_var._rotation_absolute, tr1);
    rot_mul(_PUMA_KB_VFM_out_var._rotation_absolute, tr1, _PUMA_KB_VFM_out_var._rotation_relative);
    _PUMA_KB_VFM_out_var._rotation_is_identity =  rot_test_identity(_PUMA_KB_VFM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_VFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_KB_VFM_out_var._position_absolute = coords_add(_PUMA_KB_VFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mirror_KB_VFM_var._position_absolute, _PUMA_KB_VFM_out_var._position_absolute);
    _PUMA_KB_VFM_out_var._position_relative = rot_apply(_PUMA_KB_VFM_out_var._rotation_absolute, tc1);
  } /* PUMA_KB_VFM_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_KB_VFM_out", _PUMA_KB_VFM_out_var._position_absolute, _PUMA_KB_VFM_out_var._rotation_absolute);
  instrument->_position_absolute[167] = _PUMA_KB_VFM_out_var._position_absolute;
  instrument->_position_relative[167] = _PUMA_KB_VFM_out_var._position_relative;
    _PUMA_KB_VFM_out_var._position_relative_is_zero =  coords_test_zero(_PUMA_KB_VFM_out_var._position_relative);
  instrument->counter_N[167]  = instrument->counter_P[167] = instrument->counter_P2[167] = 0;
  instrument->counter_AbsorbProp[167]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0166_PUMA_KB_VFM_out", _PUMA_KB_VFM_out_var._position_absolute, _PUMA_KB_VFM_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_KB_VFM_out_setpos */

/* component PUMA_mon_KB_VFM_out_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_KB_VFM_out_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_KB_VFM_out_xy_setpos] component PUMA_mon_KB_VFM_out_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_KB_VFM_out_xy_var._name, "PUMA_mon_KB_VFM_out_xy", 16384);
  stracpy(_PUMA_mon_KB_VFM_out_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_KB_VFM_out_xy_var._index=168;
  int current_setpos_index = 168;
  if("PUMA_Position_after_KB_VFM_Mirror" && strlen("PUMA_Position_after_KB_VFM_Mirror"))
    stracpy(_PUMA_mon_KB_VFM_out_xy_var._parameters.filename, "PUMA_Position_after_KB_VFM_Mirror" ? "PUMA_Position_after_KB_VFM_Mirror" : "", 16384);
  else 
  _PUMA_mon_KB_VFM_out_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_KB_VFM_out_xy_var._parameters.xwidth = 0.05;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.yheight = 0.03;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.radius = 0;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.nx = 100;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.ny = 100;
  _PUMA_mon_KB_VFM_out_xy_var._parameters.nr = 0;


  /* component PUMA_mon_KB_VFM_out_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_VFM_out_var._rotation_absolute, _PUMA_mon_KB_VFM_out_xy_var._rotation_absolute);
    rot_transpose(_PUMA_mirror_KB_VFM_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, tr1, _PUMA_mon_KB_VFM_out_xy_var._rotation_relative);
    _PUMA_mon_KB_VFM_out_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_KB_VFM_out_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_VFM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_KB_VFM_out_xy_var._position_absolute = coords_add(_PUMA_KB_VFM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mirror_KB_VFM_var._position_absolute, _PUMA_mon_KB_VFM_out_xy_var._position_absolute);
    _PUMA_mon_KB_VFM_out_xy_var._position_relative = rot_apply(_PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_KB_VFM_out_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_KB_VFM_out_xy", _PUMA_mon_KB_VFM_out_xy_var._position_absolute, _PUMA_mon_KB_VFM_out_xy_var._rotation_absolute);
  instrument->_position_absolute[168] = _PUMA_mon_KB_VFM_out_xy_var._position_absolute;
  instrument->_position_relative[168] = _PUMA_mon_KB_VFM_out_xy_var._position_relative;
    _PUMA_mon_KB_VFM_out_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_KB_VFM_out_xy_var._position_relative);
  instrument->counter_N[168]  = instrument->counter_P[168] = instrument->counter_P2[168] = 0;
  instrument->counter_AbsorbProp[168]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", _PUMA_mon_KB_VFM_out_xy_var._position_absolute, _PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "filename", 0, "PUMA_Position_after_KB_VFM_Mirror", "char*");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "yheight", "0.05", "0.03","MCNUM");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0167_PUMA_mon_KB_VFM_out_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_KB_VFM_out_xy_setpos */

/* component PUMA_KB_HFM_location=Arm() SETTING, POSITION/ROTATION */
int _PUMA_KB_HFM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_KB_HFM_location_setpos] component PUMA_KB_HFM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_KB_HFM_location_var._name, "PUMA_KB_HFM_location", 16384);
  stracpy(_PUMA_KB_HFM_location_var._type, "Arm", 16384);
  _PUMA_KB_HFM_location_var._index=169;
  int current_setpos_index = 169;
  /* component PUMA_KB_HFM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, _PUMA_KB_HFM_location_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_KB_HFM_location_var._rotation_absolute, tr1, _PUMA_KB_HFM_location_var._rotation_relative);
    _PUMA_KB_HFM_location_var._rotation_is_identity =  rot_test_identity(_PUMA_KB_HFM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 62.975 - 62.515 ));
    rot_transpose(_PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_KB_HFM_location_var._position_absolute = coords_add(_PUMA_mon_KB_VFM_out_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_VFM_out_xy_var._position_absolute, _PUMA_KB_HFM_location_var._position_absolute);
    _PUMA_KB_HFM_location_var._position_relative = rot_apply(_PUMA_KB_HFM_location_var._rotation_absolute, tc1);
  } /* PUMA_KB_HFM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_KB_HFM_location", _PUMA_KB_HFM_location_var._position_absolute, _PUMA_KB_HFM_location_var._rotation_absolute);
  instrument->_position_absolute[169] = _PUMA_KB_HFM_location_var._position_absolute;
  instrument->_position_relative[169] = _PUMA_KB_HFM_location_var._position_relative;
    _PUMA_KB_HFM_location_var._position_relative_is_zero =  coords_test_zero(_PUMA_KB_HFM_location_var._position_relative);
  instrument->counter_N[169]  = instrument->counter_P[169] = instrument->counter_P2[169] = 0;
  instrument->counter_AbsorbProp[169]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0168_PUMA_KB_HFM_location", _PUMA_KB_HFM_location_var._position_absolute, _PUMA_KB_HFM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_KB_HFM_location_setpos */

/* component PUMA_KB_HFM_rotated=Arm() SETTING, POSITION/ROTATION */
int _PUMA_KB_HFM_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_KB_HFM_rotated_setpos] component PUMA_KB_HFM_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_KB_HFM_rotated_var._name, "PUMA_KB_HFM_rotated", 16384);
  stracpy(_PUMA_KB_HFM_rotated_var._type, "Arm", 16384);
  _PUMA_KB_HFM_rotated_var._index=170;
  int current_setpos_index = 170;
  /* component PUMA_KB_HFM_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.PUMA_KB_angle / 2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_HFM_location_var._rotation_absolute, _PUMA_KB_HFM_rotated_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_KB_HFM_rotated_var._rotation_absolute, tr1, _PUMA_KB_HFM_rotated_var._rotation_relative);
    _PUMA_KB_HFM_rotated_var._rotation_is_identity =  rot_test_identity(_PUMA_KB_HFM_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_HFM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_KB_HFM_rotated_var._position_absolute = coords_add(_PUMA_KB_HFM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_VFM_out_xy_var._position_absolute, _PUMA_KB_HFM_rotated_var._position_absolute);
    _PUMA_KB_HFM_rotated_var._position_relative = rot_apply(_PUMA_KB_HFM_rotated_var._rotation_absolute, tc1);
  } /* PUMA_KB_HFM_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_KB_HFM_rotated", _PUMA_KB_HFM_rotated_var._position_absolute, _PUMA_KB_HFM_rotated_var._rotation_absolute);
  instrument->_position_absolute[170] = _PUMA_KB_HFM_rotated_var._position_absolute;
  instrument->_position_relative[170] = _PUMA_KB_HFM_rotated_var._position_relative;
    _PUMA_KB_HFM_rotated_var._position_relative_is_zero =  coords_test_zero(_PUMA_KB_HFM_rotated_var._position_relative);
  instrument->counter_N[170]  = instrument->counter_P[170] = instrument->counter_P2[170] = 0;
  instrument->counter_AbsorbProp[170]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0169_PUMA_KB_HFM_rotated", _PUMA_KB_HFM_rotated_var._position_absolute, _PUMA_KB_HFM_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_KB_HFM_rotated_setpos */

/* component PUMA_mirror_KB_HFM=Mirror_curved() SETTING, POSITION/ROTATION */
int _PUMA_mirror_KB_HFM_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mirror_KB_HFM_setpos] component PUMA_mirror_KB_HFM=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PUMA_mirror_KB_HFM_var._name, "PUMA_mirror_KB_HFM", 16384);
  stracpy(_PUMA_mirror_KB_HFM_var._type, "Mirror_curved", 16384);
  _PUMA_mirror_KB_HFM_var._index=171;
  int current_setpos_index = 171;
  _PUMA_mirror_KB_HFM_var._parameters.radius = PUMA_KB_HFM_radius;
  _PUMA_mirror_KB_HFM_var._parameters.R0 = 1;
  if(_instrument_var._parameters.PUMA_KB_coating && strlen(_instrument_var._parameters.PUMA_KB_coating))
    stracpy(_PUMA_mirror_KB_HFM_var._parameters.coating, _instrument_var._parameters.PUMA_KB_coating ? _instrument_var._parameters.PUMA_KB_coating : "", 16384);
  else 
  _PUMA_mirror_KB_HFM_var._parameters.coating[0]='\0';
  _PUMA_mirror_KB_HFM_var._parameters.zdepth = 0.2;
  _PUMA_mirror_KB_HFM_var._parameters.yheight = 0.2;
  _PUMA_mirror_KB_HFM_var._parameters.length = 0.3;
  _PUMA_mirror_KB_HFM_var._parameters.width = 0.04;


  /* component PUMA_mirror_KB_HFM=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_HFM_rotated_var._rotation_absolute, _PUMA_mirror_KB_HFM_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_VFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mirror_KB_HFM_var._rotation_absolute, tr1, _PUMA_mirror_KB_HFM_var._rotation_relative);
    _PUMA_mirror_KB_HFM_var._rotation_is_identity =  rot_test_identity(_PUMA_mirror_KB_HFM_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_HFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mirror_KB_HFM_var._position_absolute = coords_add(_PUMA_KB_HFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_VFM_out_xy_var._position_absolute, _PUMA_mirror_KB_HFM_var._position_absolute);
    _PUMA_mirror_KB_HFM_var._position_relative = rot_apply(_PUMA_mirror_KB_HFM_var._rotation_absolute, tc1);
  } /* PUMA_mirror_KB_HFM=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mirror_KB_HFM", _PUMA_mirror_KB_HFM_var._position_absolute, _PUMA_mirror_KB_HFM_var._rotation_absolute);
  instrument->_position_absolute[171] = _PUMA_mirror_KB_HFM_var._position_absolute;
  instrument->_position_relative[171] = _PUMA_mirror_KB_HFM_var._position_relative;
    _PUMA_mirror_KB_HFM_var._position_relative_is_zero =  coords_test_zero(_PUMA_mirror_KB_HFM_var._position_relative);
  instrument->counter_N[171]  = instrument->counter_P[171] = instrument->counter_P2[171] = 0;
  instrument->counter_AbsorbProp[171]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", _PUMA_mirror_KB_HFM_var._position_absolute, _PUMA_mirror_KB_HFM_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "radius", "1", "PUMA_KB_HFM_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "coating", "Be.txt", _instrument_var._parameters.PUMA_KB_coating, "char*");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "length", "0", "0.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0170_PUMA_mirror_KB_HFM", "width", "0", "0.04","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mirror_KB_HFM_setpos */

/* component PUMA_KB_HFM_out=Arm() SETTING, POSITION/ROTATION */
int _PUMA_KB_HFM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_KB_HFM_out_setpos] component PUMA_KB_HFM_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_KB_HFM_out_var._name, "PUMA_KB_HFM_out", 16384);
  stracpy(_PUMA_KB_HFM_out_var._type, "Arm", 16384);
  _PUMA_KB_HFM_out_var._index=172;
  int current_setpos_index = 172;
  /* component PUMA_KB_HFM_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.PUMA_KB_angle / 2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_HFM_rotated_var._rotation_absolute, _PUMA_KB_HFM_out_var._rotation_absolute);
    rot_transpose(_PUMA_mirror_KB_HFM_var._rotation_absolute, tr1);
    rot_mul(_PUMA_KB_HFM_out_var._rotation_absolute, tr1, _PUMA_KB_HFM_out_var._rotation_relative);
    _PUMA_KB_HFM_out_var._rotation_is_identity =  rot_test_identity(_PUMA_KB_HFM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_HFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_KB_HFM_out_var._position_absolute = coords_add(_PUMA_KB_HFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mirror_KB_HFM_var._position_absolute, _PUMA_KB_HFM_out_var._position_absolute);
    _PUMA_KB_HFM_out_var._position_relative = rot_apply(_PUMA_KB_HFM_out_var._rotation_absolute, tc1);
  } /* PUMA_KB_HFM_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_KB_HFM_out", _PUMA_KB_HFM_out_var._position_absolute, _PUMA_KB_HFM_out_var._rotation_absolute);
  instrument->_position_absolute[172] = _PUMA_KB_HFM_out_var._position_absolute;
  instrument->_position_relative[172] = _PUMA_KB_HFM_out_var._position_relative;
    _PUMA_KB_HFM_out_var._position_relative_is_zero =  coords_test_zero(_PUMA_KB_HFM_out_var._position_relative);
  instrument->counter_N[172]  = instrument->counter_P[172] = instrument->counter_P2[172] = 0;
  instrument->counter_AbsorbProp[172]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0171_PUMA_KB_HFM_out", _PUMA_KB_HFM_out_var._position_absolute, _PUMA_KB_HFM_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_KB_HFM_out_setpos */

/* component PUMA_mon_KB_HFM_out_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_KB_HFM_out_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_KB_HFM_out_xy_setpos] component PUMA_mon_KB_HFM_out_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_KB_HFM_out_xy_var._name, "PUMA_mon_KB_HFM_out_xy", 16384);
  stracpy(_PUMA_mon_KB_HFM_out_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_KB_HFM_out_xy_var._index=173;
  int current_setpos_index = 173;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_KB_HFM_out_xy_var._parameters.xwidth = 0.01;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.yheight = 0.01;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.radius = 0;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.nx = 100;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.ny = 100;
  _PUMA_mon_KB_HFM_out_xy_var._parameters.nr = 0;


  /* component PUMA_mon_KB_HFM_out_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_KB_HFM_out_var._rotation_absolute, _PUMA_mon_KB_HFM_out_xy_var._rotation_absolute);
    rot_transpose(_PUMA_mirror_KB_HFM_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, tr1, _PUMA_mon_KB_HFM_out_xy_var._rotation_relative);
    _PUMA_mon_KB_HFM_out_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_KB_HFM_out_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_KB_HFM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_KB_HFM_out_xy_var._position_absolute = coords_add(_PUMA_KB_HFM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mirror_KB_HFM_var._position_absolute, _PUMA_mon_KB_HFM_out_xy_var._position_absolute);
    _PUMA_mon_KB_HFM_out_xy_var._position_relative = rot_apply(_PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_KB_HFM_out_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_KB_HFM_out_xy", _PUMA_mon_KB_HFM_out_xy_var._position_absolute, _PUMA_mon_KB_HFM_out_xy_var._rotation_absolute);
  instrument->_position_absolute[173] = _PUMA_mon_KB_HFM_out_xy_var._position_absolute;
  instrument->_position_relative[173] = _PUMA_mon_KB_HFM_out_xy_var._position_relative;
    _PUMA_mon_KB_HFM_out_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_KB_HFM_out_xy_var._position_relative);
  instrument->counter_N[173]  = instrument->counter_P[173] = instrument->counter_P2[173] = 0;
  instrument->counter_AbsorbProp[173]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", _PUMA_mon_KB_HFM_out_xy_var._position_absolute, _PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "xwidth", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0172_PUMA_mon_KB_HFM_out_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_KB_HFM_out_xy_setpos */

/* component PUMA_sample_location=Arm() SETTING, POSITION/ROTATION */
int _PUMA_sample_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_sample_location_setpos] component PUMA_sample_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PUMA_sample_location_var._name, "PUMA_sample_location", 16384);
  stracpy(_PUMA_sample_location_var._type, "Arm", 16384);
  _PUMA_sample_location_var._index=174;
  int current_setpos_index = 174;
  /* component PUMA_sample_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, _PUMA_sample_location_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_sample_location_var._rotation_absolute, tr1, _PUMA_sample_location_var._rotation_relative);
    _PUMA_sample_location_var._rotation_is_identity =  rot_test_identity(_PUMA_sample_location_var._rotation_relative);
    tc1 = coords_set(
      -7.88e-5, 0.002366, ( 63.3 - 62.975 ));
    rot_transpose(_PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_sample_location_var._position_absolute = coords_add(_PUMA_mon_KB_HFM_out_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_HFM_out_xy_var._position_absolute, _PUMA_sample_location_var._position_absolute);
    _PUMA_sample_location_var._position_relative = rot_apply(_PUMA_sample_location_var._rotation_absolute, tc1);
  } /* PUMA_sample_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PUMA_sample_location", _PUMA_sample_location_var._position_absolute, _PUMA_sample_location_var._rotation_absolute);
  instrument->_position_absolute[174] = _PUMA_sample_location_var._position_absolute;
  instrument->_position_relative[174] = _PUMA_sample_location_var._position_relative;
    _PUMA_sample_location_var._position_relative_is_zero =  coords_test_zero(_PUMA_sample_location_var._position_relative);
  instrument->counter_N[174]  = instrument->counter_P[174] = instrument->counter_P2[174] = 0;
  instrument->counter_AbsorbProp[174]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0173_PUMA_sample_location", _PUMA_sample_location_var._position_absolute, _PUMA_sample_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_sample_location_setpos */

/* component PUMA_mon_sample_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_sample_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_sample_xy_setpos] component PUMA_mon_sample_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PUMA_mon_sample_xy_var._name, "PUMA_mon_sample_xy", 16384);
  stracpy(_PUMA_mon_sample_xy_var._type, "PSD_monitor", 16384);
  _PUMA_mon_sample_xy_var._index=175;
  int current_setpos_index = 175;
  _PUMA_mon_sample_xy_var._parameters.filename[0]='\0';
  _PUMA_mon_sample_xy_var._parameters.xwidth = 5e-4;
  _PUMA_mon_sample_xy_var._parameters.yheight = 5e-4;
  _PUMA_mon_sample_xy_var._parameters.radius = 0;
  _PUMA_mon_sample_xy_var._parameters.restore_xray = 1;
  _PUMA_mon_sample_xy_var._parameters.nowritefile = 0;
  _PUMA_mon_sample_xy_var._parameters.nx = 200;
  _PUMA_mon_sample_xy_var._parameters.ny = 200;
  _PUMA_mon_sample_xy_var._parameters.nr = 0;


  /* component PUMA_mon_sample_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_sample_location_var._rotation_absolute, _PUMA_mon_sample_xy_var._rotation_absolute);
    rot_transpose(_PUMA_mon_KB_HFM_out_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_sample_xy_var._rotation_absolute, tr1, _PUMA_mon_sample_xy_var._rotation_relative);
    _PUMA_mon_sample_xy_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_sample_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_sample_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_sample_xy_var._position_absolute = coords_add(_PUMA_sample_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_KB_HFM_out_xy_var._position_absolute, _PUMA_mon_sample_xy_var._position_absolute);
    _PUMA_mon_sample_xy_var._position_relative = rot_apply(_PUMA_mon_sample_xy_var._rotation_absolute, tc1);
  } /* PUMA_mon_sample_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_sample_xy", _PUMA_mon_sample_xy_var._position_absolute, _PUMA_mon_sample_xy_var._rotation_absolute);
  instrument->_position_absolute[175] = _PUMA_mon_sample_xy_var._position_absolute;
  instrument->_position_relative[175] = _PUMA_mon_sample_xy_var._position_relative;
    _PUMA_mon_sample_xy_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_sample_xy_var._position_relative);
  instrument->counter_N[175]  = instrument->counter_P[175] = instrument->counter_P2[175] = 0;
  instrument->counter_AbsorbProp[175]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0174_PUMA_mon_sample_xy", _PUMA_mon_sample_xy_var._position_absolute, _PUMA_mon_sample_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "xwidth", "0.05", "5e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "yheight", "0.05", "5e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "nx", "90", "200","int");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "ny", "90", "200","int");
        mccomp_param_nexus(nxhandle,"0174_PUMA_mon_sample_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_sample_xy_setpos */

/* component PUMA_mon_sample_e=E_monitor() SETTING, POSITION/ROTATION */
int _PUMA_mon_sample_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PUMA_mon_sample_e_setpos] component PUMA_mon_sample_e=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_PUMA_mon_sample_e_var._name, "PUMA_mon_sample_e", 16384);
  stracpy(_PUMA_mon_sample_e_var._type, "E_monitor", 16384);
  _PUMA_mon_sample_e_var._index=176;
  int current_setpos_index = 176;
  _PUMA_mon_sample_e_var._parameters.nE = 200;
  if("PUMA_Energy_before_sample" && strlen("PUMA_Energy_before_sample"))
    stracpy(_PUMA_mon_sample_e_var._parameters.filename, "PUMA_Energy_before_sample" ? "PUMA_Energy_before_sample" : "", 16384);
  else 
  _PUMA_mon_sample_e_var._parameters.filename[0]='\0';
  _PUMA_mon_sample_e_var._parameters.xwidth = 0.1;
  _PUMA_mon_sample_e_var._parameters.yheight = 0.1;
  _PUMA_mon_sample_e_var._parameters.Emin = _instrument_var._parameters.PUMA_E0 - _instrument_var._parameters.PUMA_dE * 1.1;
  _PUMA_mon_sample_e_var._parameters.Emax = _instrument_var._parameters.PUMA_E0 + _instrument_var._parameters.PUMA_dE * 1.1;
  _PUMA_mon_sample_e_var._parameters.restore_xray = 0;


  /* component PUMA_mon_sample_e=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_sample_xy_var._rotation_absolute, _PUMA_mon_sample_e_var._rotation_absolute);
    rot_transpose(_PUMA_mon_sample_xy_var._rotation_absolute, tr1);
    rot_mul(_PUMA_mon_sample_e_var._rotation_absolute, tr1, _PUMA_mon_sample_e_var._rotation_relative);
    _PUMA_mon_sample_e_var._rotation_is_identity =  rot_test_identity(_PUMA_mon_sample_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_mon_sample_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PUMA_mon_sample_e_var._position_absolute = coords_add(_PUMA_mon_sample_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_sample_xy_var._position_absolute, _PUMA_mon_sample_e_var._position_absolute);
    _PUMA_mon_sample_e_var._position_relative = rot_apply(_PUMA_mon_sample_e_var._rotation_absolute, tc1);
  } /* PUMA_mon_sample_e=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("PUMA_mon_sample_e", _PUMA_mon_sample_e_var._position_absolute, _PUMA_mon_sample_e_var._rotation_absolute);
  instrument->_position_absolute[176] = _PUMA_mon_sample_e_var._position_absolute;
  instrument->_position_relative[176] = _PUMA_mon_sample_e_var._position_relative;
    _PUMA_mon_sample_e_var._position_relative_is_zero =  coords_test_zero(_PUMA_mon_sample_e_var._position_relative);
  instrument->counter_N[176]  = instrument->counter_P[176] = instrument->counter_P2[176] = 0;
  instrument->counter_AbsorbProp[176]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0175_PUMA_mon_sample_e", _PUMA_mon_sample_e_var._position_absolute, _PUMA_mon_sample_e_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "nE", "20", "200","MCNUM");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "filename", 0, "PUMA_Energy_before_sample", "char*");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "Emin", "NONE", "_instrument_var._parameters.PUMA_E0 - _instrument_var._parameters.PUMA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "Emax", "NONE", "_instrument_var._parameters.PUMA_E0 + _instrument_var._parameters.PUMA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0175_PUMA_mon_sample_e", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PUMA_mon_sample_e_setpos */

/* component beamdump_181=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_181_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_181_setpos] component beamdump_181=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_181_var._name, "beamdump_181", 16384);
  stracpy(_beamdump_181_var._type, "Beamstop", 16384);
  _beamdump_181_var._index=177;
  int current_setpos_index = 177;
  _beamdump_181_var._parameters.xmin = -0.05;
  _beamdump_181_var._parameters.xmax = 0.05;
  _beamdump_181_var._parameters.ymin = -0.05;
  _beamdump_181_var._parameters.ymax = 0.05;
  _beamdump_181_var._parameters.xwidth = 0;
  _beamdump_181_var._parameters.yheight = 0;
  _beamdump_181_var._parameters.radius = 0;

  /* component beamdump_181=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PUMA_mon_sample_e_var._rotation_absolute, _beamdump_181_var._rotation_absolute);
    rot_transpose(_PUMA_mon_sample_e_var._rotation_absolute, tr1);
    rot_mul(_beamdump_181_var._rotation_absolute, tr1, _beamdump_181_var._rotation_relative);
    _beamdump_181_var._rotation_is_identity =  rot_test_identity(_beamdump_181_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PUMA_mon_sample_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_181_var._position_absolute = coords_add(_PUMA_mon_sample_e_var._position_absolute, tc2);
    tc1 = coords_sub(_PUMA_mon_sample_e_var._position_absolute, _beamdump_181_var._position_absolute);
    _beamdump_181_var._position_relative = rot_apply(_beamdump_181_var._rotation_absolute, tc1);
  } /* beamdump_181=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_181", _beamdump_181_var._position_absolute, _beamdump_181_var._rotation_absolute);
  instrument->_position_absolute[177] = _beamdump_181_var._position_absolute;
  instrument->_position_relative[177] = _beamdump_181_var._position_relative;
    _beamdump_181_var._position_relative_is_zero =  coords_test_zero(_beamdump_181_var._position_relative);
  instrument->counter_N[177]  = instrument->counter_P[177] = instrument->counter_P2[177] = 0;
  instrument->counter_AbsorbProp[177]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0176_beamdump_181", _beamdump_181_var._position_absolute, _beamdump_181_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0176_beamdump_181", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_181_setpos */

/* component CRISTAL_pos=Text() SETTING, POSITION/ROTATION */
int _CRISTAL_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_pos_setpos] component CRISTAL_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_CRISTAL_pos_var._name, "CRISTAL_pos", 16384);
  stracpy(_CRISTAL_pos_var._type, "Text", 16384);
  _CRISTAL_pos_var._index=178;
  int current_setpos_index = 178;
  if("CRISTAL" && strlen("CRISTAL"))
    stracpy(_CRISTAL_pos_var._parameters.text, "CRISTAL" ? "CRISTAL" : "", 16384);
  else 
  _CRISTAL_pos_var._parameters.text[0]='\0';
  _CRISTAL_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_CRISTAL_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _CRISTAL_pos_var._parameters.plane[0]='\0';
  _CRISTAL_pos_var._parameters.pen_thickness = 0.1;


  /* component CRISTAL_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-123.814)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _CRISTAL_pos_var._rotation_absolute);
    rot_transpose(_beamdump_181_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_pos_var._rotation_absolute, tr1, _CRISTAL_pos_var._rotation_relative);
    _CRISTAL_pos_var._rotation_is_identity =  rot_test_identity(_CRISTAL_pos_var._rotation_relative);
    tc1 = coords_set(
      -31.353, 0, 46.810);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_181_var._position_absolute, _CRISTAL_pos_var._position_absolute);
    _CRISTAL_pos_var._position_relative = rot_apply(_CRISTAL_pos_var._rotation_absolute, tc1);
  } /* CRISTAL_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_pos", _CRISTAL_pos_var._position_absolute, _CRISTAL_pos_var._rotation_absolute);
  instrument->_position_absolute[178] = _CRISTAL_pos_var._position_absolute;
  instrument->_position_relative[178] = _CRISTAL_pos_var._position_relative;
    _CRISTAL_pos_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_pos_var._position_relative);
  instrument->counter_N[178]  = instrument->counter_P[178] = instrument->counter_P2[178] = 0;
  instrument->counter_AbsorbProp[178]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0177_CRISTAL_pos", _CRISTAL_pos_var._position_absolute, _CRISTAL_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0177_CRISTAL_pos", "text", "NONE", "CRISTAL", "char*");
        mccomp_param_nexus(nxhandle,"0177_CRISTAL_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0177_CRISTAL_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0177_CRISTAL_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_pos_setpos */

/* component CRISTAL=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_setpos] component CRISTAL=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_var._name, "CRISTAL", 16384);
  stracpy(_CRISTAL_var._type, "Arm", 16384);
  _CRISTAL_var._index=179;
  int current_setpos_index = 179;
  /* component CRISTAL=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_pos_var._rotation_absolute, _CRISTAL_var._rotation_absolute);
    rot_transpose(_CRISTAL_pos_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_var._rotation_absolute, tr1, _CRISTAL_var._rotation_relative);
    _CRISTAL_var._rotation_is_identity =  rot_test_identity(_CRISTAL_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_var._position_absolute = coords_add(_CRISTAL_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_pos_var._position_absolute, _CRISTAL_var._position_absolute);
    _CRISTAL_var._position_relative = rot_apply(_CRISTAL_var._rotation_absolute, tc1);
  } /* CRISTAL=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL", _CRISTAL_var._position_absolute, _CRISTAL_var._rotation_absolute);
  instrument->_position_absolute[179] = _CRISTAL_var._position_absolute;
  instrument->_position_relative[179] = _CRISTAL_var._position_relative;
    _CRISTAL_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_var._position_relative);
  instrument->counter_N[179]  = instrument->counter_P[179] = instrument->counter_P2[179] = 0;
  instrument->counter_AbsorbProp[179]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0178_CRISTAL", _CRISTAL_var._position_absolute, _CRISTAL_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_setpos */

/* component CRISTAL_Source=Undulator() SETTING, POSITION/ROTATION */
int _CRISTAL_Source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_Source_setpos] component CRISTAL_Source=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_CRISTAL_Source_var._name, "CRISTAL_Source", 16384);
  stracpy(_CRISTAL_Source_var._type, "Undulator", 16384);
  _CRISTAL_Source_var._index=180;
  int current_setpos_index = 180;
  _CRISTAL_Source_var._parameters.E0 = _instrument_var._parameters.CRISTAL_E0;
  _CRISTAL_Source_var._parameters.dE = _instrument_var._parameters.CRISTAL_dE;
  _CRISTAL_Source_var._parameters.phase = 0;
  _CRISTAL_Source_var._parameters.randomphase = 1;
  _CRISTAL_Source_var._parameters.Ee = 2.75;
  _CRISTAL_Source_var._parameters.dEe = 0;
  _CRISTAL_Source_var._parameters.Ie = 0.5;
  _CRISTAL_Source_var._parameters.B = 0;
  _CRISTAL_Source_var._parameters.K = 5;
  _CRISTAL_Source_var._parameters.Nper = 1;
  _CRISTAL_Source_var._parameters.lu = 16e-3;
  _CRISTAL_Source_var._parameters.sigey = 8.1e-6;
  _CRISTAL_Source_var._parameters.sigex = 388e-6;
  _CRISTAL_Source_var._parameters.sigepx = 14.5e-6;
  _CRISTAL_Source_var._parameters.sigepy = 4.61e-6;
  _CRISTAL_Source_var._parameters.focus_xw = CRISTAL_Slit1Width;
  _CRISTAL_Source_var._parameters.focus_yh = CRISTAL_Slit1Height;
  _CRISTAL_Source_var._parameters.dist = CRISTAL_DistanceSourceToSlit1;
  _CRISTAL_Source_var._parameters.quick_integ = 0;
  _CRISTAL_Source_var._parameters.E1st = 0;
  _CRISTAL_Source_var._parameters.verbose = 0;
  _CRISTAL_Source_var._parameters.Br = 1.35;


  /* component CRISTAL_Source=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_var._rotation_absolute, _CRISTAL_Source_var._rotation_absolute);
    rot_transpose(_CRISTAL_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_Source_var._rotation_absolute, tr1, _CRISTAL_Source_var._rotation_relative);
    _CRISTAL_Source_var._rotation_is_identity =  rot_test_identity(_CRISTAL_Source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_Source_var._position_absolute = coords_add(_CRISTAL_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_var._position_absolute, _CRISTAL_Source_var._position_absolute);
    _CRISTAL_Source_var._position_relative = rot_apply(_CRISTAL_Source_var._rotation_absolute, tc1);
  } /* CRISTAL_Source=Undulator() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_Source", _CRISTAL_Source_var._position_absolute, _CRISTAL_Source_var._rotation_absolute);
  instrument->_position_absolute[180] = _CRISTAL_Source_var._position_absolute;
  instrument->_position_relative[180] = _CRISTAL_Source_var._position_relative;
    _CRISTAL_Source_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_Source_var._position_relative);
  instrument->counter_N[180]  = instrument->counter_P[180] = instrument->counter_P2[180] = 0;
  instrument->counter_AbsorbProp[180]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0179_CRISTAL_Source", _CRISTAL_Source_var._position_absolute, _CRISTAL_Source_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "E0", "0", "_instrument_var._parameters.CRISTAL_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "dE", "0", "_instrument_var._parameters.CRISTAL_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "dEe", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "K", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "Nper", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "lu", "16e-3", "16e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "sigey", "0", "8.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "sigex", "0", "388e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "sigepx", "0", "14.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "sigepy", "0", "4.61e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "focus_xw", "0", "CRISTAL_Slit1Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "focus_yh", "0", "CRISTAL_Slit1Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "dist", "1", "CRISTAL_DistanceSourceToSlit1","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0179_CRISTAL_Source", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_Source_setpos */

/* component CRISTAL_slit1=Slit() SETTING, POSITION/ROTATION */
int _CRISTAL_slit1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_slit1_setpos] component CRISTAL_slit1=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_CRISTAL_slit1_var._name, "CRISTAL_slit1", 16384);
  stracpy(_CRISTAL_slit1_var._type, "Slit", 16384);
  _CRISTAL_slit1_var._index=181;
  int current_setpos_index = 181;
  _CRISTAL_slit1_var._parameters.xmin = 0;
  _CRISTAL_slit1_var._parameters.xmax = 0;
  _CRISTAL_slit1_var._parameters.ymin = 0;
  _CRISTAL_slit1_var._parameters.ymax = 0;
  _CRISTAL_slit1_var._parameters.radius = 0;
  _CRISTAL_slit1_var._parameters.xwidth = CRISTAL_Slit1Width;
  _CRISTAL_slit1_var._parameters.yheight = CRISTAL_Slit1Height;
  _CRISTAL_slit1_var._parameters.dist = 0;
  _CRISTAL_slit1_var._parameters.focus_xw = 0;
  _CRISTAL_slit1_var._parameters.focus_yh = 0;
  _CRISTAL_slit1_var._parameters.focus_x0 = 0;
  _CRISTAL_slit1_var._parameters.focus_y0 = 0;

  /* component CRISTAL_slit1=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_Source_var._rotation_absolute, _CRISTAL_slit1_var._rotation_absolute);
    rot_transpose(_CRISTAL_Source_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_slit1_var._rotation_absolute, tr1, _CRISTAL_slit1_var._rotation_relative);
    _CRISTAL_slit1_var._rotation_is_identity =  rot_test_identity(_CRISTAL_slit1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, CRISTAL_DistanceSourceToSlit1);
    rot_transpose(_CRISTAL_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_slit1_var._position_absolute = coords_add(_CRISTAL_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_Source_var._position_absolute, _CRISTAL_slit1_var._position_absolute);
    _CRISTAL_slit1_var._position_relative = rot_apply(_CRISTAL_slit1_var._rotation_absolute, tc1);
  } /* CRISTAL_slit1=Slit() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_slit1", _CRISTAL_slit1_var._position_absolute, _CRISTAL_slit1_var._rotation_absolute);
  instrument->_position_absolute[181] = _CRISTAL_slit1_var._position_absolute;
  instrument->_position_relative[181] = _CRISTAL_slit1_var._position_relative;
    _CRISTAL_slit1_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_slit1_var._position_relative);
  instrument->counter_N[181]  = instrument->counter_P[181] = instrument->counter_P2[181] = 0;
  instrument->counter_AbsorbProp[181]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0180_CRISTAL_slit1", _CRISTAL_slit1_var._position_absolute, _CRISTAL_slit1_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "xwidth", "0.001", "CRISTAL_Slit1Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "yheight", "0.001", "CRISTAL_Slit1Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0180_CRISTAL_slit1", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_slit1_setpos */

/* component CRISTAL_dcm_location=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_dcm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_dcm_location_setpos] component CRISTAL_dcm_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_dcm_location_var._name, "CRISTAL_dcm_location", 16384);
  stracpy(_CRISTAL_dcm_location_var._type, "Arm", 16384);
  _CRISTAL_dcm_location_var._index=182;
  int current_setpos_index = 182;
  /* component CRISTAL_dcm_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_slit1_var._rotation_absolute, _CRISTAL_dcm_location_var._rotation_absolute);
    rot_transpose(_CRISTAL_slit1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_dcm_location_var._rotation_absolute, tr1, _CRISTAL_dcm_location_var._rotation_relative);
    _CRISTAL_dcm_location_var._rotation_is_identity =  rot_test_identity(_CRISTAL_dcm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, CRISTAL_DistanceSourceToDCM - CRISTAL_DistanceSourceToSlit1);
    rot_transpose(_CRISTAL_slit1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_dcm_location_var._position_absolute = coords_add(_CRISTAL_slit1_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_slit1_var._position_absolute, _CRISTAL_dcm_location_var._position_absolute);
    _CRISTAL_dcm_location_var._position_relative = rot_apply(_CRISTAL_dcm_location_var._rotation_absolute, tc1);
  } /* CRISTAL_dcm_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_dcm_location", _CRISTAL_dcm_location_var._position_absolute, _CRISTAL_dcm_location_var._rotation_absolute);
  instrument->_position_absolute[182] = _CRISTAL_dcm_location_var._position_absolute;
  instrument->_position_relative[182] = _CRISTAL_dcm_location_var._position_relative;
    _CRISTAL_dcm_location_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_dcm_location_var._position_relative);
  instrument->counter_N[182]  = instrument->counter_P[182] = instrument->counter_P2[182] = 0;
  instrument->counter_AbsorbProp[182]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0181_CRISTAL_dcm_location", _CRISTAL_dcm_location_var._position_absolute, _CRISTAL_dcm_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_dcm_location_setpos */

/* component CRISTAL_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _CRISTAL_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_dcm_xtal0_setpos] component CRISTAL_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_CRISTAL_dcm_xtal0_var._name, "CRISTAL_dcm_xtal0", 16384);
  stracpy(_CRISTAL_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _CRISTAL_dcm_xtal0_var._index=183;
  int current_setpos_index = 183;
  _CRISTAL_dcm_xtal0_var._parameters.length = 0.1;
  _CRISTAL_dcm_xtal0_var._parameters.width = 0.05;
  _CRISTAL_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_CRISTAL_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _CRISTAL_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_CRISTAL_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _CRISTAL_dcm_xtal0_var._parameters.material[0]='\0';
  _CRISTAL_dcm_xtal0_var._parameters.alpha = 0;
  _CRISTAL_dcm_xtal0_var._parameters.R0 = 0;
  _CRISTAL_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _CRISTAL_dcm_xtal0_var._parameters.crystal_type = 2;
  _CRISTAL_dcm_xtal0_var._parameters.h = 1;
  _CRISTAL_dcm_xtal0_var._parameters.k = 1;
  _CRISTAL_dcm_xtal0_var._parameters.l = 1;
  _CRISTAL_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _CRISTAL_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component CRISTAL_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- CRISTAL_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_dcm_location_var._rotation_absolute, _CRISTAL_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_CRISTAL_slit1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_dcm_xtal0_var._rotation_absolute, tr1, _CRISTAL_dcm_xtal0_var._rotation_relative);
    _CRISTAL_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_CRISTAL_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_dcm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_dcm_xtal0_var._position_absolute = coords_add(_CRISTAL_dcm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_slit1_var._position_absolute, _CRISTAL_dcm_xtal0_var._position_absolute);
    _CRISTAL_dcm_xtal0_var._position_relative = rot_apply(_CRISTAL_dcm_xtal0_var._rotation_absolute, tc1);
  } /* CRISTAL_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_dcm_xtal0", _CRISTAL_dcm_xtal0_var._position_absolute, _CRISTAL_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[183] = _CRISTAL_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[183] = _CRISTAL_dcm_xtal0_var._position_relative;
    _CRISTAL_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_dcm_xtal0_var._position_relative);
  instrument->counter_N[183]  = instrument->counter_P[183] = instrument->counter_P2[183] = 0;
  instrument->counter_AbsorbProp[183]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", _CRISTAL_dcm_xtal0_var._position_absolute, _CRISTAL_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "length", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "width", "0.02", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "alpha", "0.0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0182_CRISTAL_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_dcm_xtal0_setpos */

/* component CRISTAL_arm_xtal0=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_arm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_arm_xtal0_setpos] component CRISTAL_arm_xtal0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_arm_xtal0_var._name, "CRISTAL_arm_xtal0", 16384);
  stracpy(_CRISTAL_arm_xtal0_var._type, "Arm", 16384);
  _CRISTAL_arm_xtal0_var._index=184;
  int current_setpos_index = 184;
  /* component CRISTAL_arm_xtal0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- CRISTAL_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_dcm_xtal0_var._rotation_absolute, _CRISTAL_arm_xtal0_var._rotation_absolute);
    rot_transpose(_CRISTAL_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_arm_xtal0_var._rotation_absolute, tr1, _CRISTAL_arm_xtal0_var._rotation_relative);
    _CRISTAL_arm_xtal0_var._rotation_is_identity =  rot_test_identity(_CRISTAL_arm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_arm_xtal0_var._position_absolute = coords_add(_CRISTAL_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_dcm_xtal0_var._position_absolute, _CRISTAL_arm_xtal0_var._position_absolute);
    _CRISTAL_arm_xtal0_var._position_relative = rot_apply(_CRISTAL_arm_xtal0_var._rotation_absolute, tc1);
  } /* CRISTAL_arm_xtal0=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_arm_xtal0", _CRISTAL_arm_xtal0_var._position_absolute, _CRISTAL_arm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[184] = _CRISTAL_arm_xtal0_var._position_absolute;
  instrument->_position_relative[184] = _CRISTAL_arm_xtal0_var._position_relative;
    _CRISTAL_arm_xtal0_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_arm_xtal0_var._position_relative);
  instrument->counter_N[184]  = instrument->counter_P[184] = instrument->counter_P2[184] = 0;
  instrument->counter_AbsorbProp[184]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0183_CRISTAL_arm_xtal0", _CRISTAL_arm_xtal0_var._position_absolute, _CRISTAL_arm_xtal0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_arm_xtal0_setpos */

/* component CRISTAL_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _CRISTAL_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_dcm_xtal1_setpos] component CRISTAL_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_CRISTAL_dcm_xtal1_var._name, "CRISTAL_dcm_xtal1", 16384);
  stracpy(_CRISTAL_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _CRISTAL_dcm_xtal1_var._index=185;
  int current_setpos_index = 185;
  _CRISTAL_dcm_xtal1_var._parameters.length = 0.1;
  _CRISTAL_dcm_xtal1_var._parameters.width = 0.05;
  _CRISTAL_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_CRISTAL_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _CRISTAL_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_CRISTAL_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _CRISTAL_dcm_xtal1_var._parameters.material[0]='\0';
  _CRISTAL_dcm_xtal1_var._parameters.alpha = 0;
  _CRISTAL_dcm_xtal1_var._parameters.R0 = 0;
  _CRISTAL_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _CRISTAL_dcm_xtal1_var._parameters.crystal_type = 2;
  _CRISTAL_dcm_xtal1_var._parameters.h = 1;
  _CRISTAL_dcm_xtal1_var._parameters.k = 1;
  _CRISTAL_dcm_xtal1_var._parameters.l = 1;
  _CRISTAL_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _CRISTAL_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component CRISTAL_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (CRISTAL_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_arm_xtal0_var._rotation_absolute, _CRISTAL_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_CRISTAL_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_dcm_xtal1_var._rotation_absolute, tr1, _CRISTAL_dcm_xtal1_var._rotation_relative);
    _CRISTAL_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_CRISTAL_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, CRISTAL_dcm_gap, CRISTAL_DCM_theta ? CRISTAL_dcm_gap / tan ( CRISTAL_DCM_theta * DEG2RAD ) : 0);
    rot_transpose(_CRISTAL_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_dcm_xtal1_var._position_absolute = coords_add(_CRISTAL_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_dcm_xtal0_var._position_absolute, _CRISTAL_dcm_xtal1_var._position_absolute);
    _CRISTAL_dcm_xtal1_var._position_relative = rot_apply(_CRISTAL_dcm_xtal1_var._rotation_absolute, tc1);
  } /* CRISTAL_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_dcm_xtal1", _CRISTAL_dcm_xtal1_var._position_absolute, _CRISTAL_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[185] = _CRISTAL_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[185] = _CRISTAL_dcm_xtal1_var._position_relative;
    _CRISTAL_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_dcm_xtal1_var._position_relative);
  instrument->counter_N[185]  = instrument->counter_P[185] = instrument->counter_P2[185] = 0;
  instrument->counter_AbsorbProp[185]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", _CRISTAL_dcm_xtal1_var._position_absolute, _CRISTAL_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "length", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "width", "0.02", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "alpha", "0.0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0184_CRISTAL_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_dcm_xtal1_setpos */

/* component CRISTAL_arm_xtal1=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_arm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_arm_xtal1_setpos] component CRISTAL_arm_xtal1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_arm_xtal1_var._name, "CRISTAL_arm_xtal1", 16384);
  stracpy(_CRISTAL_arm_xtal1_var._type, "Arm", 16384);
  _CRISTAL_arm_xtal1_var._index=186;
  int current_setpos_index = 186;
  /* component CRISTAL_arm_xtal1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (CRISTAL_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_dcm_xtal1_var._rotation_absolute, _CRISTAL_arm_xtal1_var._rotation_absolute);
    rot_transpose(_CRISTAL_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_arm_xtal1_var._rotation_absolute, tr1, _CRISTAL_arm_xtal1_var._rotation_relative);
    _CRISTAL_arm_xtal1_var._rotation_is_identity =  rot_test_identity(_CRISTAL_arm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_arm_xtal1_var._position_absolute = coords_add(_CRISTAL_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_dcm_xtal1_var._position_absolute, _CRISTAL_arm_xtal1_var._position_absolute);
    _CRISTAL_arm_xtal1_var._position_relative = rot_apply(_CRISTAL_arm_xtal1_var._rotation_absolute, tc1);
  } /* CRISTAL_arm_xtal1=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_arm_xtal1", _CRISTAL_arm_xtal1_var._position_absolute, _CRISTAL_arm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[186] = _CRISTAL_arm_xtal1_var._position_absolute;
  instrument->_position_relative[186] = _CRISTAL_arm_xtal1_var._position_relative;
    _CRISTAL_arm_xtal1_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_arm_xtal1_var._position_relative);
  instrument->counter_N[186]  = instrument->counter_P[186] = instrument->counter_P2[186] = 0;
  instrument->counter_AbsorbProp[186]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0185_CRISTAL_arm_xtal1", _CRISTAL_arm_xtal1_var._position_absolute, _CRISTAL_arm_xtal1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_arm_xtal1_setpos */

/* component CRISTAL_emon_dcm=E_monitor() SETTING, POSITION/ROTATION */
int _CRISTAL_emon_dcm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_emon_dcm_setpos] component CRISTAL_emon_dcm=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_CRISTAL_emon_dcm_var._name, "CRISTAL_emon_dcm", 16384);
  stracpy(_CRISTAL_emon_dcm_var._type, "E_monitor", 16384);
  _CRISTAL_emon_dcm_var._index=187;
  int current_setpos_index = 187;
  _CRISTAL_emon_dcm_var._parameters.nE = 101;
  if("CRISTAL_emon_dcm" && strlen("CRISTAL_emon_dcm"))
    stracpy(_CRISTAL_emon_dcm_var._parameters.filename, "CRISTAL_emon_dcm" ? "CRISTAL_emon_dcm" : "", 16384);
  else 
  _CRISTAL_emon_dcm_var._parameters.filename[0]='\0';
  _CRISTAL_emon_dcm_var._parameters.xwidth = 0.05;
  _CRISTAL_emon_dcm_var._parameters.yheight = 0.05;
  _CRISTAL_emon_dcm_var._parameters.Emin = _instrument_var._parameters.CRISTAL_E0 -3 * _instrument_var._parameters.CRISTAL_dE;
  _CRISTAL_emon_dcm_var._parameters.Emax = _instrument_var._parameters.CRISTAL_E0 + 3 * _instrument_var._parameters.CRISTAL_dE;
  _CRISTAL_emon_dcm_var._parameters.restore_xray = 0;


  /* component CRISTAL_emon_dcm=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_arm_xtal1_var._rotation_absolute, _CRISTAL_emon_dcm_var._rotation_absolute);
    rot_transpose(_CRISTAL_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_emon_dcm_var._rotation_absolute, tr1, _CRISTAL_emon_dcm_var._rotation_relative);
    _CRISTAL_emon_dcm_var._rotation_is_identity =  rot_test_identity(_CRISTAL_emon_dcm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.05);
    rot_transpose(_CRISTAL_arm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_emon_dcm_var._position_absolute = coords_add(_CRISTAL_arm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_dcm_xtal1_var._position_absolute, _CRISTAL_emon_dcm_var._position_absolute);
    _CRISTAL_emon_dcm_var._position_relative = rot_apply(_CRISTAL_emon_dcm_var._rotation_absolute, tc1);
  } /* CRISTAL_emon_dcm=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_emon_dcm", _CRISTAL_emon_dcm_var._position_absolute, _CRISTAL_emon_dcm_var._rotation_absolute);
  instrument->_position_absolute[187] = _CRISTAL_emon_dcm_var._position_absolute;
  instrument->_position_relative[187] = _CRISTAL_emon_dcm_var._position_relative;
    _CRISTAL_emon_dcm_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_emon_dcm_var._position_relative);
  instrument->counter_N[187]  = instrument->counter_P[187] = instrument->counter_P2[187] = 0;
  instrument->counter_AbsorbProp[187]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0186_CRISTAL_emon_dcm", _CRISTAL_emon_dcm_var._position_absolute, _CRISTAL_emon_dcm_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "nE", "20", "101","MCNUM");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "filename", 0, "CRISTAL_emon_dcm", "char*");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "xwidth", "0.1", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "yheight", "0.1", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "Emin", "NONE", "_instrument_var._parameters.CRISTAL_E0 -3 * _instrument_var._parameters.CRISTAL_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "Emax", "NONE", "_instrument_var._parameters.CRISTAL_E0 + 3 * _instrument_var._parameters.CRISTAL_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0186_CRISTAL_emon_dcm", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_emon_dcm_setpos */

/* component CRISTAL_M1_location=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_M1_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M1_location_setpos] component CRISTAL_M1_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_M1_location_var._name, "CRISTAL_M1_location", 16384);
  stracpy(_CRISTAL_M1_location_var._type, "Arm", 16384);
  _CRISTAL_M1_location_var._index=188;
  int current_setpos_index = 188;
  /* component CRISTAL_M1_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_emon_dcm_var._rotation_absolute, _CRISTAL_M1_location_var._rotation_absolute);
    rot_transpose(_CRISTAL_emon_dcm_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M1_location_var._rotation_absolute, tr1, _CRISTAL_M1_location_var._rotation_relative);
    _CRISTAL_M1_location_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M1_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, CRISTAL_DistanceSourceToM1 - CRISTAL_DistanceSourceToDCM -0.05);
    rot_transpose(_CRISTAL_emon_dcm_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M1_location_var._position_absolute = coords_add(_CRISTAL_emon_dcm_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_emon_dcm_var._position_absolute, _CRISTAL_M1_location_var._position_absolute);
    _CRISTAL_M1_location_var._position_relative = rot_apply(_CRISTAL_M1_location_var._rotation_absolute, tc1);
  } /* CRISTAL_M1_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M1_location", _CRISTAL_M1_location_var._position_absolute, _CRISTAL_M1_location_var._rotation_absolute);
  instrument->_position_absolute[188] = _CRISTAL_M1_location_var._position_absolute;
  instrument->_position_relative[188] = _CRISTAL_M1_location_var._position_relative;
    _CRISTAL_M1_location_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M1_location_var._position_relative);
  instrument->counter_N[188]  = instrument->counter_P[188] = instrument->counter_P2[188] = 0;
  instrument->counter_AbsorbProp[188]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0187_CRISTAL_M1_location", _CRISTAL_M1_location_var._position_absolute, _CRISTAL_M1_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M1_location_setpos */

/* component CRISTAL_M1_rotated=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_M1_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M1_rotated_setpos] component CRISTAL_M1_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_M1_rotated_var._name, "CRISTAL_M1_rotated", 16384);
  stracpy(_CRISTAL_M1_rotated_var._type, "Arm", 16384);
  _CRISTAL_M1_rotated_var._index=189;
  int current_setpos_index = 189;
  /* component CRISTAL_M1_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.CRISTAL_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M1_location_var._rotation_absolute, _CRISTAL_M1_rotated_var._rotation_absolute);
    rot_transpose(_CRISTAL_emon_dcm_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M1_rotated_var._rotation_absolute, tr1, _CRISTAL_M1_rotated_var._rotation_relative);
    _CRISTAL_M1_rotated_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M1_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_M1_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M1_rotated_var._position_absolute = coords_add(_CRISTAL_M1_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_emon_dcm_var._position_absolute, _CRISTAL_M1_rotated_var._position_absolute);
    _CRISTAL_M1_rotated_var._position_relative = rot_apply(_CRISTAL_M1_rotated_var._rotation_absolute, tc1);
  } /* CRISTAL_M1_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M1_rotated", _CRISTAL_M1_rotated_var._position_absolute, _CRISTAL_M1_rotated_var._rotation_absolute);
  instrument->_position_absolute[189] = _CRISTAL_M1_rotated_var._position_absolute;
  instrument->_position_relative[189] = _CRISTAL_M1_rotated_var._position_relative;
    _CRISTAL_M1_rotated_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M1_rotated_var._position_relative);
  instrument->counter_N[189]  = instrument->counter_P[189] = instrument->counter_P2[189] = 0;
  instrument->counter_AbsorbProp[189]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0188_CRISTAL_M1_rotated", _CRISTAL_M1_rotated_var._position_absolute, _CRISTAL_M1_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M1_rotated_setpos */

/* component CRISTAL_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _CRISTAL_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M1_setpos] component CRISTAL_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_CRISTAL_M1_var._name, "CRISTAL_M1", 16384);
  stracpy(_CRISTAL_M1_var._type, "Mirror_curved", 16384);
  _CRISTAL_M1_var._index=190;
  int current_setpos_index = 190;
  _CRISTAL_M1_var._parameters.radius = _instrument_var._parameters.CRISTAL_M1_radius;
  _CRISTAL_M1_var._parameters.R0 = 1;
  if(_instrument_var._parameters.CRISTAL_M_coating && strlen(_instrument_var._parameters.CRISTAL_M_coating))
    stracpy(_CRISTAL_M1_var._parameters.coating, _instrument_var._parameters.CRISTAL_M_coating ? _instrument_var._parameters.CRISTAL_M_coating : "", 16384);
  else 
  _CRISTAL_M1_var._parameters.coating[0]='\0';
  _CRISTAL_M1_var._parameters.zdepth = 0.2;
  _CRISTAL_M1_var._parameters.yheight = 0.2;
  _CRISTAL_M1_var._parameters.length = CRISTAL_M_length;
  _CRISTAL_M1_var._parameters.width = CRISTAL_M_width;


  /* component CRISTAL_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M1_rotated_var._rotation_absolute, _CRISTAL_M1_var._rotation_absolute);
    rot_transpose(_CRISTAL_emon_dcm_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M1_var._rotation_absolute, tr1, _CRISTAL_M1_var._rotation_relative);
    _CRISTAL_M1_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M1_var._position_absolute = coords_add(_CRISTAL_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_emon_dcm_var._position_absolute, _CRISTAL_M1_var._position_absolute);
    _CRISTAL_M1_var._position_relative = rot_apply(_CRISTAL_M1_var._rotation_absolute, tc1);
  } /* CRISTAL_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M1", _CRISTAL_M1_var._position_absolute, _CRISTAL_M1_var._rotation_absolute);
  instrument->_position_absolute[190] = _CRISTAL_M1_var._position_absolute;
  instrument->_position_relative[190] = _CRISTAL_M1_var._position_relative;
    _CRISTAL_M1_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M1_var._position_relative);
  instrument->counter_N[190]  = instrument->counter_P[190] = instrument->counter_P2[190] = 0;
  instrument->counter_AbsorbProp[190]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0189_CRISTAL_M1", _CRISTAL_M1_var._position_absolute, _CRISTAL_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "radius", "1", "_instrument_var._parameters.CRISTAL_M1_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "coating", "Be.txt", _instrument_var._parameters.CRISTAL_M_coating, "char*");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "length", "0", "CRISTAL_M_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0189_CRISTAL_M1", "width", "0", "CRISTAL_M_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M1_setpos */

/* component CRISTAL_M1_out=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_M1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M1_out_setpos] component CRISTAL_M1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_M1_out_var._name, "CRISTAL_M1_out", 16384);
  stracpy(_CRISTAL_M1_out_var._type, "Arm", 16384);
  _CRISTAL_M1_out_var._index=191;
  int current_setpos_index = 191;
  /* component CRISTAL_M1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.CRISTAL_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M1_rotated_var._rotation_absolute, _CRISTAL_M1_out_var._rotation_absolute);
    rot_transpose(_CRISTAL_M1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M1_out_var._rotation_absolute, tr1, _CRISTAL_M1_out_var._rotation_relative);
    _CRISTAL_M1_out_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M1_out_var._position_absolute = coords_add(_CRISTAL_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_M1_var._position_absolute, _CRISTAL_M1_out_var._position_absolute);
    _CRISTAL_M1_out_var._position_relative = rot_apply(_CRISTAL_M1_out_var._rotation_absolute, tc1);
  } /* CRISTAL_M1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M1_out", _CRISTAL_M1_out_var._position_absolute, _CRISTAL_M1_out_var._rotation_absolute);
  instrument->_position_absolute[191] = _CRISTAL_M1_out_var._position_absolute;
  instrument->_position_relative[191] = _CRISTAL_M1_out_var._position_relative;
    _CRISTAL_M1_out_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M1_out_var._position_relative);
  instrument->counter_N[191]  = instrument->counter_P[191] = instrument->counter_P2[191] = 0;
  instrument->counter_AbsorbProp[191]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0190_CRISTAL_M1_out", _CRISTAL_M1_out_var._position_absolute, _CRISTAL_M1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M1_out_setpos */

/* component CRISTAL_M2_location=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_M2_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M2_location_setpos] component CRISTAL_M2_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_M2_location_var._name, "CRISTAL_M2_location", 16384);
  stracpy(_CRISTAL_M2_location_var._type, "Arm", 16384);
  _CRISTAL_M2_location_var._index=192;
  int current_setpos_index = 192;
  /* component CRISTAL_M2_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M1_out_var._rotation_absolute, _CRISTAL_M2_location_var._rotation_absolute);
    rot_transpose(_CRISTAL_M1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M2_location_var._rotation_absolute, tr1, _CRISTAL_M2_location_var._rotation_relative);
    _CRISTAL_M2_location_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M2_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, CRISTAL_DistanceM1ToM2);
    rot_transpose(_CRISTAL_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M2_location_var._position_absolute = coords_add(_CRISTAL_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_M1_var._position_absolute, _CRISTAL_M2_location_var._position_absolute);
    _CRISTAL_M2_location_var._position_relative = rot_apply(_CRISTAL_M2_location_var._rotation_absolute, tc1);
  } /* CRISTAL_M2_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M2_location", _CRISTAL_M2_location_var._position_absolute, _CRISTAL_M2_location_var._rotation_absolute);
  instrument->_position_absolute[192] = _CRISTAL_M2_location_var._position_absolute;
  instrument->_position_relative[192] = _CRISTAL_M2_location_var._position_relative;
    _CRISTAL_M2_location_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M2_location_var._position_relative);
  instrument->counter_N[192]  = instrument->counter_P[192] = instrument->counter_P2[192] = 0;
  instrument->counter_AbsorbProp[192]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0191_CRISTAL_M2_location", _CRISTAL_M2_location_var._position_absolute, _CRISTAL_M2_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M2_location_setpos */

/* component CRISTAL_M2_rotated=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_M2_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M2_rotated_setpos] component CRISTAL_M2_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_M2_rotated_var._name, "CRISTAL_M2_rotated", 16384);
  stracpy(_CRISTAL_M2_rotated_var._type, "Arm", 16384);
  _CRISTAL_M2_rotated_var._index=193;
  int current_setpos_index = 193;
  /* component CRISTAL_M2_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.CRISTAL_M2_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M2_location_var._rotation_absolute, _CRISTAL_M2_rotated_var._rotation_absolute);
    rot_transpose(_CRISTAL_M1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M2_rotated_var._rotation_absolute, tr1, _CRISTAL_M2_rotated_var._rotation_relative);
    _CRISTAL_M2_rotated_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M2_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_M2_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M2_rotated_var._position_absolute = coords_add(_CRISTAL_M2_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_M1_var._position_absolute, _CRISTAL_M2_rotated_var._position_absolute);
    _CRISTAL_M2_rotated_var._position_relative = rot_apply(_CRISTAL_M2_rotated_var._rotation_absolute, tc1);
  } /* CRISTAL_M2_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M2_rotated", _CRISTAL_M2_rotated_var._position_absolute, _CRISTAL_M2_rotated_var._rotation_absolute);
  instrument->_position_absolute[193] = _CRISTAL_M2_rotated_var._position_absolute;
  instrument->_position_relative[193] = _CRISTAL_M2_rotated_var._position_relative;
    _CRISTAL_M2_rotated_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M2_rotated_var._position_relative);
  instrument->counter_N[193]  = instrument->counter_P[193] = instrument->counter_P2[193] = 0;
  instrument->counter_AbsorbProp[193]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0192_CRISTAL_M2_rotated", _CRISTAL_M2_rotated_var._position_absolute, _CRISTAL_M2_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M2_rotated_setpos */

/* component CRISTAL_M2=Mirror_curved() SETTING, POSITION/ROTATION */
int _CRISTAL_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M2_setpos] component CRISTAL_M2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_CRISTAL_M2_var._name, "CRISTAL_M2", 16384);
  stracpy(_CRISTAL_M2_var._type, "Mirror_curved", 16384);
  _CRISTAL_M2_var._index=194;
  int current_setpos_index = 194;
  _CRISTAL_M2_var._parameters.radius = _instrument_var._parameters.CRISTAL_M2_radius;
  _CRISTAL_M2_var._parameters.R0 = 1;
  if(_instrument_var._parameters.CRISTAL_M_coating && strlen(_instrument_var._parameters.CRISTAL_M_coating))
    stracpy(_CRISTAL_M2_var._parameters.coating, _instrument_var._parameters.CRISTAL_M_coating ? _instrument_var._parameters.CRISTAL_M_coating : "", 16384);
  else 
  _CRISTAL_M2_var._parameters.coating[0]='\0';
  _CRISTAL_M2_var._parameters.zdepth = 0.2;
  _CRISTAL_M2_var._parameters.yheight = 0.2;
  _CRISTAL_M2_var._parameters.length = CRISTAL_M_length;
  _CRISTAL_M2_var._parameters.width = CRISTAL_M_width;


  /* component CRISTAL_M2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M2_rotated_var._rotation_absolute, _CRISTAL_M2_var._rotation_absolute);
    rot_transpose(_CRISTAL_M1_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M2_var._rotation_absolute, tr1, _CRISTAL_M2_var._rotation_relative);
    _CRISTAL_M2_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M2_var._position_absolute = coords_add(_CRISTAL_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_M1_var._position_absolute, _CRISTAL_M2_var._position_absolute);
    _CRISTAL_M2_var._position_relative = rot_apply(_CRISTAL_M2_var._rotation_absolute, tc1);
  } /* CRISTAL_M2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M2", _CRISTAL_M2_var._position_absolute, _CRISTAL_M2_var._rotation_absolute);
  instrument->_position_absolute[194] = _CRISTAL_M2_var._position_absolute;
  instrument->_position_relative[194] = _CRISTAL_M2_var._position_relative;
    _CRISTAL_M2_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M2_var._position_relative);
  instrument->counter_N[194]  = instrument->counter_P[194] = instrument->counter_P2[194] = 0;
  instrument->counter_AbsorbProp[194]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0193_CRISTAL_M2", _CRISTAL_M2_var._position_absolute, _CRISTAL_M2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "radius", "1", "_instrument_var._parameters.CRISTAL_M2_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "coating", "Be.txt", _instrument_var._parameters.CRISTAL_M_coating, "char*");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "length", "0", "CRISTAL_M_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0193_CRISTAL_M2", "width", "0", "CRISTAL_M_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M2_setpos */

/* component CRISTAL_M2_out=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_M2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_M2_out_setpos] component CRISTAL_M2_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_M2_out_var._name, "CRISTAL_M2_out", 16384);
  stracpy(_CRISTAL_M2_out_var._type, "Arm", 16384);
  _CRISTAL_M2_out_var._index=195;
  int current_setpos_index = 195;
  /* component CRISTAL_M2_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.CRISTAL_M2_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M2_rotated_var._rotation_absolute, _CRISTAL_M2_out_var._rotation_absolute);
    rot_transpose(_CRISTAL_M2_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_M2_out_var._rotation_absolute, tr1, _CRISTAL_M2_out_var._rotation_relative);
    _CRISTAL_M2_out_var._rotation_is_identity =  rot_test_identity(_CRISTAL_M2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_M2_out_var._position_absolute = coords_add(_CRISTAL_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_M2_var._position_absolute, _CRISTAL_M2_out_var._position_absolute);
    _CRISTAL_M2_out_var._position_relative = rot_apply(_CRISTAL_M2_out_var._rotation_absolute, tc1);
  } /* CRISTAL_M2_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_M2_out", _CRISTAL_M2_out_var._position_absolute, _CRISTAL_M2_out_var._rotation_absolute);
  instrument->_position_absolute[195] = _CRISTAL_M2_out_var._position_absolute;
  instrument->_position_relative[195] = _CRISTAL_M2_out_var._position_relative;
    _CRISTAL_M2_out_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_M2_out_var._position_relative);
  instrument->counter_N[195]  = instrument->counter_P[195] = instrument->counter_P2[195] = 0;
  instrument->counter_AbsorbProp[195]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0194_CRISTAL_M2_out", _CRISTAL_M2_out_var._position_absolute, _CRISTAL_M2_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_M2_out_setpos */

/* component CRISTAL_slit2=Slit() SETTING, POSITION/ROTATION */
int _CRISTAL_slit2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_slit2_setpos] component CRISTAL_slit2=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_CRISTAL_slit2_var._name, "CRISTAL_slit2", 16384);
  stracpy(_CRISTAL_slit2_var._type, "Slit", 16384);
  _CRISTAL_slit2_var._index=196;
  int current_setpos_index = 196;
  _CRISTAL_slit2_var._parameters.xmin = 0;
  _CRISTAL_slit2_var._parameters.xmax = 0;
  _CRISTAL_slit2_var._parameters.ymin = 0;
  _CRISTAL_slit2_var._parameters.ymax = 0;
  _CRISTAL_slit2_var._parameters.radius = 0;
  _CRISTAL_slit2_var._parameters.xwidth = CRISTAL_Slit2Width;
  _CRISTAL_slit2_var._parameters.yheight = CRISTAL_Slit2Height;
  _CRISTAL_slit2_var._parameters.dist = 0;
  _CRISTAL_slit2_var._parameters.focus_xw = 0;
  _CRISTAL_slit2_var._parameters.focus_yh = 0;
  _CRISTAL_slit2_var._parameters.focus_x0 = 0;
  _CRISTAL_slit2_var._parameters.focus_y0 = 0;

  /* component CRISTAL_slit2=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_M2_out_var._rotation_absolute, _CRISTAL_slit2_var._rotation_absolute);
    rot_transpose(_CRISTAL_M2_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_slit2_var._rotation_absolute, tr1, _CRISTAL_slit2_var._rotation_relative);
    _CRISTAL_slit2_var._rotation_is_identity =  rot_test_identity(_CRISTAL_slit2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, CRISTAL_DistanceSourceToSlit2 - CRISTAL_DistanceSourceToM1 - CRISTAL_DistanceM1ToM2);
    rot_transpose(_CRISTAL_M2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_slit2_var._position_absolute = coords_add(_CRISTAL_M2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_M2_var._position_absolute, _CRISTAL_slit2_var._position_absolute);
    _CRISTAL_slit2_var._position_relative = rot_apply(_CRISTAL_slit2_var._rotation_absolute, tc1);
  } /* CRISTAL_slit2=Slit() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_slit2", _CRISTAL_slit2_var._position_absolute, _CRISTAL_slit2_var._rotation_absolute);
  instrument->_position_absolute[196] = _CRISTAL_slit2_var._position_absolute;
  instrument->_position_relative[196] = _CRISTAL_slit2_var._position_relative;
    _CRISTAL_slit2_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_slit2_var._position_relative);
  instrument->counter_N[196]  = instrument->counter_P[196] = instrument->counter_P2[196] = 0;
  instrument->counter_AbsorbProp[196]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0195_CRISTAL_slit2", _CRISTAL_slit2_var._position_absolute, _CRISTAL_slit2_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "xwidth", "0.001", "CRISTAL_Slit2Width","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "yheight", "0.001", "CRISTAL_Slit2Height","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0195_CRISTAL_slit2", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_slit2_setpos */

/* component CRISTAL_psd_slit2=PSD_monitor() SETTING, POSITION/ROTATION */
int _CRISTAL_psd_slit2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_psd_slit2_setpos] component CRISTAL_psd_slit2=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_CRISTAL_psd_slit2_var._name, "CRISTAL_psd_slit2", 16384);
  stracpy(_CRISTAL_psd_slit2_var._type, "PSD_monitor", 16384);
  _CRISTAL_psd_slit2_var._index=197;
  int current_setpos_index = 197;
  if("CRISTAL_psd_slit2" && strlen("CRISTAL_psd_slit2"))
    stracpy(_CRISTAL_psd_slit2_var._parameters.filename, "CRISTAL_psd_slit2" ? "CRISTAL_psd_slit2" : "", 16384);
  else 
  _CRISTAL_psd_slit2_var._parameters.filename[0]='\0';
  _CRISTAL_psd_slit2_var._parameters.xwidth = 0.05;
  _CRISTAL_psd_slit2_var._parameters.yheight = 0.05;
  _CRISTAL_psd_slit2_var._parameters.radius = 0;
  _CRISTAL_psd_slit2_var._parameters.restore_xray = 1;
  _CRISTAL_psd_slit2_var._parameters.nowritefile = 0;
  _CRISTAL_psd_slit2_var._parameters.nx = 90;
  _CRISTAL_psd_slit2_var._parameters.ny = 90;
  _CRISTAL_psd_slit2_var._parameters.nr = 0;


  /* component CRISTAL_psd_slit2=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_slit2_var._rotation_absolute, _CRISTAL_psd_slit2_var._rotation_absolute);
    rot_transpose(_CRISTAL_slit2_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_psd_slit2_var._rotation_absolute, tr1, _CRISTAL_psd_slit2_var._rotation_relative);
    _CRISTAL_psd_slit2_var._rotation_is_identity =  rot_test_identity(_CRISTAL_psd_slit2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_slit2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_psd_slit2_var._position_absolute = coords_add(_CRISTAL_slit2_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_slit2_var._position_absolute, _CRISTAL_psd_slit2_var._position_absolute);
    _CRISTAL_psd_slit2_var._position_relative = rot_apply(_CRISTAL_psd_slit2_var._rotation_absolute, tc1);
  } /* CRISTAL_psd_slit2=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_psd_slit2", _CRISTAL_psd_slit2_var._position_absolute, _CRISTAL_psd_slit2_var._rotation_absolute);
  instrument->_position_absolute[197] = _CRISTAL_psd_slit2_var._position_absolute;
  instrument->_position_relative[197] = _CRISTAL_psd_slit2_var._position_relative;
    _CRISTAL_psd_slit2_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_psd_slit2_var._position_relative);
  instrument->counter_N[197]  = instrument->counter_P[197] = instrument->counter_P2[197] = 0;
  instrument->counter_AbsorbProp[197]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0196_CRISTAL_psd_slit2", _CRISTAL_psd_slit2_var._position_absolute, _CRISTAL_psd_slit2_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "filename", 0, "CRISTAL_psd_slit2", "char*");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "yheight", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0196_CRISTAL_psd_slit2", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_psd_slit2_setpos */

/* component CRISTAL_sample_stage=Arm() SETTING, POSITION/ROTATION */
int _CRISTAL_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_sample_stage_setpos] component CRISTAL_sample_stage=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CRISTAL_sample_stage_var._name, "CRISTAL_sample_stage", 16384);
  stracpy(_CRISTAL_sample_stage_var._type, "Arm", 16384);
  _CRISTAL_sample_stage_var._index=198;
  int current_setpos_index = 198;
  /* component CRISTAL_sample_stage=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_psd_slit2_var._rotation_absolute, _CRISTAL_sample_stage_var._rotation_absolute);
    rot_transpose(_CRISTAL_psd_slit2_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_sample_stage_var._rotation_absolute, tr1, _CRISTAL_sample_stage_var._rotation_relative);
    _CRISTAL_sample_stage_var._rotation_is_identity =  rot_test_identity(_CRISTAL_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, CRISTAL_DistanceSourceToSample - CRISTAL_DistanceSourceToSlit2);
    rot_transpose(_CRISTAL_psd_slit2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_sample_stage_var._position_absolute = coords_add(_CRISTAL_psd_slit2_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_psd_slit2_var._position_absolute, _CRISTAL_sample_stage_var._position_absolute);
    _CRISTAL_sample_stage_var._position_relative = rot_apply(_CRISTAL_sample_stage_var._rotation_absolute, tc1);
  } /* CRISTAL_sample_stage=Arm() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_sample_stage", _CRISTAL_sample_stage_var._position_absolute, _CRISTAL_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[198] = _CRISTAL_sample_stage_var._position_absolute;
  instrument->_position_relative[198] = _CRISTAL_sample_stage_var._position_relative;
    _CRISTAL_sample_stage_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_sample_stage_var._position_relative);
  instrument->counter_N[198]  = instrument->counter_P[198] = instrument->counter_P2[198] = 0;
  instrument->counter_AbsorbProp[198]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0197_CRISTAL_sample_stage", _CRISTAL_sample_stage_var._position_absolute, _CRISTAL_sample_stage_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_sample_stage_setpos */

/* component CRISTAL_fluo=FluoPowder() SETTING, POSITION/ROTATION */
int _CRISTAL_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_fluo_setpos] component CRISTAL_fluo=FluoPowder() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");
  stracpy(_CRISTAL_fluo_var._name, "CRISTAL_fluo", 16384);
  stracpy(_CRISTAL_fluo_var._type, "FluoPowder", 16384);
  _CRISTAL_fluo_var._index=199;
  int current_setpos_index = 199;
  _CRISTAL_fluo_var._parameters.geometry[0]='\0';
  _CRISTAL_fluo_var._parameters.radius = 0;
  _CRISTAL_fluo_var._parameters.thickness = 0;
  _CRISTAL_fluo_var._parameters.xwidth = 0.001;
  _CRISTAL_fluo_var._parameters.yheight = 0.01;
  _CRISTAL_fluo_var._parameters.zdepth = 5e-6;
  _CRISTAL_fluo_var._parameters.concentric = 0;
  if(_instrument_var._parameters.CRISTAL_reflections && strlen(_instrument_var._parameters.CRISTAL_reflections))
    stracpy(_CRISTAL_fluo_var._parameters.material, _instrument_var._parameters.CRISTAL_reflections ? _instrument_var._parameters.CRISTAL_reflections : "", 16384);
  else 
  _CRISTAL_fluo_var._parameters.material[0]='\0';
  _CRISTAL_fluo_var._parameters.packing_factor = 0;
  _CRISTAL_fluo_var._parameters.density = 0;
  _CRISTAL_fluo_var._parameters.weight = 0;
  _CRISTAL_fluo_var._parameters.p_interact = 0.99;
  _CRISTAL_fluo_var._parameters.target_x = 0;
  _CRISTAL_fluo_var._parameters.target_y = 0;
  _CRISTAL_fluo_var._parameters.target_z = 1;
  _CRISTAL_fluo_var._parameters.focus_r = 0;
  _CRISTAL_fluo_var._parameters.focus_xw = 0;
  _CRISTAL_fluo_var._parameters.focus_yh = 0;
  _CRISTAL_fluo_var._parameters.focus_aw = 180;
  _CRISTAL_fluo_var._parameters.focus_ah = asin ( 0.02 / CRISTAL_DetectorRadius ) * RAD2DEG;
  _CRISTAL_fluo_var._parameters.target_index = 0;
  _CRISTAL_fluo_var._parameters.flag_compton = 1;
  _CRISTAL_fluo_var._parameters.flag_rayleigh = 0;
  _CRISTAL_fluo_var._parameters.flag_lorentzian = 0;
  _CRISTAL_fluo_var._parameters.flag_powder = 1;
  _CRISTAL_fluo_var._parameters.flag_kissel = 0;
  if("" && strlen(""))
    stracpy(_CRISTAL_fluo_var._parameters.powder_refl, "" ? "" : "", 16384);
  else 
  _CRISTAL_fluo_var._parameters.powder_refl[0]='\0';
  _CRISTAL_fluo_var._parameters.powder_format[0] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[1] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[2] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[3] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[4] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[5] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[6] = 0;
  _CRISTAL_fluo_var._parameters.powder_format[7] = 0;
  _CRISTAL_fluo_var._parameters.Vc = 0;
  _CRISTAL_fluo_var._parameters.delta_d_d = 0;
  _CRISTAL_fluo_var._parameters.DW = 0;
  _CRISTAL_fluo_var._parameters.d_phi = asin ( 0.02 / CRISTAL_DetectorRadius ) * RAD2DEG;
  _CRISTAL_fluo_var._parameters.nb_atoms = 1;
  _CRISTAL_fluo_var._parameters.barns = 1;
  _CRISTAL_fluo_var._parameters.tth_sign = 0;
  _CRISTAL_fluo_var._parameters.order = 1;


  /* component CRISTAL_fluo=FluoPowder() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_sample_stage_var._rotation_absolute, _CRISTAL_fluo_var._rotation_absolute);
    rot_transpose(_CRISTAL_psd_slit2_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_fluo_var._rotation_absolute, tr1, _CRISTAL_fluo_var._rotation_relative);
    _CRISTAL_fluo_var._rotation_is_identity =  rot_test_identity(_CRISTAL_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_fluo_var._position_absolute = coords_add(_CRISTAL_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_psd_slit2_var._position_absolute, _CRISTAL_fluo_var._position_absolute);
    _CRISTAL_fluo_var._position_relative = rot_apply(_CRISTAL_fluo_var._rotation_absolute, tc1);
  } /* CRISTAL_fluo=FluoPowder() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_fluo", _CRISTAL_fluo_var._position_absolute, _CRISTAL_fluo_var._rotation_absolute);
  instrument->_position_absolute[199] = _CRISTAL_fluo_var._position_absolute;
  instrument->_position_relative[199] = _CRISTAL_fluo_var._position_relative;
    _CRISTAL_fluo_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_fluo_var._position_relative);
  instrument->counter_N[199]  = instrument->counter_P[199] = instrument->counter_P2[199] = 0;
  instrument->counter_AbsorbProp[199]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0198_CRISTAL_fluo", _CRISTAL_fluo_var._position_absolute, _CRISTAL_fluo_var._rotation_absolute, "FluoPowder");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "xwidth", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "zdepth", "0", "5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "material", "LaB6.cif", _instrument_var._parameters.CRISTAL_reflections, "char*");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "p_interact", "0", "0.99","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "target_z", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "focus_aw", "0", "180","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "focus_ah", "0", "asin ( 0.02 / CRISTAL_DetectorRadius ) * RAD2DEG","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "flag_rayleigh", "1", "0","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "flag_powder", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "powder_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "powder_format", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "Vc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "delta_d_d", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "DW", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "d_phi", "0", "asin ( 0.02 / CRISTAL_DetectorRadius ) * RAD2DEG","MCNUM");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "nb_atoms", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "tth_sign", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0198_CRISTAL_fluo", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_fluo_setpos */

/* component CRISTAL_detector_diffraction=Monitor_nD() SETTING, POSITION/ROTATION */
int _CRISTAL_detector_diffraction_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_detector_diffraction_setpos] component CRISTAL_detector_diffraction=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_CRISTAL_detector_diffraction_var._name, "CRISTAL_detector_diffraction", 16384);
  stracpy(_CRISTAL_detector_diffraction_var._type, "Monitor_nD", 16384);
  _CRISTAL_detector_diffraction_var._index=200;
  int current_setpos_index = 200;
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.user9[0]='\0';
  _CRISTAL_detector_diffraction_var._parameters.xwidth = 0;
  _CRISTAL_detector_diffraction_var._parameters.yheight = 0.02;
  _CRISTAL_detector_diffraction_var._parameters.zdepth = 0;
  _CRISTAL_detector_diffraction_var._parameters.bins = 50000;
  _CRISTAL_detector_diffraction_var._parameters.min = 2;
  _CRISTAL_detector_diffraction_var._parameters.max = 100;
  _CRISTAL_detector_diffraction_var._parameters.restore_xray = 1;
  _CRISTAL_detector_diffraction_var._parameters.radius = CRISTAL_DetectorRadius;
  if("abs theta" && strlen("abs theta"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.options, "abs theta" ? "abs theta" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.geometry[0]='\0';
  _CRISTAL_detector_diffraction_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_diffraction_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_diffraction_var._parameters.username9[0]='\0';


  /* component CRISTAL_detector_diffraction=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_sample_stage_var._rotation_absolute, _CRISTAL_detector_diffraction_var._rotation_absolute);
    rot_transpose(_CRISTAL_fluo_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_detector_diffraction_var._rotation_absolute, tr1, _CRISTAL_detector_diffraction_var._rotation_relative);
    _CRISTAL_detector_diffraction_var._rotation_is_identity =  rot_test_identity(_CRISTAL_detector_diffraction_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_detector_diffraction_var._position_absolute = coords_add(_CRISTAL_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_fluo_var._position_absolute, _CRISTAL_detector_diffraction_var._position_absolute);
    _CRISTAL_detector_diffraction_var._position_relative = rot_apply(_CRISTAL_detector_diffraction_var._rotation_absolute, tc1);
  } /* CRISTAL_detector_diffraction=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_detector_diffraction", _CRISTAL_detector_diffraction_var._position_absolute, _CRISTAL_detector_diffraction_var._rotation_absolute);
  instrument->_position_absolute[200] = _CRISTAL_detector_diffraction_var._position_absolute;
  instrument->_position_relative[200] = _CRISTAL_detector_diffraction_var._position_relative;
    _CRISTAL_detector_diffraction_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_detector_diffraction_var._position_relative);
  instrument->counter_N[200]  = instrument->counter_P[200] = instrument->counter_P2[200] = 0;
  instrument->counter_AbsorbProp[200]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", _CRISTAL_detector_diffraction_var._position_absolute, _CRISTAL_detector_diffraction_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "bins", "0", "50000","int");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "min", "-1e40", "2","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "max", "1e40", "100","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "radius", "0", "CRISTAL_DetectorRadius","MCNUM");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "options", "NULL", "abs theta", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0199_CRISTAL_detector_diffraction", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_detector_diffraction_setpos */

/* component CRISTAL_detector_fluo=Monitor_nD() SETTING, POSITION/ROTATION */
int _CRISTAL_detector_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CRISTAL_detector_fluo_setpos] component CRISTAL_detector_fluo=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_CRISTAL_detector_fluo_var._name, "CRISTAL_detector_fluo", 16384);
  stracpy(_CRISTAL_detector_fluo_var._type, "Monitor_nD", 16384);
  _CRISTAL_detector_fluo_var._index=201;
  int current_setpos_index = 201;
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_CRISTAL_detector_fluo_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.user9[0]='\0';
  _CRISTAL_detector_fluo_var._parameters.xwidth = 0;
  _CRISTAL_detector_fluo_var._parameters.yheight = 0.02;
  _CRISTAL_detector_fluo_var._parameters.zdepth = 0;
  _CRISTAL_detector_fluo_var._parameters.bins = 1024;
  _CRISTAL_detector_fluo_var._parameters.min = 0;
  _CRISTAL_detector_fluo_var._parameters.max = _instrument_var._parameters.CRISTAL_E0 * 1.2;
  _CRISTAL_detector_fluo_var._parameters.restore_xray = 0;
  _CRISTAL_detector_fluo_var._parameters.radius = CRISTAL_DetectorRadius;
  if("energy" && strlen("energy"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.geometry[0]='\0';
  _CRISTAL_detector_fluo_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CRISTAL_detector_fluo_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _CRISTAL_detector_fluo_var._parameters.username9[0]='\0';


  /* component CRISTAL_detector_fluo=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_sample_stage_var._rotation_absolute, _CRISTAL_detector_fluo_var._rotation_absolute);
    rot_transpose(_CRISTAL_detector_diffraction_var._rotation_absolute, tr1);
    rot_mul(_CRISTAL_detector_fluo_var._rotation_absolute, tr1, _CRISTAL_detector_fluo_var._rotation_relative);
    _CRISTAL_detector_fluo_var._rotation_is_identity =  rot_test_identity(_CRISTAL_detector_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CRISTAL_detector_fluo_var._position_absolute = coords_add(_CRISTAL_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_detector_diffraction_var._position_absolute, _CRISTAL_detector_fluo_var._position_absolute);
    _CRISTAL_detector_fluo_var._position_relative = rot_apply(_CRISTAL_detector_fluo_var._rotation_absolute, tc1);
  } /* CRISTAL_detector_fluo=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("CRISTAL_detector_fluo", _CRISTAL_detector_fluo_var._position_absolute, _CRISTAL_detector_fluo_var._rotation_absolute);
  instrument->_position_absolute[201] = _CRISTAL_detector_fluo_var._position_absolute;
  instrument->_position_relative[201] = _CRISTAL_detector_fluo_var._position_relative;
    _CRISTAL_detector_fluo_var._position_relative_is_zero =  coords_test_zero(_CRISTAL_detector_fluo_var._position_relative);
  instrument->counter_N[201]  = instrument->counter_P[201] = instrument->counter_P2[201] = 0;
  instrument->counter_AbsorbProp[201]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0200_CRISTAL_detector_fluo", _CRISTAL_detector_fluo_var._position_absolute, _CRISTAL_detector_fluo_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "bins", "0", "1024","int");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "min", "-1e40", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "max", "1e40", "_instrument_var._parameters.CRISTAL_E0 * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "radius", "0", "CRISTAL_DetectorRadius","MCNUM");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0200_CRISTAL_detector_fluo", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CRISTAL_detector_fluo_setpos */

/* component beamdump_207=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_207_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_207_setpos] component beamdump_207=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_207_var._name, "beamdump_207", 16384);
  stracpy(_beamdump_207_var._type, "Beamstop", 16384);
  _beamdump_207_var._index=202;
  int current_setpos_index = 202;
  _beamdump_207_var._parameters.xmin = -0.05;
  _beamdump_207_var._parameters.xmax = 0.05;
  _beamdump_207_var._parameters.ymin = -0.05;
  _beamdump_207_var._parameters.ymax = 0.05;
  _beamdump_207_var._parameters.xwidth = 0;
  _beamdump_207_var._parameters.yheight = 0;
  _beamdump_207_var._parameters.radius = 0;

  /* component beamdump_207=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CRISTAL_detector_fluo_var._rotation_absolute, _beamdump_207_var._rotation_absolute);
    rot_transpose(_CRISTAL_detector_fluo_var._rotation_absolute, tr1);
    rot_mul(_beamdump_207_var._rotation_absolute, tr1, _beamdump_207_var._rotation_relative);
    _beamdump_207_var._rotation_is_identity =  rot_test_identity(_beamdump_207_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CRISTAL_detector_fluo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_207_var._position_absolute = coords_add(_CRISTAL_detector_fluo_var._position_absolute, tc2);
    tc1 = coords_sub(_CRISTAL_detector_fluo_var._position_absolute, _beamdump_207_var._position_absolute);
    _beamdump_207_var._position_relative = rot_apply(_beamdump_207_var._rotation_absolute, tc1);
  } /* beamdump_207=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_207", _beamdump_207_var._position_absolute, _beamdump_207_var._rotation_absolute);
  instrument->_position_absolute[202] = _beamdump_207_var._position_absolute;
  instrument->_position_relative[202] = _beamdump_207_var._position_relative;
    _beamdump_207_var._position_relative_is_zero =  coords_test_zero(_beamdump_207_var._position_relative);
  instrument->counter_N[202]  = instrument->counter_P[202] = instrument->counter_P2[202] = 0;
  instrument->counter_AbsorbProp[202]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0201_beamdump_207", _beamdump_207_var._position_absolute, _beamdump_207_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0201_beamdump_207", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_207_setpos */

/* component DEIMOS_pos=Text() SETTING, POSITION/ROTATION */
int _DEIMOS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DEIMOS_pos_setpos] component DEIMOS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_DEIMOS_pos_var._name, "DEIMOS_pos", 16384);
  stracpy(_DEIMOS_pos_var._type, "Text", 16384);
  _DEIMOS_pos_var._index=203;
  int current_setpos_index = 203;
  if("DEIMOS" && strlen("DEIMOS"))
    stracpy(_DEIMOS_pos_var._parameters.text, "DEIMOS" ? "DEIMOS" : "", 16384);
  else 
  _DEIMOS_pos_var._parameters.text[0]='\0';
  _DEIMOS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_DEIMOS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _DEIMOS_pos_var._parameters.plane[0]='\0';
  _DEIMOS_pos_var._parameters.pen_thickness = 0.1;


  /* component DEIMOS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-134.685)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _DEIMOS_pos_var._rotation_absolute);
    rot_transpose(_beamdump_207_var._rotation_absolute, tr1);
    rot_mul(_DEIMOS_pos_var._rotation_absolute, tr1, _DEIMOS_pos_var._rotation_relative);
    _DEIMOS_pos_var._rotation_is_identity =  rot_test_identity(_DEIMOS_pos_var._rotation_relative);
    tc1 = coords_set(
      -39.62, 0, 40.05);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DEIMOS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_207_var._position_absolute, _DEIMOS_pos_var._position_absolute);
    _DEIMOS_pos_var._position_relative = rot_apply(_DEIMOS_pos_var._rotation_absolute, tc1);
  } /* DEIMOS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("DEIMOS_pos", _DEIMOS_pos_var._position_absolute, _DEIMOS_pos_var._rotation_absolute);
  instrument->_position_absolute[203] = _DEIMOS_pos_var._position_absolute;
  instrument->_position_relative[203] = _DEIMOS_pos_var._position_relative;
    _DEIMOS_pos_var._position_relative_is_zero =  coords_test_zero(_DEIMOS_pos_var._position_relative);
  instrument->counter_N[203]  = instrument->counter_P[203] = instrument->counter_P2[203] = 0;
  instrument->counter_AbsorbProp[203]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0202_DEIMOS_pos", _DEIMOS_pos_var._position_absolute, _DEIMOS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0202_DEIMOS_pos", "text", "NONE", "DEIMOS", "char*");
        mccomp_param_nexus(nxhandle,"0202_DEIMOS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0202_DEIMOS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0202_DEIMOS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DEIMOS_pos_setpos */

/* component GALAXIES_pos=Text() SETTING, POSITION/ROTATION */
int _GALAXIES_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_pos_setpos] component GALAXIES_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_GALAXIES_pos_var._name, "GALAXIES_pos", 16384);
  stracpy(_GALAXIES_pos_var._type, "Text", 16384);
  _GALAXIES_pos_var._index=204;
  int current_setpos_index = 204;
  if("GALAXIES" && strlen("GALAXIES"))
    stracpy(_GALAXIES_pos_var._parameters.text, "GALAXIES" ? "GALAXIES" : "", 16384);
  else 
  _GALAXIES_pos_var._parameters.text[0]='\0';
  _GALAXIES_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_GALAXIES_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _GALAXIES_pos_var._parameters.plane[0]='\0';
  _GALAXIES_pos_var._parameters.pen_thickness = 0.1;


  /* component GALAXIES_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-146.420)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _GALAXIES_pos_var._rotation_absolute);
    rot_transpose(_DEIMOS_pos_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_pos_var._rotation_absolute, tr1, _GALAXIES_pos_var._rotation_relative);
    _GALAXIES_pos_var._rotation_is_identity =  rot_test_identity(_GALAXIES_pos_var._rotation_relative);
    tc1 = coords_set(
      -46.94, 0, 31.16);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_DEIMOS_pos_var._position_absolute, _GALAXIES_pos_var._position_absolute);
    _GALAXIES_pos_var._position_relative = rot_apply(_GALAXIES_pos_var._rotation_absolute, tc1);
  } /* GALAXIES_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_pos", _GALAXIES_pos_var._position_absolute, _GALAXIES_pos_var._rotation_absolute);
  instrument->_position_absolute[204] = _GALAXIES_pos_var._position_absolute;
  instrument->_position_relative[204] = _GALAXIES_pos_var._position_relative;
    _GALAXIES_pos_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_pos_var._position_relative);
  instrument->counter_N[204]  = instrument->counter_P[204] = instrument->counter_P2[204] = 0;
  instrument->counter_AbsorbProp[204]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0203_GALAXIES_pos", _GALAXIES_pos_var._position_absolute, _GALAXIES_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0203_GALAXIES_pos", "text", "NONE", "GALAXIES", "char*");
        mccomp_param_nexus(nxhandle,"0203_GALAXIES_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0203_GALAXIES_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0203_GALAXIES_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_pos_setpos */

/* component GALAXIES=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_setpos] component GALAXIES=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_var._name, "GALAXIES", 16384);
  stracpy(_GALAXIES_var._type, "Arm", 16384);
  _GALAXIES_var._index=205;
  int current_setpos_index = 205;
  /* component GALAXIES=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_pos_var._rotation_absolute, _GALAXIES_var._rotation_absolute);
    rot_transpose(_GALAXIES_pos_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_var._rotation_absolute, tr1, _GALAXIES_var._rotation_relative);
    _GALAXIES_var._rotation_is_identity =  rot_test_identity(_GALAXIES_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_var._position_absolute = coords_add(_GALAXIES_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_pos_var._position_absolute, _GALAXIES_var._position_absolute);
    _GALAXIES_var._position_relative = rot_apply(_GALAXIES_var._rotation_absolute, tc1);
  } /* GALAXIES=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES", _GALAXIES_var._position_absolute, _GALAXIES_var._rotation_absolute);
  instrument->_position_absolute[205] = _GALAXIES_var._position_absolute;
  instrument->_position_relative[205] = _GALAXIES_var._position_relative;
    _GALAXIES_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_var._position_relative);
  instrument->counter_N[205]  = instrument->counter_P[205] = instrument->counter_P2[205] = 0;
  instrument->counter_AbsorbProp[205]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0204_GALAXIES", _GALAXIES_var._position_absolute, _GALAXIES_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_setpos */

/* component GALAXIES_Source_U20=Undulator() SETTING, POSITION/ROTATION */
int _GALAXIES_Source_U20_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_Source_U20_setpos] component GALAXIES_Source_U20=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_GALAXIES_Source_U20_var._name, "GALAXIES_Source_U20", 16384);
  stracpy(_GALAXIES_Source_U20_var._type, "Undulator", 16384);
  _GALAXIES_Source_U20_var._index=206;
  int current_setpos_index = 206;
  _GALAXIES_Source_U20_var._parameters.E0 = _instrument_var._parameters.GALAXIES_E0;
  _GALAXIES_Source_U20_var._parameters.dE = _instrument_var._parameters.GALAXIES_dE;
  _GALAXIES_Source_U20_var._parameters.phase = 0;
  _GALAXIES_Source_U20_var._parameters.randomphase = 1;
  _GALAXIES_Source_U20_var._parameters.Ee = 2.75;
  _GALAXIES_Source_U20_var._parameters.dEe = 0;
  _GALAXIES_Source_U20_var._parameters.Ie = 0.5;
  _GALAXIES_Source_U20_var._parameters.B = 0;
  _GALAXIES_Source_U20_var._parameters.K = GALAXIES_K;
  _GALAXIES_Source_U20_var._parameters.Nper = GALAXIES_Nper;
  _GALAXIES_Source_U20_var._parameters.lu = GALAXIES_lu;
  _GALAXIES_Source_U20_var._parameters.sigey = GALAXIES_sigey;
  _GALAXIES_Source_U20_var._parameters.sigex = GALAXIES_sigex;
  _GALAXIES_Source_U20_var._parameters.sigepx = GALAXIES_sigepx;
  _GALAXIES_Source_U20_var._parameters.sigepy = GALAXIES_sigepy;
  _GALAXIES_Source_U20_var._parameters.focus_xw = 0;
  _GALAXIES_Source_U20_var._parameters.focus_yh = 0;
  _GALAXIES_Source_U20_var._parameters.dist = GALAXIES_DistanceToPrimarySlit;
  _GALAXIES_Source_U20_var._parameters.quick_integ = 0;
  _GALAXIES_Source_U20_var._parameters.E1st = 0;
  _GALAXIES_Source_U20_var._parameters.verbose = 0;
  _GALAXIES_Source_U20_var._parameters.Br = 1.35;


  /* component GALAXIES_Source_U20=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_var._rotation_absolute, _GALAXIES_Source_U20_var._rotation_absolute);
    rot_transpose(_GALAXIES_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_Source_U20_var._rotation_absolute, tr1, _GALAXIES_Source_U20_var._rotation_relative);
    _GALAXIES_Source_U20_var._rotation_is_identity =  rot_test_identity(_GALAXIES_Source_U20_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_Source_U20_var._position_absolute = coords_add(_GALAXIES_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_var._position_absolute, _GALAXIES_Source_U20_var._position_absolute);
    _GALAXIES_Source_U20_var._position_relative = rot_apply(_GALAXIES_Source_U20_var._rotation_absolute, tc1);
  } /* GALAXIES_Source_U20=Undulator() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_Source_U20", _GALAXIES_Source_U20_var._position_absolute, _GALAXIES_Source_U20_var._rotation_absolute);
  instrument->_position_absolute[206] = _GALAXIES_Source_U20_var._position_absolute;
  instrument->_position_relative[206] = _GALAXIES_Source_U20_var._position_relative;
    _GALAXIES_Source_U20_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_Source_U20_var._position_relative);
  instrument->counter_N[206]  = instrument->counter_P[206] = instrument->counter_P2[206] = 0;
  instrument->counter_AbsorbProp[206]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0205_GALAXIES_Source_U20", _GALAXIES_Source_U20_var._position_absolute, _GALAXIES_Source_U20_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "E0", "0", "_instrument_var._parameters.GALAXIES_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "dE", "0", "_instrument_var._parameters.GALAXIES_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "dEe", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "K", "0", "GALAXIES_K","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "Nper", "1", "GALAXIES_Nper","int");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "lu", "16e-3", "GALAXIES_lu","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "sigey", "0", "GALAXIES_sigey","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "sigex", "0", "GALAXIES_sigex","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "sigepx", "0", "GALAXIES_sigepx","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "sigepy", "0", "GALAXIES_sigepy","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "dist", "1", "GALAXIES_DistanceToPrimarySlit","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0205_GALAXIES_Source_U20", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_Source_U20_setpos */

/* component GALAXIES_mon_src_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_src_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_src_xy_setpos] component GALAXIES_mon_src_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_src_xy_var._name, "GALAXIES_mon_src_xy", 16384);
  stracpy(_GALAXIES_mon_src_xy_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_src_xy_var._index=207;
  int current_setpos_index = 207;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.user9[0]='\0';
  _GALAXIES_mon_src_xy_var._parameters.xwidth = 5e-3;
  _GALAXIES_mon_src_xy_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_src_xy_var._parameters.zdepth = 0;
  _GALAXIES_mon_src_xy_var._parameters.bins = 128;
  _GALAXIES_mon_src_xy_var._parameters.min = -1e40;
  _GALAXIES_mon_src_xy_var._parameters.max = 1e40;
  _GALAXIES_mon_src_xy_var._parameters.restore_xray = 1;
  _GALAXIES_mon_src_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.options[0]='\0';
  if("GALAXIES_mon_src_xy" && strlen("GALAXIES_mon_src_xy"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.filename, "GALAXIES_mon_src_xy" ? "GALAXIES_mon_src_xy" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_src_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_xy_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_src_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_Source_U20_var._rotation_absolute, _GALAXIES_mon_src_xy_var._rotation_absolute);
    rot_transpose(_GALAXIES_Source_U20_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_src_xy_var._rotation_absolute, tr1, _GALAXIES_mon_src_xy_var._rotation_relative);
    _GALAXIES_mon_src_xy_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_src_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToPrimarySlit -0.1);
    rot_transpose(_GALAXIES_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_src_xy_var._position_absolute = coords_add(_GALAXIES_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_Source_U20_var._position_absolute, _GALAXIES_mon_src_xy_var._position_absolute);
    _GALAXIES_mon_src_xy_var._position_relative = rot_apply(_GALAXIES_mon_src_xy_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_src_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_src_xy", _GALAXIES_mon_src_xy_var._position_absolute, _GALAXIES_mon_src_xy_var._rotation_absolute);
  instrument->_position_absolute[207] = _GALAXIES_mon_src_xy_var._position_absolute;
  instrument->_position_relative[207] = _GALAXIES_mon_src_xy_var._position_relative;
    _GALAXIES_mon_src_xy_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_src_xy_var._position_relative);
  instrument->counter_N[207]  = instrument->counter_P[207] = instrument->counter_P2[207] = 0;
  instrument->counter_AbsorbProp[207]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", _GALAXIES_mon_src_xy_var._position_absolute, _GALAXIES_mon_src_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "xwidth", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "filename", "NULL", "GALAXIES_mon_src_xy", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0206_GALAXIES_mon_src_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_src_xy_setpos */

/* component GALAXIES_mon_src_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_src_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_src_e_setpos] component GALAXIES_mon_src_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_src_e_var._name, "GALAXIES_mon_src_e", 16384);
  stracpy(_GALAXIES_mon_src_e_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_src_e_var._index=208;
  int current_setpos_index = 208;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_src_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.user9[0]='\0';
  _GALAXIES_mon_src_e_var._parameters.xwidth = 5e-3;
  _GALAXIES_mon_src_e_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_src_e_var._parameters.zdepth = 0;
  _GALAXIES_mon_src_e_var._parameters.bins = 256;
  _GALAXIES_mon_src_e_var._parameters.min = _instrument_var._parameters.GALAXIES_E0 - _instrument_var._parameters.GALAXIES_dE * 1.2;
  _GALAXIES_mon_src_e_var._parameters.max = _instrument_var._parameters.GALAXIES_E0 + _instrument_var._parameters.GALAXIES_dE * 1.2;
  _GALAXIES_mon_src_e_var._parameters.restore_xray = 1;
  _GALAXIES_mon_src_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.options[0]='\0';
  if("GALAXIES_mon_src_e" && strlen("GALAXIES_mon_src_e"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.filename, "GALAXIES_mon_src_e" ? "GALAXIES_mon_src_e" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_src_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_src_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_src_e_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_src_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_mon_src_xy_var._rotation_absolute, _GALAXIES_mon_src_e_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_src_e_var._rotation_absolute, tr1, _GALAXIES_mon_src_e_var._rotation_relative);
    _GALAXIES_mon_src_e_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_src_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_mon_src_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_src_e_var._position_absolute = coords_add(_GALAXIES_mon_src_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_src_xy_var._position_absolute, _GALAXIES_mon_src_e_var._position_absolute);
    _GALAXIES_mon_src_e_var._position_relative = rot_apply(_GALAXIES_mon_src_e_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_src_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_src_e", _GALAXIES_mon_src_e_var._position_absolute, _GALAXIES_mon_src_e_var._rotation_absolute);
  instrument->_position_absolute[208] = _GALAXIES_mon_src_e_var._position_absolute;
  instrument->_position_relative[208] = _GALAXIES_mon_src_e_var._position_relative;
    _GALAXIES_mon_src_e_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_src_e_var._position_relative);
  instrument->counter_N[208]  = instrument->counter_P[208] = instrument->counter_P2[208] = 0;
  instrument->counter_AbsorbProp[208]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0207_GALAXIES_mon_src_e", _GALAXIES_mon_src_e_var._position_absolute, _GALAXIES_mon_src_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "xwidth", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "bins", "0", "256","int");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "min", "-1e40", "_instrument_var._parameters.GALAXIES_E0 - _instrument_var._parameters.GALAXIES_dE * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "max", "1e40", "_instrument_var._parameters.GALAXIES_E0 + _instrument_var._parameters.GALAXIES_dE * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "filename", "NULL", "GALAXIES_mon_src_e", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0207_GALAXIES_mon_src_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_src_e_setpos */

/* component GALAXIES_absorber=Slit() SETTING, POSITION/ROTATION */
int _GALAXIES_absorber_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_absorber_setpos] component GALAXIES_absorber=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_GALAXIES_absorber_var._name, "GALAXIES_absorber", 16384);
  stracpy(_GALAXIES_absorber_var._type, "Slit", 16384);
  _GALAXIES_absorber_var._index=209;
  int current_setpos_index = 209;
  _GALAXIES_absorber_var._parameters.xmin = 0;
  _GALAXIES_absorber_var._parameters.xmax = 0;
  _GALAXIES_absorber_var._parameters.ymin = 0;
  _GALAXIES_absorber_var._parameters.ymax = 0;
  _GALAXIES_absorber_var._parameters.radius = 0;
  _GALAXIES_absorber_var._parameters.xwidth = GALAXIES_AbsorberWidth;
  _GALAXIES_absorber_var._parameters.yheight = GALAXIES_AbsorberHeight;
  _GALAXIES_absorber_var._parameters.dist = 0;
  _GALAXIES_absorber_var._parameters.focus_xw = 0;
  _GALAXIES_absorber_var._parameters.focus_yh = 0;
  _GALAXIES_absorber_var._parameters.focus_x0 = 0;
  _GALAXIES_absorber_var._parameters.focus_y0 = 0;

  /* component GALAXIES_absorber=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_Source_U20_var._rotation_absolute, _GALAXIES_absorber_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_src_e_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_absorber_var._rotation_absolute, tr1, _GALAXIES_absorber_var._rotation_relative);
    _GALAXIES_absorber_var._rotation_is_identity =  rot_test_identity(_GALAXIES_absorber_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToAbsorber);
    rot_transpose(_GALAXIES_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_absorber_var._position_absolute = coords_add(_GALAXIES_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_src_e_var._position_absolute, _GALAXIES_absorber_var._position_absolute);
    _GALAXIES_absorber_var._position_relative = rot_apply(_GALAXIES_absorber_var._rotation_absolute, tc1);
  } /* GALAXIES_absorber=Slit() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_absorber", _GALAXIES_absorber_var._position_absolute, _GALAXIES_absorber_var._rotation_absolute);
  instrument->_position_absolute[209] = _GALAXIES_absorber_var._position_absolute;
  instrument->_position_relative[209] = _GALAXIES_absorber_var._position_relative;
    _GALAXIES_absorber_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_absorber_var._position_relative);
  instrument->counter_N[209]  = instrument->counter_P[209] = instrument->counter_P2[209] = 0;
  instrument->counter_AbsorbProp[209]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0208_GALAXIES_absorber", _GALAXIES_absorber_var._position_absolute, _GALAXIES_absorber_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "xwidth", "0.001", "GALAXIES_AbsorberWidth","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "yheight", "0.001", "GALAXIES_AbsorberHeight","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0208_GALAXIES_absorber", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_absorber_setpos */

/* component GALAXIES_diaphragme=Slit() SETTING, POSITION/ROTATION */
int _GALAXIES_diaphragme_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_diaphragme_setpos] component GALAXIES_diaphragme=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_GALAXIES_diaphragme_var._name, "GALAXIES_diaphragme", 16384);
  stracpy(_GALAXIES_diaphragme_var._type, "Slit", 16384);
  _GALAXIES_diaphragme_var._index=210;
  int current_setpos_index = 210;
  _GALAXIES_diaphragme_var._parameters.xmin = 0;
  _GALAXIES_diaphragme_var._parameters.xmax = 0;
  _GALAXIES_diaphragme_var._parameters.ymin = 0;
  _GALAXIES_diaphragme_var._parameters.ymax = 0;
  _GALAXIES_diaphragme_var._parameters.radius = 0;
  _GALAXIES_diaphragme_var._parameters.xwidth = GALAXIES_DiaphragmWidth;
  _GALAXIES_diaphragme_var._parameters.yheight = GALAXIES_DiaphragmHeight;
  _GALAXIES_diaphragme_var._parameters.dist = 0;
  _GALAXIES_diaphragme_var._parameters.focus_xw = 0;
  _GALAXIES_diaphragme_var._parameters.focus_yh = 0;
  _GALAXIES_diaphragme_var._parameters.focus_x0 = 0;
  _GALAXIES_diaphragme_var._parameters.focus_y0 = 0;

  /* component GALAXIES_diaphragme=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_Source_U20_var._rotation_absolute, _GALAXIES_diaphragme_var._rotation_absolute);
    rot_transpose(_GALAXIES_absorber_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_diaphragme_var._rotation_absolute, tr1, _GALAXIES_diaphragme_var._rotation_relative);
    _GALAXIES_diaphragme_var._rotation_is_identity =  rot_test_identity(_GALAXIES_diaphragme_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToDiaphragm);
    rot_transpose(_GALAXIES_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_diaphragme_var._position_absolute = coords_add(_GALAXIES_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_absorber_var._position_absolute, _GALAXIES_diaphragme_var._position_absolute);
    _GALAXIES_diaphragme_var._position_relative = rot_apply(_GALAXIES_diaphragme_var._rotation_absolute, tc1);
  } /* GALAXIES_diaphragme=Slit() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_diaphragme", _GALAXIES_diaphragme_var._position_absolute, _GALAXIES_diaphragme_var._rotation_absolute);
  instrument->_position_absolute[210] = _GALAXIES_diaphragme_var._position_absolute;
  instrument->_position_relative[210] = _GALAXIES_diaphragme_var._position_relative;
    _GALAXIES_diaphragme_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_diaphragme_var._position_relative);
  instrument->counter_N[210]  = instrument->counter_P[210] = instrument->counter_P2[210] = 0;
  instrument->counter_AbsorbProp[210]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0209_GALAXIES_diaphragme", _GALAXIES_diaphragme_var._position_absolute, _GALAXIES_diaphragme_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "xwidth", "0.001", "GALAXIES_DiaphragmWidth","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "yheight", "0.001", "GALAXIES_DiaphragmHeight","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0209_GALAXIES_diaphragme", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_diaphragme_setpos */

/* component GALAXIES_fentes_primaires=Slit() SETTING, POSITION/ROTATION */
int _GALAXIES_fentes_primaires_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_fentes_primaires_setpos] component GALAXIES_fentes_primaires=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_GALAXIES_fentes_primaires_var._name, "GALAXIES_fentes_primaires", 16384);
  stracpy(_GALAXIES_fentes_primaires_var._type, "Slit", 16384);
  _GALAXIES_fentes_primaires_var._index=211;
  int current_setpos_index = 211;
  _GALAXIES_fentes_primaires_var._parameters.xmin = 0;
  _GALAXIES_fentes_primaires_var._parameters.xmax = 0;
  _GALAXIES_fentes_primaires_var._parameters.ymin = 0;
  _GALAXIES_fentes_primaires_var._parameters.ymax = 0;
  _GALAXIES_fentes_primaires_var._parameters.radius = 0;
  _GALAXIES_fentes_primaires_var._parameters.xwidth = GALAXIES_PrimarySlitWidth;
  _GALAXIES_fentes_primaires_var._parameters.yheight = GALAXIES_PrimarySlitHeight;
  _GALAXIES_fentes_primaires_var._parameters.dist = 0;
  _GALAXIES_fentes_primaires_var._parameters.focus_xw = 0;
  _GALAXIES_fentes_primaires_var._parameters.focus_yh = 0;
  _GALAXIES_fentes_primaires_var._parameters.focus_x0 = 0;
  _GALAXIES_fentes_primaires_var._parameters.focus_y0 = 0;

  /* component GALAXIES_fentes_primaires=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_Source_U20_var._rotation_absolute, _GALAXIES_fentes_primaires_var._rotation_absolute);
    rot_transpose(_GALAXIES_diaphragme_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_fentes_primaires_var._rotation_absolute, tr1, _GALAXIES_fentes_primaires_var._rotation_relative);
    _GALAXIES_fentes_primaires_var._rotation_is_identity =  rot_test_identity(_GALAXIES_fentes_primaires_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToPrimarySlit);
    rot_transpose(_GALAXIES_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_fentes_primaires_var._position_absolute = coords_add(_GALAXIES_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_diaphragme_var._position_absolute, _GALAXIES_fentes_primaires_var._position_absolute);
    _GALAXIES_fentes_primaires_var._position_relative = rot_apply(_GALAXIES_fentes_primaires_var._rotation_absolute, tc1);
  } /* GALAXIES_fentes_primaires=Slit() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_fentes_primaires", _GALAXIES_fentes_primaires_var._position_absolute, _GALAXIES_fentes_primaires_var._rotation_absolute);
  instrument->_position_absolute[211] = _GALAXIES_fentes_primaires_var._position_absolute;
  instrument->_position_relative[211] = _GALAXIES_fentes_primaires_var._position_relative;
    _GALAXIES_fentes_primaires_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_fentes_primaires_var._position_relative);
  instrument->counter_N[211]  = instrument->counter_P[211] = instrument->counter_P2[211] = 0;
  instrument->counter_AbsorbProp[211]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", _GALAXIES_fentes_primaires_var._position_absolute, _GALAXIES_fentes_primaires_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "xwidth", "0.001", "GALAXIES_PrimarySlitWidth","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "yheight", "0.001", "GALAXIES_PrimarySlitHeight","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0210_GALAXIES_fentes_primaires", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_fentes_primaires_setpos */

/* component GALAXIES_mon_prim_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_prim_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_prim_xy_setpos] component GALAXIES_mon_prim_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_prim_xy_var._name, "GALAXIES_mon_prim_xy", 16384);
  stracpy(_GALAXIES_mon_prim_xy_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_prim_xy_var._index=212;
  int current_setpos_index = 212;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.user9[0]='\0';
  _GALAXIES_mon_prim_xy_var._parameters.xwidth = 5e-3;
  _GALAXIES_mon_prim_xy_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_prim_xy_var._parameters.zdepth = 0;
  _GALAXIES_mon_prim_xy_var._parameters.bins = 128;
  _GALAXIES_mon_prim_xy_var._parameters.min = -1e40;
  _GALAXIES_mon_prim_xy_var._parameters.max = 1e40;
  _GALAXIES_mon_prim_xy_var._parameters.restore_xray = 1;
  _GALAXIES_mon_prim_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.options[0]='\0';
  if("GALAXIES_mon_prim_xy" && strlen("GALAXIES_mon_prim_xy"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.filename, "GALAXIES_mon_prim_xy" ? "GALAXIES_mon_prim_xy" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_prim_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_prim_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_prim_xy_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_prim_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_fentes_primaires_var._rotation_absolute, _GALAXIES_mon_prim_xy_var._rotation_absolute);
    rot_transpose(_GALAXIES_fentes_primaires_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_prim_xy_var._rotation_absolute, tr1, _GALAXIES_mon_prim_xy_var._rotation_relative);
    _GALAXIES_mon_prim_xy_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_prim_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_fentes_primaires_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_prim_xy_var._position_absolute = coords_add(_GALAXIES_fentes_primaires_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_fentes_primaires_var._position_absolute, _GALAXIES_mon_prim_xy_var._position_absolute);
    _GALAXIES_mon_prim_xy_var._position_relative = rot_apply(_GALAXIES_mon_prim_xy_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_prim_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_prim_xy", _GALAXIES_mon_prim_xy_var._position_absolute, _GALAXIES_mon_prim_xy_var._rotation_absolute);
  instrument->_position_absolute[212] = _GALAXIES_mon_prim_xy_var._position_absolute;
  instrument->_position_relative[212] = _GALAXIES_mon_prim_xy_var._position_relative;
    _GALAXIES_mon_prim_xy_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_prim_xy_var._position_relative);
  instrument->counter_N[212]  = instrument->counter_P[212] = instrument->counter_P2[212] = 0;
  instrument->counter_AbsorbProp[212]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", _GALAXIES_mon_prim_xy_var._position_absolute, _GALAXIES_mon_prim_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "xwidth", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "filename", "NULL", "GALAXIES_mon_prim_xy", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0211_GALAXIES_mon_prim_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_prim_xy_setpos */

/* component GALAXIES_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_DCM_location_setpos] component GALAXIES_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_DCM_location_var._name, "GALAXIES_DCM_location", 16384);
  stracpy(_GALAXIES_DCM_location_var._type, "Arm", 16384);
  _GALAXIES_DCM_location_var._index=213;
  int current_setpos_index = 213;
  /* component GALAXIES_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_Source_U20_var._rotation_absolute, _GALAXIES_DCM_location_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_prim_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_DCM_location_var._rotation_absolute, tr1, _GALAXIES_DCM_location_var._rotation_relative);
    _GALAXIES_DCM_location_var._rotation_is_identity =  rot_test_identity(_GALAXIES_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToDCM);
    rot_transpose(_GALAXIES_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_DCM_location_var._position_absolute = coords_add(_GALAXIES_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_prim_xy_var._position_absolute, _GALAXIES_DCM_location_var._position_absolute);
    _GALAXIES_DCM_location_var._position_relative = rot_apply(_GALAXIES_DCM_location_var._rotation_absolute, tc1);
  } /* GALAXIES_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_DCM_location", _GALAXIES_DCM_location_var._position_absolute, _GALAXIES_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[213] = _GALAXIES_DCM_location_var._position_absolute;
  instrument->_position_relative[213] = _GALAXIES_DCM_location_var._position_relative;
    _GALAXIES_DCM_location_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_DCM_location_var._position_relative);
  instrument->counter_N[213]  = instrument->counter_P[213] = instrument->counter_P2[213] = 0;
  instrument->counter_AbsorbProp[213]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0212_GALAXIES_DCM_location", _GALAXIES_DCM_location_var._position_absolute, _GALAXIES_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_DCM_location_setpos */

/* component GALAXIES_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _GALAXIES_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_dcm_xtal0_setpos] component GALAXIES_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_GALAXIES_dcm_xtal0_var._name, "GALAXIES_dcm_xtal0", 16384);
  stracpy(_GALAXIES_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _GALAXIES_dcm_xtal0_var._index=214;
  int current_setpos_index = 214;
  _GALAXIES_dcm_xtal0_var._parameters.length = 0.05;
  _GALAXIES_dcm_xtal0_var._parameters.width = 0.01;
  _GALAXIES_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_GALAXIES_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _GALAXIES_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_GALAXIES_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _GALAXIES_dcm_xtal0_var._parameters.material[0]='\0';
  _GALAXIES_dcm_xtal0_var._parameters.alpha = 0.0;
  _GALAXIES_dcm_xtal0_var._parameters.R0 = 0;
  _GALAXIES_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _GALAXIES_dcm_xtal0_var._parameters.crystal_type = 2;
  _GALAXIES_dcm_xtal0_var._parameters.h = 1;
  _GALAXIES_dcm_xtal0_var._parameters.k = 1;
  _GALAXIES_dcm_xtal0_var._parameters.l = 1;
  _GALAXIES_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _GALAXIES_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component GALAXIES_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_DCM_location_var._rotation_absolute, _GALAXIES_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_prim_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_dcm_xtal0_var._rotation_absolute, tr1, _GALAXIES_dcm_xtal0_var._rotation_relative);
    _GALAXIES_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_GALAXIES_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_dcm_xtal0_var._position_absolute = coords_add(_GALAXIES_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_prim_xy_var._position_absolute, _GALAXIES_dcm_xtal0_var._position_absolute);
    _GALAXIES_dcm_xtal0_var._position_relative = rot_apply(_GALAXIES_dcm_xtal0_var._rotation_absolute, tc1);
  } /* GALAXIES_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_dcm_xtal0", _GALAXIES_dcm_xtal0_var._position_absolute, _GALAXIES_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[214] = _GALAXIES_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[214] = _GALAXIES_dcm_xtal0_var._position_relative;
    _GALAXIES_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_dcm_xtal0_var._position_relative);
  instrument->counter_N[214]  = instrument->counter_P[214] = instrument->counter_P2[214] = 0;
  instrument->counter_AbsorbProp[214]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", _GALAXIES_dcm_xtal0_var._position_absolute, _GALAXIES_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "width", "0.02", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0213_GALAXIES_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_dcm_xtal0_setpos */

/* component GALAXIES_dcm0=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_dcm0_setpos] component GALAXIES_dcm0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_dcm0_var._name, "GALAXIES_dcm0", 16384);
  stracpy(_GALAXIES_dcm0_var._type, "Arm", 16384);
  _GALAXIES_dcm0_var._index=215;
  int current_setpos_index = 215;
  /* component GALAXIES_dcm0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_dcm_xtal0_var._rotation_absolute, _GALAXIES_dcm0_var._rotation_absolute);
    rot_transpose(_GALAXIES_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_dcm0_var._rotation_absolute, tr1, _GALAXIES_dcm0_var._rotation_relative);
    _GALAXIES_dcm0_var._rotation_is_identity =  rot_test_identity(_GALAXIES_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_dcm0_var._position_absolute = coords_add(_GALAXIES_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_dcm_xtal0_var._position_absolute, _GALAXIES_dcm0_var._position_absolute);
    _GALAXIES_dcm0_var._position_relative = rot_apply(_GALAXIES_dcm0_var._rotation_absolute, tc1);
  } /* GALAXIES_dcm0=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_dcm0", _GALAXIES_dcm0_var._position_absolute, _GALAXIES_dcm0_var._rotation_absolute);
  instrument->_position_absolute[215] = _GALAXIES_dcm0_var._position_absolute;
  instrument->_position_relative[215] = _GALAXIES_dcm0_var._position_relative;
    _GALAXIES_dcm0_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_dcm0_var._position_relative);
  instrument->counter_N[215]  = instrument->counter_P[215] = instrument->counter_P2[215] = 0;
  instrument->counter_AbsorbProp[215]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0214_GALAXIES_dcm0", _GALAXIES_dcm0_var._position_absolute, _GALAXIES_dcm0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_dcm0_setpos */

/* component GALAXIES_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _GALAXIES_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_dcm_xtal1_setpos] component GALAXIES_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_GALAXIES_dcm_xtal1_var._name, "GALAXIES_dcm_xtal1", 16384);
  stracpy(_GALAXIES_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _GALAXIES_dcm_xtal1_var._index=216;
  int current_setpos_index = 216;
  _GALAXIES_dcm_xtal1_var._parameters.length = 0.05;
  _GALAXIES_dcm_xtal1_var._parameters.width = 0.01;
  _GALAXIES_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_GALAXIES_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _GALAXIES_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_GALAXIES_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _GALAXIES_dcm_xtal1_var._parameters.material[0]='\0';
  _GALAXIES_dcm_xtal1_var._parameters.alpha = 0.0;
  _GALAXIES_dcm_xtal1_var._parameters.R0 = 0;
  _GALAXIES_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _GALAXIES_dcm_xtal1_var._parameters.crystal_type = 2;
  _GALAXIES_dcm_xtal1_var._parameters.h = 1;
  _GALAXIES_dcm_xtal1_var._parameters.k = 1;
  _GALAXIES_dcm_xtal1_var._parameters.l = 1;
  _GALAXIES_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _GALAXIES_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component GALAXIES_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_dcm0_var._rotation_absolute, _GALAXIES_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_GALAXIES_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_dcm_xtal1_var._rotation_absolute, tr1, _GALAXIES_dcm_xtal1_var._rotation_relative);
    _GALAXIES_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_GALAXIES_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, GALAXIES_DcmGap, GALAXIES_dcm_theta ? GALAXIES_DcmGap / tan ( GALAXIES_dcm_theta * DEG2RAD ) : 0);
    rot_transpose(_GALAXIES_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_dcm_xtal1_var._position_absolute = coords_add(_GALAXIES_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_dcm_xtal0_var._position_absolute, _GALAXIES_dcm_xtal1_var._position_absolute);
    _GALAXIES_dcm_xtal1_var._position_relative = rot_apply(_GALAXIES_dcm_xtal1_var._rotation_absolute, tc1);
  } /* GALAXIES_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_dcm_xtal1", _GALAXIES_dcm_xtal1_var._position_absolute, _GALAXIES_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[216] = _GALAXIES_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[216] = _GALAXIES_dcm_xtal1_var._position_relative;
    _GALAXIES_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_dcm_xtal1_var._position_relative);
  instrument->counter_N[216]  = instrument->counter_P[216] = instrument->counter_P2[216] = 0;
  instrument->counter_AbsorbProp[216]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", _GALAXIES_dcm_xtal1_var._position_absolute, _GALAXIES_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "width", "0.02", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0215_GALAXIES_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_dcm_xtal1_setpos */

/* component GALAXIES_dcm1=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_dcm1_setpos] component GALAXIES_dcm1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_dcm1_var._name, "GALAXIES_dcm1", 16384);
  stracpy(_GALAXIES_dcm1_var._type, "Arm", 16384);
  _GALAXIES_dcm1_var._index=217;
  int current_setpos_index = 217;
  /* component GALAXIES_dcm1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_dcm_xtal1_var._rotation_absolute, _GALAXIES_dcm1_var._rotation_absolute);
    rot_transpose(_GALAXIES_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_dcm1_var._rotation_absolute, tr1, _GALAXIES_dcm1_var._rotation_relative);
    _GALAXIES_dcm1_var._rotation_is_identity =  rot_test_identity(_GALAXIES_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_dcm1_var._position_absolute = coords_add(_GALAXIES_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_dcm_xtal1_var._position_absolute, _GALAXIES_dcm1_var._position_absolute);
    _GALAXIES_dcm1_var._position_relative = rot_apply(_GALAXIES_dcm1_var._rotation_absolute, tc1);
  } /* GALAXIES_dcm1=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_dcm1", _GALAXIES_dcm1_var._position_absolute, _GALAXIES_dcm1_var._rotation_absolute);
  instrument->_position_absolute[217] = _GALAXIES_dcm1_var._position_absolute;
  instrument->_position_relative[217] = _GALAXIES_dcm1_var._position_relative;
    _GALAXIES_dcm1_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_dcm1_var._position_relative);
  instrument->counter_N[217]  = instrument->counter_P[217] = instrument->counter_P2[217] = 0;
  instrument->counter_AbsorbProp[217]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0216_GALAXIES_dcm1", _GALAXIES_dcm1_var._position_absolute, _GALAXIES_dcm1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_dcm1_setpos */

/* component GALAXIES_mon_dcm_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_dcm_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_dcm_e_setpos] component GALAXIES_mon_dcm_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_dcm_e_var._name, "GALAXIES_mon_dcm_e", 16384);
  stracpy(_GALAXIES_mon_dcm_e_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_dcm_e_var._index=218;
  int current_setpos_index = 218;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.user9[0]='\0';
  _GALAXIES_mon_dcm_e_var._parameters.xwidth = 5e-3;
  _GALAXIES_mon_dcm_e_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_dcm_e_var._parameters.zdepth = 0;
  _GALAXIES_mon_dcm_e_var._parameters.bins = 256;
  _GALAXIES_mon_dcm_e_var._parameters.min = _instrument_var._parameters.GALAXIES_E0 - _instrument_var._parameters.GALAXIES_dE * 1.2;
  _GALAXIES_mon_dcm_e_var._parameters.max = _instrument_var._parameters.GALAXIES_E0 + _instrument_var._parameters.GALAXIES_dE * 1.2;
  _GALAXIES_mon_dcm_e_var._parameters.restore_xray = 1;
  _GALAXIES_mon_dcm_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.options[0]='\0';
  if("GALAXIES_mon_dcm_e" && strlen("GALAXIES_mon_dcm_e"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.filename, "GALAXIES_mon_dcm_e" ? "GALAXIES_mon_dcm_e" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_dcm_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_e_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_dcm_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_dcm1_var._rotation_absolute, _GALAXIES_mon_dcm_e_var._rotation_absolute);
    rot_transpose(_GALAXIES_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_dcm_e_var._rotation_absolute, tr1, _GALAXIES_mon_dcm_e_var._rotation_relative);
    _GALAXIES_mon_dcm_e_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_dcm_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_GALAXIES_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_dcm_e_var._position_absolute = coords_add(_GALAXIES_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_dcm_xtal1_var._position_absolute, _GALAXIES_mon_dcm_e_var._position_absolute);
    _GALAXIES_mon_dcm_e_var._position_relative = rot_apply(_GALAXIES_mon_dcm_e_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_dcm_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_dcm_e", _GALAXIES_mon_dcm_e_var._position_absolute, _GALAXIES_mon_dcm_e_var._rotation_absolute);
  instrument->_position_absolute[218] = _GALAXIES_mon_dcm_e_var._position_absolute;
  instrument->_position_relative[218] = _GALAXIES_mon_dcm_e_var._position_relative;
    _GALAXIES_mon_dcm_e_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_dcm_e_var._position_relative);
  instrument->counter_N[218]  = instrument->counter_P[218] = instrument->counter_P2[218] = 0;
  instrument->counter_AbsorbProp[218]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", _GALAXIES_mon_dcm_e_var._position_absolute, _GALAXIES_mon_dcm_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "xwidth", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "bins", "0", "256","int");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "min", "-1e40", "_instrument_var._parameters.GALAXIES_E0 - _instrument_var._parameters.GALAXIES_dE * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "max", "1e40", "_instrument_var._parameters.GALAXIES_E0 + _instrument_var._parameters.GALAXIES_dE * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "filename", "NULL", "GALAXIES_mon_dcm_e", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0217_GALAXIES_mon_dcm_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_dcm_e_setpos */

/* component GALAXIES_mon_dcm_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_dcm_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_dcm_xy_setpos] component GALAXIES_mon_dcm_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_dcm_xy_var._name, "GALAXIES_mon_dcm_xy", 16384);
  stracpy(_GALAXIES_mon_dcm_xy_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_dcm_xy_var._index=219;
  int current_setpos_index = 219;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.user9[0]='\0';
  _GALAXIES_mon_dcm_xy_var._parameters.xwidth = 5e-3;
  _GALAXIES_mon_dcm_xy_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_dcm_xy_var._parameters.zdepth = 0;
  _GALAXIES_mon_dcm_xy_var._parameters.bins = 128;
  _GALAXIES_mon_dcm_xy_var._parameters.min = -1e40;
  _GALAXIES_mon_dcm_xy_var._parameters.max = 1e40;
  _GALAXIES_mon_dcm_xy_var._parameters.restore_xray = 1;
  _GALAXIES_mon_dcm_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.options[0]='\0';
  if("GALAXIES_mon_dcm_xy" && strlen("GALAXIES_mon_dcm_xy"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.filename, "GALAXIES_mon_dcm_xy" ? "GALAXIES_mon_dcm_xy" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_dcm_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_dcm_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_dcm_xy_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_dcm_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_mon_dcm_e_var._rotation_absolute, _GALAXIES_mon_dcm_xy_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_dcm_e_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_dcm_xy_var._rotation_absolute, tr1, _GALAXIES_mon_dcm_xy_var._rotation_relative);
    _GALAXIES_mon_dcm_xy_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_dcm_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_dcm_xy_var._position_absolute = coords_add(_GALAXIES_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_dcm_e_var._position_absolute, _GALAXIES_mon_dcm_xy_var._position_absolute);
    _GALAXIES_mon_dcm_xy_var._position_relative = rot_apply(_GALAXIES_mon_dcm_xy_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_dcm_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_dcm_xy", _GALAXIES_mon_dcm_xy_var._position_absolute, _GALAXIES_mon_dcm_xy_var._rotation_absolute);
  instrument->_position_absolute[219] = _GALAXIES_mon_dcm_xy_var._position_absolute;
  instrument->_position_relative[219] = _GALAXIES_mon_dcm_xy_var._position_relative;
    _GALAXIES_mon_dcm_xy_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_dcm_xy_var._position_relative);
  instrument->counter_N[219]  = instrument->counter_P[219] = instrument->counter_P2[219] = 0;
  instrument->counter_AbsorbProp[219]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", _GALAXIES_mon_dcm_xy_var._position_absolute, _GALAXIES_mon_dcm_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "xwidth", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "filename", "NULL", "GALAXIES_mon_dcm_xy", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0218_GALAXIES_mon_dcm_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_dcm_xy_setpos */

/* component GALAXIES_M1_location=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M1_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M1_location_setpos] component GALAXIES_M1_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M1_location_var._name, "GALAXIES_M1_location", 16384);
  stracpy(_GALAXIES_M1_location_var._type, "Arm", 16384);
  _GALAXIES_M1_location_var._index=220;
  int current_setpos_index = 220;
  /* component GALAXIES_M1_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_dcm1_var._rotation_absolute, _GALAXIES_M1_location_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M1_location_var._rotation_absolute, tr1, _GALAXIES_M1_location_var._rotation_relative);
    _GALAXIES_M1_location_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M1_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToM1 - GALAXIES_DistanceToDCM);
    rot_transpose(_GALAXIES_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M1_location_var._position_absolute = coords_add(_GALAXIES_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_dcm_xy_var._position_absolute, _GALAXIES_M1_location_var._position_absolute);
    _GALAXIES_M1_location_var._position_relative = rot_apply(_GALAXIES_M1_location_var._rotation_absolute, tc1);
  } /* GALAXIES_M1_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M1_location", _GALAXIES_M1_location_var._position_absolute, _GALAXIES_M1_location_var._rotation_absolute);
  instrument->_position_absolute[220] = _GALAXIES_M1_location_var._position_absolute;
  instrument->_position_relative[220] = _GALAXIES_M1_location_var._position_relative;
    _GALAXIES_M1_location_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M1_location_var._position_relative);
  instrument->counter_N[220]  = instrument->counter_P[220] = instrument->counter_P2[220] = 0;
  instrument->counter_AbsorbProp[220]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0219_GALAXIES_M1_location", _GALAXIES_M1_location_var._position_absolute, _GALAXIES_M1_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M1_location_setpos */

/* component GALAXIES_M1_rotated=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M1_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M1_rotated_setpos] component GALAXIES_M1_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M1_rotated_var._name, "GALAXIES_M1_rotated", 16384);
  stracpy(_GALAXIES_M1_rotated_var._type, "Arm", 16384);
  _GALAXIES_M1_rotated_var._index=221;
  int current_setpos_index = 221;
  /* component GALAXIES_M1_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_M1_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M1_location_var._rotation_absolute, _GALAXIES_M1_rotated_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M1_rotated_var._rotation_absolute, tr1, _GALAXIES_M1_rotated_var._rotation_relative);
    _GALAXIES_M1_rotated_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M1_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M1_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M1_rotated_var._position_absolute = coords_add(_GALAXIES_M1_location_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_dcm_xy_var._position_absolute, _GALAXIES_M1_rotated_var._position_absolute);
    _GALAXIES_M1_rotated_var._position_relative = rot_apply(_GALAXIES_M1_rotated_var._rotation_absolute, tc1);
  } /* GALAXIES_M1_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M1_rotated", _GALAXIES_M1_rotated_var._position_absolute, _GALAXIES_M1_rotated_var._rotation_absolute);
  instrument->_position_absolute[221] = _GALAXIES_M1_rotated_var._position_absolute;
  instrument->_position_relative[221] = _GALAXIES_M1_rotated_var._position_relative;
    _GALAXIES_M1_rotated_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M1_rotated_var._position_relative);
  instrument->counter_N[221]  = instrument->counter_P[221] = instrument->counter_P2[221] = 0;
  instrument->counter_AbsorbProp[221]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0220_GALAXIES_M1_rotated", _GALAXIES_M1_rotated_var._position_absolute, _GALAXIES_M1_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M1_rotated_setpos */

/* component GALAXIES_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _GALAXIES_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M1_setpos] component GALAXIES_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_GALAXIES_M1_var._name, "GALAXIES_M1", 16384);
  stracpy(_GALAXIES_M1_var._type, "Mirror_curved", 16384);
  _GALAXIES_M1_var._index=222;
  int current_setpos_index = 222;
  _GALAXIES_M1_var._parameters.radius = GALAXIES_M1_R;
  _GALAXIES_M1_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_GALAXIES_M1_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _GALAXIES_M1_var._parameters.coating[0]='\0';
  _GALAXIES_M1_var._parameters.zdepth = 0.2;
  _GALAXIES_M1_var._parameters.yheight = 0.2;
  _GALAXIES_M1_var._parameters.length = GALAXIES_M1_length;
  _GALAXIES_M1_var._parameters.width = GALAXIES_M1_width;


  /* component GALAXIES_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M1_rotated_var._rotation_absolute, _GALAXIES_M1_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M1_var._rotation_absolute, tr1, _GALAXIES_M1_var._rotation_relative);
    _GALAXIES_M1_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M1_var._position_absolute = coords_add(_GALAXIES_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_dcm_xy_var._position_absolute, _GALAXIES_M1_var._position_absolute);
    _GALAXIES_M1_var._position_relative = rot_apply(_GALAXIES_M1_var._rotation_absolute, tc1);
  } /* GALAXIES_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M1", _GALAXIES_M1_var._position_absolute, _GALAXIES_M1_var._rotation_absolute);
  instrument->_position_absolute[222] = _GALAXIES_M1_var._position_absolute;
  instrument->_position_relative[222] = _GALAXIES_M1_var._position_relative;
    _GALAXIES_M1_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M1_var._position_relative);
  instrument->counter_N[222]  = instrument->counter_P[222] = instrument->counter_P2[222] = 0;
  instrument->counter_AbsorbProp[222]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0221_GALAXIES_M1", _GALAXIES_M1_var._position_absolute, _GALAXIES_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "radius", "1", "GALAXIES_M1_R","MCNUM");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "length", "0", "GALAXIES_M1_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0221_GALAXIES_M1", "width", "0", "GALAXIES_M1_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M1_setpos */

/* component GALAXIES_M1_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M1_out_setpos] component GALAXIES_M1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M1_out_var._name, "GALAXIES_M1_out", 16384);
  stracpy(_GALAXIES_M1_out_var._type, "Arm", 16384);
  _GALAXIES_M1_out_var._index=223;
  int current_setpos_index = 223;
  /* component GALAXIES_M1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_M1_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M1_rotated_var._rotation_absolute, _GALAXIES_M1_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_M1_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M1_out_var._rotation_absolute, tr1, _GALAXIES_M1_out_var._rotation_relative);
    _GALAXIES_M1_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M1_out_var._position_absolute = coords_add(_GALAXIES_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M1_var._position_absolute, _GALAXIES_M1_out_var._position_absolute);
    _GALAXIES_M1_out_var._position_relative = rot_apply(_GALAXIES_M1_out_var._rotation_absolute, tc1);
  } /* GALAXIES_M1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M1_out", _GALAXIES_M1_out_var._position_absolute, _GALAXIES_M1_out_var._rotation_absolute);
  instrument->_position_absolute[223] = _GALAXIES_M1_out_var._position_absolute;
  instrument->_position_relative[223] = _GALAXIES_M1_out_var._position_relative;
    _GALAXIES_M1_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M1_out_var._position_relative);
  instrument->counter_N[223]  = instrument->counter_P[223] = instrument->counter_P2[223] = 0;
  instrument->counter_AbsorbProp[223]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0222_GALAXIES_M1_out", _GALAXIES_M1_out_var._position_absolute, _GALAXIES_M1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M1_out_setpos */

/* component GALAXIES_HRM_gate_in=Slit() SETTING, POSITION/ROTATION */
int _GALAXIES_HRM_gate_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_HRM_gate_in_setpos] component GALAXIES_HRM_gate_in=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_GALAXIES_HRM_gate_in_var._name, "GALAXIES_HRM_gate_in", 16384);
  stracpy(_GALAXIES_HRM_gate_in_var._type, "Slit", 16384);
  _GALAXIES_HRM_gate_in_var._index=224;
  int current_setpos_index = 224;
  _GALAXIES_HRM_gate_in_var._parameters.xmin = 0;
  _GALAXIES_HRM_gate_in_var._parameters.xmax = 0;
  _GALAXIES_HRM_gate_in_var._parameters.ymin = 0;
  _GALAXIES_HRM_gate_in_var._parameters.ymax = 0;
  _GALAXIES_HRM_gate_in_var._parameters.radius = 0;
  _GALAXIES_HRM_gate_in_var._parameters.xwidth = ( _instrument_var._parameters.GALAXIES_hrm ? 0.010 : 0 );
  _GALAXIES_HRM_gate_in_var._parameters.yheight = ( _instrument_var._parameters.GALAXIES_hrm ? 0.005 : 0 );
  _GALAXIES_HRM_gate_in_var._parameters.dist = 0;
  _GALAXIES_HRM_gate_in_var._parameters.focus_xw = 0;
  _GALAXIES_HRM_gate_in_var._parameters.focus_yh = 0;
  _GALAXIES_HRM_gate_in_var._parameters.focus_x0 = 0;
  _GALAXIES_HRM_gate_in_var._parameters.focus_y0 = 0;

  /* component GALAXIES_HRM_gate_in=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M1_out_var._rotation_absolute, _GALAXIES_HRM_gate_in_var._rotation_absolute);
    rot_transpose(_GALAXIES_M1_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_HRM_gate_in_var._rotation_absolute, tr1, _GALAXIES_HRM_gate_in_var._rotation_relative);
    _GALAXIES_HRM_gate_in_var._rotation_is_identity =  rot_test_identity(_GALAXIES_HRM_gate_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToHRM - GALAXIES_DistanceToM1);
    rot_transpose(_GALAXIES_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_HRM_gate_in_var._position_absolute = coords_add(_GALAXIES_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M1_var._position_absolute, _GALAXIES_HRM_gate_in_var._position_absolute);
    _GALAXIES_HRM_gate_in_var._position_relative = rot_apply(_GALAXIES_HRM_gate_in_var._rotation_absolute, tc1);
  } /* GALAXIES_HRM_gate_in=Slit() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_HRM_gate_in", _GALAXIES_HRM_gate_in_var._position_absolute, _GALAXIES_HRM_gate_in_var._rotation_absolute);
  instrument->_position_absolute[224] = _GALAXIES_HRM_gate_in_var._position_absolute;
  instrument->_position_relative[224] = _GALAXIES_HRM_gate_in_var._position_relative;
    _GALAXIES_HRM_gate_in_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_HRM_gate_in_var._position_relative);
  instrument->counter_N[224]  = instrument->counter_P[224] = instrument->counter_P2[224] = 0;
  instrument->counter_AbsorbProp[224]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", _GALAXIES_HRM_gate_in_var._position_absolute, _GALAXIES_HRM_gate_in_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "xwidth", "0.001", "( _instrument_var._parameters.GALAXIES_hrm ? 0.010 : 0 )","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "yheight", "0.001", "( _instrument_var._parameters.GALAXIES_hrm ? 0.005 : 0 )","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0223_GALAXIES_HRM_gate_in", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_HRM_gate_in_setpos */

/* component GALAXIES_M2A_location=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M2A_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2A_location_setpos] component GALAXIES_M2A_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M2A_location_var._name, "GALAXIES_M2A_location", 16384);
  stracpy(_GALAXIES_M2A_location_var._type, "Arm", 16384);
  _GALAXIES_M2A_location_var._index=225;
  int current_setpos_index = 225;
  /* component GALAXIES_M2A_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_HRM_gate_in_var._rotation_absolute, _GALAXIES_M2A_location_var._rotation_absolute);
    rot_transpose(_GALAXIES_HRM_gate_in_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2A_location_var._rotation_absolute, tr1, _GALAXIES_M2A_location_var._rotation_relative);
    _GALAXIES_M2A_location_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2A_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToM2A - GALAXIES_DistanceToHRM);
    rot_transpose(_GALAXIES_HRM_gate_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2A_location_var._position_absolute = coords_add(_GALAXIES_HRM_gate_in_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_HRM_gate_in_var._position_absolute, _GALAXIES_M2A_location_var._position_absolute);
    _GALAXIES_M2A_location_var._position_relative = rot_apply(_GALAXIES_M2A_location_var._rotation_absolute, tc1);
  } /* GALAXIES_M2A_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2A_location", _GALAXIES_M2A_location_var._position_absolute, _GALAXIES_M2A_location_var._rotation_absolute);
  instrument->_position_absolute[225] = _GALAXIES_M2A_location_var._position_absolute;
  instrument->_position_relative[225] = _GALAXIES_M2A_location_var._position_relative;
    _GALAXIES_M2A_location_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2A_location_var._position_relative);
  instrument->counter_N[225]  = instrument->counter_P[225] = instrument->counter_P2[225] = 0;
  instrument->counter_AbsorbProp[225]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0224_GALAXIES_M2A_location", _GALAXIES_M2A_location_var._position_absolute, _GALAXIES_M2A_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2A_location_setpos */

/* component GALAXIES_M2A_rotated=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M2A_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2A_rotated_setpos] component GALAXIES_M2A_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M2A_rotated_var._name, "GALAXIES_M2A_rotated", 16384);
  stracpy(_GALAXIES_M2A_rotated_var._type, "Arm", 16384);
  _GALAXIES_M2A_rotated_var._index=226;
  int current_setpos_index = 226;
  /* component GALAXIES_M2A_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_M2_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2A_location_var._rotation_absolute, _GALAXIES_M2A_rotated_var._rotation_absolute);
    rot_transpose(_GALAXIES_HRM_gate_in_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2A_rotated_var._rotation_absolute, tr1, _GALAXIES_M2A_rotated_var._rotation_relative);
    _GALAXIES_M2A_rotated_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2A_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M2A_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2A_rotated_var._position_absolute = coords_add(_GALAXIES_M2A_location_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_HRM_gate_in_var._position_absolute, _GALAXIES_M2A_rotated_var._position_absolute);
    _GALAXIES_M2A_rotated_var._position_relative = rot_apply(_GALAXIES_M2A_rotated_var._rotation_absolute, tc1);
  } /* GALAXIES_M2A_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2A_rotated", _GALAXIES_M2A_rotated_var._position_absolute, _GALAXIES_M2A_rotated_var._rotation_absolute);
  instrument->_position_absolute[226] = _GALAXIES_M2A_rotated_var._position_absolute;
  instrument->_position_relative[226] = _GALAXIES_M2A_rotated_var._position_relative;
    _GALAXIES_M2A_rotated_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2A_rotated_var._position_relative);
  instrument->counter_N[226]  = instrument->counter_P[226] = instrument->counter_P2[226] = 0;
  instrument->counter_AbsorbProp[226]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0225_GALAXIES_M2A_rotated", _GALAXIES_M2A_rotated_var._position_absolute, _GALAXIES_M2A_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2A_rotated_setpos */

/* component GALAXIES_M2A=Mirror_toroid() SETTING, POSITION/ROTATION */
int _GALAXIES_M2A_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2A_setpos] component GALAXIES_M2A=Mirror_toroid() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_toroid.comp:60]");
  stracpy(_GALAXIES_M2A_var._name, "GALAXIES_M2A", 16384);
  stracpy(_GALAXIES_M2A_var._type, "Mirror_toroid", 16384);
  _GALAXIES_M2A_var._index=227;
  int current_setpos_index = 227;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_GALAXIES_M2A_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _GALAXIES_M2A_var._parameters.coating[0]='\0';
  _GALAXIES_M2A_var._parameters.zdepth = GALAXIES_M2_length;
  _GALAXIES_M2A_var._parameters.xwidth = GALAXIES_M2_width;
  _GALAXIES_M2A_var._parameters.radius = GALAXIES_M2_Rt;
  _GALAXIES_M2A_var._parameters.radius_o = GALAXIES_M2_Rs;
  _GALAXIES_M2A_var._parameters.R0 = 0;


  /* component GALAXIES_M2A=Mirror_toroid() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2A_rotated_var._rotation_absolute, _GALAXIES_M2A_var._rotation_absolute);
    rot_transpose(_GALAXIES_HRM_gate_in_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2A_var._rotation_absolute, tr1, _GALAXIES_M2A_var._rotation_relative);
    _GALAXIES_M2A_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2A_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M2A_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2A_var._position_absolute = coords_add(_GALAXIES_M2A_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_HRM_gate_in_var._position_absolute, _GALAXIES_M2A_var._position_absolute);
    _GALAXIES_M2A_var._position_relative = rot_apply(_GALAXIES_M2A_var._rotation_absolute, tc1);
  } /* GALAXIES_M2A=Mirror_toroid() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2A", _GALAXIES_M2A_var._position_absolute, _GALAXIES_M2A_var._rotation_absolute);
  instrument->_position_absolute[227] = _GALAXIES_M2A_var._position_absolute;
  instrument->_position_relative[227] = _GALAXIES_M2A_var._position_relative;
    _GALAXIES_M2A_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2A_var._position_relative);
  instrument->counter_N[227]  = instrument->counter_P[227] = instrument->counter_P2[227] = 0;
  instrument->counter_AbsorbProp[227]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0226_GALAXIES_M2A", _GALAXIES_M2A_var._position_absolute, _GALAXIES_M2A_var._rotation_absolute, "Mirror_toroid");
        mccomp_param_nexus(nxhandle,"0226_GALAXIES_M2A", "coating", "", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0226_GALAXIES_M2A", "zdepth", "0.1", "GALAXIES_M2_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0226_GALAXIES_M2A", "xwidth", "0.01", "GALAXIES_M2_width","MCNUM");
        mccomp_param_nexus(nxhandle,"0226_GALAXIES_M2A", "radius", "NONE", "GALAXIES_M2_Rt","MCNUM");
        mccomp_param_nexus(nxhandle,"0226_GALAXIES_M2A", "radius_o", "NONE", "GALAXIES_M2_Rs","MCNUM");
        mccomp_param_nexus(nxhandle,"0226_GALAXIES_M2A", "R0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2A_setpos */

/* component GALAXIES_M2A_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M2A_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2A_out_setpos] component GALAXIES_M2A_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M2A_out_var._name, "GALAXIES_M2A_out", 16384);
  stracpy(_GALAXIES_M2A_out_var._type, "Arm", 16384);
  _GALAXIES_M2A_out_var._index=228;
  int current_setpos_index = 228;
  /* component GALAXIES_M2A_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_M2_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2A_rotated_var._rotation_absolute, _GALAXIES_M2A_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_M2A_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2A_out_var._rotation_absolute, tr1, _GALAXIES_M2A_out_var._rotation_relative);
    _GALAXIES_M2A_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2A_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M2A_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2A_out_var._position_absolute = coords_add(_GALAXIES_M2A_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M2A_var._position_absolute, _GALAXIES_M2A_out_var._position_absolute);
    _GALAXIES_M2A_out_var._position_relative = rot_apply(_GALAXIES_M2A_out_var._rotation_absolute, tc1);
  } /* GALAXIES_M2A_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2A_out", _GALAXIES_M2A_out_var._position_absolute, _GALAXIES_M2A_out_var._rotation_absolute);
  instrument->_position_absolute[228] = _GALAXIES_M2A_out_var._position_absolute;
  instrument->_position_relative[228] = _GALAXIES_M2A_out_var._position_relative;
    _GALAXIES_M2A_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2A_out_var._position_relative);
  instrument->counter_N[228]  = instrument->counter_P[228] = instrument->counter_P2[228] = 0;
  instrument->counter_AbsorbProp[228]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0227_GALAXIES_M2A_out", _GALAXIES_M2A_out_var._position_absolute, _GALAXIES_M2A_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2A_out_setpos */

/* component GALAXIES_secondary_slits=Slit() SETTING, POSITION/ROTATION */
int _GALAXIES_secondary_slits_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_secondary_slits_setpos] component GALAXIES_secondary_slits=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_GALAXIES_secondary_slits_var._name, "GALAXIES_secondary_slits", 16384);
  stracpy(_GALAXIES_secondary_slits_var._type, "Slit", 16384);
  _GALAXIES_secondary_slits_var._index=229;
  int current_setpos_index = 229;
  _GALAXIES_secondary_slits_var._parameters.xmin = 0;
  _GALAXIES_secondary_slits_var._parameters.xmax = 0;
  _GALAXIES_secondary_slits_var._parameters.ymin = 0;
  _GALAXIES_secondary_slits_var._parameters.ymax = 0;
  _GALAXIES_secondary_slits_var._parameters.radius = 0;
  _GALAXIES_secondary_slits_var._parameters.xwidth = _instrument_var._parameters.GALAXIES_sec_slits;
  _GALAXIES_secondary_slits_var._parameters.yheight = _instrument_var._parameters.GALAXIES_sec_slits;
  _GALAXIES_secondary_slits_var._parameters.dist = 0;
  _GALAXIES_secondary_slits_var._parameters.focus_xw = 0;
  _GALAXIES_secondary_slits_var._parameters.focus_yh = 0;
  _GALAXIES_secondary_slits_var._parameters.focus_x0 = 0;
  _GALAXIES_secondary_slits_var._parameters.focus_y0 = 0;

  /* component GALAXIES_secondary_slits=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2A_out_var._rotation_absolute, _GALAXIES_secondary_slits_var._rotation_absolute);
    rot_transpose(_GALAXIES_M2A_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_secondary_slits_var._rotation_absolute, tr1, _GALAXIES_secondary_slits_var._rotation_relative);
    _GALAXIES_secondary_slits_var._rotation_is_identity =  rot_test_identity(_GALAXIES_secondary_slits_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToSecSlits - GALAXIES_DistanceToM2A);
    rot_transpose(_GALAXIES_M2A_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_secondary_slits_var._position_absolute = coords_add(_GALAXIES_M2A_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M2A_var._position_absolute, _GALAXIES_secondary_slits_var._position_absolute);
    _GALAXIES_secondary_slits_var._position_relative = rot_apply(_GALAXIES_secondary_slits_var._rotation_absolute, tc1);
  } /* GALAXIES_secondary_slits=Slit() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_secondary_slits", _GALAXIES_secondary_slits_var._position_absolute, _GALAXIES_secondary_slits_var._rotation_absolute);
  instrument->_position_absolute[229] = _GALAXIES_secondary_slits_var._position_absolute;
  instrument->_position_relative[229] = _GALAXIES_secondary_slits_var._position_relative;
    _GALAXIES_secondary_slits_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_secondary_slits_var._position_relative);
  instrument->counter_N[229]  = instrument->counter_P[229] = instrument->counter_P2[229] = 0;
  instrument->counter_AbsorbProp[229]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0228_GALAXIES_secondary_slits", _GALAXIES_secondary_slits_var._position_absolute, _GALAXIES_secondary_slits_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "xwidth", "0.001", "_instrument_var._parameters.GALAXIES_sec_slits","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "yheight", "0.001", "_instrument_var._parameters.GALAXIES_sec_slits","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0228_GALAXIES_secondary_slits", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_secondary_slits_setpos */

/* component GALAXIES_mon_sec_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_sec_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_sec_xy_setpos] component GALAXIES_mon_sec_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_sec_xy_var._name, "GALAXIES_mon_sec_xy", 16384);
  stracpy(_GALAXIES_mon_sec_xy_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_sec_xy_var._index=230;
  int current_setpos_index = 230;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.user9[0]='\0';
  _GALAXIES_mon_sec_xy_var._parameters.xwidth = 2e-3;
  _GALAXIES_mon_sec_xy_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_sec_xy_var._parameters.zdepth = 0;
  _GALAXIES_mon_sec_xy_var._parameters.bins = 128;
  _GALAXIES_mon_sec_xy_var._parameters.min = -1e40;
  _GALAXIES_mon_sec_xy_var._parameters.max = 1e40;
  _GALAXIES_mon_sec_xy_var._parameters.restore_xray = 1;
  _GALAXIES_mon_sec_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.options[0]='\0';
  if("GALAXIES_mon_sec_xy" && strlen("GALAXIES_mon_sec_xy"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.filename, "GALAXIES_mon_sec_xy" ? "GALAXIES_mon_sec_xy" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_sec_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sec_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sec_xy_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_sec_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_secondary_slits_var._rotation_absolute, _GALAXIES_mon_sec_xy_var._rotation_absolute);
    rot_transpose(_GALAXIES_secondary_slits_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_sec_xy_var._rotation_absolute, tr1, _GALAXIES_mon_sec_xy_var._rotation_relative);
    _GALAXIES_mon_sec_xy_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_sec_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.01);
    rot_transpose(_GALAXIES_secondary_slits_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_sec_xy_var._position_absolute = coords_add(_GALAXIES_secondary_slits_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_secondary_slits_var._position_absolute, _GALAXIES_mon_sec_xy_var._position_absolute);
    _GALAXIES_mon_sec_xy_var._position_relative = rot_apply(_GALAXIES_mon_sec_xy_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_sec_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_sec_xy", _GALAXIES_mon_sec_xy_var._position_absolute, _GALAXIES_mon_sec_xy_var._rotation_absolute);
  instrument->_position_absolute[230] = _GALAXIES_mon_sec_xy_var._position_absolute;
  instrument->_position_relative[230] = _GALAXIES_mon_sec_xy_var._position_relative;
    _GALAXIES_mon_sec_xy_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_sec_xy_var._position_relative);
  instrument->counter_N[230]  = instrument->counter_P[230] = instrument->counter_P2[230] = 0;
  instrument->counter_AbsorbProp[230]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", _GALAXIES_mon_sec_xy_var._position_absolute, _GALAXIES_mon_sec_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "filename", "NULL", "GALAXIES_mon_sec_xy", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0229_GALAXIES_mon_sec_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_sec_xy_setpos */

/* component GALAXIES_M2B_location=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M2B_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2B_location_setpos] component GALAXIES_M2B_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M2B_location_var._name, "GALAXIES_M2B_location", 16384);
  stracpy(_GALAXIES_M2B_location_var._type, "Arm", 16384);
  _GALAXIES_M2B_location_var._index=231;
  int current_setpos_index = 231;
  /* component GALAXIES_M2B_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_secondary_slits_var._rotation_absolute, _GALAXIES_M2B_location_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_sec_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2B_location_var._rotation_absolute, tr1, _GALAXIES_M2B_location_var._rotation_relative);
    _GALAXIES_M2B_location_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2B_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToM2B - GALAXIES_DistanceToSecSlits);
    rot_transpose(_GALAXIES_secondary_slits_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2B_location_var._position_absolute = coords_add(_GALAXIES_secondary_slits_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_sec_xy_var._position_absolute, _GALAXIES_M2B_location_var._position_absolute);
    _GALAXIES_M2B_location_var._position_relative = rot_apply(_GALAXIES_M2B_location_var._rotation_absolute, tc1);
  } /* GALAXIES_M2B_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2B_location", _GALAXIES_M2B_location_var._position_absolute, _GALAXIES_M2B_location_var._rotation_absolute);
  instrument->_position_absolute[231] = _GALAXIES_M2B_location_var._position_absolute;
  instrument->_position_relative[231] = _GALAXIES_M2B_location_var._position_relative;
    _GALAXIES_M2B_location_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2B_location_var._position_relative);
  instrument->counter_N[231]  = instrument->counter_P[231] = instrument->counter_P2[231] = 0;
  instrument->counter_AbsorbProp[231]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0230_GALAXIES_M2B_location", _GALAXIES_M2B_location_var._position_absolute, _GALAXIES_M2B_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2B_location_setpos */

/* component GALAXIES_M2B_rotated=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M2B_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2B_rotated_setpos] component GALAXIES_M2B_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M2B_rotated_var._name, "GALAXIES_M2B_rotated", 16384);
  stracpy(_GALAXIES_M2B_rotated_var._type, "Arm", 16384);
  _GALAXIES_M2B_rotated_var._index=232;
  int current_setpos_index = 232;
  /* component GALAXIES_M2B_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_M2_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2B_location_var._rotation_absolute, _GALAXIES_M2B_rotated_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_sec_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2B_rotated_var._rotation_absolute, tr1, _GALAXIES_M2B_rotated_var._rotation_relative);
    _GALAXIES_M2B_rotated_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2B_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M2B_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2B_rotated_var._position_absolute = coords_add(_GALAXIES_M2B_location_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_sec_xy_var._position_absolute, _GALAXIES_M2B_rotated_var._position_absolute);
    _GALAXIES_M2B_rotated_var._position_relative = rot_apply(_GALAXIES_M2B_rotated_var._rotation_absolute, tc1);
  } /* GALAXIES_M2B_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2B_rotated", _GALAXIES_M2B_rotated_var._position_absolute, _GALAXIES_M2B_rotated_var._rotation_absolute);
  instrument->_position_absolute[232] = _GALAXIES_M2B_rotated_var._position_absolute;
  instrument->_position_relative[232] = _GALAXIES_M2B_rotated_var._position_relative;
    _GALAXIES_M2B_rotated_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2B_rotated_var._position_relative);
  instrument->counter_N[232]  = instrument->counter_P[232] = instrument->counter_P2[232] = 0;
  instrument->counter_AbsorbProp[232]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0231_GALAXIES_M2B_rotated", _GALAXIES_M2B_rotated_var._position_absolute, _GALAXIES_M2B_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2B_rotated_setpos */

/* component GALAXIES_M2B=Mirror_toroid() SETTING, POSITION/ROTATION */
int _GALAXIES_M2B_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2B_setpos] component GALAXIES_M2B=Mirror_toroid() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_toroid.comp:60]");
  stracpy(_GALAXIES_M2B_var._name, "GALAXIES_M2B", 16384);
  stracpy(_GALAXIES_M2B_var._type, "Mirror_toroid", 16384);
  _GALAXIES_M2B_var._index=233;
  int current_setpos_index = 233;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_GALAXIES_M2B_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _GALAXIES_M2B_var._parameters.coating[0]='\0';
  _GALAXIES_M2B_var._parameters.zdepth = GALAXIES_M2_length;
  _GALAXIES_M2B_var._parameters.xwidth = GALAXIES_M2_width;
  _GALAXIES_M2B_var._parameters.radius = GALAXIES_M2_Rt;
  _GALAXIES_M2B_var._parameters.radius_o = GALAXIES_M2_Rs;
  _GALAXIES_M2B_var._parameters.R0 = 0;


  /* component GALAXIES_M2B=Mirror_toroid() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2B_rotated_var._rotation_absolute, _GALAXIES_M2B_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_sec_xy_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2B_var._rotation_absolute, tr1, _GALAXIES_M2B_var._rotation_relative);
    _GALAXIES_M2B_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2B_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M2B_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2B_var._position_absolute = coords_add(_GALAXIES_M2B_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_sec_xy_var._position_absolute, _GALAXIES_M2B_var._position_absolute);
    _GALAXIES_M2B_var._position_relative = rot_apply(_GALAXIES_M2B_var._rotation_absolute, tc1);
  } /* GALAXIES_M2B=Mirror_toroid() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2B", _GALAXIES_M2B_var._position_absolute, _GALAXIES_M2B_var._rotation_absolute);
  instrument->_position_absolute[233] = _GALAXIES_M2B_var._position_absolute;
  instrument->_position_relative[233] = _GALAXIES_M2B_var._position_relative;
    _GALAXIES_M2B_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2B_var._position_relative);
  instrument->counter_N[233]  = instrument->counter_P[233] = instrument->counter_P2[233] = 0;
  instrument->counter_AbsorbProp[233]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0232_GALAXIES_M2B", _GALAXIES_M2B_var._position_absolute, _GALAXIES_M2B_var._rotation_absolute, "Mirror_toroid");
        mccomp_param_nexus(nxhandle,"0232_GALAXIES_M2B", "coating", "", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0232_GALAXIES_M2B", "zdepth", "0.1", "GALAXIES_M2_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0232_GALAXIES_M2B", "xwidth", "0.01", "GALAXIES_M2_width","MCNUM");
        mccomp_param_nexus(nxhandle,"0232_GALAXIES_M2B", "radius", "NONE", "GALAXIES_M2_Rt","MCNUM");
        mccomp_param_nexus(nxhandle,"0232_GALAXIES_M2B", "radius_o", "NONE", "GALAXIES_M2_Rs","MCNUM");
        mccomp_param_nexus(nxhandle,"0232_GALAXIES_M2B", "R0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2B_setpos */

/* component GALAXIES_M2B_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_M2B_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_M2B_out_setpos] component GALAXIES_M2B_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_M2B_out_var._name, "GALAXIES_M2B_out", 16384);
  stracpy(_GALAXIES_M2B_out_var._type, "Arm", 16384);
  _GALAXIES_M2B_out_var._index=234;
  int current_setpos_index = 234;
  /* component GALAXIES_M2B_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_M2_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2B_rotated_var._rotation_absolute, _GALAXIES_M2B_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_M2B_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_M2B_out_var._rotation_absolute, tr1, _GALAXIES_M2B_out_var._rotation_relative);
    _GALAXIES_M2B_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_M2B_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_M2B_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_M2B_out_var._position_absolute = coords_add(_GALAXIES_M2B_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M2B_var._position_absolute, _GALAXIES_M2B_out_var._position_absolute);
    _GALAXIES_M2B_out_var._position_relative = rot_apply(_GALAXIES_M2B_out_var._rotation_absolute, tc1);
  } /* GALAXIES_M2B_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_M2B_out", _GALAXIES_M2B_out_var._position_absolute, _GALAXIES_M2B_out_var._rotation_absolute);
  instrument->_position_absolute[234] = _GALAXIES_M2B_out_var._position_absolute;
  instrument->_position_relative[234] = _GALAXIES_M2B_out_var._position_relative;
    _GALAXIES_M2B_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_M2B_out_var._position_relative);
  instrument->counter_N[234]  = instrument->counter_P[234] = instrument->counter_P2[234] = 0;
  instrument->counter_AbsorbProp[234]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0233_GALAXIES_M2B_out", _GALAXIES_M2B_out_var._position_absolute, _GALAXIES_M2B_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_M2B_out_setpos */

/* component GALAXIES_VFM_location=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_VFM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_VFM_location_setpos] component GALAXIES_VFM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_VFM_location_var._name, "GALAXIES_VFM_location", 16384);
  stracpy(_GALAXIES_VFM_location_var._type, "Arm", 16384);
  _GALAXIES_VFM_location_var._index=235;
  int current_setpos_index = 235;
  /* component GALAXIES_VFM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2B_out_var._rotation_absolute, _GALAXIES_VFM_location_var._rotation_absolute);
    rot_transpose(_GALAXIES_M2B_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_VFM_location_var._rotation_absolute, tr1, _GALAXIES_VFM_location_var._rotation_relative);
    _GALAXIES_VFM_location_var._rotation_is_identity =  rot_test_identity(_GALAXIES_VFM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToVFM - GALAXIES_DistanceToM2B);
    rot_transpose(_GALAXIES_M2B_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_VFM_location_var._position_absolute = coords_add(_GALAXIES_M2B_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M2B_var._position_absolute, _GALAXIES_VFM_location_var._position_absolute);
    _GALAXIES_VFM_location_var._position_relative = rot_apply(_GALAXIES_VFM_location_var._rotation_absolute, tc1);
  } /* GALAXIES_VFM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_VFM_location", _GALAXIES_VFM_location_var._position_absolute, _GALAXIES_VFM_location_var._rotation_absolute);
  instrument->_position_absolute[235] = _GALAXIES_VFM_location_var._position_absolute;
  instrument->_position_relative[235] = _GALAXIES_VFM_location_var._position_relative;
    _GALAXIES_VFM_location_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_VFM_location_var._position_relative);
  instrument->counter_N[235]  = instrument->counter_P[235] = instrument->counter_P2[235] = 0;
  instrument->counter_AbsorbProp[235]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0234_GALAXIES_VFM_location", _GALAXIES_VFM_location_var._position_absolute, _GALAXIES_VFM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_VFM_location_setpos */

/* component GALAXIES_VFM_rotated=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_VFM_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_VFM_rotated_setpos] component GALAXIES_VFM_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_VFM_rotated_var._name, "GALAXIES_VFM_rotated", 16384);
  stracpy(_GALAXIES_VFM_rotated_var._type, "Arm", 16384);
  _GALAXIES_VFM_rotated_var._index=236;
  int current_setpos_index = 236;
  /* component GALAXIES_VFM_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_KB_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_VFM_location_var._rotation_absolute, _GALAXIES_VFM_rotated_var._rotation_absolute);
    rot_transpose(_GALAXIES_M2B_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_VFM_rotated_var._rotation_absolute, tr1, _GALAXIES_VFM_rotated_var._rotation_relative);
    _GALAXIES_VFM_rotated_var._rotation_is_identity =  rot_test_identity(_GALAXIES_VFM_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_VFM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_VFM_rotated_var._position_absolute = coords_add(_GALAXIES_VFM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M2B_var._position_absolute, _GALAXIES_VFM_rotated_var._position_absolute);
    _GALAXIES_VFM_rotated_var._position_relative = rot_apply(_GALAXIES_VFM_rotated_var._rotation_absolute, tc1);
  } /* GALAXIES_VFM_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_VFM_rotated", _GALAXIES_VFM_rotated_var._position_absolute, _GALAXIES_VFM_rotated_var._rotation_absolute);
  instrument->_position_absolute[236] = _GALAXIES_VFM_rotated_var._position_absolute;
  instrument->_position_relative[236] = _GALAXIES_VFM_rotated_var._position_relative;
    _GALAXIES_VFM_rotated_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_VFM_rotated_var._position_relative);
  instrument->counter_N[236]  = instrument->counter_P[236] = instrument->counter_P2[236] = 0;
  instrument->counter_AbsorbProp[236]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0235_GALAXIES_VFM_rotated", _GALAXIES_VFM_rotated_var._position_absolute, _GALAXIES_VFM_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_VFM_rotated_setpos */

/* component GALAXIES_VFM=Mirror_curved() SETTING, POSITION/ROTATION */
int _GALAXIES_VFM_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_VFM_setpos] component GALAXIES_VFM=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_GALAXIES_VFM_var._name, "GALAXIES_VFM", 16384);
  stracpy(_GALAXIES_VFM_var._type, "Mirror_curved", 16384);
  _GALAXIES_VFM_var._index=237;
  int current_setpos_index = 237;
  _GALAXIES_VFM_var._parameters.radius = GALAXIES_vfm_radius;
  _GALAXIES_VFM_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_GALAXIES_VFM_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _GALAXIES_VFM_var._parameters.coating[0]='\0';
  _GALAXIES_VFM_var._parameters.zdepth = 0.2;
  _GALAXIES_VFM_var._parameters.yheight = 0.2;
  _GALAXIES_VFM_var._parameters.length = GALAXIES_KB_length;
  _GALAXIES_VFM_var._parameters.width = GALAXIES_KB_width;


  /* component GALAXIES_VFM=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_VFM_rotated_var._rotation_absolute, _GALAXIES_VFM_var._rotation_absolute);
    rot_transpose(_GALAXIES_M2B_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_VFM_var._rotation_absolute, tr1, _GALAXIES_VFM_var._rotation_relative);
    _GALAXIES_VFM_var._rotation_is_identity =  rot_test_identity(_GALAXIES_VFM_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_VFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_VFM_var._position_absolute = coords_add(_GALAXIES_VFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_M2B_var._position_absolute, _GALAXIES_VFM_var._position_absolute);
    _GALAXIES_VFM_var._position_relative = rot_apply(_GALAXIES_VFM_var._rotation_absolute, tc1);
  } /* GALAXIES_VFM=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_VFM", _GALAXIES_VFM_var._position_absolute, _GALAXIES_VFM_var._rotation_absolute);
  instrument->_position_absolute[237] = _GALAXIES_VFM_var._position_absolute;
  instrument->_position_relative[237] = _GALAXIES_VFM_var._position_relative;
    _GALAXIES_VFM_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_VFM_var._position_relative);
  instrument->counter_N[237]  = instrument->counter_P[237] = instrument->counter_P2[237] = 0;
  instrument->counter_AbsorbProp[237]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0236_GALAXIES_VFM", _GALAXIES_VFM_var._position_absolute, _GALAXIES_VFM_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "radius", "1", "GALAXIES_vfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "length", "0", "GALAXIES_KB_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0236_GALAXIES_VFM", "width", "0", "GALAXIES_KB_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_VFM_setpos */

/* component GALAXIES_VFM_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_VFM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_VFM_out_setpos] component GALAXIES_VFM_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_VFM_out_var._name, "GALAXIES_VFM_out", 16384);
  stracpy(_GALAXIES_VFM_out_var._type, "Arm", 16384);
  _GALAXIES_VFM_out_var._index=238;
  int current_setpos_index = 238;
  /* component GALAXIES_VFM_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_KB_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_VFM_rotated_var._rotation_absolute, _GALAXIES_VFM_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_VFM_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_VFM_out_var._rotation_absolute, tr1, _GALAXIES_VFM_out_var._rotation_relative);
    _GALAXIES_VFM_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_VFM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_VFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_VFM_out_var._position_absolute = coords_add(_GALAXIES_VFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_VFM_var._position_absolute, _GALAXIES_VFM_out_var._position_absolute);
    _GALAXIES_VFM_out_var._position_relative = rot_apply(_GALAXIES_VFM_out_var._rotation_absolute, tc1);
  } /* GALAXIES_VFM_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_VFM_out", _GALAXIES_VFM_out_var._position_absolute, _GALAXIES_VFM_out_var._rotation_absolute);
  instrument->_position_absolute[238] = _GALAXIES_VFM_out_var._position_absolute;
  instrument->_position_relative[238] = _GALAXIES_VFM_out_var._position_relative;
    _GALAXIES_VFM_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_VFM_out_var._position_relative);
  instrument->counter_N[238]  = instrument->counter_P[238] = instrument->counter_P2[238] = 0;
  instrument->counter_AbsorbProp[238]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0237_GALAXIES_VFM_out", _GALAXIES_VFM_out_var._position_absolute, _GALAXIES_VFM_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_VFM_out_setpos */

/* component GALAXIES_HFM_rotated=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_HFM_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_HFM_rotated_setpos] component GALAXIES_HFM_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_HFM_rotated_var._name, "GALAXIES_HFM_rotated", 16384);
  stracpy(_GALAXIES_HFM_rotated_var._type, "Arm", 16384);
  _GALAXIES_HFM_rotated_var._index=239;
  int current_setpos_index = 239;
  /* component GALAXIES_HFM_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- GALAXIES_KB_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_VFM_out_var._rotation_absolute, _GALAXIES_HFM_rotated_var._rotation_absolute);
    rot_transpose(_GALAXIES_VFM_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_HFM_rotated_var._rotation_absolute, tr1, _GALAXIES_HFM_rotated_var._rotation_relative);
    _GALAXIES_HFM_rotated_var._rotation_is_identity =  rot_test_identity(_GALAXIES_HFM_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToHFM - GALAXIES_DistanceToVFM);
    rot_transpose(_GALAXIES_VFM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_HFM_rotated_var._position_absolute = coords_add(_GALAXIES_VFM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_VFM_var._position_absolute, _GALAXIES_HFM_rotated_var._position_absolute);
    _GALAXIES_HFM_rotated_var._position_relative = rot_apply(_GALAXIES_HFM_rotated_var._rotation_absolute, tc1);
  } /* GALAXIES_HFM_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_HFM_rotated", _GALAXIES_HFM_rotated_var._position_absolute, _GALAXIES_HFM_rotated_var._rotation_absolute);
  instrument->_position_absolute[239] = _GALAXIES_HFM_rotated_var._position_absolute;
  instrument->_position_relative[239] = _GALAXIES_HFM_rotated_var._position_relative;
    _GALAXIES_HFM_rotated_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_HFM_rotated_var._position_relative);
  instrument->counter_N[239]  = instrument->counter_P[239] = instrument->counter_P2[239] = 0;
  instrument->counter_AbsorbProp[239]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0238_GALAXIES_HFM_rotated", _GALAXIES_HFM_rotated_var._position_absolute, _GALAXIES_HFM_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_HFM_rotated_setpos */

/* component GALAXIES_HFM=Mirror_curved() SETTING, POSITION/ROTATION */
int _GALAXIES_HFM_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_HFM_setpos] component GALAXIES_HFM=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_GALAXIES_HFM_var._name, "GALAXIES_HFM", 16384);
  stracpy(_GALAXIES_HFM_var._type, "Mirror_curved", 16384);
  _GALAXIES_HFM_var._index=240;
  int current_setpos_index = 240;
  _GALAXIES_HFM_var._parameters.radius = GALAXIES_hfm_radius;
  _GALAXIES_HFM_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_GALAXIES_HFM_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _GALAXIES_HFM_var._parameters.coating[0]='\0';
  _GALAXIES_HFM_var._parameters.zdepth = 0.2;
  _GALAXIES_HFM_var._parameters.yheight = 0.2;
  _GALAXIES_HFM_var._parameters.length = GALAXIES_KB_length;
  _GALAXIES_HFM_var._parameters.width = GALAXIES_KB_width;


  /* component GALAXIES_HFM=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_HFM_rotated_var._rotation_absolute, _GALAXIES_HFM_var._rotation_absolute);
    rot_transpose(_GALAXIES_VFM_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_HFM_var._rotation_absolute, tr1, _GALAXIES_HFM_var._rotation_relative);
    _GALAXIES_HFM_var._rotation_is_identity =  rot_test_identity(_GALAXIES_HFM_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_HFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_HFM_var._position_absolute = coords_add(_GALAXIES_HFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_VFM_var._position_absolute, _GALAXIES_HFM_var._position_absolute);
    _GALAXIES_HFM_var._position_relative = rot_apply(_GALAXIES_HFM_var._rotation_absolute, tc1);
  } /* GALAXIES_HFM=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_HFM", _GALAXIES_HFM_var._position_absolute, _GALAXIES_HFM_var._rotation_absolute);
  instrument->_position_absolute[240] = _GALAXIES_HFM_var._position_absolute;
  instrument->_position_relative[240] = _GALAXIES_HFM_var._position_relative;
    _GALAXIES_HFM_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_HFM_var._position_relative);
  instrument->counter_N[240]  = instrument->counter_P[240] = instrument->counter_P2[240] = 0;
  instrument->counter_AbsorbProp[240]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0239_GALAXIES_HFM", _GALAXIES_HFM_var._position_absolute, _GALAXIES_HFM_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "radius", "1", "GALAXIES_hfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "length", "0", "GALAXIES_KB_length","MCNUM");
        mccomp_param_nexus(nxhandle,"0239_GALAXIES_HFM", "width", "0", "GALAXIES_KB_width","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_HFM_setpos */

/* component GALAXIES_HFM_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_HFM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_HFM_out_setpos] component GALAXIES_HFM_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_HFM_out_var._name, "GALAXIES_HFM_out", 16384);
  stracpy(_GALAXIES_HFM_out_var._type, "Arm", 16384);
  _GALAXIES_HFM_out_var._index=241;
  int current_setpos_index = 241;
  /* component GALAXIES_HFM_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (GALAXIES_KB_angle * RAD2DEG / 1000)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_HFM_rotated_var._rotation_absolute, _GALAXIES_HFM_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_HFM_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_HFM_out_var._rotation_absolute, tr1, _GALAXIES_HFM_out_var._rotation_relative);
    _GALAXIES_HFM_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_HFM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_HFM_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_HFM_out_var._position_absolute = coords_add(_GALAXIES_HFM_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_HFM_var._position_absolute, _GALAXIES_HFM_out_var._position_absolute);
    _GALAXIES_HFM_out_var._position_relative = rot_apply(_GALAXIES_HFM_out_var._rotation_absolute, tc1);
  } /* GALAXIES_HFM_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_HFM_out", _GALAXIES_HFM_out_var._position_absolute, _GALAXIES_HFM_out_var._rotation_absolute);
  instrument->_position_absolute[241] = _GALAXIES_HFM_out_var._position_absolute;
  instrument->_position_relative[241] = _GALAXIES_HFM_out_var._position_relative;
    _GALAXIES_HFM_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_HFM_out_var._position_relative);
  instrument->counter_N[241]  = instrument->counter_P[241] = instrument->counter_P2[241] = 0;
  instrument->counter_AbsorbProp[241]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0240_GALAXIES_HFM_out", _GALAXIES_HFM_out_var._position_absolute, _GALAXIES_HFM_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_HFM_out_setpos */

/* component GALAXIES_mon_sample_xy_kb=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_sample_xy_kb_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_sample_xy_kb_setpos] component GALAXIES_mon_sample_xy_kb=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_sample_xy_kb_var._name, "GALAXIES_mon_sample_xy_kb", 16384);
  stracpy(_GALAXIES_mon_sample_xy_kb_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_sample_xy_kb_var._index=242;
  int current_setpos_index = 242;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.user9[0]='\0';
  _GALAXIES_mon_sample_xy_kb_var._parameters.xwidth = 1e-3;
  _GALAXIES_mon_sample_xy_kb_var._parameters.yheight = 1e-3;
  _GALAXIES_mon_sample_xy_kb_var._parameters.zdepth = 0;
  _GALAXIES_mon_sample_xy_kb_var._parameters.bins = 256;
  _GALAXIES_mon_sample_xy_kb_var._parameters.min = -1e40;
  _GALAXIES_mon_sample_xy_kb_var._parameters.max = 1e40;
  _GALAXIES_mon_sample_xy_kb_var._parameters.restore_xray = 1;
  _GALAXIES_mon_sample_xy_kb_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.options[0]='\0';
  if("GALAXIES_mon_sample_xy" && strlen("GALAXIES_mon_sample_xy"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.filename, "GALAXIES_mon_sample_xy" ? "GALAXIES_mon_sample_xy" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_sample_xy_kb_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_xy_kb_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_xy_kb_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_sample_xy_kb=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_HFM_out_var._rotation_absolute, _GALAXIES_mon_sample_xy_kb_var._rotation_absolute);
    rot_transpose(_GALAXIES_HFM_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_sample_xy_kb_var._rotation_absolute, tr1, _GALAXIES_mon_sample_xy_kb_var._rotation_relative);
    _GALAXIES_mon_sample_xy_kb_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_sample_xy_kb_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToSample - GALAXIES_DistanceToHFM);
    rot_transpose(_GALAXIES_HFM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_sample_xy_kb_var._position_absolute = coords_add(_GALAXIES_HFM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_HFM_var._position_absolute, _GALAXIES_mon_sample_xy_kb_var._position_absolute);
    _GALAXIES_mon_sample_xy_kb_var._position_relative = rot_apply(_GALAXIES_mon_sample_xy_kb_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_sample_xy_kb=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_sample_xy_kb", _GALAXIES_mon_sample_xy_kb_var._position_absolute, _GALAXIES_mon_sample_xy_kb_var._rotation_absolute);
  instrument->_position_absolute[242] = _GALAXIES_mon_sample_xy_kb_var._position_absolute;
  instrument->_position_relative[242] = _GALAXIES_mon_sample_xy_kb_var._position_relative;
    _GALAXIES_mon_sample_xy_kb_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_sample_xy_kb_var._position_relative);
  instrument->counter_N[242]  = instrument->counter_P[242] = instrument->counter_P2[242] = 0;
  instrument->counter_AbsorbProp[242]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", _GALAXIES_mon_sample_xy_kb_var._position_absolute, _GALAXIES_mon_sample_xy_kb_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "xwidth", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "yheight", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "bins", "0", "256","int");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "filename", "NULL", "GALAXIES_mon_sample_xy", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0241_GALAXIES_mon_sample_xy_kb", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_sample_xy_kb_setpos */

/* component GALAXIES_mon_sample_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_mon_sample_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_mon_sample_e_setpos] component GALAXIES_mon_sample_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_mon_sample_e_var._name, "GALAXIES_mon_sample_e", 16384);
  stracpy(_GALAXIES_mon_sample_e_var._type, "Monitor_nD", 16384);
  _GALAXIES_mon_sample_e_var._index=243;
  int current_setpos_index = 243;
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.user9[0]='\0';
  _GALAXIES_mon_sample_e_var._parameters.xwidth = 5e-3;
  _GALAXIES_mon_sample_e_var._parameters.yheight = 2e-3;
  _GALAXIES_mon_sample_e_var._parameters.zdepth = 0;
  _GALAXIES_mon_sample_e_var._parameters.bins = 256;
  _GALAXIES_mon_sample_e_var._parameters.min = _instrument_var._parameters.GALAXIES_E0 - _instrument_var._parameters.GALAXIES_dE * 1.2;
  _GALAXIES_mon_sample_e_var._parameters.max = _instrument_var._parameters.GALAXIES_E0 + _instrument_var._parameters.GALAXIES_dE * 1.2;
  _GALAXIES_mon_sample_e_var._parameters.restore_xray = 1;
  _GALAXIES_mon_sample_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.options[0]='\0';
  if("GALAXIES_mon_sample_e" && strlen("GALAXIES_mon_sample_e"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.filename, "GALAXIES_mon_sample_e" ? "GALAXIES_mon_sample_e" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.geometry[0]='\0';
  _GALAXIES_mon_sample_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_mon_sample_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_mon_sample_e_var._parameters.username9[0]='\0';


  /* component GALAXIES_mon_sample_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_mon_sample_xy_kb_var._rotation_absolute, _GALAXIES_mon_sample_e_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_sample_xy_kb_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_mon_sample_e_var._rotation_absolute, tr1, _GALAXIES_mon_sample_e_var._rotation_relative);
    _GALAXIES_mon_sample_e_var._rotation_is_identity =  rot_test_identity(_GALAXIES_mon_sample_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.001);
    rot_transpose(_GALAXIES_mon_sample_xy_kb_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_mon_sample_e_var._position_absolute = coords_add(_GALAXIES_mon_sample_xy_kb_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_sample_xy_kb_var._position_absolute, _GALAXIES_mon_sample_e_var._position_absolute);
    _GALAXIES_mon_sample_e_var._position_relative = rot_apply(_GALAXIES_mon_sample_e_var._rotation_absolute, tc1);
  } /* GALAXIES_mon_sample_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_mon_sample_e", _GALAXIES_mon_sample_e_var._position_absolute, _GALAXIES_mon_sample_e_var._rotation_absolute);
  instrument->_position_absolute[243] = _GALAXIES_mon_sample_e_var._position_absolute;
  instrument->_position_relative[243] = _GALAXIES_mon_sample_e_var._position_relative;
    _GALAXIES_mon_sample_e_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_mon_sample_e_var._position_relative);
  instrument->counter_N[243]  = instrument->counter_P[243] = instrument->counter_P2[243] = 0;
  instrument->counter_AbsorbProp[243]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", _GALAXIES_mon_sample_e_var._position_absolute, _GALAXIES_mon_sample_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "xwidth", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "bins", "0", "256","int");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "min", "-1e40", "_instrument_var._parameters.GALAXIES_E0 - _instrument_var._parameters.GALAXIES_dE * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "max", "1e40", "_instrument_var._parameters.GALAXIES_E0 + _instrument_var._parameters.GALAXIES_dE * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "filename", "NULL", "GALAXIES_mon_sample_e", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0242_GALAXIES_mon_sample_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_mon_sample_e_setpos */

/* component GALAXIES_sample_stage=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_sample_stage_setpos] component GALAXIES_sample_stage=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_sample_stage_var._name, "GALAXIES_sample_stage", 16384);
  stracpy(_GALAXIES_sample_stage_var._type, "Arm", 16384);
  _GALAXIES_sample_stage_var._index=244;
  int current_setpos_index = 244;
  /* component GALAXIES_sample_stage=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_M2B_out_var._rotation_absolute, _GALAXIES_sample_stage_var._rotation_absolute);
    rot_transpose(_GALAXIES_mon_sample_e_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_sample_stage_var._rotation_absolute, tr1, _GALAXIES_sample_stage_var._rotation_relative);
    _GALAXIES_sample_stage_var._rotation_is_identity =  rot_test_identity(_GALAXIES_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, GALAXIES_DistanceToSample - GALAXIES_DistanceToM2B);
    rot_transpose(_GALAXIES_M2B_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_sample_stage_var._position_absolute = coords_add(_GALAXIES_M2B_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_mon_sample_e_var._position_absolute, _GALAXIES_sample_stage_var._position_absolute);
    _GALAXIES_sample_stage_var._position_relative = rot_apply(_GALAXIES_sample_stage_var._rotation_absolute, tc1);
  } /* GALAXIES_sample_stage=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_sample_stage", _GALAXIES_sample_stage_var._position_absolute, _GALAXIES_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[244] = _GALAXIES_sample_stage_var._position_absolute;
  instrument->_position_relative[244] = _GALAXIES_sample_stage_var._position_relative;
    _GALAXIES_sample_stage_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_sample_stage_var._position_relative);
  instrument->counter_N[244]  = instrument->counter_P[244] = instrument->counter_P2[244] = 0;
  instrument->counter_AbsorbProp[244]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0243_GALAXIES_sample_stage", _GALAXIES_sample_stage_var._position_absolute, _GALAXIES_sample_stage_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_sample_stage_setpos */

/* component GALAXIES_sample=FluoCrystal() SETTING, POSITION/ROTATION */
int _GALAXIES_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_sample_setpos] component GALAXIES_sample=FluoCrystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoCrystal.comp:240]");
  stracpy(_GALAXIES_sample_var._name, "GALAXIES_sample", 16384);
  stracpy(_GALAXIES_sample_var._type, "FluoCrystal", 16384);
  _GALAXIES_sample_var._index=245;
  int current_setpos_index = 245;
  _GALAXIES_sample_var._parameters.geometry[0]='\0';
  _GALAXIES_sample_var._parameters.radius = 0;
  _GALAXIES_sample_var._parameters.thickness = 0;
  _GALAXIES_sample_var._parameters.xwidth = 1e-3;
  _GALAXIES_sample_var._parameters.yheight = 1e-3;
  _GALAXIES_sample_var._parameters.zdepth = 1e-3;
  _GALAXIES_sample_var._parameters.concentric = 0;
  if(_instrument_var._parameters.GALAXIES_sample && strlen(_instrument_var._parameters.GALAXIES_sample))
    stracpy(_GALAXIES_sample_var._parameters.material, _instrument_var._parameters.GALAXIES_sample ? _instrument_var._parameters.GALAXIES_sample : "", 16384);
  else 
  _GALAXIES_sample_var._parameters.material[0]='\0';
  _GALAXIES_sample_var._parameters.packing_factor = 0;
  _GALAXIES_sample_var._parameters.density = 0;
  _GALAXIES_sample_var._parameters.weight = 0;
  _GALAXIES_sample_var._parameters.p_interact = 0.9;
  _GALAXIES_sample_var._parameters.target_x = 0;
  _GALAXIES_sample_var._parameters.target_y = 0;
  _GALAXIES_sample_var._parameters.target_z = 0;
  _GALAXIES_sample_var._parameters.focus_r = 0;
  _GALAXIES_sample_var._parameters.focus_xw = 0;
  _GALAXIES_sample_var._parameters.focus_yh = 0;
  _GALAXIES_sample_var._parameters.focus_aw = 0;
  _GALAXIES_sample_var._parameters.focus_ah = 0;
  _GALAXIES_sample_var._parameters.target_index = 0;
  _GALAXIES_sample_var._parameters.flag_compton = 1;
  _GALAXIES_sample_var._parameters.flag_rayleigh = 1;
  _GALAXIES_sample_var._parameters.flag_lorentzian = 0;
  _GALAXIES_sample_var._parameters.flag_kissel = 1;
  if("" && strlen(""))
    stracpy(_GALAXIES_sample_var._parameters.sx_refl, "" ? "" : "", 16384);
  else 
  _GALAXIES_sample_var._parameters.sx_refl[0]='\0';
  _GALAXIES_sample_var._parameters.flag_sx = 1;
  _GALAXIES_sample_var._parameters.delta_d_d = 1e-3;
  _GALAXIES_sample_var._parameters.barns = 1;
  _GALAXIES_sample_var._parameters.recip_cell = 0;
  _GALAXIES_sample_var._parameters.ax = 0;
  _GALAXIES_sample_var._parameters.ay = 0;
  _GALAXIES_sample_var._parameters.az = 0;
  _GALAXIES_sample_var._parameters.bx = 0;
  _GALAXIES_sample_var._parameters.by = 0;
  _GALAXIES_sample_var._parameters.bz = 0;
  _GALAXIES_sample_var._parameters.cx = 0;
  _GALAXIES_sample_var._parameters.cy = 0;
  _GALAXIES_sample_var._parameters.cz = 0;
  _GALAXIES_sample_var._parameters.aa = 0;
  _GALAXIES_sample_var._parameters.bb = 0;
  _GALAXIES_sample_var._parameters.cc = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[0] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[1] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[2] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[3] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[4] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[5] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[6] = 0;
  _GALAXIES_sample_var._parameters.mosaic_AB[7] = 0;
  _GALAXIES_sample_var._parameters.mosaic = 1e-4;
  _GALAXIES_sample_var._parameters.mosaic_a = -1;
  _GALAXIES_sample_var._parameters.mosaic_b = -1;
  _GALAXIES_sample_var._parameters.mosaic_c = -1;
  _GALAXIES_sample_var._parameters.order = 1;


  /* component GALAXIES_sample=FluoCrystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_sample_stage_var._rotation_absolute, _GALAXIES_sample_var._rotation_absolute);
    rot_transpose(_GALAXIES_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_sample_var._rotation_absolute, tr1, _GALAXIES_sample_var._rotation_relative);
    _GALAXIES_sample_var._rotation_is_identity =  rot_test_identity(_GALAXIES_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_sample_var._position_absolute = coords_add(_GALAXIES_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_sample_stage_var._position_absolute, _GALAXIES_sample_var._position_absolute);
    _GALAXIES_sample_var._position_relative = rot_apply(_GALAXIES_sample_var._rotation_absolute, tc1);
  } /* GALAXIES_sample=FluoCrystal() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_sample", _GALAXIES_sample_var._position_absolute, _GALAXIES_sample_var._rotation_absolute);
  instrument->_position_absolute[245] = _GALAXIES_sample_var._position_absolute;
  instrument->_position_relative[245] = _GALAXIES_sample_var._position_relative;
    _GALAXIES_sample_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_sample_var._position_relative);
  instrument->counter_N[245]  = instrument->counter_P[245] = instrument->counter_P2[245] = 0;
  instrument->counter_AbsorbProp[245]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0244_GALAXIES_sample", _GALAXIES_sample_var._position_absolute, _GALAXIES_sample_var._rotation_absolute, "FluoCrystal");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "xwidth", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "yheight", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "zdepth", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "material", "LaB6.cif", _instrument_var._parameters.GALAXIES_sample, "char*");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "p_interact", "0", "0.9","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "target_z", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "focus_aw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "focus_ah", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "flag_kissel", "0", "1","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "sx_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "flag_sx", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "delta_d_d", "1e-3", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "recip_cell", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "ax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "ay", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "az", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "bx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "by", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "bz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "cx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "cy", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "cz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "aa", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "bb", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "cc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "mosaic_AB", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "mosaic", "3", "1e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "mosaic_a", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "mosaic_b", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "mosaic_c", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0244_GALAXIES_sample", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_sample_setpos */

/* component GALAXIES_sample_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_sample_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_sample_out_setpos] component GALAXIES_sample_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_sample_out_var._name, "GALAXIES_sample_out", 16384);
  stracpy(_GALAXIES_sample_out_var._type, "Arm", 16384);
  _GALAXIES_sample_out_var._index=246;
  int current_setpos_index = 246;
  /* component GALAXIES_sample_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_sample_stage_var._rotation_absolute, _GALAXIES_sample_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_sample_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_sample_out_var._rotation_absolute, tr1, _GALAXIES_sample_out_var._rotation_relative);
    _GALAXIES_sample_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_sample_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_sample_out_var._position_absolute = coords_add(_GALAXIES_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_sample_var._position_absolute, _GALAXIES_sample_out_var._position_absolute);
    _GALAXIES_sample_out_var._position_relative = rot_apply(_GALAXIES_sample_out_var._rotation_absolute, tc1);
  } /* GALAXIES_sample_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_sample_out", _GALAXIES_sample_out_var._position_absolute, _GALAXIES_sample_out_var._rotation_absolute);
  instrument->_position_absolute[246] = _GALAXIES_sample_out_var._position_absolute;
  instrument->_position_relative[246] = _GALAXIES_sample_out_var._position_relative;
    _GALAXIES_sample_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_sample_out_var._position_relative);
  instrument->counter_N[246]  = instrument->counter_P[246] = instrument->counter_P2[246] = 0;
  instrument->counter_AbsorbProp[246]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0245_GALAXIES_sample_out", _GALAXIES_sample_out_var._position_absolute, _GALAXIES_sample_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_sample_out_setpos */

/* component GALAXIES_ana_arm=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_ana_arm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_ana_arm_setpos] component GALAXIES_ana_arm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_ana_arm_var._name, "GALAXIES_ana_arm", 16384);
  stracpy(_GALAXIES_ana_arm_var._type, "Arm", 16384);
  _GALAXIES_ana_arm_var._index=247;
  int current_setpos_index = 247;
  /* component GALAXIES_ana_arm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.GALAXIES_ana_deg)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_sample_out_var._rotation_absolute, _GALAXIES_ana_arm_var._rotation_absolute);
    rot_transpose(_GALAXIES_sample_out_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_ana_arm_var._rotation_absolute, tr1, _GALAXIES_ana_arm_var._rotation_relative);
    _GALAXIES_ana_arm_var._rotation_is_identity =  rot_test_identity(_GALAXIES_ana_arm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_sample_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_ana_arm_var._position_absolute = coords_add(_GALAXIES_sample_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_sample_out_var._position_absolute, _GALAXIES_ana_arm_var._position_absolute);
    _GALAXIES_ana_arm_var._position_relative = rot_apply(_GALAXIES_ana_arm_var._rotation_absolute, tc1);
  } /* GALAXIES_ana_arm=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_ana_arm", _GALAXIES_ana_arm_var._position_absolute, _GALAXIES_ana_arm_var._rotation_absolute);
  instrument->_position_absolute[247] = _GALAXIES_ana_arm_var._position_absolute;
  instrument->_position_relative[247] = _GALAXIES_ana_arm_var._position_relative;
    _GALAXIES_ana_arm_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_ana_arm_var._position_relative);
  instrument->counter_N[247]  = instrument->counter_P[247] = instrument->counter_P2[247] = 0;
  instrument->counter_AbsorbProp[247]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0246_GALAXIES_ana_arm", _GALAXIES_ana_arm_var._position_absolute, _GALAXIES_ana_arm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_ana_arm_setpos */

/* component GALAXIES_analyzer=Bragg_crystal() SETTING, POSITION/ROTATION */
int _GALAXIES_analyzer_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_analyzer_setpos] component GALAXIES_analyzer=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_GALAXIES_analyzer_var._name, "GALAXIES_analyzer", 16384);
  stracpy(_GALAXIES_analyzer_var._type, "Bragg_crystal", 16384);
  _GALAXIES_analyzer_var._index=248;
  int current_setpos_index = 248;
  _GALAXIES_analyzer_var._parameters.length = 0.1;
  _GALAXIES_analyzer_var._parameters.width = 0.05;
  _GALAXIES_analyzer_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_GALAXIES_analyzer_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _GALAXIES_analyzer_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_GALAXIES_analyzer_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _GALAXIES_analyzer_var._parameters.material[0]='\0';
  _GALAXIES_analyzer_var._parameters.alpha = 0.0;
  _GALAXIES_analyzer_var._parameters.R0 = 0;
  _GALAXIES_analyzer_var._parameters.debye_waller_B = 0.4632;
  _GALAXIES_analyzer_var._parameters.crystal_type = 2;
  _GALAXIES_analyzer_var._parameters.h = 6;
  _GALAXIES_analyzer_var._parameters.k = 2;
  _GALAXIES_analyzer_var._parameters.l = 0;
  _GALAXIES_analyzer_var._parameters.structure_factor_scale_r = 0.0;
  _GALAXIES_analyzer_var._parameters.structure_factor_scale_i = 0.0;


  /* component GALAXIES_analyzer=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- asin ( 2 * PI / E2K / _instrument_var._parameters.GALAXIES_E0 / ( 2 * ( 5.4909 / sqrt ( 6 * 6 + 2 * 2 ) ) ) ) * RAD2DEG)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_ana_arm_var._rotation_absolute, _GALAXIES_analyzer_var._rotation_absolute);
    rot_transpose(_GALAXIES_sample_out_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_analyzer_var._rotation_absolute, tr1, _GALAXIES_analyzer_var._rotation_relative);
    _GALAXIES_analyzer_var._rotation_is_identity =  rot_test_identity(_GALAXIES_analyzer_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.GALAXIES_ana_R);
    rot_transpose(_GALAXIES_ana_arm_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_analyzer_var._position_absolute = coords_add(_GALAXIES_ana_arm_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_sample_out_var._position_absolute, _GALAXIES_analyzer_var._position_absolute);
    _GALAXIES_analyzer_var._position_relative = rot_apply(_GALAXIES_analyzer_var._rotation_absolute, tc1);
  } /* GALAXIES_analyzer=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_analyzer", _GALAXIES_analyzer_var._position_absolute, _GALAXIES_analyzer_var._rotation_absolute);
  instrument->_position_absolute[248] = _GALAXIES_analyzer_var._position_absolute;
  instrument->_position_relative[248] = _GALAXIES_analyzer_var._position_relative;
    _GALAXIES_analyzer_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_analyzer_var._position_relative);
  instrument->counter_N[248]  = instrument->counter_P[248] = instrument->counter_P2[248] = 0;
  instrument->counter_AbsorbProp[248]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0247_GALAXIES_analyzer", _GALAXIES_analyzer_var._position_absolute, _GALAXIES_analyzer_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "length", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "width", "0.02", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "h", "1", "6","int");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "k", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "l", "1", "0","int");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0247_GALAXIES_analyzer", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_analyzer_setpos */

/* component GALAXIES_ana_out=Arm() SETTING, POSITION/ROTATION */
int _GALAXIES_ana_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_ana_out_setpos] component GALAXIES_ana_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_GALAXIES_ana_out_var._name, "GALAXIES_ana_out", 16384);
  stracpy(_GALAXIES_ana_out_var._type, "Arm", 16384);
  _GALAXIES_ana_out_var._index=249;
  int current_setpos_index = 249;
  /* component GALAXIES_ana_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (asin ( 2 * PI / E2K / _instrument_var._parameters.GALAXIES_E0 / ( 2 * ( 5.4909 / sqrt ( 40 ) ) ) ) * RAD2DEG)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_analyzer_var._rotation_absolute, _GALAXIES_ana_out_var._rotation_absolute);
    rot_transpose(_GALAXIES_analyzer_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_ana_out_var._rotation_absolute, tr1, _GALAXIES_ana_out_var._rotation_relative);
    _GALAXIES_ana_out_var._rotation_is_identity =  rot_test_identity(_GALAXIES_ana_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_analyzer_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_ana_out_var._position_absolute = coords_add(_GALAXIES_analyzer_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_analyzer_var._position_absolute, _GALAXIES_ana_out_var._position_absolute);
    _GALAXIES_ana_out_var._position_relative = rot_apply(_GALAXIES_ana_out_var._rotation_absolute, tc1);
  } /* GALAXIES_ana_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_ana_out", _GALAXIES_ana_out_var._position_absolute, _GALAXIES_ana_out_var._rotation_absolute);
  instrument->_position_absolute[249] = _GALAXIES_ana_out_var._position_absolute;
  instrument->_position_relative[249] = _GALAXIES_ana_out_var._position_relative;
    _GALAXIES_ana_out_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_ana_out_var._position_relative);
  instrument->counter_N[249]  = instrument->counter_P[249] = instrument->counter_P2[249] = 0;
  instrument->counter_AbsorbProp[249]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0248_GALAXIES_ana_out", _GALAXIES_ana_out_var._position_absolute, _GALAXIES_ana_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_ana_out_setpos */

/* component GALAXIES_IXS_det=Monitor_nD() SETTING, POSITION/ROTATION */
int _GALAXIES_IXS_det_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_GALAXIES_IXS_det_setpos] component GALAXIES_IXS_det=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_GALAXIES_IXS_det_var._name, "GALAXIES_IXS_det", 16384);
  stracpy(_GALAXIES_IXS_det_var._type, "Monitor_nD", 16384);
  _GALAXIES_IXS_det_var._index=250;
  int current_setpos_index = 250;
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_GALAXIES_IXS_det_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.user9[0]='\0';
  _GALAXIES_IXS_det_var._parameters.xwidth = 0.02;
  _GALAXIES_IXS_det_var._parameters.yheight = 0.02;
  _GALAXIES_IXS_det_var._parameters.zdepth = 0;
  _GALAXIES_IXS_det_var._parameters.bins = 128;
  _GALAXIES_IXS_det_var._parameters.min = -1e40;
  _GALAXIES_IXS_det_var._parameters.max = 1e40;
  _GALAXIES_IXS_det_var._parameters.restore_xray = 0;
  _GALAXIES_IXS_det_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_GALAXIES_IXS_det_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.options[0]='\0';
  if("GALAXIES_IXS_det" && strlen("GALAXIES_IXS_det"))
    stracpy(_GALAXIES_IXS_det_var._parameters.filename, "GALAXIES_IXS_det" ? "GALAXIES_IXS_det" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.geometry[0]='\0';
  _GALAXIES_IXS_det_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_GALAXIES_IXS_det_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _GALAXIES_IXS_det_var._parameters.username9[0]='\0';


  /* component GALAXIES_IXS_det=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_ana_out_var._rotation_absolute, _GALAXIES_IXS_det_var._rotation_absolute);
    rot_transpose(_GALAXIES_analyzer_var._rotation_absolute, tr1);
    rot_mul(_GALAXIES_IXS_det_var._rotation_absolute, tr1, _GALAXIES_IXS_det_var._rotation_relative);
    _GALAXIES_IXS_det_var._rotation_is_identity =  rot_test_identity(_GALAXIES_IXS_det_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.GALAXIES_ana_R);
    rot_transpose(_GALAXIES_ana_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _GALAXIES_IXS_det_var._position_absolute = coords_add(_GALAXIES_ana_out_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_analyzer_var._position_absolute, _GALAXIES_IXS_det_var._position_absolute);
    _GALAXIES_IXS_det_var._position_relative = rot_apply(_GALAXIES_IXS_det_var._rotation_absolute, tc1);
  } /* GALAXIES_IXS_det=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("GALAXIES_IXS_det", _GALAXIES_IXS_det_var._position_absolute, _GALAXIES_IXS_det_var._rotation_absolute);
  instrument->_position_absolute[250] = _GALAXIES_IXS_det_var._position_absolute;
  instrument->_position_relative[250] = _GALAXIES_IXS_det_var._position_relative;
    _GALAXIES_IXS_det_var._position_relative_is_zero =  coords_test_zero(_GALAXIES_IXS_det_var._position_relative);
  instrument->counter_N[250]  = instrument->counter_P[250] = instrument->counter_P2[250] = 0;
  instrument->counter_AbsorbProp[250]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0249_GALAXIES_IXS_det", _GALAXIES_IXS_det_var._position_absolute, _GALAXIES_IXS_det_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "filename", "NULL", "GALAXIES_IXS_det", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0249_GALAXIES_IXS_det", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _GALAXIES_IXS_det_setpos */

/* component beamdump_257=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_257_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_257_setpos] component beamdump_257=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_257_var._name, "beamdump_257", 16384);
  stracpy(_beamdump_257_var._type, "Beamstop", 16384);
  _beamdump_257_var._index=251;
  int current_setpos_index = 251;
  _beamdump_257_var._parameters.xmin = -0.05;
  _beamdump_257_var._parameters.xmax = 0.05;
  _beamdump_257_var._parameters.ymin = -0.05;
  _beamdump_257_var._parameters.ymax = 0.05;
  _beamdump_257_var._parameters.xwidth = 0;
  _beamdump_257_var._parameters.yheight = 0;
  _beamdump_257_var._parameters.radius = 0;

  /* component beamdump_257=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _GALAXIES_IXS_det_var._rotation_absolute, _beamdump_257_var._rotation_absolute);
    rot_transpose(_GALAXIES_IXS_det_var._rotation_absolute, tr1);
    rot_mul(_beamdump_257_var._rotation_absolute, tr1, _beamdump_257_var._rotation_relative);
    _beamdump_257_var._rotation_is_identity =  rot_test_identity(_beamdump_257_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_GALAXIES_IXS_det_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_257_var._position_absolute = coords_add(_GALAXIES_IXS_det_var._position_absolute, tc2);
    tc1 = coords_sub(_GALAXIES_IXS_det_var._position_absolute, _beamdump_257_var._position_absolute);
    _beamdump_257_var._position_relative = rot_apply(_beamdump_257_var._rotation_absolute, tc1);
  } /* beamdump_257=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_257", _beamdump_257_var._position_absolute, _beamdump_257_var._rotation_absolute);
  instrument->_position_absolute[251] = _beamdump_257_var._position_absolute;
  instrument->_position_relative[251] = _beamdump_257_var._position_relative;
    _beamdump_257_var._position_relative_is_zero =  coords_test_zero(_beamdump_257_var._position_relative);
  instrument->counter_N[251]  = instrument->counter_P[251] = instrument->counter_P2[251] = 0;
  instrument->counter_AbsorbProp[251]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0250_beamdump_257", _beamdump_257_var._position_absolute, _beamdump_257_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0250_beamdump_257", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_257_setpos */

/* component TEMPO_pos=Text() SETTING, POSITION/ROTATION */
int _TEMPO_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_TEMPO_pos_setpos] component TEMPO_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_TEMPO_pos_var._name, "TEMPO_pos", 16384);
  stracpy(_TEMPO_pos_var._type, "Text", 16384);
  _TEMPO_pos_var._index=252;
  int current_setpos_index = 252;
  if("TEMPO" && strlen("TEMPO"))
    stracpy(_TEMPO_pos_var._parameters.text, "TEMPO" ? "TEMPO" : "", 16384);
  else 
  _TEMPO_pos_var._parameters.text[0]='\0';
  _TEMPO_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_TEMPO_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _TEMPO_pos_var._parameters.plane[0]='\0';
  _TEMPO_pos_var._parameters.pen_thickness = 0.1;


  /* component TEMPO_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-157.220)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _TEMPO_pos_var._rotation_absolute);
    rot_transpose(_beamdump_257_var._rotation_absolute, tr1);
    rot_mul(_TEMPO_pos_var._rotation_absolute, tr1, _TEMPO_pos_var._rotation_relative);
    _TEMPO_pos_var._rotation_is_identity =  rot_test_identity(_TEMPO_pos_var._rotation_relative);
    tc1 = coords_set(
      -51.94, 0, 21.81);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _TEMPO_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_257_var._position_absolute, _TEMPO_pos_var._position_absolute);
    _TEMPO_pos_var._position_relative = rot_apply(_TEMPO_pos_var._rotation_absolute, tc1);
  } /* TEMPO_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("TEMPO_pos", _TEMPO_pos_var._position_absolute, _TEMPO_pos_var._rotation_absolute);
  instrument->_position_absolute[252] = _TEMPO_pos_var._position_absolute;
  instrument->_position_relative[252] = _TEMPO_pos_var._position_relative;
    _TEMPO_pos_var._position_relative_is_zero =  coords_test_zero(_TEMPO_pos_var._position_relative);
  instrument->counter_N[252]  = instrument->counter_P[252] = instrument->counter_P2[252] = 0;
  instrument->counter_AbsorbProp[252]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0251_TEMPO_pos", _TEMPO_pos_var._position_absolute, _TEMPO_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0251_TEMPO_pos", "text", "NONE", "TEMPO", "char*");
        mccomp_param_nexus(nxhandle,"0251_TEMPO_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0251_TEMPO_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0251_TEMPO_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _TEMPO_pos_setpos */

/* component SAMBA_pos=Text() SETTING, POSITION/ROTATION */
int _SAMBA_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_pos_setpos] component SAMBA_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_SAMBA_pos_var._name, "SAMBA_pos", 16384);
  stracpy(_SAMBA_pos_var._type, "Text", 16384);
  _SAMBA_pos_var._index=253;
  int current_setpos_index = 253;
  if("SAMBA" && strlen("SAMBA"))
    stracpy(_SAMBA_pos_var._parameters.text, "SAMBA" ? "SAMBA" : "", 16384);
  else 
  _SAMBA_pos_var._parameters.text[0]='\0';
  _SAMBA_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_SAMBA_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _SAMBA_pos_var._parameters.plane[0]='\0';
  _SAMBA_pos_var._parameters.pen_thickness = 0.1;


  /* component SAMBA_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-195.163)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _SAMBA_pos_var._rotation_absolute);
    rot_transpose(_TEMPO_pos_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_pos_var._rotation_absolute, tr1, _SAMBA_pos_var._rotation_relative);
    _SAMBA_pos_var._rotation_is_identity =  rot_test_identity(_SAMBA_pos_var._rotation_relative);
    tc1 = coords_set(
      -54.37, 0, -14.74);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_TEMPO_pos_var._position_absolute, _SAMBA_pos_var._position_absolute);
    _SAMBA_pos_var._position_relative = rot_apply(_SAMBA_pos_var._rotation_absolute, tc1);
  } /* SAMBA_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_pos", _SAMBA_pos_var._position_absolute, _SAMBA_pos_var._rotation_absolute);
  instrument->_position_absolute[253] = _SAMBA_pos_var._position_absolute;
  instrument->_position_relative[253] = _SAMBA_pos_var._position_relative;
    _SAMBA_pos_var._position_relative_is_zero =  coords_test_zero(_SAMBA_pos_var._position_relative);
  instrument->counter_N[253]  = instrument->counter_P[253] = instrument->counter_P2[253] = 0;
  instrument->counter_AbsorbProp[253]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0252_SAMBA_pos", _SAMBA_pos_var._position_absolute, _SAMBA_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0252_SAMBA_pos", "text", "NONE", "SAMBA", "char*");
        mccomp_param_nexus(nxhandle,"0252_SAMBA_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0252_SAMBA_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0252_SAMBA_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_pos_setpos */

/* component SAMBA=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_setpos] component SAMBA=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_var._name, "SAMBA", 16384);
  stracpy(_SAMBA_var._type, "Arm", 16384);
  _SAMBA_var._index=254;
  int current_setpos_index = 254;
  /* component SAMBA=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_pos_var._rotation_absolute, _SAMBA_var._rotation_absolute);
    rot_transpose(_SAMBA_pos_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_var._rotation_absolute, tr1, _SAMBA_var._rotation_relative);
    _SAMBA_var._rotation_is_identity =  rot_test_identity(_SAMBA_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_var._position_absolute = coords_add(_SAMBA_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_pos_var._position_absolute, _SAMBA_var._position_absolute);
    _SAMBA_var._position_relative = rot_apply(_SAMBA_var._rotation_absolute, tc1);
  } /* SAMBA=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA", _SAMBA_var._position_absolute, _SAMBA_var._rotation_absolute);
  instrument->_position_absolute[254] = _SAMBA_var._position_absolute;
  instrument->_position_relative[254] = _SAMBA_var._position_relative;
    _SAMBA_var._position_relative_is_zero =  coords_test_zero(_SAMBA_var._position_relative);
  instrument->counter_N[254]  = instrument->counter_P[254] = instrument->counter_P2[254] = 0;
  instrument->counter_AbsorbProp[254]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0253_SAMBA", _SAMBA_var._position_absolute, _SAMBA_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_setpos */

/* component SAMBA_BM_source=Bending_magnet() SETTING, POSITION/ROTATION */
int _SAMBA_BM_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_BM_source_setpos] component SAMBA_BM_source=Bending_magnet() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");
  stracpy(_SAMBA_BM_source_var._name, "SAMBA_BM_source", 16384);
  stracpy(_SAMBA_BM_source_var._type, "Bending_magnet", 16384);
  _SAMBA_BM_source_var._index=255;
  int current_setpos_index = 255;
  _SAMBA_BM_source_var._parameters.E0 = _instrument_var._parameters.SAMBA_E0;
  _SAMBA_BM_source_var._parameters.dE = _instrument_var._parameters.SAMBA_dE;
  _SAMBA_BM_source_var._parameters.lambda0 = 0;
  _SAMBA_BM_source_var._parameters.dlambda = 0;
  _SAMBA_BM_source_var._parameters.phase = 0;
  _SAMBA_BM_source_var._parameters.randomphase = 1;
  _SAMBA_BM_source_var._parameters.Ee = 2.75;
  _SAMBA_BM_source_var._parameters.Ie = 0.5;
  _SAMBA_BM_source_var._parameters.B = 1.72;
  _SAMBA_BM_source_var._parameters.sigey = 24.9e-6;
  _SAMBA_BM_source_var._parameters.sigex = 60.1e-6;
  _SAMBA_BM_source_var._parameters.focus_xw = 0;
  _SAMBA_BM_source_var._parameters.focus_yh = 0;
  _SAMBA_BM_source_var._parameters.dist = 1;
  _SAMBA_BM_source_var._parameters.gauss_t = 0;


  /* component SAMBA_BM_source=Bending_magnet() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_var._rotation_absolute, _SAMBA_BM_source_var._rotation_absolute);
    rot_transpose(_SAMBA_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_BM_source_var._rotation_absolute, tr1, _SAMBA_BM_source_var._rotation_relative);
    _SAMBA_BM_source_var._rotation_is_identity =  rot_test_identity(_SAMBA_BM_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_BM_source_var._position_absolute = coords_add(_SAMBA_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_var._position_absolute, _SAMBA_BM_source_var._position_absolute);
    _SAMBA_BM_source_var._position_relative = rot_apply(_SAMBA_BM_source_var._rotation_absolute, tc1);
  } /* SAMBA_BM_source=Bending_magnet() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_BM_source", _SAMBA_BM_source_var._position_absolute, _SAMBA_BM_source_var._rotation_absolute);
  instrument->_position_absolute[255] = _SAMBA_BM_source_var._position_absolute;
  instrument->_position_relative[255] = _SAMBA_BM_source_var._position_relative;
    _SAMBA_BM_source_var._position_relative_is_zero =  coords_test_zero(_SAMBA_BM_source_var._position_relative);
  instrument->counter_N[255]  = instrument->counter_P[255] = instrument->counter_P2[255] = 0;
  instrument->counter_AbsorbProp[255]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0254_SAMBA_BM_source", _SAMBA_BM_source_var._position_absolute, _SAMBA_BM_source_var._rotation_absolute, "Bending_magnet");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "E0", "0", "_instrument_var._parameters.SAMBA_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "dE", "0", "_instrument_var._parameters.SAMBA_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "B", "1.6", "1.72","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "sigey", "0", "24.9e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "sigex", "0", "60.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0254_SAMBA_BM_source", "gauss_t", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_BM_source_setpos */

/* component SAMBA_M1_location=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_M1_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M1_location_setpos] component SAMBA_M1_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_M1_location_var._name, "SAMBA_M1_location", 16384);
  stracpy(_SAMBA_M1_location_var._type, "Arm", 16384);
  _SAMBA_M1_location_var._index=256;
  int current_setpos_index = 256;
  /* component SAMBA_M1_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_BM_source_var._rotation_absolute, _SAMBA_M1_location_var._rotation_absolute);
    rot_transpose(_SAMBA_BM_source_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M1_location_var._rotation_absolute, tr1, _SAMBA_M1_location_var._rotation_relative);
    _SAMBA_M1_location_var._rotation_is_identity =  rot_test_identity(_SAMBA_M1_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 14);
    rot_transpose(_SAMBA_BM_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M1_location_var._position_absolute = coords_add(_SAMBA_BM_source_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_BM_source_var._position_absolute, _SAMBA_M1_location_var._position_absolute);
    _SAMBA_M1_location_var._position_relative = rot_apply(_SAMBA_M1_location_var._rotation_absolute, tc1);
  } /* SAMBA_M1_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M1_location", _SAMBA_M1_location_var._position_absolute, _SAMBA_M1_location_var._rotation_absolute);
  instrument->_position_absolute[256] = _SAMBA_M1_location_var._position_absolute;
  instrument->_position_relative[256] = _SAMBA_M1_location_var._position_relative;
    _SAMBA_M1_location_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M1_location_var._position_relative);
  instrument->counter_N[256]  = instrument->counter_P[256] = instrument->counter_P2[256] = 0;
  instrument->counter_AbsorbProp[256]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0255_SAMBA_M1_location", _SAMBA_M1_location_var._position_absolute, _SAMBA_M1_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M1_location_setpos */

/* component SAMBA_M1_rotated=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_M1_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M1_rotated_setpos] component SAMBA_M1_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_M1_rotated_var._name, "SAMBA_M1_rotated", 16384);
  stracpy(_SAMBA_M1_rotated_var._type, "Arm", 16384);
  _SAMBA_M1_rotated_var._index=257;
  int current_setpos_index = 257;
  /* component SAMBA_M1_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SAMBA_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M1_location_var._rotation_absolute, _SAMBA_M1_rotated_var._rotation_absolute);
    rot_transpose(_SAMBA_BM_source_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M1_rotated_var._rotation_absolute, tr1, _SAMBA_M1_rotated_var._rotation_relative);
    _SAMBA_M1_rotated_var._rotation_is_identity =  rot_test_identity(_SAMBA_M1_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_M1_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M1_rotated_var._position_absolute = coords_add(_SAMBA_M1_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_BM_source_var._position_absolute, _SAMBA_M1_rotated_var._position_absolute);
    _SAMBA_M1_rotated_var._position_relative = rot_apply(_SAMBA_M1_rotated_var._rotation_absolute, tc1);
  } /* SAMBA_M1_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M1_rotated", _SAMBA_M1_rotated_var._position_absolute, _SAMBA_M1_rotated_var._rotation_absolute);
  instrument->_position_absolute[257] = _SAMBA_M1_rotated_var._position_absolute;
  instrument->_position_relative[257] = _SAMBA_M1_rotated_var._position_relative;
    _SAMBA_M1_rotated_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M1_rotated_var._position_relative);
  instrument->counter_N[257]  = instrument->counter_P[257] = instrument->counter_P2[257] = 0;
  instrument->counter_AbsorbProp[257]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0256_SAMBA_M1_rotated", _SAMBA_M1_rotated_var._position_absolute, _SAMBA_M1_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M1_rotated_setpos */

/* component SAMBA_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _SAMBA_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M1_setpos] component SAMBA_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SAMBA_M1_var._name, "SAMBA_M1", 16384);
  stracpy(_SAMBA_M1_var._type, "Mirror_curved", 16384);
  _SAMBA_M1_var._index=258;
  int current_setpos_index = 258;
  _SAMBA_M1_var._parameters.radius = SAMBA_M1_radius;
  _SAMBA_M1_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_SAMBA_M1_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _SAMBA_M1_var._parameters.coating[0]='\0';
  _SAMBA_M1_var._parameters.zdepth = 0.2;
  _SAMBA_M1_var._parameters.yheight = 0.2;
  _SAMBA_M1_var._parameters.length = 1.3;
  _SAMBA_M1_var._parameters.width = 0.12;


  /* component SAMBA_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M1_rotated_var._rotation_absolute, _SAMBA_M1_var._rotation_absolute);
    rot_transpose(_SAMBA_BM_source_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M1_var._rotation_absolute, tr1, _SAMBA_M1_var._rotation_relative);
    _SAMBA_M1_var._rotation_is_identity =  rot_test_identity(_SAMBA_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M1_var._position_absolute = coords_add(_SAMBA_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_BM_source_var._position_absolute, _SAMBA_M1_var._position_absolute);
    _SAMBA_M1_var._position_relative = rot_apply(_SAMBA_M1_var._rotation_absolute, tc1);
  } /* SAMBA_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M1", _SAMBA_M1_var._position_absolute, _SAMBA_M1_var._rotation_absolute);
  instrument->_position_absolute[258] = _SAMBA_M1_var._position_absolute;
  instrument->_position_relative[258] = _SAMBA_M1_var._position_relative;
    _SAMBA_M1_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M1_var._position_relative);
  instrument->counter_N[258]  = instrument->counter_P[258] = instrument->counter_P2[258] = 0;
  instrument->counter_AbsorbProp[258]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0257_SAMBA_M1", _SAMBA_M1_var._position_absolute, _SAMBA_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "radius", "1", "SAMBA_M1_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "length", "0", "1.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0257_SAMBA_M1", "width", "0", "0.12","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M1_setpos */

/* component SAMBA_M1_out=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_M1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M1_out_setpos] component SAMBA_M1_out=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_M1_out_var._name, "SAMBA_M1_out", 16384);
  stracpy(_SAMBA_M1_out_var._type, "Monitor_nD", 16384);
  _SAMBA_M1_out_var._index=259;
  int current_setpos_index = 259;
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M1_out_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.user9[0]='\0';
  _SAMBA_M1_out_var._parameters.xwidth = 0.02;
  _SAMBA_M1_out_var._parameters.yheight = 0.02;
  _SAMBA_M1_out_var._parameters.zdepth = 0;
  _SAMBA_M1_out_var._parameters.bins = 0;
  _SAMBA_M1_out_var._parameters.min = -1e40;
  _SAMBA_M1_out_var._parameters.max = 1e40;
  _SAMBA_M1_out_var._parameters.restore_xray = 1;
  _SAMBA_M1_out_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SAMBA_M1_out_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.geometry[0]='\0';
  _SAMBA_M1_out_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M1_out_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M1_out_var._parameters.username9[0]='\0';


  /* component SAMBA_M1_out=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SAMBA_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M1_location_var._rotation_absolute, _SAMBA_M1_out_var._rotation_absolute);
    rot_transpose(_SAMBA_M1_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M1_out_var._rotation_absolute, tr1, _SAMBA_M1_out_var._rotation_relative);
    _SAMBA_M1_out_var._rotation_is_identity =  rot_test_identity(_SAMBA_M1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M1_out_var._position_absolute = coords_add(_SAMBA_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_M1_var._position_absolute, _SAMBA_M1_out_var._position_absolute);
    _SAMBA_M1_out_var._position_relative = rot_apply(_SAMBA_M1_out_var._rotation_absolute, tc1);
  } /* SAMBA_M1_out=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M1_out", _SAMBA_M1_out_var._position_absolute, _SAMBA_M1_out_var._rotation_absolute);
  instrument->_position_absolute[259] = _SAMBA_M1_out_var._position_absolute;
  instrument->_position_relative[259] = _SAMBA_M1_out_var._position_relative;
    _SAMBA_M1_out_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M1_out_var._position_relative);
  instrument->counter_N[259]  = instrument->counter_P[259] = instrument->counter_P2[259] = 0;
  instrument->counter_AbsorbProp[259]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0258_SAMBA_M1_out", _SAMBA_M1_out_var._position_absolute, _SAMBA_M1_out_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0258_SAMBA_M1_out", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M1_out_setpos */

/* component SAMBA_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_DCM_location_setpos] component SAMBA_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_DCM_location_var._name, "SAMBA_DCM_location", 16384);
  stracpy(_SAMBA_DCM_location_var._type, "Arm", 16384);
  _SAMBA_DCM_location_var._index=260;
  int current_setpos_index = 260;
  /* component SAMBA_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M1_out_var._rotation_absolute, _SAMBA_DCM_location_var._rotation_absolute);
    rot_transpose(_SAMBA_M1_out_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_DCM_location_var._rotation_absolute, tr1, _SAMBA_DCM_location_var._rotation_relative);
    _SAMBA_DCM_location_var._rotation_is_identity =  rot_test_identity(_SAMBA_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2);
    rot_transpose(_SAMBA_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_DCM_location_var._position_absolute = coords_add(_SAMBA_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_M1_out_var._position_absolute, _SAMBA_DCM_location_var._position_absolute);
    _SAMBA_DCM_location_var._position_relative = rot_apply(_SAMBA_DCM_location_var._rotation_absolute, tc1);
  } /* SAMBA_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_DCM_location", _SAMBA_DCM_location_var._position_absolute, _SAMBA_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[260] = _SAMBA_DCM_location_var._position_absolute;
  instrument->_position_relative[260] = _SAMBA_DCM_location_var._position_relative;
    _SAMBA_DCM_location_var._position_relative_is_zero =  coords_test_zero(_SAMBA_DCM_location_var._position_relative);
  instrument->counter_N[260]  = instrument->counter_P[260] = instrument->counter_P2[260] = 0;
  instrument->counter_AbsorbProp[260]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0259_SAMBA_DCM_location", _SAMBA_DCM_location_var._position_absolute, _SAMBA_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_DCM_location_setpos */

/* component SAMBA_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SAMBA_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_bragg_crystal_setpos] component SAMBA_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SAMBA_bragg_crystal_var._name, "SAMBA_bragg_crystal", 16384);
  stracpy(_SAMBA_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _SAMBA_bragg_crystal_var._index=261;
  int current_setpos_index = 261;
  _SAMBA_bragg_crystal_var._parameters.length = 0.2;
  _SAMBA_bragg_crystal_var._parameters.width = 0.06;
  _SAMBA_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SAMBA_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SAMBA_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SAMBA_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SAMBA_bragg_crystal_var._parameters.material[0]='\0';
  _SAMBA_bragg_crystal_var._parameters.alpha = 0.0;
  _SAMBA_bragg_crystal_var._parameters.R0 = 0;
  _SAMBA_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _SAMBA_bragg_crystal_var._parameters.crystal_type = 1;
  _SAMBA_bragg_crystal_var._parameters.h = 1;
  _SAMBA_bragg_crystal_var._parameters.k = 1;
  _SAMBA_bragg_crystal_var._parameters.l = 1;
  _SAMBA_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _SAMBA_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component SAMBA_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- SAMBA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_DCM_location_var._rotation_absolute, _SAMBA_bragg_crystal_var._rotation_absolute);
    rot_transpose(_SAMBA_M1_out_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_bragg_crystal_var._rotation_absolute, tr1, _SAMBA_bragg_crystal_var._rotation_relative);
    _SAMBA_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_SAMBA_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_bragg_crystal_var._position_absolute = coords_add(_SAMBA_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_M1_out_var._position_absolute, _SAMBA_bragg_crystal_var._position_absolute);
    _SAMBA_bragg_crystal_var._position_relative = rot_apply(_SAMBA_bragg_crystal_var._rotation_absolute, tc1);
  } /* SAMBA_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_bragg_crystal", _SAMBA_bragg_crystal_var._position_absolute, _SAMBA_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[261] = _SAMBA_bragg_crystal_var._position_absolute;
  instrument->_position_relative[261] = _SAMBA_bragg_crystal_var._position_relative;
    _SAMBA_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_SAMBA_bragg_crystal_var._position_relative);
  instrument->counter_N[261]  = instrument->counter_P[261] = instrument->counter_P2[261] = 0;
  instrument->counter_AbsorbProp[261]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0260_SAMBA_bragg_crystal", _SAMBA_bragg_crystal_var._position_absolute, _SAMBA_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "length", "0.05", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "width", "0.02", "0.06","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0260_SAMBA_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_bragg_crystal_setpos */

/* component SAMBA_arm_crystal1=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_arm_crystal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_arm_crystal1_setpos] component SAMBA_arm_crystal1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_arm_crystal1_var._name, "SAMBA_arm_crystal1", 16384);
  stracpy(_SAMBA_arm_crystal1_var._type, "Arm", 16384);
  _SAMBA_arm_crystal1_var._index=262;
  int current_setpos_index = 262;
  /* component SAMBA_arm_crystal1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- SAMBA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_bragg_crystal_var._rotation_absolute, _SAMBA_arm_crystal1_var._rotation_absolute);
    rot_transpose(_SAMBA_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_arm_crystal1_var._rotation_absolute, tr1, _SAMBA_arm_crystal1_var._rotation_relative);
    _SAMBA_arm_crystal1_var._rotation_is_identity =  rot_test_identity(_SAMBA_arm_crystal1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_arm_crystal1_var._position_absolute = coords_add(_SAMBA_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_bragg_crystal_var._position_absolute, _SAMBA_arm_crystal1_var._position_absolute);
    _SAMBA_arm_crystal1_var._position_relative = rot_apply(_SAMBA_arm_crystal1_var._rotation_absolute, tc1);
  } /* SAMBA_arm_crystal1=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_arm_crystal1", _SAMBA_arm_crystal1_var._position_absolute, _SAMBA_arm_crystal1_var._rotation_absolute);
  instrument->_position_absolute[262] = _SAMBA_arm_crystal1_var._position_absolute;
  instrument->_position_relative[262] = _SAMBA_arm_crystal1_var._position_relative;
    _SAMBA_arm_crystal1_var._position_relative_is_zero =  coords_test_zero(_SAMBA_arm_crystal1_var._position_relative);
  instrument->counter_N[262]  = instrument->counter_P[262] = instrument->counter_P2[262] = 0;
  instrument->counter_AbsorbProp[262]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0261_SAMBA_arm_crystal1", _SAMBA_arm_crystal1_var._position_absolute, _SAMBA_arm_crystal1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_arm_crystal1_setpos */

/* component SAMBA_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SAMBA_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_bragg_crystal_two_setpos] component SAMBA_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SAMBA_bragg_crystal_two_var._name, "SAMBA_bragg_crystal_two", 16384);
  stracpy(_SAMBA_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _SAMBA_bragg_crystal_two_var._index=263;
  int current_setpos_index = 263;
  _SAMBA_bragg_crystal_two_var._parameters.length = 0.2;
  _SAMBA_bragg_crystal_two_var._parameters.width = 0.06;
  _SAMBA_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SAMBA_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SAMBA_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SAMBA_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SAMBA_bragg_crystal_two_var._parameters.material[0]='\0';
  _SAMBA_bragg_crystal_two_var._parameters.alpha = 0.0;
  _SAMBA_bragg_crystal_two_var._parameters.R0 = 0;
  _SAMBA_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _SAMBA_bragg_crystal_two_var._parameters.crystal_type = 1;
  _SAMBA_bragg_crystal_two_var._parameters.h = 1;
  _SAMBA_bragg_crystal_two_var._parameters.k = 1;
  _SAMBA_bragg_crystal_two_var._parameters.l = 1;
  _SAMBA_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _SAMBA_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component SAMBA_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (SAMBA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_arm_crystal1_var._rotation_absolute, _SAMBA_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_SAMBA_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_bragg_crystal_two_var._rotation_absolute, tr1, _SAMBA_bragg_crystal_two_var._rotation_relative);
    _SAMBA_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_SAMBA_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, SAMBA_dcm_gap, SAMBA_DCM_theta ? SAMBA_dcm_gap / tan ( SAMBA_DCM_theta * DEG2RAD ) : 0);
    rot_transpose(_SAMBA_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_bragg_crystal_two_var._position_absolute = coords_add(_SAMBA_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_bragg_crystal_var._position_absolute, _SAMBA_bragg_crystal_two_var._position_absolute);
    _SAMBA_bragg_crystal_two_var._position_relative = rot_apply(_SAMBA_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* SAMBA_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_bragg_crystal_two", _SAMBA_bragg_crystal_two_var._position_absolute, _SAMBA_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[263] = _SAMBA_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[263] = _SAMBA_bragg_crystal_two_var._position_relative;
    _SAMBA_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_SAMBA_bragg_crystal_two_var._position_relative);
  instrument->counter_N[263]  = instrument->counter_P[263] = instrument->counter_P2[263] = 0;
  instrument->counter_AbsorbProp[263]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", _SAMBA_bragg_crystal_two_var._position_absolute, _SAMBA_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "length", "0.05", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "width", "0.02", "0.06","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0262_SAMBA_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_bragg_crystal_two_setpos */

/* component SAMBA_arm_crystal2=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_arm_crystal2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_arm_crystal2_setpos] component SAMBA_arm_crystal2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_arm_crystal2_var._name, "SAMBA_arm_crystal2", 16384);
  stracpy(_SAMBA_arm_crystal2_var._type, "Arm", 16384);
  _SAMBA_arm_crystal2_var._index=264;
  int current_setpos_index = 264;
  /* component SAMBA_arm_crystal2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (SAMBA_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_bragg_crystal_two_var._rotation_absolute, _SAMBA_arm_crystal2_var._rotation_absolute);
    rot_transpose(_SAMBA_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_arm_crystal2_var._rotation_absolute, tr1, _SAMBA_arm_crystal2_var._rotation_relative);
    _SAMBA_arm_crystal2_var._rotation_is_identity =  rot_test_identity(_SAMBA_arm_crystal2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_arm_crystal2_var._position_absolute = coords_add(_SAMBA_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_bragg_crystal_two_var._position_absolute, _SAMBA_arm_crystal2_var._position_absolute);
    _SAMBA_arm_crystal2_var._position_relative = rot_apply(_SAMBA_arm_crystal2_var._rotation_absolute, tc1);
  } /* SAMBA_arm_crystal2=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_arm_crystal2", _SAMBA_arm_crystal2_var._position_absolute, _SAMBA_arm_crystal2_var._rotation_absolute);
  instrument->_position_absolute[264] = _SAMBA_arm_crystal2_var._position_absolute;
  instrument->_position_relative[264] = _SAMBA_arm_crystal2_var._position_relative;
    _SAMBA_arm_crystal2_var._position_relative_is_zero =  coords_test_zero(_SAMBA_arm_crystal2_var._position_relative);
  instrument->counter_N[264]  = instrument->counter_P[264] = instrument->counter_P2[264] = 0;
  instrument->counter_AbsorbProp[264]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0263_SAMBA_arm_crystal2", _SAMBA_arm_crystal2_var._position_absolute, _SAMBA_arm_crystal2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_arm_crystal2_setpos */

/* component SAMBA_DCM_out=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_DCM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_DCM_out_setpos] component SAMBA_DCM_out=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_DCM_out_var._name, "SAMBA_DCM_out", 16384);
  stracpy(_SAMBA_DCM_out_var._type, "Monitor_nD", 16384);
  _SAMBA_DCM_out_var._index=265;
  int current_setpos_index = 265;
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.user9[0]='\0';
  _SAMBA_DCM_out_var._parameters.xwidth = 0.02;
  _SAMBA_DCM_out_var._parameters.yheight = 0.02;
  _SAMBA_DCM_out_var._parameters.zdepth = 0;
  _SAMBA_DCM_out_var._parameters.bins = 0;
  _SAMBA_DCM_out_var._parameters.min = -1e40;
  _SAMBA_DCM_out_var._parameters.max = 1e40;
  _SAMBA_DCM_out_var._parameters.restore_xray = 1;
  _SAMBA_DCM_out_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SAMBA_DCM_out_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.geometry[0]='\0';
  _SAMBA_DCM_out_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_var._parameters.username9[0]='\0';


  /* component SAMBA_DCM_out=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_arm_crystal2_var._rotation_absolute, _SAMBA_DCM_out_var._rotation_absolute);
    rot_transpose(_SAMBA_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_DCM_out_var._rotation_absolute, tr1, _SAMBA_DCM_out_var._rotation_relative);
    _SAMBA_DCM_out_var._rotation_is_identity =  rot_test_identity(_SAMBA_DCM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_SAMBA_arm_crystal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_DCM_out_var._position_absolute = coords_add(_SAMBA_arm_crystal2_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_bragg_crystal_two_var._position_absolute, _SAMBA_DCM_out_var._position_absolute);
    _SAMBA_DCM_out_var._position_relative = rot_apply(_SAMBA_DCM_out_var._rotation_absolute, tc1);
  } /* SAMBA_DCM_out=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_DCM_out", _SAMBA_DCM_out_var._position_absolute, _SAMBA_DCM_out_var._rotation_absolute);
  instrument->_position_absolute[265] = _SAMBA_DCM_out_var._position_absolute;
  instrument->_position_relative[265] = _SAMBA_DCM_out_var._position_relative;
    _SAMBA_DCM_out_var._position_relative_is_zero =  coords_test_zero(_SAMBA_DCM_out_var._position_relative);
  instrument->counter_N[265]  = instrument->counter_P[265] = instrument->counter_P2[265] = 0;
  instrument->counter_AbsorbProp[265]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0264_SAMBA_DCM_out", _SAMBA_DCM_out_var._position_absolute, _SAMBA_DCM_out_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0264_SAMBA_DCM_out", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_DCM_out_setpos */

/* component SAMBA_DCM_out_div=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_DCM_out_div_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_DCM_out_div_setpos] component SAMBA_DCM_out_div=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_DCM_out_div_var._name, "SAMBA_DCM_out_div", 16384);
  stracpy(_SAMBA_DCM_out_div_var._type, "Monitor_nD", 16384);
  _SAMBA_DCM_out_div_var._index=266;
  int current_setpos_index = 266;
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_div_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.user9[0]='\0';
  _SAMBA_DCM_out_div_var._parameters.xwidth = 0.02;
  _SAMBA_DCM_out_div_var._parameters.yheight = 0.02;
  _SAMBA_DCM_out_div_var._parameters.zdepth = 0;
  _SAMBA_DCM_out_div_var._parameters.bins = 0;
  _SAMBA_DCM_out_div_var._parameters.min = -1e40;
  _SAMBA_DCM_out_div_var._parameters.max = 1e40;
  _SAMBA_DCM_out_div_var._parameters.restore_xray = 0;
  _SAMBA_DCM_out_div_var._parameters.radius = 0;
  if("dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" && strlen("dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.options, "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" ? "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.geometry[0]='\0';
  _SAMBA_DCM_out_div_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_div_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_div_var._parameters.username9[0]='\0';


  /* component SAMBA_DCM_out_div=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_DCM_out_var._rotation_absolute, _SAMBA_DCM_out_div_var._rotation_absolute);
    rot_transpose(_SAMBA_DCM_out_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_DCM_out_div_var._rotation_absolute, tr1, _SAMBA_DCM_out_div_var._rotation_relative);
    _SAMBA_DCM_out_div_var._rotation_is_identity =  rot_test_identity(_SAMBA_DCM_out_div_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_DCM_out_div_var._position_absolute = coords_add(_SAMBA_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_DCM_out_var._position_absolute, _SAMBA_DCM_out_div_var._position_absolute);
    _SAMBA_DCM_out_div_var._position_relative = rot_apply(_SAMBA_DCM_out_div_var._rotation_absolute, tc1);
  } /* SAMBA_DCM_out_div=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_DCM_out_div", _SAMBA_DCM_out_div_var._position_absolute, _SAMBA_DCM_out_div_var._rotation_absolute);
  instrument->_position_absolute[266] = _SAMBA_DCM_out_div_var._position_absolute;
  instrument->_position_relative[266] = _SAMBA_DCM_out_div_var._position_relative;
    _SAMBA_DCM_out_div_var._position_relative_is_zero =  coords_test_zero(_SAMBA_DCM_out_div_var._position_relative);
  instrument->counter_N[266]  = instrument->counter_P[266] = instrument->counter_P2[266] = 0;
  instrument->counter_AbsorbProp[266]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0265_SAMBA_DCM_out_div", _SAMBA_DCM_out_div_var._position_absolute, _SAMBA_DCM_out_div_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "options", "NULL", "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0265_SAMBA_DCM_out_div", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_DCM_out_div_setpos */

/* component SAMBA_DCM_out_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_DCM_out_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_DCM_out_e_setpos] component SAMBA_DCM_out_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_DCM_out_e_var._name, "SAMBA_DCM_out_e", 16384);
  stracpy(_SAMBA_DCM_out_e_var._type, "Monitor_nD", 16384);
  _SAMBA_DCM_out_e_var._index=267;
  int current_setpos_index = 267;
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_DCM_out_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.user9[0]='\0';
  _SAMBA_DCM_out_e_var._parameters.xwidth = 0.1;
  _SAMBA_DCM_out_e_var._parameters.yheight = 0.2;
  _SAMBA_DCM_out_e_var._parameters.zdepth = 0;
  _SAMBA_DCM_out_e_var._parameters.bins = 512;
  _SAMBA_DCM_out_e_var._parameters.min = _instrument_var._parameters.SAMBA_E0 - _instrument_var._parameters.SAMBA_dE;
  _SAMBA_DCM_out_e_var._parameters.max = _instrument_var._parameters.SAMBA_E0 + _instrument_var._parameters.SAMBA_dE;
  _SAMBA_DCM_out_e_var._parameters.restore_xray = 0;
  _SAMBA_DCM_out_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.geometry[0]='\0';
  _SAMBA_DCM_out_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_DCM_out_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_DCM_out_e_var._parameters.username9[0]='\0';


  /* component SAMBA_DCM_out_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_DCM_out_var._rotation_absolute, _SAMBA_DCM_out_e_var._rotation_absolute);
    rot_transpose(_SAMBA_DCM_out_div_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_DCM_out_e_var._rotation_absolute, tr1, _SAMBA_DCM_out_e_var._rotation_relative);
    _SAMBA_DCM_out_e_var._rotation_is_identity =  rot_test_identity(_SAMBA_DCM_out_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_DCM_out_e_var._position_absolute = coords_add(_SAMBA_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_DCM_out_div_var._position_absolute, _SAMBA_DCM_out_e_var._position_absolute);
    _SAMBA_DCM_out_e_var._position_relative = rot_apply(_SAMBA_DCM_out_e_var._rotation_absolute, tc1);
  } /* SAMBA_DCM_out_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_DCM_out_e", _SAMBA_DCM_out_e_var._position_absolute, _SAMBA_DCM_out_e_var._rotation_absolute);
  instrument->_position_absolute[267] = _SAMBA_DCM_out_e_var._position_absolute;
  instrument->_position_relative[267] = _SAMBA_DCM_out_e_var._position_relative;
    _SAMBA_DCM_out_e_var._position_relative_is_zero =  coords_test_zero(_SAMBA_DCM_out_e_var._position_relative);
  instrument->counter_N[267]  = instrument->counter_P[267] = instrument->counter_P2[267] = 0;
  instrument->counter_AbsorbProp[267]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0266_SAMBA_DCM_out_e", _SAMBA_DCM_out_e_var._position_absolute, _SAMBA_DCM_out_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "yheight", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "min", "-1e40", "_instrument_var._parameters.SAMBA_E0 - _instrument_var._parameters.SAMBA_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "max", "1e40", "_instrument_var._parameters.SAMBA_E0 + _instrument_var._parameters.SAMBA_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0266_SAMBA_DCM_out_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_DCM_out_e_setpos */

/* component SAMBA_M2_loc=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_M2_loc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M2_loc_setpos] component SAMBA_M2_loc=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_M2_loc_var._name, "SAMBA_M2_loc", 16384);
  stracpy(_SAMBA_M2_loc_var._type, "Arm", 16384);
  _SAMBA_M2_loc_var._index=268;
  int current_setpos_index = 268;
  /* component SAMBA_M2_loc=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_DCM_out_var._rotation_absolute, _SAMBA_M2_loc_var._rotation_absolute);
    rot_transpose(_SAMBA_DCM_out_e_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M2_loc_var._rotation_absolute, tr1, _SAMBA_M2_loc_var._rotation_relative);
    _SAMBA_M2_loc_var._rotation_is_identity =  rot_test_identity(_SAMBA_M2_loc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.5);
    rot_transpose(_SAMBA_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M2_loc_var._position_absolute = coords_add(_SAMBA_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_DCM_out_e_var._position_absolute, _SAMBA_M2_loc_var._position_absolute);
    _SAMBA_M2_loc_var._position_relative = rot_apply(_SAMBA_M2_loc_var._rotation_absolute, tc1);
  } /* SAMBA_M2_loc=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M2_loc", _SAMBA_M2_loc_var._position_absolute, _SAMBA_M2_loc_var._rotation_absolute);
  instrument->_position_absolute[268] = _SAMBA_M2_loc_var._position_absolute;
  instrument->_position_relative[268] = _SAMBA_M2_loc_var._position_relative;
    _SAMBA_M2_loc_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M2_loc_var._position_relative);
  instrument->counter_N[268]  = instrument->counter_P[268] = instrument->counter_P2[268] = 0;
  instrument->counter_AbsorbProp[268]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0267_SAMBA_M2_loc", _SAMBA_M2_loc_var._position_absolute, _SAMBA_M2_loc_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M2_loc_setpos */

/* component SAMBA_M2_rotated=Arm() SETTING, POSITION/ROTATION */
int _SAMBA_M2_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M2_rotated_setpos] component SAMBA_M2_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SAMBA_M2_rotated_var._name, "SAMBA_M2_rotated", 16384);
  stracpy(_SAMBA_M2_rotated_var._type, "Arm", 16384);
  _SAMBA_M2_rotated_var._index=269;
  int current_setpos_index = 269;
  /* component SAMBA_M2_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SAMBA_M2_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M2_loc_var._rotation_absolute, _SAMBA_M2_rotated_var._rotation_absolute);
    rot_transpose(_SAMBA_DCM_out_e_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M2_rotated_var._rotation_absolute, tr1, _SAMBA_M2_rotated_var._rotation_relative);
    _SAMBA_M2_rotated_var._rotation_is_identity =  rot_test_identity(_SAMBA_M2_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_M2_loc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M2_rotated_var._position_absolute = coords_add(_SAMBA_M2_loc_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_DCM_out_e_var._position_absolute, _SAMBA_M2_rotated_var._position_absolute);
    _SAMBA_M2_rotated_var._position_relative = rot_apply(_SAMBA_M2_rotated_var._rotation_absolute, tc1);
  } /* SAMBA_M2_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M2_rotated", _SAMBA_M2_rotated_var._position_absolute, _SAMBA_M2_rotated_var._rotation_absolute);
  instrument->_position_absolute[269] = _SAMBA_M2_rotated_var._position_absolute;
  instrument->_position_relative[269] = _SAMBA_M2_rotated_var._position_relative;
    _SAMBA_M2_rotated_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M2_rotated_var._position_relative);
  instrument->counter_N[269]  = instrument->counter_P[269] = instrument->counter_P2[269] = 0;
  instrument->counter_AbsorbProp[269]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0268_SAMBA_M2_rotated", _SAMBA_M2_rotated_var._position_absolute, _SAMBA_M2_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M2_rotated_setpos */

/* component SAMBA_M2=Mirror_curved() SETTING, POSITION/ROTATION */
int _SAMBA_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M2_setpos] component SAMBA_M2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SAMBA_M2_var._name, "SAMBA_M2", 16384);
  stracpy(_SAMBA_M2_var._type, "Mirror_curved", 16384);
  _SAMBA_M2_var._index=270;
  int current_setpos_index = 270;
  _SAMBA_M2_var._parameters.radius = SAMBA_M2_radius;
  _SAMBA_M2_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_SAMBA_M2_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _SAMBA_M2_var._parameters.coating[0]='\0';
  _SAMBA_M2_var._parameters.zdepth = 0.2;
  _SAMBA_M2_var._parameters.yheight = 0.2;
  _SAMBA_M2_var._parameters.length = 1.3;
  _SAMBA_M2_var._parameters.width = 0.12;


  /* component SAMBA_M2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M2_rotated_var._rotation_absolute, _SAMBA_M2_var._rotation_absolute);
    rot_transpose(_SAMBA_DCM_out_e_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M2_var._rotation_absolute, tr1, _SAMBA_M2_var._rotation_relative);
    _SAMBA_M2_var._rotation_is_identity =  rot_test_identity(_SAMBA_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M2_var._position_absolute = coords_add(_SAMBA_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_DCM_out_e_var._position_absolute, _SAMBA_M2_var._position_absolute);
    _SAMBA_M2_var._position_relative = rot_apply(_SAMBA_M2_var._rotation_absolute, tc1);
  } /* SAMBA_M2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M2", _SAMBA_M2_var._position_absolute, _SAMBA_M2_var._rotation_absolute);
  instrument->_position_absolute[270] = _SAMBA_M2_var._position_absolute;
  instrument->_position_relative[270] = _SAMBA_M2_var._position_relative;
    _SAMBA_M2_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M2_var._position_relative);
  instrument->counter_N[270]  = instrument->counter_P[270] = instrument->counter_P2[270] = 0;
  instrument->counter_AbsorbProp[270]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0269_SAMBA_M2", _SAMBA_M2_var._position_absolute, _SAMBA_M2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "radius", "1", "SAMBA_M2_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "length", "0", "1.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0269_SAMBA_M2", "width", "0", "0.12","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M2_setpos */

/* component SAMBA_M2_out=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_M2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_M2_out_setpos] component SAMBA_M2_out=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_M2_out_var._name, "SAMBA_M2_out", 16384);
  stracpy(_SAMBA_M2_out_var._type, "Monitor_nD", 16384);
  _SAMBA_M2_out_var._index=271;
  int current_setpos_index = 271;
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_M2_out_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.user9[0]='\0';
  _SAMBA_M2_out_var._parameters.xwidth = 0.02;
  _SAMBA_M2_out_var._parameters.yheight = 0.02;
  _SAMBA_M2_out_var._parameters.zdepth = 0;
  _SAMBA_M2_out_var._parameters.bins = 0;
  _SAMBA_M2_out_var._parameters.min = -1e40;
  _SAMBA_M2_out_var._parameters.max = 1e40;
  _SAMBA_M2_out_var._parameters.restore_xray = 1;
  _SAMBA_M2_out_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SAMBA_M2_out_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.geometry[0]='\0';
  _SAMBA_M2_out_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_M2_out_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_M2_out_var._parameters.username9[0]='\0';


  /* component SAMBA_M2_out=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SAMBA_M2_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M2_loc_var._rotation_absolute, _SAMBA_M2_out_var._rotation_absolute);
    rot_transpose(_SAMBA_M2_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_M2_out_var._rotation_absolute, tr1, _SAMBA_M2_out_var._rotation_relative);
    _SAMBA_M2_out_var._rotation_is_identity =  rot_test_identity(_SAMBA_M2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_M2_out_var._position_absolute = coords_add(_SAMBA_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_M2_var._position_absolute, _SAMBA_M2_out_var._position_absolute);
    _SAMBA_M2_out_var._position_relative = rot_apply(_SAMBA_M2_out_var._rotation_absolute, tc1);
  } /* SAMBA_M2_out=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_M2_out", _SAMBA_M2_out_var._position_absolute, _SAMBA_M2_out_var._rotation_absolute);
  instrument->_position_absolute[271] = _SAMBA_M2_out_var._position_absolute;
  instrument->_position_relative[271] = _SAMBA_M2_out_var._position_relative;
    _SAMBA_M2_out_var._position_relative_is_zero =  coords_test_zero(_SAMBA_M2_out_var._position_relative);
  instrument->counter_N[271]  = instrument->counter_P[271] = instrument->counter_P2[271] = 0;
  instrument->counter_AbsorbProp[271]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0270_SAMBA_M2_out", _SAMBA_M2_out_var._position_absolute, _SAMBA_M2_out_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0270_SAMBA_M2_out", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_M2_out_setpos */

/* component SAMBA_sample_stage=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_sample_stage_setpos] component SAMBA_sample_stage=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_sample_stage_var._name, "SAMBA_sample_stage", 16384);
  stracpy(_SAMBA_sample_stage_var._type, "Monitor_nD", 16384);
  _SAMBA_sample_stage_var._index=272;
  int current_setpos_index = 272;
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_sample_stage_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.user9[0]='\0';
  _SAMBA_sample_stage_var._parameters.xwidth = 0.02;
  _SAMBA_sample_stage_var._parameters.yheight = 0.02;
  _SAMBA_sample_stage_var._parameters.zdepth = 0;
  _SAMBA_sample_stage_var._parameters.bins = 0;
  _SAMBA_sample_stage_var._parameters.min = -1e40;
  _SAMBA_sample_stage_var._parameters.max = 1e40;
  _SAMBA_sample_stage_var._parameters.restore_xray = 1;
  _SAMBA_sample_stage_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SAMBA_sample_stage_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.geometry[0]='\0';
  _SAMBA_sample_stage_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_sample_stage_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_sample_stage_var._parameters.username9[0]='\0';


  /* component SAMBA_sample_stage=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_M2_out_var._rotation_absolute, _SAMBA_sample_stage_var._rotation_absolute);
    rot_transpose(_SAMBA_M2_out_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_sample_stage_var._rotation_absolute, tr1, _SAMBA_sample_stage_var._rotation_relative);
    _SAMBA_sample_stage_var._rotation_is_identity =  rot_test_identity(_SAMBA_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 11.5);
    rot_transpose(_SAMBA_M2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_sample_stage_var._position_absolute = coords_add(_SAMBA_M2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_M2_out_var._position_absolute, _SAMBA_sample_stage_var._position_absolute);
    _SAMBA_sample_stage_var._position_relative = rot_apply(_SAMBA_sample_stage_var._rotation_absolute, tc1);
  } /* SAMBA_sample_stage=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_sample_stage", _SAMBA_sample_stage_var._position_absolute, _SAMBA_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[272] = _SAMBA_sample_stage_var._position_absolute;
  instrument->_position_relative[272] = _SAMBA_sample_stage_var._position_relative;
    _SAMBA_sample_stage_var._position_relative_is_zero =  coords_test_zero(_SAMBA_sample_stage_var._position_relative);
  instrument->counter_N[272]  = instrument->counter_P[272] = instrument->counter_P2[272] = 0;
  instrument->counter_AbsorbProp[272]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0271_SAMBA_sample_stage", _SAMBA_sample_stage_var._position_absolute, _SAMBA_sample_stage_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0271_SAMBA_sample_stage", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_sample_stage_setpos */

/* component SAMBA_fluo=FluoPowder() SETTING, POSITION/ROTATION */
int _SAMBA_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_fluo_setpos] component SAMBA_fluo=FluoPowder() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");
  stracpy(_SAMBA_fluo_var._name, "SAMBA_fluo", 16384);
  stracpy(_SAMBA_fluo_var._type, "FluoPowder", 16384);
  _SAMBA_fluo_var._index=273;
  int current_setpos_index = 273;
  _SAMBA_fluo_var._parameters.geometry[0]='\0';
  _SAMBA_fluo_var._parameters.radius = 0;
  _SAMBA_fluo_var._parameters.thickness = 0;
  _SAMBA_fluo_var._parameters.xwidth = 0.002;
  _SAMBA_fluo_var._parameters.yheight = 0.002;
  _SAMBA_fluo_var._parameters.zdepth = 1e-5;
  _SAMBA_fluo_var._parameters.concentric = 0;
  if(_instrument_var._parameters.SAMBA_sample && strlen(_instrument_var._parameters.SAMBA_sample))
    stracpy(_SAMBA_fluo_var._parameters.material, _instrument_var._parameters.SAMBA_sample ? _instrument_var._parameters.SAMBA_sample : "", 16384);
  else 
  _SAMBA_fluo_var._parameters.material[0]='\0';
  _SAMBA_fluo_var._parameters.packing_factor = 0;
  _SAMBA_fluo_var._parameters.density = 0;
  _SAMBA_fluo_var._parameters.weight = 0;
  _SAMBA_fluo_var._parameters.p_interact = 1;
  _SAMBA_fluo_var._parameters.target_x = 0;
  _SAMBA_fluo_var._parameters.target_y = 0;
  _SAMBA_fluo_var._parameters.target_z = 1;
  _SAMBA_fluo_var._parameters.focus_r = 0;
  _SAMBA_fluo_var._parameters.focus_xw = 0;
  _SAMBA_fluo_var._parameters.focus_yh = 0;
  _SAMBA_fluo_var._parameters.focus_aw = 0;
  _SAMBA_fluo_var._parameters.focus_ah = 0;
  _SAMBA_fluo_var._parameters.target_index = 0;
  _SAMBA_fluo_var._parameters.flag_compton = 1;
  _SAMBA_fluo_var._parameters.flag_rayleigh = 1;
  _SAMBA_fluo_var._parameters.flag_lorentzian = 0;
  _SAMBA_fluo_var._parameters.flag_powder = 1;
  _SAMBA_fluo_var._parameters.flag_kissel = 0;
  if("" && strlen(""))
    stracpy(_SAMBA_fluo_var._parameters.powder_refl, "" ? "" : "", 16384);
  else 
  _SAMBA_fluo_var._parameters.powder_refl[0]='\0';
  _SAMBA_fluo_var._parameters.powder_format[0] = 0;
  _SAMBA_fluo_var._parameters.powder_format[1] = 0;
  _SAMBA_fluo_var._parameters.powder_format[2] = 0;
  _SAMBA_fluo_var._parameters.powder_format[3] = 0;
  _SAMBA_fluo_var._parameters.powder_format[4] = 0;
  _SAMBA_fluo_var._parameters.powder_format[5] = 0;
  _SAMBA_fluo_var._parameters.powder_format[6] = 0;
  _SAMBA_fluo_var._parameters.powder_format[7] = 0;
  _SAMBA_fluo_var._parameters.Vc = 0;
  _SAMBA_fluo_var._parameters.delta_d_d = 0;
  _SAMBA_fluo_var._parameters.DW = 0;
  _SAMBA_fluo_var._parameters.d_phi = 0;
  _SAMBA_fluo_var._parameters.nb_atoms = 1;
  _SAMBA_fluo_var._parameters.barns = 1;
  _SAMBA_fluo_var._parameters.tth_sign = 0;
  _SAMBA_fluo_var._parameters.order = 1;


  /* component SAMBA_fluo=FluoPowder() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_sample_stage_var._rotation_absolute, _SAMBA_fluo_var._rotation_absolute);
    rot_transpose(_SAMBA_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_fluo_var._rotation_absolute, tr1, _SAMBA_fluo_var._rotation_relative);
    _SAMBA_fluo_var._rotation_is_identity =  rot_test_identity(_SAMBA_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_fluo_var._position_absolute = coords_add(_SAMBA_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_sample_stage_var._position_absolute, _SAMBA_fluo_var._position_absolute);
    _SAMBA_fluo_var._position_relative = rot_apply(_SAMBA_fluo_var._rotation_absolute, tc1);
  } /* SAMBA_fluo=FluoPowder() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_fluo", _SAMBA_fluo_var._position_absolute, _SAMBA_fluo_var._rotation_absolute);
  instrument->_position_absolute[273] = _SAMBA_fluo_var._position_absolute;
  instrument->_position_relative[273] = _SAMBA_fluo_var._position_relative;
    _SAMBA_fluo_var._position_relative_is_zero =  coords_test_zero(_SAMBA_fluo_var._position_relative);
  instrument->counter_N[273]  = instrument->counter_P[273] = instrument->counter_P2[273] = 0;
  instrument->counter_AbsorbProp[273]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0272_SAMBA_fluo", _SAMBA_fluo_var._position_absolute, _SAMBA_fluo_var._rotation_absolute, "FluoPowder");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "xwidth", "0", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "yheight", "0", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "zdepth", "0", "1e-5","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "material", "LaB6.cif", _instrument_var._parameters.SAMBA_sample, "char*");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "p_interact", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "target_z", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "focus_aw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "focus_ah", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "flag_powder", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "powder_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "powder_format", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "Vc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "delta_d_d", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "DW", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "d_phi", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "nb_atoms", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "tth_sign", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0272_SAMBA_fluo", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_fluo_setpos */

/* component SAMBA_det_trans=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_det_trans_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_det_trans_setpos] component SAMBA_det_trans=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_det_trans_var._name, "SAMBA_det_trans", 16384);
  stracpy(_SAMBA_det_trans_var._type, "Monitor_nD", 16384);
  _SAMBA_det_trans_var._index=274;
  int current_setpos_index = 274;
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_trans_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.user9[0]='\0';
  _SAMBA_det_trans_var._parameters.xwidth = 0;
  _SAMBA_det_trans_var._parameters.yheight = 0;
  _SAMBA_det_trans_var._parameters.zdepth = 0;
  _SAMBA_det_trans_var._parameters.bins = 128;
  _SAMBA_det_trans_var._parameters.min = -1e40;
  _SAMBA_det_trans_var._parameters.max = 1e40;
  _SAMBA_det_trans_var._parameters.restore_xray = 0;
  _SAMBA_det_trans_var._parameters.radius = 0.1;
  if("energy" && strlen("energy"))
    stracpy(_SAMBA_det_trans_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.geometry[0]='\0';
  _SAMBA_det_trans_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_trans_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_trans_var._parameters.username9[0]='\0';


  /* component SAMBA_det_trans=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_sample_stage_var._rotation_absolute, _SAMBA_det_trans_var._rotation_absolute);
    rot_transpose(_SAMBA_fluo_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_det_trans_var._rotation_absolute, tr1, _SAMBA_det_trans_var._rotation_relative);
    _SAMBA_det_trans_var._rotation_is_identity =  rot_test_identity(_SAMBA_det_trans_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1);
    rot_transpose(_SAMBA_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_det_trans_var._position_absolute = coords_add(_SAMBA_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_fluo_var._position_absolute, _SAMBA_det_trans_var._position_absolute);
    _SAMBA_det_trans_var._position_relative = rot_apply(_SAMBA_det_trans_var._rotation_absolute, tc1);
  } /* SAMBA_det_trans=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_det_trans", _SAMBA_det_trans_var._position_absolute, _SAMBA_det_trans_var._rotation_absolute);
  instrument->_position_absolute[274] = _SAMBA_det_trans_var._position_absolute;
  instrument->_position_relative[274] = _SAMBA_det_trans_var._position_relative;
    _SAMBA_det_trans_var._position_relative_is_zero =  coords_test_zero(_SAMBA_det_trans_var._position_relative);
  instrument->counter_N[274]  = instrument->counter_P[274] = instrument->counter_P2[274] = 0;
  instrument->counter_AbsorbProp[274]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0273_SAMBA_det_trans", _SAMBA_det_trans_var._position_absolute, _SAMBA_det_trans_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "radius", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0273_SAMBA_det_trans", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_det_trans_setpos */

/* component SAMBA_det_fluo=Monitor_nD() SETTING, POSITION/ROTATION */
int _SAMBA_det_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SAMBA_det_fluo_setpos] component SAMBA_det_fluo=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SAMBA_det_fluo_var._name, "SAMBA_det_fluo", 16384);
  stracpy(_SAMBA_det_fluo_var._type, "Monitor_nD", 16384);
  _SAMBA_det_fluo_var._index=275;
  int current_setpos_index = 275;
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SAMBA_det_fluo_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.user9[0]='\0';
  _SAMBA_det_fluo_var._parameters.xwidth = 0;
  _SAMBA_det_fluo_var._parameters.yheight = 0;
  _SAMBA_det_fluo_var._parameters.zdepth = 0;
  _SAMBA_det_fluo_var._parameters.bins = 128;
  _SAMBA_det_fluo_var._parameters.min = -1e40;
  _SAMBA_det_fluo_var._parameters.max = 1e40;
  _SAMBA_det_fluo_var._parameters.restore_xray = 0;
  _SAMBA_det_fluo_var._parameters.radius = 0.1;
  if("energy" && strlen("energy"))
    stracpy(_SAMBA_det_fluo_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.geometry[0]='\0';
  _SAMBA_det_fluo_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SAMBA_det_fluo_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SAMBA_det_fluo_var._parameters.username9[0]='\0';


  /* component SAMBA_det_fluo=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_sample_stage_var._rotation_absolute, _SAMBA_det_fluo_var._rotation_absolute);
    rot_transpose(_SAMBA_det_trans_var._rotation_absolute, tr1);
    rot_mul(_SAMBA_det_fluo_var._rotation_absolute, tr1, _SAMBA_det_fluo_var._rotation_relative);
    _SAMBA_det_fluo_var._rotation_is_identity =  rot_test_identity(_SAMBA_det_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1);
    rot_transpose(_SAMBA_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SAMBA_det_fluo_var._position_absolute = coords_add(_SAMBA_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_det_trans_var._position_absolute, _SAMBA_det_fluo_var._position_absolute);
    _SAMBA_det_fluo_var._position_relative = rot_apply(_SAMBA_det_fluo_var._rotation_absolute, tc1);
  } /* SAMBA_det_fluo=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SAMBA_det_fluo", _SAMBA_det_fluo_var._position_absolute, _SAMBA_det_fluo_var._rotation_absolute);
  instrument->_position_absolute[275] = _SAMBA_det_fluo_var._position_absolute;
  instrument->_position_relative[275] = _SAMBA_det_fluo_var._position_relative;
    _SAMBA_det_fluo_var._position_relative_is_zero =  coords_test_zero(_SAMBA_det_fluo_var._position_relative);
  instrument->counter_N[275]  = instrument->counter_P[275] = instrument->counter_P2[275] = 0;
  instrument->counter_AbsorbProp[275]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0274_SAMBA_det_fluo", _SAMBA_det_fluo_var._position_absolute, _SAMBA_det_fluo_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "radius", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0274_SAMBA_det_fluo", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SAMBA_det_fluo_setpos */

/* component beamdump_283=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_283_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_283_setpos] component beamdump_283=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_283_var._name, "beamdump_283", 16384);
  stracpy(_beamdump_283_var._type, "Beamstop", 16384);
  _beamdump_283_var._index=276;
  int current_setpos_index = 276;
  _beamdump_283_var._parameters.xmin = -0.05;
  _beamdump_283_var._parameters.xmax = 0.05;
  _beamdump_283_var._parameters.ymin = -0.05;
  _beamdump_283_var._parameters.ymax = 0.05;
  _beamdump_283_var._parameters.xwidth = 0;
  _beamdump_283_var._parameters.yheight = 0;
  _beamdump_283_var._parameters.radius = 0;

  /* component beamdump_283=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SAMBA_det_fluo_var._rotation_absolute, _beamdump_283_var._rotation_absolute);
    rot_transpose(_SAMBA_det_fluo_var._rotation_absolute, tr1);
    rot_mul(_beamdump_283_var._rotation_absolute, tr1, _beamdump_283_var._rotation_relative);
    _beamdump_283_var._rotation_is_identity =  rot_test_identity(_beamdump_283_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SAMBA_det_fluo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_283_var._position_absolute = coords_add(_SAMBA_det_fluo_var._position_absolute, tc2);
    tc1 = coords_sub(_SAMBA_det_fluo_var._position_absolute, _beamdump_283_var._position_absolute);
    _beamdump_283_var._position_relative = rot_apply(_beamdump_283_var._rotation_absolute, tc1);
  } /* beamdump_283=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_283", _beamdump_283_var._position_absolute, _beamdump_283_var._rotation_absolute);
  instrument->_position_absolute[276] = _beamdump_283_var._position_absolute;
  instrument->_position_relative[276] = _beamdump_283_var._position_relative;
    _beamdump_283_var._position_relative_is_zero =  coords_test_zero(_beamdump_283_var._position_relative);
  instrument->counter_N[276]  = instrument->counter_P[276] = instrument->counter_P2[276] = 0;
  instrument->counter_AbsorbProp[276]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0275_beamdump_283", _beamdump_283_var._position_absolute, _beamdump_283_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0275_beamdump_283", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_283_setpos */

/* component HERMES_pos=Text() SETTING, POSITION/ROTATION */
int _HERMES_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_HERMES_pos_setpos] component HERMES_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_HERMES_pos_var._name, "HERMES_pos", 16384);
  stracpy(_HERMES_pos_var._type, "Text", 16384);
  _HERMES_pos_var._index=277;
  int current_setpos_index = 277;
  if("HERMES" && strlen("HERMES"))
    stracpy(_HERMES_pos_var._parameters.text, "HERMES" ? "HERMES" : "", 16384);
  else 
  _HERMES_pos_var._parameters.text[0]='\0';
  _HERMES_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_HERMES_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _HERMES_pos_var._parameters.plane[0]='\0';
  _HERMES_pos_var._parameters.pen_thickness = 0.1;


  /* component HERMES_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-202.454)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _HERMES_pos_var._rotation_absolute);
    rot_transpose(_beamdump_283_var._rotation_absolute, tr1);
    rot_mul(_HERMES_pos_var._rotation_absolute, tr1, _HERMES_pos_var._rotation_relative);
    _HERMES_pos_var._rotation_is_identity =  rot_test_identity(_HERMES_pos_var._rotation_relative);
    tc1 = coords_set(
      -52.07, 0, -21.52);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _HERMES_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_283_var._position_absolute, _HERMES_pos_var._position_absolute);
    _HERMES_pos_var._position_relative = rot_apply(_HERMES_pos_var._rotation_absolute, tc1);
  } /* HERMES_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("HERMES_pos", _HERMES_pos_var._position_absolute, _HERMES_pos_var._rotation_absolute);
  instrument->_position_absolute[277] = _HERMES_pos_var._position_absolute;
  instrument->_position_relative[277] = _HERMES_pos_var._position_relative;
    _HERMES_pos_var._position_relative_is_zero =  coords_test_zero(_HERMES_pos_var._position_relative);
  instrument->counter_N[277]  = instrument->counter_P[277] = instrument->counter_P2[277] = 0;
  instrument->counter_AbsorbProp[277]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0276_HERMES_pos", _HERMES_pos_var._position_absolute, _HERMES_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0276_HERMES_pos", "text", "NONE", "HERMES", "char*");
        mccomp_param_nexus(nxhandle,"0276_HERMES_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0276_HERMES_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0276_HERMES_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _HERMES_pos_setpos */

/* component PX1_pos=Text() SETTING, POSITION/ROTATION */
int _PX1_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_pos_setpos] component PX1_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_PX1_pos_var._name, "PX1_pos", 16384);
  stracpy(_PX1_pos_var._type, "Text", 16384);
  _PX1_pos_var._index=278;
  int current_setpos_index = 278;
  if("PX1" && strlen("PX1"))
    stracpy(_PX1_pos_var._parameters.text, "PX1" ? "PX1" : "", 16384);
  else 
  _PX1_pos_var._parameters.text[0]='\0';
  _PX1_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_PX1_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _PX1_pos_var._parameters.plane[0]='\0';
  _PX1_pos_var._parameters.pen_thickness = 0.1;


  /* component PX1_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-213.834)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _PX1_pos_var._rotation_absolute);
    rot_transpose(_HERMES_pos_var._rotation_absolute, tr1);
    rot_mul(_PX1_pos_var._rotation_absolute, tr1, _PX1_pos_var._rotation_relative);
    _PX1_pos_var._rotation_is_identity =  rot_test_identity(_PX1_pos_var._rotation_relative);
    tc1 = coords_set(
      -46.80, 0, -31.37);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_HERMES_pos_var._position_absolute, _PX1_pos_var._position_absolute);
    _PX1_pos_var._position_relative = rot_apply(_PX1_pos_var._rotation_absolute, tc1);
  } /* PX1_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("PX1_pos", _PX1_pos_var._position_absolute, _PX1_pos_var._rotation_absolute);
  instrument->_position_absolute[278] = _PX1_pos_var._position_absolute;
  instrument->_position_relative[278] = _PX1_pos_var._position_relative;
    _PX1_pos_var._position_relative_is_zero =  coords_test_zero(_PX1_pos_var._position_relative);
  instrument->counter_N[278]  = instrument->counter_P[278] = instrument->counter_P2[278] = 0;
  instrument->counter_AbsorbProp[278]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0277_PX1_pos", _PX1_pos_var._position_absolute, _PX1_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0277_PX1_pos", "text", "NONE", "PX1", "char*");
        mccomp_param_nexus(nxhandle,"0277_PX1_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0277_PX1_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0277_PX1_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_pos_setpos */

/* component PX1=Arm() SETTING, POSITION/ROTATION */
int _PX1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_setpos] component PX1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX1_var._name, "PX1", 16384);
  stracpy(_PX1_var._type, "Arm", 16384);
  _PX1_var._index=279;
  int current_setpos_index = 279;
  /* component PX1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_pos_var._rotation_absolute, _PX1_var._rotation_absolute);
    rot_transpose(_PX1_pos_var._rotation_absolute, tr1);
    rot_mul(_PX1_var._rotation_absolute, tr1, _PX1_var._rotation_relative);
    _PX1_var._rotation_is_identity =  rot_test_identity(_PX1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_var._position_absolute = coords_add(_PX1_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_pos_var._position_absolute, _PX1_var._position_absolute);
    _PX1_var._position_relative = rot_apply(_PX1_var._rotation_absolute, tc1);
  } /* PX1=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX1", _PX1_var._position_absolute, _PX1_var._rotation_absolute);
  instrument->_position_absolute[279] = _PX1_var._position_absolute;
  instrument->_position_relative[279] = _PX1_var._position_relative;
    _PX1_var._position_relative_is_zero =  coords_test_zero(_PX1_var._position_relative);
  instrument->counter_N[279]  = instrument->counter_P[279] = instrument->counter_P2[279] = 0;
  instrument->counter_AbsorbProp[279]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0278_PX1", _PX1_var._position_absolute, _PX1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_setpos */

/* component PX1_undulator=Undulator() SETTING, POSITION/ROTATION */
int _PX1_undulator_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_undulator_setpos] component PX1_undulator=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_PX1_undulator_var._name, "PX1_undulator", 16384);
  stracpy(_PX1_undulator_var._type, "Undulator", 16384);
  _PX1_undulator_var._index=280;
  int current_setpos_index = 280;
  _PX1_undulator_var._parameters.E0 = _instrument_var._parameters.PX1_E0;
  _PX1_undulator_var._parameters.dE = _instrument_var._parameters.PX1_dE;
  _PX1_undulator_var._parameters.phase = 0;
  _PX1_undulator_var._parameters.randomphase = 1;
  _PX1_undulator_var._parameters.Ee = 2.75;
  _PX1_undulator_var._parameters.dEe = 0.001;
  _PX1_undulator_var._parameters.Ie = 0.5;
  _PX1_undulator_var._parameters.B = 0;
  _PX1_undulator_var._parameters.K = _instrument_var._parameters.PX1_K;
  _PX1_undulator_var._parameters.Nper = 100;
  _PX1_undulator_var._parameters.lu = 2.0e-2;
  _PX1_undulator_var._parameters.sigey = 6.4e-6;
  _PX1_undulator_var._parameters.sigex = 90.5e-6;
  _PX1_undulator_var._parameters.sigepx = 41.3e-6;
  _PX1_undulator_var._parameters.sigepy = 5.9e-6;
  _PX1_undulator_var._parameters.focus_xw = 0;
  _PX1_undulator_var._parameters.focus_yh = 0;
  _PX1_undulator_var._parameters.dist = 16.397;
  _PX1_undulator_var._parameters.quick_integ = 0;
  _PX1_undulator_var._parameters.E1st = 0;
  _PX1_undulator_var._parameters.verbose = 0;
  _PX1_undulator_var._parameters.Br = 1.35;


  /* component PX1_undulator=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_var._rotation_absolute, _PX1_undulator_var._rotation_absolute);
    rot_transpose(_PX1_var._rotation_absolute, tr1);
    rot_mul(_PX1_undulator_var._rotation_absolute, tr1, _PX1_undulator_var._rotation_relative);
    _PX1_undulator_var._rotation_is_identity =  rot_test_identity(_PX1_undulator_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_undulator_var._position_absolute = coords_add(_PX1_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_var._position_absolute, _PX1_undulator_var._position_absolute);
    _PX1_undulator_var._position_relative = rot_apply(_PX1_undulator_var._rotation_absolute, tc1);
  } /* PX1_undulator=Undulator() AT ROTATED */
  DEBUG_COMPONENT("PX1_undulator", _PX1_undulator_var._position_absolute, _PX1_undulator_var._rotation_absolute);
  instrument->_position_absolute[280] = _PX1_undulator_var._position_absolute;
  instrument->_position_relative[280] = _PX1_undulator_var._position_relative;
    _PX1_undulator_var._position_relative_is_zero =  coords_test_zero(_PX1_undulator_var._position_relative);
  instrument->counter_N[280]  = instrument->counter_P[280] = instrument->counter_P2[280] = 0;
  instrument->counter_AbsorbProp[280]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0279_PX1_undulator", _PX1_undulator_var._position_absolute, _PX1_undulator_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "E0", "0", "_instrument_var._parameters.PX1_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "dE", "0", "_instrument_var._parameters.PX1_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "dEe", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "K", "0", "_instrument_var._parameters.PX1_K","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "Nper", "1", "100","int");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "lu", "16e-3", "2.0e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "sigey", "0", "6.4e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "sigex", "0", "90.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "sigepx", "0", "41.3e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "sigepy", "0", "5.9e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "dist", "1", "16.397","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0279_PX1_undulator", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_undulator_setpos */

/* component PX1_bragg_crystal_location=Arm() SETTING, POSITION/ROTATION */
int _PX1_bragg_crystal_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_bragg_crystal_location_setpos] component PX1_bragg_crystal_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX1_bragg_crystal_location_var._name, "PX1_bragg_crystal_location", 16384);
  stracpy(_PX1_bragg_crystal_location_var._type, "Arm", 16384);
  _PX1_bragg_crystal_location_var._index=281;
  int current_setpos_index = 281;
  /* component PX1_bragg_crystal_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_undulator_var._rotation_absolute, _PX1_bragg_crystal_location_var._rotation_absolute);
    rot_transpose(_PX1_undulator_var._rotation_absolute, tr1);
    rot_mul(_PX1_bragg_crystal_location_var._rotation_absolute, tr1, _PX1_bragg_crystal_location_var._rotation_relative);
    _PX1_bragg_crystal_location_var._rotation_is_identity =  rot_test_identity(_PX1_bragg_crystal_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 16.397);
    rot_transpose(_PX1_undulator_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_bragg_crystal_location_var._position_absolute = coords_add(_PX1_undulator_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_undulator_var._position_absolute, _PX1_bragg_crystal_location_var._position_absolute);
    _PX1_bragg_crystal_location_var._position_relative = rot_apply(_PX1_bragg_crystal_location_var._rotation_absolute, tc1);
  } /* PX1_bragg_crystal_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX1_bragg_crystal_location", _PX1_bragg_crystal_location_var._position_absolute, _PX1_bragg_crystal_location_var._rotation_absolute);
  instrument->_position_absolute[281] = _PX1_bragg_crystal_location_var._position_absolute;
  instrument->_position_relative[281] = _PX1_bragg_crystal_location_var._position_relative;
    _PX1_bragg_crystal_location_var._position_relative_is_zero =  coords_test_zero(_PX1_bragg_crystal_location_var._position_relative);
  instrument->counter_N[281]  = instrument->counter_P[281] = instrument->counter_P2[281] = 0;
  instrument->counter_AbsorbProp[281]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0280_PX1_bragg_crystal_location", _PX1_bragg_crystal_location_var._position_absolute, _PX1_bragg_crystal_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_bragg_crystal_location_setpos */

/* component PX1_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PX1_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_bragg_crystal_setpos] component PX1_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PX1_bragg_crystal_var._name, "PX1_bragg_crystal", 16384);
  stracpy(_PX1_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _PX1_bragg_crystal_var._index=282;
  int current_setpos_index = 282;
  _PX1_bragg_crystal_var._parameters.length = 0.05;
  _PX1_bragg_crystal_var._parameters.width = 0.02;
  _PX1_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PX1_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PX1_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PX1_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PX1_bragg_crystal_var._parameters.material[0]='\0';
  _PX1_bragg_crystal_var._parameters.alpha = 0.0;
  _PX1_bragg_crystal_var._parameters.R0 = 0;
  _PX1_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _PX1_bragg_crystal_var._parameters.crystal_type = 2;
  _PX1_bragg_crystal_var._parameters.h = 1;
  _PX1_bragg_crystal_var._parameters.k = 1;
  _PX1_bragg_crystal_var._parameters.l = 1;
  _PX1_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _PX1_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component PX1_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- PX1_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_bragg_crystal_location_var._rotation_absolute, _PX1_bragg_crystal_var._rotation_absolute);
    rot_transpose(_PX1_undulator_var._rotation_absolute, tr1);
    rot_mul(_PX1_bragg_crystal_var._rotation_absolute, tr1, _PX1_bragg_crystal_var._rotation_relative);
    _PX1_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_PX1_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_bragg_crystal_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_bragg_crystal_var._position_absolute = coords_add(_PX1_bragg_crystal_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_undulator_var._position_absolute, _PX1_bragg_crystal_var._position_absolute);
    _PX1_bragg_crystal_var._position_relative = rot_apply(_PX1_bragg_crystal_var._rotation_absolute, tc1);
  } /* PX1_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PX1_bragg_crystal", _PX1_bragg_crystal_var._position_absolute, _PX1_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[282] = _PX1_bragg_crystal_var._position_absolute;
  instrument->_position_relative[282] = _PX1_bragg_crystal_var._position_relative;
    _PX1_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_PX1_bragg_crystal_var._position_relative);
  instrument->counter_N[282]  = instrument->counter_P[282] = instrument->counter_P2[282] = 0;
  instrument->counter_AbsorbProp[282]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0281_PX1_bragg_crystal", _PX1_bragg_crystal_var._position_absolute, _PX1_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0281_PX1_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_bragg_crystal_setpos */

/* component PX1_arm=Arm() SETTING, POSITION/ROTATION */
int _PX1_arm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_arm_setpos] component PX1_arm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX1_arm_var._name, "PX1_arm", 16384);
  stracpy(_PX1_arm_var._type, "Arm", 16384);
  _PX1_arm_var._index=283;
  int current_setpos_index = 283;
  /* component PX1_arm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- PX1_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_bragg_crystal_var._rotation_absolute, _PX1_arm_var._rotation_absolute);
    rot_transpose(_PX1_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_PX1_arm_var._rotation_absolute, tr1, _PX1_arm_var._rotation_relative);
    _PX1_arm_var._rotation_is_identity =  rot_test_identity(_PX1_arm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_arm_var._position_absolute = coords_add(_PX1_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_bragg_crystal_var._position_absolute, _PX1_arm_var._position_absolute);
    _PX1_arm_var._position_relative = rot_apply(_PX1_arm_var._rotation_absolute, tc1);
  } /* PX1_arm=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX1_arm", _PX1_arm_var._position_absolute, _PX1_arm_var._rotation_absolute);
  instrument->_position_absolute[283] = _PX1_arm_var._position_absolute;
  instrument->_position_relative[283] = _PX1_arm_var._position_relative;
    _PX1_arm_var._position_relative_is_zero =  coords_test_zero(_PX1_arm_var._position_relative);
  instrument->counter_N[283]  = instrument->counter_P[283] = instrument->counter_P2[283] = 0;
  instrument->counter_AbsorbProp[283]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0282_PX1_arm", _PX1_arm_var._position_absolute, _PX1_arm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_arm_setpos */

/* component PX1_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PX1_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_bragg_crystal_two_setpos] component PX1_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PX1_bragg_crystal_two_var._name, "PX1_bragg_crystal_two", 16384);
  stracpy(_PX1_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _PX1_bragg_crystal_two_var._index=284;
  int current_setpos_index = 284;
  _PX1_bragg_crystal_two_var._parameters.length = 0.05;
  _PX1_bragg_crystal_two_var._parameters.width = 0.02;
  _PX1_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PX1_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PX1_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PX1_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PX1_bragg_crystal_two_var._parameters.material[0]='\0';
  _PX1_bragg_crystal_two_var._parameters.alpha = 0.0;
  _PX1_bragg_crystal_two_var._parameters.R0 = 0;
  _PX1_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _PX1_bragg_crystal_two_var._parameters.crystal_type = 2;
  _PX1_bragg_crystal_two_var._parameters.h = 1;
  _PX1_bragg_crystal_two_var._parameters.k = 1;
  _PX1_bragg_crystal_two_var._parameters.l = 1;
  _PX1_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _PX1_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component PX1_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (PX1_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_arm_var._rotation_absolute, _PX1_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_PX1_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_PX1_bragg_crystal_two_var._rotation_absolute, tr1, _PX1_bragg_crystal_two_var._rotation_relative);
    _PX1_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_PX1_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0.006, PX1_calculated_angle ? 0.006 / tan ( PX1_calculated_angle * DEG2RAD ) : 0);
    rot_transpose(_PX1_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_bragg_crystal_two_var._position_absolute = coords_add(_PX1_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_bragg_crystal_var._position_absolute, _PX1_bragg_crystal_two_var._position_absolute);
    _PX1_bragg_crystal_two_var._position_relative = rot_apply(_PX1_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* PX1_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PX1_bragg_crystal_two", _PX1_bragg_crystal_two_var._position_absolute, _PX1_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[284] = _PX1_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[284] = _PX1_bragg_crystal_two_var._position_relative;
    _PX1_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_PX1_bragg_crystal_two_var._position_relative);
  instrument->counter_N[284]  = instrument->counter_P[284] = instrument->counter_P2[284] = 0;
  instrument->counter_AbsorbProp[284]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0283_PX1_bragg_crystal_two", _PX1_bragg_crystal_two_var._position_absolute, _PX1_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0283_PX1_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_bragg_crystal_two_setpos */

/* component PX1_arm_two=Arm() SETTING, POSITION/ROTATION */
int _PX1_arm_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_arm_two_setpos] component PX1_arm_two=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX1_arm_two_var._name, "PX1_arm_two", 16384);
  stracpy(_PX1_arm_two_var._type, "Arm", 16384);
  _PX1_arm_two_var._index=285;
  int current_setpos_index = 285;
  /* component PX1_arm_two=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (PX1_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_bragg_crystal_two_var._rotation_absolute, _PX1_arm_two_var._rotation_absolute);
    rot_transpose(_PX1_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_PX1_arm_two_var._rotation_absolute, tr1, _PX1_arm_two_var._rotation_relative);
    _PX1_arm_two_var._rotation_is_identity =  rot_test_identity(_PX1_arm_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_arm_two_var._position_absolute = coords_add(_PX1_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_bragg_crystal_two_var._position_absolute, _PX1_arm_two_var._position_absolute);
    _PX1_arm_two_var._position_relative = rot_apply(_PX1_arm_two_var._rotation_absolute, tc1);
  } /* PX1_arm_two=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX1_arm_two", _PX1_arm_two_var._position_absolute, _PX1_arm_two_var._rotation_absolute);
  instrument->_position_absolute[285] = _PX1_arm_two_var._position_absolute;
  instrument->_position_relative[285] = _PX1_arm_two_var._position_relative;
    _PX1_arm_two_var._position_relative_is_zero =  coords_test_zero(_PX1_arm_two_var._position_relative);
  instrument->counter_N[285]  = instrument->counter_P[285] = instrument->counter_P2[285] = 0;
  instrument->counter_AbsorbProp[285]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0284_PX1_arm_two", _PX1_arm_two_var._position_absolute, _PX1_arm_two_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_arm_two_setpos */

/* component PX1_bragg_crystal_out=E_monitor() SETTING, POSITION/ROTATION */
int _PX1_bragg_crystal_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_bragg_crystal_out_setpos] component PX1_bragg_crystal_out=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_PX1_bragg_crystal_out_var._name, "PX1_bragg_crystal_out", 16384);
  stracpy(_PX1_bragg_crystal_out_var._type, "E_monitor", 16384);
  _PX1_bragg_crystal_out_var._index=286;
  int current_setpos_index = 286;
  _PX1_bragg_crystal_out_var._parameters.nE = 512;
  _PX1_bragg_crystal_out_var._parameters.filename[0]='\0';
  _PX1_bragg_crystal_out_var._parameters.xwidth = 0.1;
  _PX1_bragg_crystal_out_var._parameters.yheight = 0.1;
  _PX1_bragg_crystal_out_var._parameters.Emin = _instrument_var._parameters.PX1_E0 - _instrument_var._parameters.PX1_dE;
  _PX1_bragg_crystal_out_var._parameters.Emax = _instrument_var._parameters.PX1_E0 + _instrument_var._parameters.PX1_dE;
  _PX1_bragg_crystal_out_var._parameters.restore_xray = 0;


  /* component PX1_bragg_crystal_out=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_arm_two_var._rotation_absolute, _PX1_bragg_crystal_out_var._rotation_absolute);
    rot_transpose(_PX1_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_PX1_bragg_crystal_out_var._rotation_absolute, tr1, _PX1_bragg_crystal_out_var._rotation_relative);
    _PX1_bragg_crystal_out_var._rotation_is_identity =  rot_test_identity(_PX1_bragg_crystal_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_PX1_arm_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_bragg_crystal_out_var._position_absolute = coords_add(_PX1_arm_two_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_bragg_crystal_two_var._position_absolute, _PX1_bragg_crystal_out_var._position_absolute);
    _PX1_bragg_crystal_out_var._position_relative = rot_apply(_PX1_bragg_crystal_out_var._rotation_absolute, tc1);
  } /* PX1_bragg_crystal_out=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("PX1_bragg_crystal_out", _PX1_bragg_crystal_out_var._position_absolute, _PX1_bragg_crystal_out_var._rotation_absolute);
  instrument->_position_absolute[286] = _PX1_bragg_crystal_out_var._position_absolute;
  instrument->_position_relative[286] = _PX1_bragg_crystal_out_var._position_relative;
    _PX1_bragg_crystal_out_var._position_relative_is_zero =  coords_test_zero(_PX1_bragg_crystal_out_var._position_relative);
  instrument->counter_N[286]  = instrument->counter_P[286] = instrument->counter_P2[286] = 0;
  instrument->counter_AbsorbProp[286]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0285_PX1_bragg_crystal_out", _PX1_bragg_crystal_out_var._position_absolute, _PX1_bragg_crystal_out_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "nE", "20", "512","MCNUM");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "Emin", "NONE", "_instrument_var._parameters.PX1_E0 - _instrument_var._parameters.PX1_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "Emax", "NONE", "_instrument_var._parameters.PX1_E0 + _instrument_var._parameters.PX1_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0285_PX1_bragg_crystal_out", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_bragg_crystal_out_setpos */

/* component PX1_secondary_slits=Slit() SETTING, POSITION/ROTATION */
int _PX1_secondary_slits_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_secondary_slits_setpos] component PX1_secondary_slits=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_PX1_secondary_slits_var._name, "PX1_secondary_slits", 16384);
  stracpy(_PX1_secondary_slits_var._type, "Slit", 16384);
  _PX1_secondary_slits_var._index=287;
  int current_setpos_index = 287;
  _PX1_secondary_slits_var._parameters.xmin = 0;
  _PX1_secondary_slits_var._parameters.xmax = 0;
  _PX1_secondary_slits_var._parameters.ymin = 0;
  _PX1_secondary_slits_var._parameters.ymax = 0;
  _PX1_secondary_slits_var._parameters.radius = 0;
  _PX1_secondary_slits_var._parameters.xwidth = 1e-3;
  _PX1_secondary_slits_var._parameters.yheight = 1e-3;
  _PX1_secondary_slits_var._parameters.dist = 0;
  _PX1_secondary_slits_var._parameters.focus_xw = 0;
  _PX1_secondary_slits_var._parameters.focus_yh = 0;
  _PX1_secondary_slits_var._parameters.focus_x0 = 0;
  _PX1_secondary_slits_var._parameters.focus_y0 = 0;

  /* component PX1_secondary_slits=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_arm_two_var._rotation_absolute, _PX1_secondary_slits_var._rotation_absolute);
    rot_transpose(_PX1_bragg_crystal_out_var._rotation_absolute, tr1);
    rot_mul(_PX1_secondary_slits_var._rotation_absolute, tr1, _PX1_secondary_slits_var._rotation_relative);
    _PX1_secondary_slits_var._rotation_is_identity =  rot_test_identity(_PX1_secondary_slits_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 18.5 -16.397);
    rot_transpose(_PX1_arm_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_secondary_slits_var._position_absolute = coords_add(_PX1_arm_two_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_bragg_crystal_out_var._position_absolute, _PX1_secondary_slits_var._position_absolute);
    _PX1_secondary_slits_var._position_relative = rot_apply(_PX1_secondary_slits_var._rotation_absolute, tc1);
  } /* PX1_secondary_slits=Slit() AT ROTATED */
  DEBUG_COMPONENT("PX1_secondary_slits", _PX1_secondary_slits_var._position_absolute, _PX1_secondary_slits_var._rotation_absolute);
  instrument->_position_absolute[287] = _PX1_secondary_slits_var._position_absolute;
  instrument->_position_relative[287] = _PX1_secondary_slits_var._position_relative;
    _PX1_secondary_slits_var._position_relative_is_zero =  coords_test_zero(_PX1_secondary_slits_var._position_relative);
  instrument->counter_N[287]  = instrument->counter_P[287] = instrument->counter_P2[287] = 0;
  instrument->counter_AbsorbProp[287]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0286_PX1_secondary_slits", _PX1_secondary_slits_var._position_absolute, _PX1_secondary_slits_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "xwidth", "0.001", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "yheight", "0.001", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0286_PX1_secondary_slits", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_secondary_slits_setpos */

/* component PX1_vfm_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX1_vfm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_vfm_location_setpos] component PX1_vfm_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX1_vfm_location_var._name, "PX1_vfm_location", 16384);
  stracpy(_PX1_vfm_location_var._type, "Monitor_nD", 16384);
  _PX1_vfm_location_var._index=288;
  int current_setpos_index = 288;
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.user9[0]='\0';
  _PX1_vfm_location_var._parameters.xwidth = 0.01;
  _PX1_vfm_location_var._parameters.yheight = 0.01;
  _PX1_vfm_location_var._parameters.zdepth = 0;
  _PX1_vfm_location_var._parameters.bins = 100;
  _PX1_vfm_location_var._parameters.min = -1e40;
  _PX1_vfm_location_var._parameters.max = 1e40;
  _PX1_vfm_location_var._parameters.restore_xray = 0;
  _PX1_vfm_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX1_vfm_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.geometry[0]='\0';
  _PX1_vfm_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_location_var._parameters.username9[0]='\0';


  /* component PX1_vfm_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_secondary_slits_var._rotation_absolute, _PX1_vfm_location_var._rotation_absolute);
    rot_transpose(_PX1_secondary_slits_var._rotation_absolute, tr1);
    rot_mul(_PX1_vfm_location_var._rotation_absolute, tr1, _PX1_vfm_location_var._rotation_relative);
    _PX1_vfm_location_var._rotation_is_identity =  rot_test_identity(_PX1_vfm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 21.45 -18.5);
    rot_transpose(_PX1_secondary_slits_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_vfm_location_var._position_absolute = coords_add(_PX1_secondary_slits_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_secondary_slits_var._position_absolute, _PX1_vfm_location_var._position_absolute);
    _PX1_vfm_location_var._position_relative = rot_apply(_PX1_vfm_location_var._rotation_absolute, tc1);
  } /* PX1_vfm_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX1_vfm_location", _PX1_vfm_location_var._position_absolute, _PX1_vfm_location_var._rotation_absolute);
  instrument->_position_absolute[288] = _PX1_vfm_location_var._position_absolute;
  instrument->_position_relative[288] = _PX1_vfm_location_var._position_relative;
    _PX1_vfm_location_var._position_relative_is_zero =  coords_test_zero(_PX1_vfm_location_var._position_relative);
  instrument->counter_N[288]  = instrument->counter_P[288] = instrument->counter_P2[288] = 0;
  instrument->counter_AbsorbProp[288]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0287_PX1_vfm_location", _PX1_vfm_location_var._position_absolute, _PX1_vfm_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0287_PX1_vfm_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_vfm_location_setpos */

/* component PX1_vfm_in_xz_plane=Arm() SETTING, POSITION/ROTATION */
int _PX1_vfm_in_xz_plane_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_vfm_in_xz_plane_setpos] component PX1_vfm_in_xz_plane=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX1_vfm_in_xz_plane_var._name, "PX1_vfm_in_xz_plane", 16384);
  stracpy(_PX1_vfm_in_xz_plane_var._type, "Arm", 16384);
  _PX1_vfm_in_xz_plane_var._index=289;
  int current_setpos_index = 289;
  /* component PX1_vfm_in_xz_plane=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _PX1_vfm_location_var._rotation_absolute, _PX1_vfm_in_xz_plane_var._rotation_absolute);
    rot_transpose(_PX1_vfm_location_var._rotation_absolute, tr1);
    rot_mul(_PX1_vfm_in_xz_plane_var._rotation_absolute, tr1, _PX1_vfm_in_xz_plane_var._rotation_relative);
    _PX1_vfm_in_xz_plane_var._rotation_is_identity =  rot_test_identity(_PX1_vfm_in_xz_plane_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_vfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_vfm_in_xz_plane_var._position_absolute = coords_add(_PX1_vfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_vfm_location_var._position_absolute, _PX1_vfm_in_xz_plane_var._position_absolute);
    _PX1_vfm_in_xz_plane_var._position_relative = rot_apply(_PX1_vfm_in_xz_plane_var._rotation_absolute, tc1);
  } /* PX1_vfm_in_xz_plane=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX1_vfm_in_xz_plane", _PX1_vfm_in_xz_plane_var._position_absolute, _PX1_vfm_in_xz_plane_var._rotation_absolute);
  instrument->_position_absolute[289] = _PX1_vfm_in_xz_plane_var._position_absolute;
  instrument->_position_relative[289] = _PX1_vfm_in_xz_plane_var._position_relative;
    _PX1_vfm_in_xz_plane_var._position_relative_is_zero =  coords_test_zero(_PX1_vfm_in_xz_plane_var._position_relative);
  instrument->counter_N[289]  = instrument->counter_P[289] = instrument->counter_P2[289] = 0;
  instrument->counter_AbsorbProp[289]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0288_PX1_vfm_in_xz_plane", _PX1_vfm_in_xz_plane_var._position_absolute, _PX1_vfm_in_xz_plane_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_vfm_in_xz_plane_setpos */

/* component PX1_vfm=Mirror_curved() SETTING, POSITION/ROTATION */
int _PX1_vfm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_vfm_setpos] component PX1_vfm=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PX1_vfm_var._name, "PX1_vfm", 16384);
  stracpy(_PX1_vfm_var._type, "Mirror_curved", 16384);
  _PX1_vfm_var._index=290;
  int current_setpos_index = 290;
  _PX1_vfm_var._parameters.radius = _instrument_var._parameters.PX1_vfm_radius;
  _PX1_vfm_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_PX1_vfm_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _PX1_vfm_var._parameters.coating[0]='\0';
  _PX1_vfm_var._parameters.zdepth = 0.2;
  _PX1_vfm_var._parameters.yheight = 0.2;
  _PX1_vfm_var._parameters.length = 450e-3;
  _PX1_vfm_var._parameters.width = 0.1;


  /* component PX1_vfm=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.PX1_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_vfm_in_xz_plane_var._rotation_absolute, _PX1_vfm_var._rotation_absolute);
    rot_transpose(_PX1_vfm_location_var._rotation_absolute, tr1);
    rot_mul(_PX1_vfm_var._rotation_absolute, tr1, _PX1_vfm_var._rotation_relative);
    _PX1_vfm_var._rotation_is_identity =  rot_test_identity(_PX1_vfm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_vfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_vfm_var._position_absolute = coords_add(_PX1_vfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_vfm_location_var._position_absolute, _PX1_vfm_var._position_absolute);
    _PX1_vfm_var._position_relative = rot_apply(_PX1_vfm_var._rotation_absolute, tc1);
  } /* PX1_vfm=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PX1_vfm", _PX1_vfm_var._position_absolute, _PX1_vfm_var._rotation_absolute);
  instrument->_position_absolute[290] = _PX1_vfm_var._position_absolute;
  instrument->_position_relative[290] = _PX1_vfm_var._position_relative;
    _PX1_vfm_var._position_relative_is_zero =  coords_test_zero(_PX1_vfm_var._position_relative);
  instrument->counter_N[290]  = instrument->counter_P[290] = instrument->counter_P2[290] = 0;
  instrument->counter_AbsorbProp[290]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0289_PX1_vfm", _PX1_vfm_var._position_absolute, _PX1_vfm_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "radius", "1", "_instrument_var._parameters.PX1_vfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "length", "0", "450e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0289_PX1_vfm", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_vfm_setpos */

/* component PX1_vfm_takeoff=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX1_vfm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_vfm_takeoff_setpos] component PX1_vfm_takeoff=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX1_vfm_takeoff_var._name, "PX1_vfm_takeoff", 16384);
  stracpy(_PX1_vfm_takeoff_var._type, "Monitor_nD", 16384);
  _PX1_vfm_takeoff_var._index=291;
  int current_setpos_index = 291;
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_vfm_takeoff_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.user9[0]='\0';
  _PX1_vfm_takeoff_var._parameters.xwidth = 0.01;
  _PX1_vfm_takeoff_var._parameters.yheight = 0.01;
  _PX1_vfm_takeoff_var._parameters.zdepth = 0;
  _PX1_vfm_takeoff_var._parameters.bins = 100;
  _PX1_vfm_takeoff_var._parameters.min = -1e40;
  _PX1_vfm_takeoff_var._parameters.max = 1e40;
  _PX1_vfm_takeoff_var._parameters.restore_xray = 0;
  _PX1_vfm_takeoff_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX1_vfm_takeoff_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.geometry[0]='\0';
  _PX1_vfm_takeoff_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_vfm_takeoff_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_vfm_takeoff_var._parameters.username9[0]='\0';


  /* component PX1_vfm_takeoff=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-2 * _instrument_var._parameters.PX1_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_vfm_location_var._rotation_absolute, _PX1_vfm_takeoff_var._rotation_absolute);
    rot_transpose(_PX1_vfm_var._rotation_absolute, tr1);
    rot_mul(_PX1_vfm_takeoff_var._rotation_absolute, tr1, _PX1_vfm_takeoff_var._rotation_relative);
    _PX1_vfm_takeoff_var._rotation_is_identity =  rot_test_identity(_PX1_vfm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_vfm_in_xz_plane_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_vfm_takeoff_var._position_absolute = coords_add(_PX1_vfm_in_xz_plane_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_vfm_var._position_absolute, _PX1_vfm_takeoff_var._position_absolute);
    _PX1_vfm_takeoff_var._position_relative = rot_apply(_PX1_vfm_takeoff_var._rotation_absolute, tc1);
  } /* PX1_vfm_takeoff=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX1_vfm_takeoff", _PX1_vfm_takeoff_var._position_absolute, _PX1_vfm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[291] = _PX1_vfm_takeoff_var._position_absolute;
  instrument->_position_relative[291] = _PX1_vfm_takeoff_var._position_relative;
    _PX1_vfm_takeoff_var._position_relative_is_zero =  coords_test_zero(_PX1_vfm_takeoff_var._position_relative);
  instrument->counter_N[291]  = instrument->counter_P[291] = instrument->counter_P2[291] = 0;
  instrument->counter_AbsorbProp[291]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0290_PX1_vfm_takeoff", _PX1_vfm_takeoff_var._position_absolute, _PX1_vfm_takeoff_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0290_PX1_vfm_takeoff", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_vfm_takeoff_setpos */

/* component PX1_hfm_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX1_hfm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_hfm_location_setpos] component PX1_hfm_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX1_hfm_location_var._name, "PX1_hfm_location", 16384);
  stracpy(_PX1_hfm_location_var._type, "Monitor_nD", 16384);
  _PX1_hfm_location_var._index=292;
  int current_setpos_index = 292;
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.user9[0]='\0';
  _PX1_hfm_location_var._parameters.xwidth = 0.01;
  _PX1_hfm_location_var._parameters.yheight = 0.01;
  _PX1_hfm_location_var._parameters.zdepth = 0;
  _PX1_hfm_location_var._parameters.bins = 100;
  _PX1_hfm_location_var._parameters.min = -1e40;
  _PX1_hfm_location_var._parameters.max = 1e40;
  _PX1_hfm_location_var._parameters.restore_xray = 0;
  _PX1_hfm_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX1_hfm_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.geometry[0]='\0';
  _PX1_hfm_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_location_var._parameters.username9[0]='\0';


  /* component PX1_hfm_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_vfm_takeoff_var._rotation_absolute, _PX1_hfm_location_var._rotation_absolute);
    rot_transpose(_PX1_vfm_takeoff_var._rotation_absolute, tr1);
    rot_mul(_PX1_hfm_location_var._rotation_absolute, tr1, _PX1_hfm_location_var._rotation_relative);
    _PX1_hfm_location_var._rotation_is_identity =  rot_test_identity(_PX1_hfm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 21.9 -21.45);
    rot_transpose(_PX1_vfm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_hfm_location_var._position_absolute = coords_add(_PX1_vfm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_vfm_takeoff_var._position_absolute, _PX1_hfm_location_var._position_absolute);
    _PX1_hfm_location_var._position_relative = rot_apply(_PX1_hfm_location_var._rotation_absolute, tc1);
  } /* PX1_hfm_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX1_hfm_location", _PX1_hfm_location_var._position_absolute, _PX1_hfm_location_var._rotation_absolute);
  instrument->_position_absolute[292] = _PX1_hfm_location_var._position_absolute;
  instrument->_position_relative[292] = _PX1_hfm_location_var._position_relative;
    _PX1_hfm_location_var._position_relative_is_zero =  coords_test_zero(_PX1_hfm_location_var._position_relative);
  instrument->counter_N[292]  = instrument->counter_P[292] = instrument->counter_P2[292] = 0;
  instrument->counter_AbsorbProp[292]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0291_PX1_hfm_location", _PX1_hfm_location_var._position_absolute, _PX1_hfm_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0291_PX1_hfm_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_hfm_location_setpos */

/* component PX1_hfm=Mirror_curved() SETTING, POSITION/ROTATION */
int _PX1_hfm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_hfm_setpos] component PX1_hfm=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PX1_hfm_var._name, "PX1_hfm", 16384);
  stracpy(_PX1_hfm_var._type, "Mirror_curved", 16384);
  _PX1_hfm_var._index=293;
  int current_setpos_index = 293;
  _PX1_hfm_var._parameters.radius = _instrument_var._parameters.PX1_hfm_radius;
  _PX1_hfm_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_PX1_hfm_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _PX1_hfm_var._parameters.coating[0]='\0';
  _PX1_hfm_var._parameters.zdepth = 0.2;
  _PX1_hfm_var._parameters.yheight = 0.2;
  _PX1_hfm_var._parameters.length = 450e-3;
  _PX1_hfm_var._parameters.width = 0.1;


  /* component PX1_hfm=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.PX1_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_hfm_location_var._rotation_absolute, _PX1_hfm_var._rotation_absolute);
    rot_transpose(_PX1_hfm_location_var._rotation_absolute, tr1);
    rot_mul(_PX1_hfm_var._rotation_absolute, tr1, _PX1_hfm_var._rotation_relative);
    _PX1_hfm_var._rotation_is_identity =  rot_test_identity(_PX1_hfm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_hfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_hfm_var._position_absolute = coords_add(_PX1_hfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_hfm_location_var._position_absolute, _PX1_hfm_var._position_absolute);
    _PX1_hfm_var._position_relative = rot_apply(_PX1_hfm_var._rotation_absolute, tc1);
  } /* PX1_hfm=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PX1_hfm", _PX1_hfm_var._position_absolute, _PX1_hfm_var._rotation_absolute);
  instrument->_position_absolute[293] = _PX1_hfm_var._position_absolute;
  instrument->_position_relative[293] = _PX1_hfm_var._position_relative;
    _PX1_hfm_var._position_relative_is_zero =  coords_test_zero(_PX1_hfm_var._position_relative);
  instrument->counter_N[293]  = instrument->counter_P[293] = instrument->counter_P2[293] = 0;
  instrument->counter_AbsorbProp[293]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0292_PX1_hfm", _PX1_hfm_var._position_absolute, _PX1_hfm_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "radius", "1", "_instrument_var._parameters.PX1_hfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "length", "0", "450e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0292_PX1_hfm", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_hfm_setpos */

/* component PX1_hfm_takeoff=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX1_hfm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_hfm_takeoff_setpos] component PX1_hfm_takeoff=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX1_hfm_takeoff_var._name, "PX1_hfm_takeoff", 16384);
  stracpy(_PX1_hfm_takeoff_var._type, "Monitor_nD", 16384);
  _PX1_hfm_takeoff_var._index=294;
  int current_setpos_index = 294;
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_hfm_takeoff_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.user9[0]='\0';
  _PX1_hfm_takeoff_var._parameters.xwidth = 0.01;
  _PX1_hfm_takeoff_var._parameters.yheight = 0.01;
  _PX1_hfm_takeoff_var._parameters.zdepth = 0;
  _PX1_hfm_takeoff_var._parameters.bins = 100;
  _PX1_hfm_takeoff_var._parameters.min = -1e40;
  _PX1_hfm_takeoff_var._parameters.max = 1e40;
  _PX1_hfm_takeoff_var._parameters.restore_xray = 0;
  _PX1_hfm_takeoff_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX1_hfm_takeoff_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.geometry[0]='\0';
  _PX1_hfm_takeoff_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_hfm_takeoff_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_hfm_takeoff_var._parameters.username9[0]='\0';


  /* component PX1_hfm_takeoff=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-2 * _instrument_var._parameters.PX1_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX1_hfm_location_var._rotation_absolute, _PX1_hfm_takeoff_var._rotation_absolute);
    rot_transpose(_PX1_hfm_var._rotation_absolute, tr1);
    rot_mul(_PX1_hfm_takeoff_var._rotation_absolute, tr1, _PX1_hfm_takeoff_var._rotation_relative);
    _PX1_hfm_takeoff_var._rotation_is_identity =  rot_test_identity(_PX1_hfm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_hfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_hfm_takeoff_var._position_absolute = coords_add(_PX1_hfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_hfm_var._position_absolute, _PX1_hfm_takeoff_var._position_absolute);
    _PX1_hfm_takeoff_var._position_relative = rot_apply(_PX1_hfm_takeoff_var._rotation_absolute, tc1);
  } /* PX1_hfm_takeoff=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX1_hfm_takeoff", _PX1_hfm_takeoff_var._position_absolute, _PX1_hfm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[294] = _PX1_hfm_takeoff_var._position_absolute;
  instrument->_position_relative[294] = _PX1_hfm_takeoff_var._position_relative;
    _PX1_hfm_takeoff_var._position_relative_is_zero =  coords_test_zero(_PX1_hfm_takeoff_var._position_relative);
  instrument->counter_N[294]  = instrument->counter_P[294] = instrument->counter_P2[294] = 0;
  instrument->counter_AbsorbProp[294]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0293_PX1_hfm_takeoff", _PX1_hfm_takeoff_var._position_absolute, _PX1_hfm_takeoff_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0293_PX1_hfm_takeoff", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_hfm_takeoff_setpos */

/* component PX1_sample_stage=Arm() SETTING, POSITION/ROTATION */
int _PX1_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_sample_stage_setpos] component PX1_sample_stage=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX1_sample_stage_var._name, "PX1_sample_stage", 16384);
  stracpy(_PX1_sample_stage_var._type, "Arm", 16384);
  _PX1_sample_stage_var._index=295;
  int current_setpos_index = 295;
  /* component PX1_sample_stage=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_hfm_takeoff_var._rotation_absolute, _PX1_sample_stage_var._rotation_absolute);
    rot_transpose(_PX1_hfm_takeoff_var._rotation_absolute, tr1);
    rot_mul(_PX1_sample_stage_var._rotation_absolute, tr1, _PX1_sample_stage_var._rotation_relative);
    _PX1_sample_stage_var._rotation_is_identity =  rot_test_identity(_PX1_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 23.846 -21.9);
    rot_transpose(_PX1_hfm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_sample_stage_var._position_absolute = coords_add(_PX1_hfm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_hfm_takeoff_var._position_absolute, _PX1_sample_stage_var._position_absolute);
    _PX1_sample_stage_var._position_relative = rot_apply(_PX1_sample_stage_var._rotation_absolute, tc1);
  } /* PX1_sample_stage=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX1_sample_stage", _PX1_sample_stage_var._position_absolute, _PX1_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[295] = _PX1_sample_stage_var._position_absolute;
  instrument->_position_relative[295] = _PX1_sample_stage_var._position_relative;
    _PX1_sample_stage_var._position_relative_is_zero =  coords_test_zero(_PX1_sample_stage_var._position_relative);
  instrument->counter_N[295]  = instrument->counter_P[295] = instrument->counter_P2[295] = 0;
  instrument->counter_AbsorbProp[295]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0294_PX1_sample_stage", _PX1_sample_stage_var._position_absolute, _PX1_sample_stage_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_sample_stage_setpos */

/* component PX1_sample_monitor=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX1_sample_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_sample_monitor_setpos] component PX1_sample_monitor=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX1_sample_monitor_var._name, "PX1_sample_monitor", 16384);
  stracpy(_PX1_sample_monitor_var._type, "Monitor_nD", 16384);
  _PX1_sample_monitor_var._index=296;
  int current_setpos_index = 296;
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX1_sample_monitor_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.user9[0]='\0';
  _PX1_sample_monitor_var._parameters.xwidth = 0.01;
  _PX1_sample_monitor_var._parameters.yheight = 0.01;
  _PX1_sample_monitor_var._parameters.zdepth = 0;
  _PX1_sample_monitor_var._parameters.bins = 100;
  _PX1_sample_monitor_var._parameters.min = -1e40;
  _PX1_sample_monitor_var._parameters.max = 1e40;
  _PX1_sample_monitor_var._parameters.restore_xray = 0;
  _PX1_sample_monitor_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX1_sample_monitor_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.geometry[0]='\0';
  _PX1_sample_monitor_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_monitor_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_monitor_var._parameters.username9[0]='\0';


  /* component PX1_sample_monitor=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_sample_stage_var._rotation_absolute, _PX1_sample_monitor_var._rotation_absolute);
    rot_transpose(_PX1_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_PX1_sample_monitor_var._rotation_absolute, tr1, _PX1_sample_monitor_var._rotation_relative);
    _PX1_sample_monitor_var._rotation_is_identity =  rot_test_identity(_PX1_sample_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_sample_monitor_var._position_absolute = coords_add(_PX1_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_sample_stage_var._position_absolute, _PX1_sample_monitor_var._position_absolute);
    _PX1_sample_monitor_var._position_relative = rot_apply(_PX1_sample_monitor_var._rotation_absolute, tc1);
  } /* PX1_sample_monitor=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX1_sample_monitor", _PX1_sample_monitor_var._position_absolute, _PX1_sample_monitor_var._rotation_absolute);
  instrument->_position_absolute[296] = _PX1_sample_monitor_var._position_absolute;
  instrument->_position_relative[296] = _PX1_sample_monitor_var._position_relative;
    _PX1_sample_monitor_var._position_relative_is_zero =  coords_test_zero(_PX1_sample_monitor_var._position_relative);
  instrument->counter_N[296]  = instrument->counter_P[296] = instrument->counter_P2[296] = 0;
  instrument->counter_AbsorbProp[296]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0295_PX1_sample_monitor", _PX1_sample_monitor_var._position_absolute, _PX1_sample_monitor_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0295_PX1_sample_monitor", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_sample_monitor_setpos */

/* component PX1_sample=Single_crystal() SETTING, POSITION/ROTATION */
int _PX1_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_sample_setpos] component PX1_sample=Single_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1265]");
  stracpy(_PX1_sample_var._name, "PX1_sample", 16384);
  stracpy(_PX1_sample_var._type, "Single_crystal", 16384);
  _PX1_sample_var._index=297;
  int current_setpos_index = 297;
  if(_instrument_var._parameters.PX1_sample && strlen(_instrument_var._parameters.PX1_sample))
    stracpy(_PX1_sample_var._parameters.reflections, _instrument_var._parameters.PX1_sample ? _instrument_var._parameters.PX1_sample : "", 16384);
  else 
  _PX1_sample_var._parameters.reflections[0]='\0';
  _PX1_sample_var._parameters.geometry[0]='\0';
  _PX1_sample_var._parameters.mosaic_AB[0] = 0;
  _PX1_sample_var._parameters.mosaic_AB[1] = 0;
  _PX1_sample_var._parameters.mosaic_AB[2] = 0;
  _PX1_sample_var._parameters.mosaic_AB[3] = 0;
  _PX1_sample_var._parameters.mosaic_AB[4] = 0;
  _PX1_sample_var._parameters.mosaic_AB[5] = 0;
  _PX1_sample_var._parameters.mosaic_AB[6] = 0;
  _PX1_sample_var._parameters.mosaic_AB[7] = 0;
  _PX1_sample_var._parameters.xwidth = 0;
  _PX1_sample_var._parameters.yheight = 5e-3;
  _PX1_sample_var._parameters.zdepth = 0;
  _PX1_sample_var._parameters.radius = .5e-4;
  _PX1_sample_var._parameters.delta_d_d = 1e-3;
  _PX1_sample_var._parameters.mosaic = 0.1;
  _PX1_sample_var._parameters.mosaic_a = -1;
  _PX1_sample_var._parameters.mosaic_b = -1;
  _PX1_sample_var._parameters.mosaic_c = -1;
  _PX1_sample_var._parameters.recip_cell = 0;
  _PX1_sample_var._parameters.barns = 0;
  _PX1_sample_var._parameters.ax = 0;
  _PX1_sample_var._parameters.ay = 0;
  _PX1_sample_var._parameters.az = 0;
  _PX1_sample_var._parameters.bx = 0;
  _PX1_sample_var._parameters.by = 0;
  _PX1_sample_var._parameters.bz = 0;
  _PX1_sample_var._parameters.cx = 0;
  _PX1_sample_var._parameters.cy = 0;
  _PX1_sample_var._parameters.cz = 0;
  _PX1_sample_var._parameters.p_transmit = 0;
  _PX1_sample_var._parameters.sigma_inc = 0;
  _PX1_sample_var._parameters.aa = 0;
  _PX1_sample_var._parameters.bb = 0;
  _PX1_sample_var._parameters.cc = 0;
  _PX1_sample_var._parameters.order = 1;
  _PX1_sample_var._parameters.extra_order = 0;
  _PX1_sample_var._parameters.RX = 0;
  _PX1_sample_var._parameters.RY = 0;
  _PX1_sample_var._parameters.powder = 0;
  _PX1_sample_var._parameters.deltak = 1e-6;
  if("NULL" && strlen("NULL"))
    stracpy(_PX1_sample_var._parameters.material_datafile, "NULL" ? "NULL" : "", 16384);
  else 
  _PX1_sample_var._parameters.material_datafile[0]='\0';
  _PX1_sample_var._parameters.surf_size = 0;
  _PX1_sample_var._parameters.surf_k = NULL; // default pointer allocation
  _PX1_sample_var._parameters.surf_FT2 = NULL; // default pointer allocation
  _PX1_sample_var._parameters.surf_dir[0] = 0;
  _PX1_sample_var._parameters.surf_dir[1] = 0;
  _PX1_sample_var._parameters.surf_dir[2] = 0;


  /* component PX1_sample=Single_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PX1_rotX)*DEG2RAD, (_instrument_var._parameters.PX1_rotY)*DEG2RAD, (_instrument_var._parameters.PX1_rotZ)*DEG2RAD);
    rot_mul(tr1, _PX1_sample_stage_var._rotation_absolute, _PX1_sample_var._rotation_absolute);
    rot_transpose(_PX1_sample_monitor_var._rotation_absolute, tr1);
    rot_mul(_PX1_sample_var._rotation_absolute, tr1, _PX1_sample_var._rotation_relative);
    _PX1_sample_var._rotation_is_identity =  rot_test_identity(_PX1_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_sample_var._position_absolute = coords_add(_PX1_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_sample_monitor_var._position_absolute, _PX1_sample_var._position_absolute);
    _PX1_sample_var._position_relative = rot_apply(_PX1_sample_var._rotation_absolute, tc1);
  } /* PX1_sample=Single_crystal() AT ROTATED */
  DEBUG_COMPONENT("PX1_sample", _PX1_sample_var._position_absolute, _PX1_sample_var._rotation_absolute);
  instrument->_position_absolute[297] = _PX1_sample_var._position_absolute;
  instrument->_position_relative[297] = _PX1_sample_var._position_relative;
    _PX1_sample_var._position_relative_is_zero =  coords_test_zero(_PX1_sample_var._position_relative);
  instrument->counter_N[297]  = instrument->counter_P[297] = instrument->counter_P2[297] = 0;
  instrument->counter_AbsorbProp[297]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0296_PX1_sample", _PX1_sample_var._position_absolute, _PX1_sample_var._rotation_absolute, "Single_crystal");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "reflections", 0, _instrument_var._parameters.PX1_sample, "char*");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "mosaic_AB", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "yheight", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "radius", "0", ".5e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "delta_d_d", "1e-3", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "mosaic", "-1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "mosaic_a", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "mosaic_b", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "mosaic_c", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "recip_cell", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "barns", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "ax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "ay", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "az", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "bx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "by", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "bz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "cx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "cy", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "cz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "p_transmit", "0.001", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "sigma_inc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "aa", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "bb", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "cc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "order", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "extra_order", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "RX", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "RY", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "powder", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "deltak", "1e-6", "1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "material_datafile", "Si.txt", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "surf_size", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "surf_k", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "surf_FT2", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0296_PX1_sample", "surf_dir", "{ 0 , 0 , 0 }", "{ 0 , 0 , 0 }","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_sample_setpos */

/* component PX1_psd4pi=PSD_monitor_4PI() SETTING, POSITION/ROTATION */
int _PX1_psd4pi_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_psd4pi_setpos] component PX1_psd4pi=PSD_monitor_4PI() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:55]");
  stracpy(_PX1_psd4pi_var._name, "PX1_psd4pi", 16384);
  stracpy(_PX1_psd4pi_var._type, "PSD_monitor_4PI", 16384);
  _PX1_psd4pi_var._index=298;
  int current_setpos_index = 298;
  _PX1_psd4pi_var._parameters.radius = 0.1;
  _PX1_psd4pi_var._parameters.restore_xray = 1;
  _PX1_psd4pi_var._parameters.nx = 180;
  _PX1_psd4pi_var._parameters.ny = 180;
  if("psd4pi" && strlen("psd4pi"))
    stracpy(_PX1_psd4pi_var._parameters.filename, "psd4pi" ? "psd4pi" : "", 16384);
  else 
  _PX1_psd4pi_var._parameters.filename[0]='\0';


  /* component PX1_psd4pi=PSD_monitor_4PI() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_sample_var._rotation_absolute, _PX1_psd4pi_var._rotation_absolute);
    rot_transpose(_PX1_sample_var._rotation_absolute, tr1);
    rot_mul(_PX1_psd4pi_var._rotation_absolute, tr1, _PX1_psd4pi_var._rotation_relative);
    _PX1_psd4pi_var._rotation_is_identity =  rot_test_identity(_PX1_psd4pi_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_psd4pi_var._position_absolute = coords_add(_PX1_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_sample_var._position_absolute, _PX1_psd4pi_var._position_absolute);
    _PX1_psd4pi_var._position_relative = rot_apply(_PX1_psd4pi_var._rotation_absolute, tc1);
  } /* PX1_psd4pi=PSD_monitor_4PI() AT ROTATED */
  DEBUG_COMPONENT("PX1_psd4pi", _PX1_psd4pi_var._position_absolute, _PX1_psd4pi_var._rotation_absolute);
  instrument->_position_absolute[298] = _PX1_psd4pi_var._position_absolute;
  instrument->_position_relative[298] = _PX1_psd4pi_var._position_relative;
    _PX1_psd4pi_var._position_relative_is_zero =  coords_test_zero(_PX1_psd4pi_var._position_relative);
  instrument->counter_N[298]  = instrument->counter_P[298] = instrument->counter_P2[298] = 0;
  instrument->counter_AbsorbProp[298]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0297_PX1_psd4pi", _PX1_psd4pi_var._position_absolute, _PX1_psd4pi_var._rotation_absolute, "PSD_monitor_4PI");
        mccomp_param_nexus(nxhandle,"0297_PX1_psd4pi", "radius", "1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0297_PX1_psd4pi", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0297_PX1_psd4pi", "nx", "90", "180","int");
        mccomp_param_nexus(nxhandle,"0297_PX1_psd4pi", "ny", "90", "180","int");
        mccomp_param_nexus(nxhandle,"0297_PX1_psd4pi", "filename", 0, "psd4pi", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_psd4pi_setpos */

/* component PX1_EigerX16M=PSD_monitor() SETTING, POSITION/ROTATION */
int _PX1_EigerX16M_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX1_EigerX16M_setpos] component PX1_EigerX16M=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PX1_EigerX16M_var._name, "PX1_EigerX16M", 16384);
  stracpy(_PX1_EigerX16M_var._type, "PSD_monitor", 16384);
  _PX1_EigerX16M_var._index=299;
  int current_setpos_index = 299;
  if("EigerX16M.dat" && strlen("EigerX16M.dat"))
    stracpy(_PX1_EigerX16M_var._parameters.filename, "EigerX16M.dat" ? "EigerX16M.dat" : "", 16384);
  else 
  _PX1_EigerX16M_var._parameters.filename[0]='\0';
  _PX1_EigerX16M_var._parameters.xwidth = 311.2e-3;
  _PX1_EigerX16M_var._parameters.yheight = 327.8e-3;
  _PX1_EigerX16M_var._parameters.radius = 0;
  _PX1_EigerX16M_var._parameters.restore_xray = 1;
  _PX1_EigerX16M_var._parameters.nowritefile = 0;
  _PX1_EigerX16M_var._parameters.nx = 4150;
  _PX1_EigerX16M_var._parameters.ny = 4371;
  _PX1_EigerX16M_var._parameters.nr = 0;


  /* component PX1_EigerX16M=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_sample_stage_var._rotation_absolute, _PX1_EigerX16M_var._rotation_absolute);
    rot_transpose(_PX1_psd4pi_var._rotation_absolute, tr1);
    rot_mul(_PX1_EigerX16M_var._rotation_absolute, tr1, _PX1_EigerX16M_var._rotation_relative);
    _PX1_EigerX16M_var._rotation_is_identity =  rot_test_identity(_PX1_EigerX16M_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.PX1_det_dist);
    rot_transpose(_PX1_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX1_EigerX16M_var._position_absolute = coords_add(_PX1_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_psd4pi_var._position_absolute, _PX1_EigerX16M_var._position_absolute);
    _PX1_EigerX16M_var._position_relative = rot_apply(_PX1_EigerX16M_var._rotation_absolute, tc1);
  } /* PX1_EigerX16M=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PX1_EigerX16M", _PX1_EigerX16M_var._position_absolute, _PX1_EigerX16M_var._rotation_absolute);
  instrument->_position_absolute[299] = _PX1_EigerX16M_var._position_absolute;
  instrument->_position_relative[299] = _PX1_EigerX16M_var._position_relative;
    _PX1_EigerX16M_var._position_relative_is_zero =  coords_test_zero(_PX1_EigerX16M_var._position_relative);
  instrument->counter_N[299]  = instrument->counter_P[299] = instrument->counter_P2[299] = 0;
  instrument->counter_AbsorbProp[299]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0298_PX1_EigerX16M", _PX1_EigerX16M_var._position_absolute, _PX1_EigerX16M_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "filename", 0, "EigerX16M.dat", "char*");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "xwidth", "0.05", "311.2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "yheight", "0.05", "327.8e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "nx", "90", "4150","int");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "ny", "90", "4371","int");
        mccomp_param_nexus(nxhandle,"0298_PX1_EigerX16M", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX1_EigerX16M_setpos */

/* component beamdump_308=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_308_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_308_setpos] component beamdump_308=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_308_var._name, "beamdump_308", 16384);
  stracpy(_beamdump_308_var._type, "Beamstop", 16384);
  _beamdump_308_var._index=300;
  int current_setpos_index = 300;
  _beamdump_308_var._parameters.xmin = -0.05;
  _beamdump_308_var._parameters.xmax = 0.05;
  _beamdump_308_var._parameters.ymin = -0.05;
  _beamdump_308_var._parameters.ymax = 0.05;
  _beamdump_308_var._parameters.xwidth = 0;
  _beamdump_308_var._parameters.yheight = 0;
  _beamdump_308_var._parameters.radius = 0;

  /* component beamdump_308=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX1_EigerX16M_var._rotation_absolute, _beamdump_308_var._rotation_absolute);
    rot_transpose(_PX1_EigerX16M_var._rotation_absolute, tr1);
    rot_mul(_beamdump_308_var._rotation_absolute, tr1, _beamdump_308_var._rotation_relative);
    _beamdump_308_var._rotation_is_identity =  rot_test_identity(_beamdump_308_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX1_EigerX16M_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_308_var._position_absolute = coords_add(_PX1_EigerX16M_var._position_absolute, tc2);
    tc1 = coords_sub(_PX1_EigerX16M_var._position_absolute, _beamdump_308_var._position_absolute);
    _beamdump_308_var._position_relative = rot_apply(_beamdump_308_var._rotation_absolute, tc1);
  } /* beamdump_308=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_308", _beamdump_308_var._position_absolute, _beamdump_308_var._rotation_absolute);
  instrument->_position_absolute[300] = _beamdump_308_var._position_absolute;
  instrument->_position_relative[300] = _beamdump_308_var._position_relative;
    _beamdump_308_var._position_relative_is_zero =  coords_test_zero(_beamdump_308_var._position_relative);
  instrument->counter_N[300]  = instrument->counter_P[300] = instrument->counter_P2[300] = 0;
  instrument->counter_AbsorbProp[300]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0299_beamdump_308", _beamdump_308_var._position_absolute, _beamdump_308_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0299_beamdump_308", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_308_setpos */

/* component PX2a_pos=Text() SETTING, POSITION/ROTATION */
int _PX2a_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_pos_setpos] component PX2a_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_PX2a_pos_var._name, "PX2a_pos", 16384);
  stracpy(_PX2a_pos_var._type, "Text", 16384);
  _PX2a_pos_var._index=301;
  int current_setpos_index = 301;
  if("PX2a" && strlen("PX2a"))
    stracpy(_PX2a_pos_var._parameters.text, "PX2a" ? "PX2a" : "", 16384);
  else 
  _PX2a_pos_var._parameters.text[0]='\0';
  _PX2a_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_PX2a_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _PX2a_pos_var._parameters.plane[0]='\0';
  _PX2a_pos_var._parameters.pen_thickness = 0.1;


  /* component PX2a_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-226.607)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _PX2a_pos_var._rotation_absolute);
    rot_transpose(_beamdump_308_var._rotation_absolute, tr1);
    rot_mul(_PX2a_pos_var._rotation_absolute, tr1, _PX2a_pos_var._rotation_relative);
    _PX2a_pos_var._rotation_is_identity =  rot_test_identity(_PX2a_pos_var._rotation_relative);
    tc1 = coords_set(
      -38.706, 0, -40.940);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_308_var._position_absolute, _PX2a_pos_var._position_absolute);
    _PX2a_pos_var._position_relative = rot_apply(_PX2a_pos_var._rotation_absolute, tc1);
  } /* PX2a_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("PX2a_pos", _PX2a_pos_var._position_absolute, _PX2a_pos_var._rotation_absolute);
  instrument->_position_absolute[301] = _PX2a_pos_var._position_absolute;
  instrument->_position_relative[301] = _PX2a_pos_var._position_relative;
    _PX2a_pos_var._position_relative_is_zero =  coords_test_zero(_PX2a_pos_var._position_relative);
  instrument->counter_N[301]  = instrument->counter_P[301] = instrument->counter_P2[301] = 0;
  instrument->counter_AbsorbProp[301]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0300_PX2a_pos", _PX2a_pos_var._position_absolute, _PX2a_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0300_PX2a_pos", "text", "NONE", "PX2a", "char*");
        mccomp_param_nexus(nxhandle,"0300_PX2a_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0300_PX2a_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0300_PX2a_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_pos_setpos */

/* component PX2a=Arm() SETTING, POSITION/ROTATION */
int _PX2a_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_setpos] component PX2a=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_var._name, "PX2a", 16384);
  stracpy(_PX2a_var._type, "Arm", 16384);
  _PX2a_var._index=302;
  int current_setpos_index = 302;
  /* component PX2a=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_pos_var._rotation_absolute, _PX2a_var._rotation_absolute);
    rot_transpose(_PX2a_pos_var._rotation_absolute, tr1);
    rot_mul(_PX2a_var._rotation_absolute, tr1, _PX2a_var._rotation_relative);
    _PX2a_var._rotation_is_identity =  rot_test_identity(_PX2a_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_var._position_absolute = coords_add(_PX2a_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_pos_var._position_absolute, _PX2a_var._position_absolute);
    _PX2a_var._position_relative = rot_apply(_PX2a_var._rotation_absolute, tc1);
  } /* PX2a=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a", _PX2a_var._position_absolute, _PX2a_var._rotation_absolute);
  instrument->_position_absolute[302] = _PX2a_var._position_absolute;
  instrument->_position_relative[302] = _PX2a_var._position_relative;
    _PX2a_var._position_relative_is_zero =  coords_test_zero(_PX2a_var._position_relative);
  instrument->counter_N[302]  = instrument->counter_P[302] = instrument->counter_P2[302] = 0;
  instrument->counter_AbsorbProp[302]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0301_PX2a", _PX2a_var._position_absolute, _PX2a_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_setpos */

/* component PX2a_undulator=Undulator() SETTING, POSITION/ROTATION */
int _PX2a_undulator_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_undulator_setpos] component PX2a_undulator=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_PX2a_undulator_var._name, "PX2a_undulator", 16384);
  stracpy(_PX2a_undulator_var._type, "Undulator", 16384);
  _PX2a_undulator_var._index=303;
  int current_setpos_index = 303;
  _PX2a_undulator_var._parameters.E0 = _instrument_var._parameters.PX2a_E0;
  _PX2a_undulator_var._parameters.dE = .1;
  _PX2a_undulator_var._parameters.phase = 0;
  _PX2a_undulator_var._parameters.randomphase = 1;
  _PX2a_undulator_var._parameters.Ee = 2.75;
  _PX2a_undulator_var._parameters.dEe = 0.001;
  _PX2a_undulator_var._parameters.Ie = 0.5;
  _PX2a_undulator_var._parameters.B = 0;
  _PX2a_undulator_var._parameters.K = 1.788;
  _PX2a_undulator_var._parameters.Nper = 80;
  _PX2a_undulator_var._parameters.lu = 2.4e-2;
  _PX2a_undulator_var._parameters.sigey = 9.8e-6;
  _PX2a_undulator_var._parameters.sigex = 219.1e-6;
  _PX2a_undulator_var._parameters.sigepx = 31.6e-6;
  _PX2a_undulator_var._parameters.sigepy = 3.7e-6;
  _PX2a_undulator_var._parameters.focus_xw = 0;
  _PX2a_undulator_var._parameters.focus_yh = 0;
  _PX2a_undulator_var._parameters.dist = 29.5;
  _PX2a_undulator_var._parameters.quick_integ = 0;
  _PX2a_undulator_var._parameters.E1st = 12.400;
  _PX2a_undulator_var._parameters.verbose = 0;
  _PX2a_undulator_var._parameters.Br = 1.35;


  /* component PX2a_undulator=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_var._rotation_absolute, _PX2a_undulator_var._rotation_absolute);
    rot_transpose(_PX2a_var._rotation_absolute, tr1);
    rot_mul(_PX2a_undulator_var._rotation_absolute, tr1, _PX2a_undulator_var._rotation_relative);
    _PX2a_undulator_var._rotation_is_identity =  rot_test_identity(_PX2a_undulator_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_undulator_var._position_absolute = coords_add(_PX2a_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_var._position_absolute, _PX2a_undulator_var._position_absolute);
    _PX2a_undulator_var._position_relative = rot_apply(_PX2a_undulator_var._rotation_absolute, tc1);
  } /* PX2a_undulator=Undulator() AT ROTATED */
  DEBUG_COMPONENT("PX2a_undulator", _PX2a_undulator_var._position_absolute, _PX2a_undulator_var._rotation_absolute);
  instrument->_position_absolute[303] = _PX2a_undulator_var._position_absolute;
  instrument->_position_relative[303] = _PX2a_undulator_var._position_relative;
    _PX2a_undulator_var._position_relative_is_zero =  coords_test_zero(_PX2a_undulator_var._position_relative);
  instrument->counter_N[303]  = instrument->counter_P[303] = instrument->counter_P2[303] = 0;
  instrument->counter_AbsorbProp[303]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0302_PX2a_undulator", _PX2a_undulator_var._position_absolute, _PX2a_undulator_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "E0", "0", "_instrument_var._parameters.PX2a_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "dE", "0", ".1","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "dEe", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "K", "0", "1.788","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "Nper", "1", "80","int");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "lu", "16e-3", "2.4e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "sigey", "0", "9.8e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "sigex", "0", "219.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "sigepx", "0", "31.6e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "sigepy", "0", "3.7e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "dist", "1", "29.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "E1st", "0", "12.400","MCNUM");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0302_PX2a_undulator", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_undulator_setpos */

/* component PX2a_bragg_crystal_location=Arm() SETTING, POSITION/ROTATION */
int _PX2a_bragg_crystal_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_bragg_crystal_location_setpos] component PX2a_bragg_crystal_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_bragg_crystal_location_var._name, "PX2a_bragg_crystal_location", 16384);
  stracpy(_PX2a_bragg_crystal_location_var._type, "Arm", 16384);
  _PX2a_bragg_crystal_location_var._index=304;
  int current_setpos_index = 304;
  /* component PX2a_bragg_crystal_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_undulator_var._rotation_absolute, _PX2a_bragg_crystal_location_var._rotation_absolute);
    rot_transpose(_PX2a_undulator_var._rotation_absolute, tr1);
    rot_mul(_PX2a_bragg_crystal_location_var._rotation_absolute, tr1, _PX2a_bragg_crystal_location_var._rotation_relative);
    _PX2a_bragg_crystal_location_var._rotation_is_identity =  rot_test_identity(_PX2a_bragg_crystal_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 29.5);
    rot_transpose(_PX2a_undulator_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_bragg_crystal_location_var._position_absolute = coords_add(_PX2a_undulator_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_undulator_var._position_absolute, _PX2a_bragg_crystal_location_var._position_absolute);
    _PX2a_bragg_crystal_location_var._position_relative = rot_apply(_PX2a_bragg_crystal_location_var._rotation_absolute, tc1);
  } /* PX2a_bragg_crystal_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_bragg_crystal_location", _PX2a_bragg_crystal_location_var._position_absolute, _PX2a_bragg_crystal_location_var._rotation_absolute);
  instrument->_position_absolute[304] = _PX2a_bragg_crystal_location_var._position_absolute;
  instrument->_position_relative[304] = _PX2a_bragg_crystal_location_var._position_relative;
    _PX2a_bragg_crystal_location_var._position_relative_is_zero =  coords_test_zero(_PX2a_bragg_crystal_location_var._position_relative);
  instrument->counter_N[304]  = instrument->counter_P[304] = instrument->counter_P2[304] = 0;
  instrument->counter_AbsorbProp[304]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0303_PX2a_bragg_crystal_location", _PX2a_bragg_crystal_location_var._position_absolute, _PX2a_bragg_crystal_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_bragg_crystal_location_setpos */

/* component PX2a_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PX2a_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_bragg_crystal_setpos] component PX2a_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PX2a_bragg_crystal_var._name, "PX2a_bragg_crystal", 16384);
  stracpy(_PX2a_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _PX2a_bragg_crystal_var._index=305;
  int current_setpos_index = 305;
  _PX2a_bragg_crystal_var._parameters.length = 0.05;
  _PX2a_bragg_crystal_var._parameters.width = 0.02;
  _PX2a_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PX2a_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PX2a_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PX2a_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PX2a_bragg_crystal_var._parameters.material[0]='\0';
  _PX2a_bragg_crystal_var._parameters.alpha = 0.0;
  _PX2a_bragg_crystal_var._parameters.R0 = 0;
  _PX2a_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _PX2a_bragg_crystal_var._parameters.crystal_type = 2;
  _PX2a_bragg_crystal_var._parameters.h = 1;
  _PX2a_bragg_crystal_var._parameters.k = 1;
  _PX2a_bragg_crystal_var._parameters.l = 1;
  _PX2a_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _PX2a_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component PX2a_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- PX2a_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_bragg_crystal_location_var._rotation_absolute, _PX2a_bragg_crystal_var._rotation_absolute);
    rot_transpose(_PX2a_undulator_var._rotation_absolute, tr1);
    rot_mul(_PX2a_bragg_crystal_var._rotation_absolute, tr1, _PX2a_bragg_crystal_var._rotation_relative);
    _PX2a_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_PX2a_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_bragg_crystal_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_bragg_crystal_var._position_absolute = coords_add(_PX2a_bragg_crystal_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_undulator_var._position_absolute, _PX2a_bragg_crystal_var._position_absolute);
    _PX2a_bragg_crystal_var._position_relative = rot_apply(_PX2a_bragg_crystal_var._rotation_absolute, tc1);
  } /* PX2a_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PX2a_bragg_crystal", _PX2a_bragg_crystal_var._position_absolute, _PX2a_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[305] = _PX2a_bragg_crystal_var._position_absolute;
  instrument->_position_relative[305] = _PX2a_bragg_crystal_var._position_relative;
    _PX2a_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_PX2a_bragg_crystal_var._position_relative);
  instrument->counter_N[305]  = instrument->counter_P[305] = instrument->counter_P2[305] = 0;
  instrument->counter_AbsorbProp[305]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0304_PX2a_bragg_crystal", _PX2a_bragg_crystal_var._position_absolute, _PX2a_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0304_PX2a_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_bragg_crystal_setpos */

/* component PX2a_arm=Arm() SETTING, POSITION/ROTATION */
int _PX2a_arm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_arm_setpos] component PX2a_arm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_arm_var._name, "PX2a_arm", 16384);
  stracpy(_PX2a_arm_var._type, "Arm", 16384);
  _PX2a_arm_var._index=306;
  int current_setpos_index = 306;
  /* component PX2a_arm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- PX2a_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_bragg_crystal_var._rotation_absolute, _PX2a_arm_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_PX2a_arm_var._rotation_absolute, tr1, _PX2a_arm_var._rotation_relative);
    _PX2a_arm_var._rotation_is_identity =  rot_test_identity(_PX2a_arm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_arm_var._position_absolute = coords_add(_PX2a_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_var._position_absolute, _PX2a_arm_var._position_absolute);
    _PX2a_arm_var._position_relative = rot_apply(_PX2a_arm_var._rotation_absolute, tc1);
  } /* PX2a_arm=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_arm", _PX2a_arm_var._position_absolute, _PX2a_arm_var._rotation_absolute);
  instrument->_position_absolute[306] = _PX2a_arm_var._position_absolute;
  instrument->_position_relative[306] = _PX2a_arm_var._position_relative;
    _PX2a_arm_var._position_relative_is_zero =  coords_test_zero(_PX2a_arm_var._position_relative);
  instrument->counter_N[306]  = instrument->counter_P[306] = instrument->counter_P2[306] = 0;
  instrument->counter_AbsorbProp[306]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0305_PX2a_arm", _PX2a_arm_var._position_absolute, _PX2a_arm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_arm_setpos */

/* component PX2a_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _PX2a_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_bragg_crystal_two_setpos] component PX2a_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_PX2a_bragg_crystal_two_var._name, "PX2a_bragg_crystal_two", 16384);
  stracpy(_PX2a_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _PX2a_bragg_crystal_two_var._index=307;
  int current_setpos_index = 307;
  _PX2a_bragg_crystal_two_var._parameters.length = 0.05;
  _PX2a_bragg_crystal_two_var._parameters.width = 0.02;
  _PX2a_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_PX2a_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _PX2a_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_PX2a_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _PX2a_bragg_crystal_two_var._parameters.material[0]='\0';
  _PX2a_bragg_crystal_two_var._parameters.alpha = 0.0;
  _PX2a_bragg_crystal_two_var._parameters.R0 = 0;
  _PX2a_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _PX2a_bragg_crystal_two_var._parameters.crystal_type = 2;
  _PX2a_bragg_crystal_two_var._parameters.h = 1;
  _PX2a_bragg_crystal_two_var._parameters.k = 1;
  _PX2a_bragg_crystal_two_var._parameters.l = 1;
  _PX2a_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _PX2a_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component PX2a_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (PX2a_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_arm_var._rotation_absolute, _PX2a_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_PX2a_bragg_crystal_two_var._rotation_absolute, tr1, _PX2a_bragg_crystal_two_var._rotation_relative);
    _PX2a_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_PX2a_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0.006, PX2a_calculated_angle ? 0.006 / tan ( PX2a_calculated_angle * DEG2RAD ) : 0);
    rot_transpose(_PX2a_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_bragg_crystal_two_var._position_absolute = coords_add(_PX2a_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_var._position_absolute, _PX2a_bragg_crystal_two_var._position_absolute);
    _PX2a_bragg_crystal_two_var._position_relative = rot_apply(_PX2a_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* PX2a_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("PX2a_bragg_crystal_two", _PX2a_bragg_crystal_two_var._position_absolute, _PX2a_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[307] = _PX2a_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[307] = _PX2a_bragg_crystal_two_var._position_relative;
    _PX2a_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_PX2a_bragg_crystal_two_var._position_relative);
  instrument->counter_N[307]  = instrument->counter_P[307] = instrument->counter_P2[307] = 0;
  instrument->counter_AbsorbProp[307]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", _PX2a_bragg_crystal_two_var._position_absolute, _PX2a_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0306_PX2a_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_bragg_crystal_two_setpos */

/* component PX2a_arm_two=Arm() SETTING, POSITION/ROTATION */
int _PX2a_arm_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_arm_two_setpos] component PX2a_arm_two=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_arm_two_var._name, "PX2a_arm_two", 16384);
  stracpy(_PX2a_arm_two_var._type, "Arm", 16384);
  _PX2a_arm_two_var._index=308;
  int current_setpos_index = 308;
  /* component PX2a_arm_two=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (PX2a_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_bragg_crystal_two_var._rotation_absolute, _PX2a_arm_two_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_PX2a_arm_two_var._rotation_absolute, tr1, _PX2a_arm_two_var._rotation_relative);
    _PX2a_arm_two_var._rotation_is_identity =  rot_test_identity(_PX2a_arm_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_arm_two_var._position_absolute = coords_add(_PX2a_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_two_var._position_absolute, _PX2a_arm_two_var._position_absolute);
    _PX2a_arm_two_var._position_relative = rot_apply(_PX2a_arm_two_var._rotation_absolute, tc1);
  } /* PX2a_arm_two=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_arm_two", _PX2a_arm_two_var._position_absolute, _PX2a_arm_two_var._rotation_absolute);
  instrument->_position_absolute[308] = _PX2a_arm_two_var._position_absolute;
  instrument->_position_relative[308] = _PX2a_arm_two_var._position_relative;
    _PX2a_arm_two_var._position_relative_is_zero =  coords_test_zero(_PX2a_arm_two_var._position_relative);
  instrument->counter_N[308]  = instrument->counter_P[308] = instrument->counter_P2[308] = 0;
  instrument->counter_AbsorbProp[308]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0307_PX2a_arm_two", _PX2a_arm_two_var._position_absolute, _PX2a_arm_two_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_arm_two_setpos */

/* component PX2a_bragg_crystal_out=E_monitor() SETTING, POSITION/ROTATION */
int _PX2a_bragg_crystal_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_bragg_crystal_out_setpos] component PX2a_bragg_crystal_out=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_PX2a_bragg_crystal_out_var._name, "PX2a_bragg_crystal_out", 16384);
  stracpy(_PX2a_bragg_crystal_out_var._type, "E_monitor", 16384);
  _PX2a_bragg_crystal_out_var._index=309;
  int current_setpos_index = 309;
  _PX2a_bragg_crystal_out_var._parameters.nE = 512;
  _PX2a_bragg_crystal_out_var._parameters.filename[0]='\0';
  _PX2a_bragg_crystal_out_var._parameters.xwidth = 0.1;
  _PX2a_bragg_crystal_out_var._parameters.yheight = 0.1;
  _PX2a_bragg_crystal_out_var._parameters.Emin = _instrument_var._parameters.PX2a_E0 -.1;
  _PX2a_bragg_crystal_out_var._parameters.Emax = _instrument_var._parameters.PX2a_E0 + .1;
  _PX2a_bragg_crystal_out_var._parameters.restore_xray = 0;


  /* component PX2a_bragg_crystal_out=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_arm_two_var._rotation_absolute, _PX2a_bragg_crystal_out_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_PX2a_bragg_crystal_out_var._rotation_absolute, tr1, _PX2a_bragg_crystal_out_var._rotation_relative);
    _PX2a_bragg_crystal_out_var._rotation_is_identity =  rot_test_identity(_PX2a_bragg_crystal_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_PX2a_arm_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_bragg_crystal_out_var._position_absolute = coords_add(_PX2a_arm_two_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_two_var._position_absolute, _PX2a_bragg_crystal_out_var._position_absolute);
    _PX2a_bragg_crystal_out_var._position_relative = rot_apply(_PX2a_bragg_crystal_out_var._rotation_absolute, tc1);
  } /* PX2a_bragg_crystal_out=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("PX2a_bragg_crystal_out", _PX2a_bragg_crystal_out_var._position_absolute, _PX2a_bragg_crystal_out_var._rotation_absolute);
  instrument->_position_absolute[309] = _PX2a_bragg_crystal_out_var._position_absolute;
  instrument->_position_relative[309] = _PX2a_bragg_crystal_out_var._position_relative;
    _PX2a_bragg_crystal_out_var._position_relative_is_zero =  coords_test_zero(_PX2a_bragg_crystal_out_var._position_relative);
  instrument->counter_N[309]  = instrument->counter_P[309] = instrument->counter_P2[309] = 0;
  instrument->counter_AbsorbProp[309]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", _PX2a_bragg_crystal_out_var._position_absolute, _PX2a_bragg_crystal_out_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "nE", "20", "512","MCNUM");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "Emin", "NONE", "_instrument_var._parameters.PX2a_E0 -.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "Emax", "NONE", "_instrument_var._parameters.PX2a_E0 + .1","MCNUM");
        mccomp_param_nexus(nxhandle,"0308_PX2a_bragg_crystal_out", "restore_xray", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_bragg_crystal_out_setpos */

/* component PX2a_hpm_location=Arm() SETTING, POSITION/ROTATION */
int _PX2a_hpm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hpm_location_setpos] component PX2a_hpm_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_hpm_location_var._name, "PX2a_hpm_location", 16384);
  stracpy(_PX2a_hpm_location_var._type, "Arm", 16384);
  _PX2a_hpm_location_var._index=310;
  int current_setpos_index = 310;
  /* component PX2a_hpm_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_arm_two_var._rotation_absolute, _PX2a_hpm_location_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_out_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hpm_location_var._rotation_absolute, tr1, _PX2a_hpm_location_var._rotation_relative);
    _PX2a_hpm_location_var._rotation_is_identity =  rot_test_identity(_PX2a_hpm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 32.1 -29.5 -0.05);
    rot_transpose(_PX2a_arm_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hpm_location_var._position_absolute = coords_add(_PX2a_arm_two_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_out_var._position_absolute, _PX2a_hpm_location_var._position_absolute);
    _PX2a_hpm_location_var._position_relative = rot_apply(_PX2a_hpm_location_var._rotation_absolute, tc1);
  } /* PX2a_hpm_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hpm_location", _PX2a_hpm_location_var._position_absolute, _PX2a_hpm_location_var._rotation_absolute);
  instrument->_position_absolute[310] = _PX2a_hpm_location_var._position_absolute;
  instrument->_position_relative[310] = _PX2a_hpm_location_var._position_relative;
    _PX2a_hpm_location_var._position_relative_is_zero =  coords_test_zero(_PX2a_hpm_location_var._position_relative);
  instrument->counter_N[310]  = instrument->counter_P[310] = instrument->counter_P2[310] = 0;
  instrument->counter_AbsorbProp[310]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0309_PX2a_hpm_location", _PX2a_hpm_location_var._position_absolute, _PX2a_hpm_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hpm_location_setpos */

/* component PX2a_hpm_in_yz_plane=Arm() SETTING, POSITION/ROTATION */
int _PX2a_hpm_in_yz_plane_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hpm_in_yz_plane_setpos] component PX2a_hpm_in_yz_plane=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_hpm_in_yz_plane_var._name, "PX2a_hpm_in_yz_plane", 16384);
  stracpy(_PX2a_hpm_in_yz_plane_var._type, "Arm", 16384);
  _PX2a_hpm_in_yz_plane_var._index=311;
  int current_setpos_index = 311;
  /* component PX2a_hpm_in_yz_plane=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _PX2a_hpm_location_var._rotation_absolute, _PX2a_hpm_in_yz_plane_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_out_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hpm_in_yz_plane_var._rotation_absolute, tr1, _PX2a_hpm_in_yz_plane_var._rotation_relative);
    _PX2a_hpm_in_yz_plane_var._rotation_is_identity =  rot_test_identity(_PX2a_hpm_in_yz_plane_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_hpm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hpm_in_yz_plane_var._position_absolute = coords_add(_PX2a_hpm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_out_var._position_absolute, _PX2a_hpm_in_yz_plane_var._position_absolute);
    _PX2a_hpm_in_yz_plane_var._position_relative = rot_apply(_PX2a_hpm_in_yz_plane_var._rotation_absolute, tc1);
  } /* PX2a_hpm_in_yz_plane=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hpm_in_yz_plane", _PX2a_hpm_in_yz_plane_var._position_absolute, _PX2a_hpm_in_yz_plane_var._rotation_absolute);
  instrument->_position_absolute[311] = _PX2a_hpm_in_yz_plane_var._position_absolute;
  instrument->_position_relative[311] = _PX2a_hpm_in_yz_plane_var._position_relative;
    _PX2a_hpm_in_yz_plane_var._position_relative_is_zero =  coords_test_zero(_PX2a_hpm_in_yz_plane_var._position_relative);
  instrument->counter_N[311]  = instrument->counter_P[311] = instrument->counter_P2[311] = 0;
  instrument->counter_AbsorbProp[311]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0310_PX2a_hpm_in_yz_plane", _PX2a_hpm_in_yz_plane_var._position_absolute, _PX2a_hpm_in_yz_plane_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hpm_in_yz_plane_setpos */

/* component PX2a_hpm=Mirror_toroid() SETTING, POSITION/ROTATION */
int _PX2a_hpm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hpm_setpos] component PX2a_hpm=Mirror_toroid() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_toroid.comp:60]");
  stracpy(_PX2a_hpm_var._name, "PX2a_hpm", 16384);
  stracpy(_PX2a_hpm_var._type, "Mirror_toroid", 16384);
  _PX2a_hpm_var._index=312;
  int current_setpos_index = 312;
  if("Ir.dat" && strlen("Ir.dat"))
    stracpy(_PX2a_hpm_var._parameters.coating, "Ir.dat" ? "Ir.dat" : "", 16384);
  else 
  _PX2a_hpm_var._parameters.coating[0]='\0';
  _PX2a_hpm_var._parameters.zdepth = 150e-3;
  _PX2a_hpm_var._parameters.xwidth = 15e-3;
  _PX2a_hpm_var._parameters.radius = 495;
  _PX2a_hpm_var._parameters.radius_o = 1000;
  _PX2a_hpm_var._parameters.R0 = 0;


  /* component PX2a_hpm=Mirror_toroid() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PX2a_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_hpm_in_yz_plane_var._rotation_absolute, _PX2a_hpm_var._rotation_absolute);
    rot_transpose(_PX2a_bragg_crystal_out_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hpm_var._rotation_absolute, tr1, _PX2a_hpm_var._rotation_relative);
    _PX2a_hpm_var._rotation_is_identity =  rot_test_identity(_PX2a_hpm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_hpm_in_yz_plane_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hpm_var._position_absolute = coords_add(_PX2a_hpm_in_yz_plane_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_bragg_crystal_out_var._position_absolute, _PX2a_hpm_var._position_absolute);
    _PX2a_hpm_var._position_relative = rot_apply(_PX2a_hpm_var._rotation_absolute, tc1);
  } /* PX2a_hpm=Mirror_toroid() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hpm", _PX2a_hpm_var._position_absolute, _PX2a_hpm_var._rotation_absolute);
  instrument->_position_absolute[312] = _PX2a_hpm_var._position_absolute;
  instrument->_position_relative[312] = _PX2a_hpm_var._position_relative;
    _PX2a_hpm_var._position_relative_is_zero =  coords_test_zero(_PX2a_hpm_var._position_relative);
  instrument->counter_N[312]  = instrument->counter_P[312] = instrument->counter_P2[312] = 0;
  instrument->counter_AbsorbProp[312]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0311_PX2a_hpm", _PX2a_hpm_var._position_absolute, _PX2a_hpm_var._rotation_absolute, "Mirror_toroid");
        mccomp_param_nexus(nxhandle,"0311_PX2a_hpm", "coating", "", "Ir.dat", "char*");
        mccomp_param_nexus(nxhandle,"0311_PX2a_hpm", "zdepth", "0.1", "150e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0311_PX2a_hpm", "xwidth", "0.01", "15e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0311_PX2a_hpm", "radius", "NONE", "495","MCNUM");
        mccomp_param_nexus(nxhandle,"0311_PX2a_hpm", "radius_o", "NONE", "1000","MCNUM");
        mccomp_param_nexus(nxhandle,"0311_PX2a_hpm", "R0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hpm_setpos */

/* component PX2a_hpm_takeoff=Arm() SETTING, POSITION/ROTATION */
int _PX2a_hpm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hpm_takeoff_setpos] component PX2a_hpm_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_hpm_takeoff_var._name, "PX2a_hpm_takeoff", 16384);
  stracpy(_PX2a_hpm_takeoff_var._type, "Arm", 16384);
  _PX2a_hpm_takeoff_var._index=313;
  int current_setpos_index = 313;
  /* component PX2a_hpm_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (2 * _instrument_var._parameters.PX2a_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_hpm_location_var._rotation_absolute, _PX2a_hpm_takeoff_var._rotation_absolute);
    rot_transpose(_PX2a_hpm_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hpm_takeoff_var._rotation_absolute, tr1, _PX2a_hpm_takeoff_var._rotation_relative);
    _PX2a_hpm_takeoff_var._rotation_is_identity =  rot_test_identity(_PX2a_hpm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_hpm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hpm_takeoff_var._position_absolute = coords_add(_PX2a_hpm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_hpm_var._position_absolute, _PX2a_hpm_takeoff_var._position_absolute);
    _PX2a_hpm_takeoff_var._position_relative = rot_apply(_PX2a_hpm_takeoff_var._rotation_absolute, tc1);
  } /* PX2a_hpm_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hpm_takeoff", _PX2a_hpm_takeoff_var._position_absolute, _PX2a_hpm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[313] = _PX2a_hpm_takeoff_var._position_absolute;
  instrument->_position_relative[313] = _PX2a_hpm_takeoff_var._position_relative;
    _PX2a_hpm_takeoff_var._position_relative_is_zero =  coords_test_zero(_PX2a_hpm_takeoff_var._position_relative);
  instrument->counter_N[313]  = instrument->counter_P[313] = instrument->counter_P2[313] = 0;
  instrument->counter_AbsorbProp[313]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0312_PX2a_hpm_takeoff", _PX2a_hpm_takeoff_var._position_absolute, _PX2a_hpm_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hpm_takeoff_setpos */

/* component PX2a_vfm_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX2a_vfm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_vfm_location_setpos] component PX2a_vfm_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX2a_vfm_location_var._name, "PX2a_vfm_location", 16384);
  stracpy(_PX2a_vfm_location_var._type, "Monitor_nD", 16384);
  _PX2a_vfm_location_var._index=314;
  int current_setpos_index = 314;
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.user9[0]='\0';
  _PX2a_vfm_location_var._parameters.xwidth = 0.01;
  _PX2a_vfm_location_var._parameters.yheight = 0.01;
  _PX2a_vfm_location_var._parameters.zdepth = 0;
  _PX2a_vfm_location_var._parameters.bins = 100;
  _PX2a_vfm_location_var._parameters.min = -1e40;
  _PX2a_vfm_location_var._parameters.max = 1e40;
  _PX2a_vfm_location_var._parameters.restore_xray = 0;
  _PX2a_vfm_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX2a_vfm_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.geometry[0]='\0';
  _PX2a_vfm_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_location_var._parameters.username9[0]='\0';


  /* component PX2a_vfm_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_hpm_takeoff_var._rotation_absolute, _PX2a_vfm_location_var._rotation_absolute);
    rot_transpose(_PX2a_hpm_var._rotation_absolute, tr1);
    rot_mul(_PX2a_vfm_location_var._rotation_absolute, tr1, _PX2a_vfm_location_var._rotation_relative);
    _PX2a_vfm_location_var._rotation_is_identity =  rot_test_identity(_PX2a_vfm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 33.9 -32.1);
    rot_transpose(_PX2a_hpm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_vfm_location_var._position_absolute = coords_add(_PX2a_hpm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_hpm_var._position_absolute, _PX2a_vfm_location_var._position_absolute);
    _PX2a_vfm_location_var._position_relative = rot_apply(_PX2a_vfm_location_var._rotation_absolute, tc1);
  } /* PX2a_vfm_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX2a_vfm_location", _PX2a_vfm_location_var._position_absolute, _PX2a_vfm_location_var._rotation_absolute);
  instrument->_position_absolute[314] = _PX2a_vfm_location_var._position_absolute;
  instrument->_position_relative[314] = _PX2a_vfm_location_var._position_relative;
    _PX2a_vfm_location_var._position_relative_is_zero =  coords_test_zero(_PX2a_vfm_location_var._position_relative);
  instrument->counter_N[314]  = instrument->counter_P[314] = instrument->counter_P2[314] = 0;
  instrument->counter_AbsorbProp[314]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0313_PX2a_vfm_location", _PX2a_vfm_location_var._position_absolute, _PX2a_vfm_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0313_PX2a_vfm_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_vfm_location_setpos */

/* component PX2a_vfm_in_xz_plane=Arm() SETTING, POSITION/ROTATION */
int _PX2a_vfm_in_xz_plane_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_vfm_in_xz_plane_setpos] component PX2a_vfm_in_xz_plane=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_vfm_in_xz_plane_var._name, "PX2a_vfm_in_xz_plane", 16384);
  stracpy(_PX2a_vfm_in_xz_plane_var._type, "Arm", 16384);
  _PX2a_vfm_in_xz_plane_var._index=315;
  int current_setpos_index = 315;
  /* component PX2a_vfm_in_xz_plane=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _PX2a_vfm_location_var._rotation_absolute, _PX2a_vfm_in_xz_plane_var._rotation_absolute);
    rot_transpose(_PX2a_vfm_location_var._rotation_absolute, tr1);
    rot_mul(_PX2a_vfm_in_xz_plane_var._rotation_absolute, tr1, _PX2a_vfm_in_xz_plane_var._rotation_relative);
    _PX2a_vfm_in_xz_plane_var._rotation_is_identity =  rot_test_identity(_PX2a_vfm_in_xz_plane_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_vfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_vfm_in_xz_plane_var._position_absolute = coords_add(_PX2a_vfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_vfm_location_var._position_absolute, _PX2a_vfm_in_xz_plane_var._position_absolute);
    _PX2a_vfm_in_xz_plane_var._position_relative = rot_apply(_PX2a_vfm_in_xz_plane_var._rotation_absolute, tc1);
  } /* PX2a_vfm_in_xz_plane=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_vfm_in_xz_plane", _PX2a_vfm_in_xz_plane_var._position_absolute, _PX2a_vfm_in_xz_plane_var._rotation_absolute);
  instrument->_position_absolute[315] = _PX2a_vfm_in_xz_plane_var._position_absolute;
  instrument->_position_relative[315] = _PX2a_vfm_in_xz_plane_var._position_relative;
    _PX2a_vfm_in_xz_plane_var._position_relative_is_zero =  coords_test_zero(_PX2a_vfm_in_xz_plane_var._position_relative);
  instrument->counter_N[315]  = instrument->counter_P[315] = instrument->counter_P2[315] = 0;
  instrument->counter_AbsorbProp[315]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0314_PX2a_vfm_in_xz_plane", _PX2a_vfm_in_xz_plane_var._position_absolute, _PX2a_vfm_in_xz_plane_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_vfm_in_xz_plane_setpos */

/* component PX2a_vfm=Mirror_curved() SETTING, POSITION/ROTATION */
int _PX2a_vfm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_vfm_setpos] component PX2a_vfm=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PX2a_vfm_var._name, "PX2a_vfm", 16384);
  stracpy(_PX2a_vfm_var._type, "Mirror_curved", 16384);
  _PX2a_vfm_var._index=316;
  int current_setpos_index = 316;
  _PX2a_vfm_var._parameters.radius = _instrument_var._parameters.PX2a_vfm_radius;
  _PX2a_vfm_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_PX2a_vfm_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _PX2a_vfm_var._parameters.coating[0]='\0';
  _PX2a_vfm_var._parameters.zdepth = 0.2;
  _PX2a_vfm_var._parameters.yheight = 0.2;
  _PX2a_vfm_var._parameters.length = 450e-3;
  _PX2a_vfm_var._parameters.width = 0.1;


  /* component PX2a_vfm=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.PX2a_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_vfm_in_xz_plane_var._rotation_absolute, _PX2a_vfm_var._rotation_absolute);
    rot_transpose(_PX2a_vfm_location_var._rotation_absolute, tr1);
    rot_mul(_PX2a_vfm_var._rotation_absolute, tr1, _PX2a_vfm_var._rotation_relative);
    _PX2a_vfm_var._rotation_is_identity =  rot_test_identity(_PX2a_vfm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_vfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_vfm_var._position_absolute = coords_add(_PX2a_vfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_vfm_location_var._position_absolute, _PX2a_vfm_var._position_absolute);
    _PX2a_vfm_var._position_relative = rot_apply(_PX2a_vfm_var._rotation_absolute, tc1);
  } /* PX2a_vfm=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PX2a_vfm", _PX2a_vfm_var._position_absolute, _PX2a_vfm_var._rotation_absolute);
  instrument->_position_absolute[316] = _PX2a_vfm_var._position_absolute;
  instrument->_position_relative[316] = _PX2a_vfm_var._position_relative;
    _PX2a_vfm_var._position_relative_is_zero =  coords_test_zero(_PX2a_vfm_var._position_relative);
  instrument->counter_N[316]  = instrument->counter_P[316] = instrument->counter_P2[316] = 0;
  instrument->counter_AbsorbProp[316]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0315_PX2a_vfm", _PX2a_vfm_var._position_absolute, _PX2a_vfm_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "radius", "1", "_instrument_var._parameters.PX2a_vfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "length", "0", "450e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0315_PX2a_vfm", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_vfm_setpos */

/* component PX2a_vfm_takeoff=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX2a_vfm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_vfm_takeoff_setpos] component PX2a_vfm_takeoff=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX2a_vfm_takeoff_var._name, "PX2a_vfm_takeoff", 16384);
  stracpy(_PX2a_vfm_takeoff_var._type, "Monitor_nD", 16384);
  _PX2a_vfm_takeoff_var._index=317;
  int current_setpos_index = 317;
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_vfm_takeoff_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.user9[0]='\0';
  _PX2a_vfm_takeoff_var._parameters.xwidth = 0.01;
  _PX2a_vfm_takeoff_var._parameters.yheight = 0.01;
  _PX2a_vfm_takeoff_var._parameters.zdepth = 0;
  _PX2a_vfm_takeoff_var._parameters.bins = 100;
  _PX2a_vfm_takeoff_var._parameters.min = -1e40;
  _PX2a_vfm_takeoff_var._parameters.max = 1e40;
  _PX2a_vfm_takeoff_var._parameters.restore_xray = 0;
  _PX2a_vfm_takeoff_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.geometry[0]='\0';
  _PX2a_vfm_takeoff_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_vfm_takeoff_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_vfm_takeoff_var._parameters.username9[0]='\0';


  /* component PX2a_vfm_takeoff=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-2 * _instrument_var._parameters.PX2a_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_vfm_location_var._rotation_absolute, _PX2a_vfm_takeoff_var._rotation_absolute);
    rot_transpose(_PX2a_vfm_var._rotation_absolute, tr1);
    rot_mul(_PX2a_vfm_takeoff_var._rotation_absolute, tr1, _PX2a_vfm_takeoff_var._rotation_relative);
    _PX2a_vfm_takeoff_var._rotation_is_identity =  rot_test_identity(_PX2a_vfm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_vfm_in_xz_plane_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_vfm_takeoff_var._position_absolute = coords_add(_PX2a_vfm_in_xz_plane_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_vfm_var._position_absolute, _PX2a_vfm_takeoff_var._position_absolute);
    _PX2a_vfm_takeoff_var._position_relative = rot_apply(_PX2a_vfm_takeoff_var._rotation_absolute, tc1);
  } /* PX2a_vfm_takeoff=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX2a_vfm_takeoff", _PX2a_vfm_takeoff_var._position_absolute, _PX2a_vfm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[317] = _PX2a_vfm_takeoff_var._position_absolute;
  instrument->_position_relative[317] = _PX2a_vfm_takeoff_var._position_relative;
    _PX2a_vfm_takeoff_var._position_relative_is_zero =  coords_test_zero(_PX2a_vfm_takeoff_var._position_relative);
  instrument->counter_N[317]  = instrument->counter_P[317] = instrument->counter_P2[317] = 0;
  instrument->counter_AbsorbProp[317]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0316_PX2a_vfm_takeoff", _PX2a_vfm_takeoff_var._position_absolute, _PX2a_vfm_takeoff_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0316_PX2a_vfm_takeoff", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_vfm_takeoff_setpos */

/* component PX2a_hfm_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX2a_hfm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hfm_location_setpos] component PX2a_hfm_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX2a_hfm_location_var._name, "PX2a_hfm_location", 16384);
  stracpy(_PX2a_hfm_location_var._type, "Monitor_nD", 16384);
  _PX2a_hfm_location_var._index=318;
  int current_setpos_index = 318;
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.user9[0]='\0';
  _PX2a_hfm_location_var._parameters.xwidth = 0.01;
  _PX2a_hfm_location_var._parameters.yheight = 0.01;
  _PX2a_hfm_location_var._parameters.zdepth = 0;
  _PX2a_hfm_location_var._parameters.bins = 100;
  _PX2a_hfm_location_var._parameters.min = -1e40;
  _PX2a_hfm_location_var._parameters.max = 1e40;
  _PX2a_hfm_location_var._parameters.restore_xray = 0;
  _PX2a_hfm_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX2a_hfm_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.geometry[0]='\0';
  _PX2a_hfm_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_location_var._parameters.username9[0]='\0';


  /* component PX2a_hfm_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_vfm_takeoff_var._rotation_absolute, _PX2a_hfm_location_var._rotation_absolute);
    rot_transpose(_PX2a_vfm_takeoff_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hfm_location_var._rotation_absolute, tr1, _PX2a_hfm_location_var._rotation_relative);
    _PX2a_hfm_location_var._rotation_is_identity =  rot_test_identity(_PX2a_hfm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 34.5 -33.9);
    rot_transpose(_PX2a_vfm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hfm_location_var._position_absolute = coords_add(_PX2a_vfm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_vfm_takeoff_var._position_absolute, _PX2a_hfm_location_var._position_absolute);
    _PX2a_hfm_location_var._position_relative = rot_apply(_PX2a_hfm_location_var._rotation_absolute, tc1);
  } /* PX2a_hfm_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hfm_location", _PX2a_hfm_location_var._position_absolute, _PX2a_hfm_location_var._rotation_absolute);
  instrument->_position_absolute[318] = _PX2a_hfm_location_var._position_absolute;
  instrument->_position_relative[318] = _PX2a_hfm_location_var._position_relative;
    _PX2a_hfm_location_var._position_relative_is_zero =  coords_test_zero(_PX2a_hfm_location_var._position_relative);
  instrument->counter_N[318]  = instrument->counter_P[318] = instrument->counter_P2[318] = 0;
  instrument->counter_AbsorbProp[318]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0317_PX2a_hfm_location", _PX2a_hfm_location_var._position_absolute, _PX2a_hfm_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0317_PX2a_hfm_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hfm_location_setpos */

/* component PX2a_hfm=Mirror_curved() SETTING, POSITION/ROTATION */
int _PX2a_hfm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hfm_setpos] component PX2a_hfm=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_PX2a_hfm_var._name, "PX2a_hfm", 16384);
  stracpy(_PX2a_hfm_var._type, "Mirror_curved", 16384);
  _PX2a_hfm_var._index=319;
  int current_setpos_index = 319;
  _PX2a_hfm_var._parameters.radius = _instrument_var._parameters.PX2a_hfm_radius;
  _PX2a_hfm_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_PX2a_hfm_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _PX2a_hfm_var._parameters.coating[0]='\0';
  _PX2a_hfm_var._parameters.zdepth = 0.2;
  _PX2a_hfm_var._parameters.yheight = 0.2;
  _PX2a_hfm_var._parameters.length = 450e-3;
  _PX2a_hfm_var._parameters.width = 0.1;


  /* component PX2a_hfm=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.PX2a_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_hfm_location_var._rotation_absolute, _PX2a_hfm_var._rotation_absolute);
    rot_transpose(_PX2a_hfm_location_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hfm_var._rotation_absolute, tr1, _PX2a_hfm_var._rotation_relative);
    _PX2a_hfm_var._rotation_is_identity =  rot_test_identity(_PX2a_hfm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_hfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hfm_var._position_absolute = coords_add(_PX2a_hfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_hfm_location_var._position_absolute, _PX2a_hfm_var._position_absolute);
    _PX2a_hfm_var._position_relative = rot_apply(_PX2a_hfm_var._rotation_absolute, tc1);
  } /* PX2a_hfm=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hfm", _PX2a_hfm_var._position_absolute, _PX2a_hfm_var._rotation_absolute);
  instrument->_position_absolute[319] = _PX2a_hfm_var._position_absolute;
  instrument->_position_relative[319] = _PX2a_hfm_var._position_relative;
    _PX2a_hfm_var._position_relative_is_zero =  coords_test_zero(_PX2a_hfm_var._position_relative);
  instrument->counter_N[319]  = instrument->counter_P[319] = instrument->counter_P2[319] = 0;
  instrument->counter_AbsorbProp[319]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0318_PX2a_hfm", _PX2a_hfm_var._position_absolute, _PX2a_hfm_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "radius", "1", "_instrument_var._parameters.PX2a_hfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "length", "0", "450e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0318_PX2a_hfm", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hfm_setpos */

/* component PX2a_hfm_takeoff=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX2a_hfm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_hfm_takeoff_setpos] component PX2a_hfm_takeoff=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX2a_hfm_takeoff_var._name, "PX2a_hfm_takeoff", 16384);
  stracpy(_PX2a_hfm_takeoff_var._type, "Monitor_nD", 16384);
  _PX2a_hfm_takeoff_var._index=320;
  int current_setpos_index = 320;
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_hfm_takeoff_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.user9[0]='\0';
  _PX2a_hfm_takeoff_var._parameters.xwidth = 0.01;
  _PX2a_hfm_takeoff_var._parameters.yheight = 0.01;
  _PX2a_hfm_takeoff_var._parameters.zdepth = 0;
  _PX2a_hfm_takeoff_var._parameters.bins = 100;
  _PX2a_hfm_takeoff_var._parameters.min = -1e40;
  _PX2a_hfm_takeoff_var._parameters.max = 1e40;
  _PX2a_hfm_takeoff_var._parameters.restore_xray = 0;
  _PX2a_hfm_takeoff_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.geometry[0]='\0';
  _PX2a_hfm_takeoff_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_hfm_takeoff_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_hfm_takeoff_var._parameters.username9[0]='\0';


  /* component PX2a_hfm_takeoff=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-2 * _instrument_var._parameters.PX2a_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _PX2a_hfm_location_var._rotation_absolute, _PX2a_hfm_takeoff_var._rotation_absolute);
    rot_transpose(_PX2a_hfm_var._rotation_absolute, tr1);
    rot_mul(_PX2a_hfm_takeoff_var._rotation_absolute, tr1, _PX2a_hfm_takeoff_var._rotation_relative);
    _PX2a_hfm_takeoff_var._rotation_is_identity =  rot_test_identity(_PX2a_hfm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_hfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_hfm_takeoff_var._position_absolute = coords_add(_PX2a_hfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_hfm_var._position_absolute, _PX2a_hfm_takeoff_var._position_absolute);
    _PX2a_hfm_takeoff_var._position_relative = rot_apply(_PX2a_hfm_takeoff_var._rotation_absolute, tc1);
  } /* PX2a_hfm_takeoff=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX2a_hfm_takeoff", _PX2a_hfm_takeoff_var._position_absolute, _PX2a_hfm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[320] = _PX2a_hfm_takeoff_var._position_absolute;
  instrument->_position_relative[320] = _PX2a_hfm_takeoff_var._position_relative;
    _PX2a_hfm_takeoff_var._position_relative_is_zero =  coords_test_zero(_PX2a_hfm_takeoff_var._position_relative);
  instrument->counter_N[320]  = instrument->counter_P[320] = instrument->counter_P2[320] = 0;
  instrument->counter_AbsorbProp[320]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0319_PX2a_hfm_takeoff", _PX2a_hfm_takeoff_var._position_absolute, _PX2a_hfm_takeoff_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0319_PX2a_hfm_takeoff", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_hfm_takeoff_setpos */

/* component PX2a_sample_stage=Arm() SETTING, POSITION/ROTATION */
int _PX2a_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_sample_stage_setpos] component PX2a_sample_stage=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_PX2a_sample_stage_var._name, "PX2a_sample_stage", 16384);
  stracpy(_PX2a_sample_stage_var._type, "Arm", 16384);
  _PX2a_sample_stage_var._index=321;
  int current_setpos_index = 321;
  /* component PX2a_sample_stage=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_hfm_takeoff_var._rotation_absolute, _PX2a_sample_stage_var._rotation_absolute);
    rot_transpose(_PX2a_hfm_takeoff_var._rotation_absolute, tr1);
    rot_mul(_PX2a_sample_stage_var._rotation_absolute, tr1, _PX2a_sample_stage_var._rotation_relative);
    _PX2a_sample_stage_var._rotation_is_identity =  rot_test_identity(_PX2a_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      1e-3, -1.1e-3, 1);
    rot_transpose(_PX2a_hfm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_sample_stage_var._position_absolute = coords_add(_PX2a_hfm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_hfm_takeoff_var._position_absolute, _PX2a_sample_stage_var._position_absolute);
    _PX2a_sample_stage_var._position_relative = rot_apply(_PX2a_sample_stage_var._rotation_absolute, tc1);
  } /* PX2a_sample_stage=Arm() AT ROTATED */
  DEBUG_COMPONENT("PX2a_sample_stage", _PX2a_sample_stage_var._position_absolute, _PX2a_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[321] = _PX2a_sample_stage_var._position_absolute;
  instrument->_position_relative[321] = _PX2a_sample_stage_var._position_relative;
    _PX2a_sample_stage_var._position_relative_is_zero =  coords_test_zero(_PX2a_sample_stage_var._position_relative);
  instrument->counter_N[321]  = instrument->counter_P[321] = instrument->counter_P2[321] = 0;
  instrument->counter_AbsorbProp[321]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0320_PX2a_sample_stage", _PX2a_sample_stage_var._position_absolute, _PX2a_sample_stage_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_sample_stage_setpos */

/* component PX2a_sample_monitor=Monitor_nD() SETTING, POSITION/ROTATION */
int _PX2a_sample_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_sample_monitor_setpos] component PX2a_sample_monitor=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_PX2a_sample_monitor_var._name, "PX2a_sample_monitor", 16384);
  stracpy(_PX2a_sample_monitor_var._type, "Monitor_nD", 16384);
  _PX2a_sample_monitor_var._index=322;
  int current_setpos_index = 322;
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_PX2a_sample_monitor_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.user9[0]='\0';
  _PX2a_sample_monitor_var._parameters.xwidth = 0.01;
  _PX2a_sample_monitor_var._parameters.yheight = 0.01;
  _PX2a_sample_monitor_var._parameters.zdepth = 0;
  _PX2a_sample_monitor_var._parameters.bins = 100;
  _PX2a_sample_monitor_var._parameters.min = -1e40;
  _PX2a_sample_monitor_var._parameters.max = 1e40;
  _PX2a_sample_monitor_var._parameters.restore_xray = 0;
  _PX2a_sample_monitor_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_PX2a_sample_monitor_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.geometry[0]='\0';
  _PX2a_sample_monitor_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_monitor_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_monitor_var._parameters.username9[0]='\0';


  /* component PX2a_sample_monitor=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_sample_stage_var._rotation_absolute, _PX2a_sample_monitor_var._rotation_absolute);
    rot_transpose(_PX2a_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_PX2a_sample_monitor_var._rotation_absolute, tr1, _PX2a_sample_monitor_var._rotation_relative);
    _PX2a_sample_monitor_var._rotation_is_identity =  rot_test_identity(_PX2a_sample_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_sample_monitor_var._position_absolute = coords_add(_PX2a_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_sample_stage_var._position_absolute, _PX2a_sample_monitor_var._position_absolute);
    _PX2a_sample_monitor_var._position_relative = rot_apply(_PX2a_sample_monitor_var._rotation_absolute, tc1);
  } /* PX2a_sample_monitor=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("PX2a_sample_monitor", _PX2a_sample_monitor_var._position_absolute, _PX2a_sample_monitor_var._rotation_absolute);
  instrument->_position_absolute[322] = _PX2a_sample_monitor_var._position_absolute;
  instrument->_position_relative[322] = _PX2a_sample_monitor_var._position_relative;
    _PX2a_sample_monitor_var._position_relative_is_zero =  coords_test_zero(_PX2a_sample_monitor_var._position_relative);
  instrument->counter_N[322]  = instrument->counter_P[322] = instrument->counter_P2[322] = 0;
  instrument->counter_AbsorbProp[322]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0321_PX2a_sample_monitor", _PX2a_sample_monitor_var._position_absolute, _PX2a_sample_monitor_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0321_PX2a_sample_monitor", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_sample_monitor_setpos */

/* component PX2a_sample=Single_crystal() SETTING, POSITION/ROTATION */
int _PX2a_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_sample_setpos] component PX2a_sample=Single_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1265]");
  stracpy(_PX2a_sample_var._name, "PX2a_sample", 16384);
  stracpy(_PX2a_sample_var._type, "Single_crystal", 16384);
  _PX2a_sample_var._index=323;
  int current_setpos_index = 323;
  if(_instrument_var._parameters.PX2a_sample && strlen(_instrument_var._parameters.PX2a_sample))
    stracpy(_PX2a_sample_var._parameters.reflections, _instrument_var._parameters.PX2a_sample ? _instrument_var._parameters.PX2a_sample : "", 16384);
  else 
  _PX2a_sample_var._parameters.reflections[0]='\0';
  _PX2a_sample_var._parameters.geometry[0]='\0';
  _PX2a_sample_var._parameters.mosaic_AB[0] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[1] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[2] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[3] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[4] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[5] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[6] = 0;
  _PX2a_sample_var._parameters.mosaic_AB[7] = 0;
  _PX2a_sample_var._parameters.xwidth = 0;
  _PX2a_sample_var._parameters.yheight = 5e-3;
  _PX2a_sample_var._parameters.zdepth = 0;
  _PX2a_sample_var._parameters.radius = .5e-4;
  _PX2a_sample_var._parameters.delta_d_d = 1e-3;
  _PX2a_sample_var._parameters.mosaic = 0.1;
  _PX2a_sample_var._parameters.mosaic_a = -1;
  _PX2a_sample_var._parameters.mosaic_b = -1;
  _PX2a_sample_var._parameters.mosaic_c = -1;
  _PX2a_sample_var._parameters.recip_cell = 0;
  _PX2a_sample_var._parameters.barns = 0;
  _PX2a_sample_var._parameters.ax = 0;
  _PX2a_sample_var._parameters.ay = 0;
  _PX2a_sample_var._parameters.az = 0;
  _PX2a_sample_var._parameters.bx = 0;
  _PX2a_sample_var._parameters.by = 0;
  _PX2a_sample_var._parameters.bz = 0;
  _PX2a_sample_var._parameters.cx = 0;
  _PX2a_sample_var._parameters.cy = 0;
  _PX2a_sample_var._parameters.cz = 0;
  _PX2a_sample_var._parameters.p_transmit = 0;
  _PX2a_sample_var._parameters.sigma_inc = 0;
  _PX2a_sample_var._parameters.aa = 0;
  _PX2a_sample_var._parameters.bb = 0;
  _PX2a_sample_var._parameters.cc = 0;
  _PX2a_sample_var._parameters.order = 1;
  _PX2a_sample_var._parameters.extra_order = 0;
  _PX2a_sample_var._parameters.RX = 0;
  _PX2a_sample_var._parameters.RY = 0;
  _PX2a_sample_var._parameters.powder = 0;
  _PX2a_sample_var._parameters.deltak = 1e-6;
  if("NULL" && strlen("NULL"))
    stracpy(_PX2a_sample_var._parameters.material_datafile, "NULL" ? "NULL" : "", 16384);
  else 
  _PX2a_sample_var._parameters.material_datafile[0]='\0';
  _PX2a_sample_var._parameters.surf_size = 0;
  _PX2a_sample_var._parameters.surf_k = NULL; // default pointer allocation
  _PX2a_sample_var._parameters.surf_FT2 = NULL; // default pointer allocation
  _PX2a_sample_var._parameters.surf_dir[0] = 0;
  _PX2a_sample_var._parameters.surf_dir[1] = 0;
  _PX2a_sample_var._parameters.surf_dir[2] = 0;


  /* component PX2a_sample=Single_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.PX2a_rotX)*DEG2RAD, (_instrument_var._parameters.PX2a_rotY)*DEG2RAD, (_instrument_var._parameters.PX2a_rotZ)*DEG2RAD);
    rot_mul(tr1, _PX2a_sample_stage_var._rotation_absolute, _PX2a_sample_var._rotation_absolute);
    rot_transpose(_PX2a_sample_monitor_var._rotation_absolute, tr1);
    rot_mul(_PX2a_sample_var._rotation_absolute, tr1, _PX2a_sample_var._rotation_relative);
    _PX2a_sample_var._rotation_is_identity =  rot_test_identity(_PX2a_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_sample_var._position_absolute = coords_add(_PX2a_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_sample_monitor_var._position_absolute, _PX2a_sample_var._position_absolute);
    _PX2a_sample_var._position_relative = rot_apply(_PX2a_sample_var._rotation_absolute, tc1);
  } /* PX2a_sample=Single_crystal() AT ROTATED */
  DEBUG_COMPONENT("PX2a_sample", _PX2a_sample_var._position_absolute, _PX2a_sample_var._rotation_absolute);
  instrument->_position_absolute[323] = _PX2a_sample_var._position_absolute;
  instrument->_position_relative[323] = _PX2a_sample_var._position_relative;
    _PX2a_sample_var._position_relative_is_zero =  coords_test_zero(_PX2a_sample_var._position_relative);
  instrument->counter_N[323]  = instrument->counter_P[323] = instrument->counter_P2[323] = 0;
  instrument->counter_AbsorbProp[323]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0322_PX2a_sample", _PX2a_sample_var._position_absolute, _PX2a_sample_var._rotation_absolute, "Single_crystal");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "reflections", 0, _instrument_var._parameters.PX2a_sample, "char*");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "mosaic_AB", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "yheight", "0", "5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "radius", "0", ".5e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "delta_d_d", "1e-3", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "mosaic", "-1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "mosaic_a", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "mosaic_b", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "mosaic_c", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "recip_cell", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "barns", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "ax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "ay", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "az", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "bx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "by", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "bz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "cx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "cy", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "cz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "p_transmit", "0.001", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "sigma_inc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "aa", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "bb", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "cc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "order", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "extra_order", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "RX", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "RY", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "powder", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "deltak", "1e-6", "1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "material_datafile", "Si.txt", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "surf_size", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "surf_k", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "surf_FT2", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0322_PX2a_sample", "surf_dir", "{ 0 , 0 , 0 }", "{ 0 , 0 , 0 }","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_sample_setpos */

/* component PX2a_psd4pi=PSD_monitor_4PI() SETTING, POSITION/ROTATION */
int _PX2a_psd4pi_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_psd4pi_setpos] component PX2a_psd4pi=PSD_monitor_4PI() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:55]");
  stracpy(_PX2a_psd4pi_var._name, "PX2a_psd4pi", 16384);
  stracpy(_PX2a_psd4pi_var._type, "PSD_monitor_4PI", 16384);
  _PX2a_psd4pi_var._index=324;
  int current_setpos_index = 324;
  _PX2a_psd4pi_var._parameters.radius = 0.1;
  _PX2a_psd4pi_var._parameters.restore_xray = 1;
  _PX2a_psd4pi_var._parameters.nx = 180;
  _PX2a_psd4pi_var._parameters.ny = 180;
  if("psd4pi" && strlen("psd4pi"))
    stracpy(_PX2a_psd4pi_var._parameters.filename, "psd4pi" ? "psd4pi" : "", 16384);
  else 
  _PX2a_psd4pi_var._parameters.filename[0]='\0';


  /* component PX2a_psd4pi=PSD_monitor_4PI() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_sample_var._rotation_absolute, _PX2a_psd4pi_var._rotation_absolute);
    rot_transpose(_PX2a_sample_var._rotation_absolute, tr1);
    rot_mul(_PX2a_psd4pi_var._rotation_absolute, tr1, _PX2a_psd4pi_var._rotation_relative);
    _PX2a_psd4pi_var._rotation_is_identity =  rot_test_identity(_PX2a_psd4pi_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_psd4pi_var._position_absolute = coords_add(_PX2a_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_sample_var._position_absolute, _PX2a_psd4pi_var._position_absolute);
    _PX2a_psd4pi_var._position_relative = rot_apply(_PX2a_psd4pi_var._rotation_absolute, tc1);
  } /* PX2a_psd4pi=PSD_monitor_4PI() AT ROTATED */
  DEBUG_COMPONENT("PX2a_psd4pi", _PX2a_psd4pi_var._position_absolute, _PX2a_psd4pi_var._rotation_absolute);
  instrument->_position_absolute[324] = _PX2a_psd4pi_var._position_absolute;
  instrument->_position_relative[324] = _PX2a_psd4pi_var._position_relative;
    _PX2a_psd4pi_var._position_relative_is_zero =  coords_test_zero(_PX2a_psd4pi_var._position_relative);
  instrument->counter_N[324]  = instrument->counter_P[324] = instrument->counter_P2[324] = 0;
  instrument->counter_AbsorbProp[324]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0323_PX2a_psd4pi", _PX2a_psd4pi_var._position_absolute, _PX2a_psd4pi_var._rotation_absolute, "PSD_monitor_4PI");
        mccomp_param_nexus(nxhandle,"0323_PX2a_psd4pi", "radius", "1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0323_PX2a_psd4pi", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0323_PX2a_psd4pi", "nx", "90", "180","int");
        mccomp_param_nexus(nxhandle,"0323_PX2a_psd4pi", "ny", "90", "180","int");
        mccomp_param_nexus(nxhandle,"0323_PX2a_psd4pi", "filename", 0, "psd4pi", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_psd4pi_setpos */

/* component PX2a_Eiger9M=PSD_monitor() SETTING, POSITION/ROTATION */
int _PX2a_Eiger9M_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_PX2a_Eiger9M_setpos] component PX2a_Eiger9M=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_PX2a_Eiger9M_var._name, "PX2a_Eiger9M", 16384);
  stracpy(_PX2a_Eiger9M_var._type, "PSD_monitor", 16384);
  _PX2a_Eiger9M_var._index=325;
  int current_setpos_index = 325;
  if("PX2a_Eiger9M.dat" && strlen("PX2a_Eiger9M.dat"))
    stracpy(_PX2a_Eiger9M_var._parameters.filename, "PX2a_Eiger9M.dat" ? "PX2a_Eiger9M.dat" : "", 16384);
  else 
  _PX2a_Eiger9M_var._parameters.filename[0]='\0';
  _PX2a_Eiger9M_var._parameters.xwidth = 233.1e-3;
  _PX2a_Eiger9M_var._parameters.yheight = 244.7e-3;
  _PX2a_Eiger9M_var._parameters.radius = 0;
  _PX2a_Eiger9M_var._parameters.restore_xray = 1;
  _PX2a_Eiger9M_var._parameters.nowritefile = 0;
  _PX2a_Eiger9M_var._parameters.nx = 3108;
  _PX2a_Eiger9M_var._parameters.ny = 3262;
  _PX2a_Eiger9M_var._parameters.nr = 0;


  /* component PX2a_Eiger9M=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_sample_stage_var._rotation_absolute, _PX2a_Eiger9M_var._rotation_absolute);
    rot_transpose(_PX2a_psd4pi_var._rotation_absolute, tr1);
    rot_mul(_PX2a_Eiger9M_var._rotation_absolute, tr1, _PX2a_Eiger9M_var._rotation_relative);
    _PX2a_Eiger9M_var._rotation_is_identity =  rot_test_identity(_PX2a_Eiger9M_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.12);
    rot_transpose(_PX2a_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _PX2a_Eiger9M_var._position_absolute = coords_add(_PX2a_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_psd4pi_var._position_absolute, _PX2a_Eiger9M_var._position_absolute);
    _PX2a_Eiger9M_var._position_relative = rot_apply(_PX2a_Eiger9M_var._rotation_absolute, tc1);
  } /* PX2a_Eiger9M=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("PX2a_Eiger9M", _PX2a_Eiger9M_var._position_absolute, _PX2a_Eiger9M_var._rotation_absolute);
  instrument->_position_absolute[325] = _PX2a_Eiger9M_var._position_absolute;
  instrument->_position_relative[325] = _PX2a_Eiger9M_var._position_relative;
    _PX2a_Eiger9M_var._position_relative_is_zero =  coords_test_zero(_PX2a_Eiger9M_var._position_relative);
  instrument->counter_N[325]  = instrument->counter_P[325] = instrument->counter_P2[325] = 0;
  instrument->counter_AbsorbProp[325]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0324_PX2a_Eiger9M", _PX2a_Eiger9M_var._position_absolute, _PX2a_Eiger9M_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "filename", 0, "PX2a_Eiger9M.dat", "char*");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "xwidth", "0.05", "233.1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "yheight", "0.05", "244.7e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "nx", "90", "3108","int");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "ny", "90", "3262","int");
        mccomp_param_nexus(nxhandle,"0324_PX2a_Eiger9M", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _PX2a_Eiger9M_setpos */

/* component beamdump_335=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_335_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_335_setpos] component beamdump_335=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_335_var._name, "beamdump_335", 16384);
  stracpy(_beamdump_335_var._type, "Beamstop", 16384);
  _beamdump_335_var._index=326;
  int current_setpos_index = 326;
  _beamdump_335_var._parameters.xmin = -0.05;
  _beamdump_335_var._parameters.xmax = 0.05;
  _beamdump_335_var._parameters.ymin = -0.05;
  _beamdump_335_var._parameters.ymax = 0.05;
  _beamdump_335_var._parameters.xwidth = 0;
  _beamdump_335_var._parameters.yheight = 0;
  _beamdump_335_var._parameters.radius = 0;

  /* component beamdump_335=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _PX2a_Eiger9M_var._rotation_absolute, _beamdump_335_var._rotation_absolute);
    rot_transpose(_PX2a_Eiger9M_var._rotation_absolute, tr1);
    rot_mul(_beamdump_335_var._rotation_absolute, tr1, _beamdump_335_var._rotation_relative);
    _beamdump_335_var._rotation_is_identity =  rot_test_identity(_beamdump_335_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_PX2a_Eiger9M_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_335_var._position_absolute = coords_add(_PX2a_Eiger9M_var._position_absolute, tc2);
    tc1 = coords_sub(_PX2a_Eiger9M_var._position_absolute, _beamdump_335_var._position_absolute);
    _beamdump_335_var._position_relative = rot_apply(_beamdump_335_var._rotation_absolute, tc1);
  } /* beamdump_335=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_335", _beamdump_335_var._position_absolute, _beamdump_335_var._rotation_absolute);
  instrument->_position_absolute[326] = _beamdump_335_var._position_absolute;
  instrument->_position_relative[326] = _beamdump_335_var._position_relative;
    _beamdump_335_var._position_relative_is_zero =  coords_test_zero(_beamdump_335_var._position_relative);
  instrument->counter_N[326]  = instrument->counter_P[326] = instrument->counter_P2[326] = 0;
  instrument->counter_AbsorbProp[326]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0325_beamdump_335", _beamdump_335_var._position_absolute, _beamdump_335_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0325_beamdump_335", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_335_setpos */

/* component SWING_pos=Text() SETTING, POSITION/ROTATION */
int _SWING_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_pos_setpos] component SWING_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_SWING_pos_var._name, "SWING_pos", 16384);
  stracpy(_SWING_pos_var._type, "Text", 16384);
  _SWING_pos_var._index=327;
  int current_setpos_index = 327;
  if("SWING" && strlen("SWING"))
    stracpy(_SWING_pos_var._parameters.text, "SWING" ? "SWING" : "", 16384);
  else 
  _SWING_pos_var._parameters.text[0]='\0';
  _SWING_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_SWING_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _SWING_pos_var._parameters.plane[0]='\0';
  _SWING_pos_var._parameters.pen_thickness = 0.1;


  /* component SWING_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-236.451)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _SWING_pos_var._rotation_absolute);
    rot_transpose(_beamdump_335_var._rotation_absolute, tr1);
    rot_mul(_SWING_pos_var._rotation_absolute, tr1, _SWING_pos_var._rotation_relative);
    _SWING_pos_var._rotation_is_identity =  rot_test_identity(_SWING_pos_var._rotation_relative);
    tc1 = coords_set(
      -31.136, 0, -46.954);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_335_var._position_absolute, _SWING_pos_var._position_absolute);
    _SWING_pos_var._position_relative = rot_apply(_SWING_pos_var._rotation_absolute, tc1);
  } /* SWING_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("SWING_pos", _SWING_pos_var._position_absolute, _SWING_pos_var._rotation_absolute);
  instrument->_position_absolute[327] = _SWING_pos_var._position_absolute;
  instrument->_position_relative[327] = _SWING_pos_var._position_relative;
    _SWING_pos_var._position_relative_is_zero =  coords_test_zero(_SWING_pos_var._position_relative);
  instrument->counter_N[327]  = instrument->counter_P[327] = instrument->counter_P2[327] = 0;
  instrument->counter_AbsorbProp[327]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0326_SWING_pos", _SWING_pos_var._position_absolute, _SWING_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0326_SWING_pos", "text", "NONE", "SWING", "char*");
        mccomp_param_nexus(nxhandle,"0326_SWING_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0326_SWING_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0326_SWING_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_pos_setpos */

/* component SWING=Arm() SETTING, POSITION/ROTATION */
int _SWING_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_setpos] component SWING=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SWING_var._name, "SWING", 16384);
  stracpy(_SWING_var._type, "Arm", 16384);
  _SWING_var._index=328;
  int current_setpos_index = 328;
  /* component SWING=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_pos_var._rotation_absolute, _SWING_var._rotation_absolute);
    rot_transpose(_SWING_pos_var._rotation_absolute, tr1);
    rot_mul(_SWING_var._rotation_absolute, tr1, _SWING_var._rotation_relative);
    _SWING_var._rotation_is_identity =  rot_test_identity(_SWING_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_var._position_absolute = coords_add(_SWING_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_pos_var._position_absolute, _SWING_var._position_absolute);
    _SWING_var._position_relative = rot_apply(_SWING_var._rotation_absolute, tc1);
  } /* SWING=Arm() AT ROTATED */
  DEBUG_COMPONENT("SWING", _SWING_var._position_absolute, _SWING_var._rotation_absolute);
  instrument->_position_absolute[328] = _SWING_var._position_absolute;
  instrument->_position_relative[328] = _SWING_var._position_relative;
    _SWING_var._position_relative_is_zero =  coords_test_zero(_SWING_var._position_relative);
  instrument->counter_N[328]  = instrument->counter_P[328] = instrument->counter_P2[328] = 0;
  instrument->counter_AbsorbProp[328]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0327_SWING", _SWING_var._position_absolute, _SWING_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_setpos */

/* component SWING_Source_U20=Undulator() SETTING, POSITION/ROTATION */
int _SWING_Source_U20_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_Source_U20_setpos] component SWING_Source_U20=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_SWING_Source_U20_var._name, "SWING_Source_U20", 16384);
  stracpy(_SWING_Source_U20_var._type, "Undulator", 16384);
  _SWING_Source_U20_var._index=329;
  int current_setpos_index = 329;
  _SWING_Source_U20_var._parameters.E0 = _instrument_var._parameters.SWING_E0;
  _SWING_Source_U20_var._parameters.dE = _instrument_var._parameters.SWING_dE;
  _SWING_Source_U20_var._parameters.phase = 0;
  _SWING_Source_U20_var._parameters.randomphase = 1;
  _SWING_Source_U20_var._parameters.Ee = 2.75;
  _SWING_Source_U20_var._parameters.dEe = 0;
  _SWING_Source_U20_var._parameters.Ie = 0.5;
  _SWING_Source_U20_var._parameters.B = 0;
  _SWING_Source_U20_var._parameters.K = 5;
  _SWING_Source_U20_var._parameters.Nper = 1;
  _SWING_Source_U20_var._parameters.lu = 16e-3;
  _SWING_Source_U20_var._parameters.sigey = 8.1e-6;
  _SWING_Source_U20_var._parameters.sigex = 388e-6;
  _SWING_Source_U20_var._parameters.sigepx = 14.5e-6;
  _SWING_Source_U20_var._parameters.sigepy = 4.61e-6;
  _SWING_Source_U20_var._parameters.focus_xw = 0;
  _SWING_Source_U20_var._parameters.focus_yh = 0;
  _SWING_Source_U20_var._parameters.dist = 1;
  _SWING_Source_U20_var._parameters.quick_integ = 0;
  _SWING_Source_U20_var._parameters.E1st = 0;
  _SWING_Source_U20_var._parameters.verbose = 0;
  _SWING_Source_U20_var._parameters.Br = 1.35;


  /* component SWING_Source_U20=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_var._rotation_absolute, _SWING_Source_U20_var._rotation_absolute);
    rot_transpose(_SWING_var._rotation_absolute, tr1);
    rot_mul(_SWING_Source_U20_var._rotation_absolute, tr1, _SWING_Source_U20_var._rotation_relative);
    _SWING_Source_U20_var._rotation_is_identity =  rot_test_identity(_SWING_Source_U20_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_Source_U20_var._position_absolute = coords_add(_SWING_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_var._position_absolute, _SWING_Source_U20_var._position_absolute);
    _SWING_Source_U20_var._position_relative = rot_apply(_SWING_Source_U20_var._rotation_absolute, tc1);
  } /* SWING_Source_U20=Undulator() AT ROTATED */
  DEBUG_COMPONENT("SWING_Source_U20", _SWING_Source_U20_var._position_absolute, _SWING_Source_U20_var._rotation_absolute);
  instrument->_position_absolute[329] = _SWING_Source_U20_var._position_absolute;
  instrument->_position_relative[329] = _SWING_Source_U20_var._position_relative;
    _SWING_Source_U20_var._position_relative_is_zero =  coords_test_zero(_SWING_Source_U20_var._position_relative);
  instrument->counter_N[329]  = instrument->counter_P[329] = instrument->counter_P2[329] = 0;
  instrument->counter_AbsorbProp[329]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0328_SWING_Source_U20", _SWING_Source_U20_var._position_absolute, _SWING_Source_U20_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "E0", "0", "_instrument_var._parameters.SWING_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "dE", "0", "_instrument_var._parameters.SWING_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "dEe", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "K", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "Nper", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "lu", "16e-3", "16e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "sigey", "0", "8.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "sigex", "0", "388e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "sigepx", "0", "14.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "sigepy", "0", "4.61e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0328_SWING_Source_U20", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_Source_U20_setpos */

/* component SWING_mon_src_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_mon_src_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_mon_src_xy_setpos] component SWING_mon_src_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_mon_src_xy_var._name, "SWING_mon_src_xy", 16384);
  stracpy(_SWING_mon_src_xy_var._type, "Monitor_nD", 16384);
  _SWING_mon_src_xy_var._index=330;
  int current_setpos_index = 330;
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.user9[0]='\0';
  _SWING_mon_src_xy_var._parameters.xwidth = 2e-3;
  _SWING_mon_src_xy_var._parameters.yheight = 2e-3;
  _SWING_mon_src_xy_var._parameters.zdepth = 0;
  _SWING_mon_src_xy_var._parameters.bins = 128;
  _SWING_mon_src_xy_var._parameters.min = -1e40;
  _SWING_mon_src_xy_var._parameters.max = 1e40;
  _SWING_mon_src_xy_var._parameters.restore_xray = 0;
  _SWING_mon_src_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_mon_src_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.geometry[0]='\0';
  _SWING_mon_src_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_xy_var._parameters.username9[0]='\0';


  /* component SWING_mon_src_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_Source_U20_var._rotation_absolute, _SWING_mon_src_xy_var._rotation_absolute);
    rot_transpose(_SWING_Source_U20_var._rotation_absolute, tr1);
    rot_mul(_SWING_mon_src_xy_var._rotation_absolute, tr1, _SWING_mon_src_xy_var._rotation_relative);
    _SWING_mon_src_xy_var._rotation_is_identity =  rot_test_identity(_SWING_mon_src_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 11.7);
    rot_transpose(_SWING_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_mon_src_xy_var._position_absolute = coords_add(_SWING_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_Source_U20_var._position_absolute, _SWING_mon_src_xy_var._position_absolute);
    _SWING_mon_src_xy_var._position_relative = rot_apply(_SWING_mon_src_xy_var._rotation_absolute, tc1);
  } /* SWING_mon_src_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_mon_src_xy", _SWING_mon_src_xy_var._position_absolute, _SWING_mon_src_xy_var._rotation_absolute);
  instrument->_position_absolute[330] = _SWING_mon_src_xy_var._position_absolute;
  instrument->_position_relative[330] = _SWING_mon_src_xy_var._position_relative;
    _SWING_mon_src_xy_var._position_relative_is_zero =  coords_test_zero(_SWING_mon_src_xy_var._position_relative);
  instrument->counter_N[330]  = instrument->counter_P[330] = instrument->counter_P2[330] = 0;
  instrument->counter_AbsorbProp[330]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0329_SWING_mon_src_xy", _SWING_mon_src_xy_var._position_absolute, _SWING_mon_src_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0329_SWING_mon_src_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_mon_src_xy_setpos */

/* component SWING_mon_src_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_mon_src_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_mon_src_e_setpos] component SWING_mon_src_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_mon_src_e_var._name, "SWING_mon_src_e", 16384);
  stracpy(_SWING_mon_src_e_var._type, "Monitor_nD", 16384);
  _SWING_mon_src_e_var._index=331;
  int current_setpos_index = 331;
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_src_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.user9[0]='\0';
  _SWING_mon_src_e_var._parameters.xwidth = 2e-3;
  _SWING_mon_src_e_var._parameters.yheight = 2e-3;
  _SWING_mon_src_e_var._parameters.zdepth = 0;
  _SWING_mon_src_e_var._parameters.bins = 128;
  _SWING_mon_src_e_var._parameters.min = _instrument_var._parameters.SWING_E0 - _instrument_var._parameters.SWING_dE * 1.1;
  _SWING_mon_src_e_var._parameters.max = _instrument_var._parameters.SWING_E0 + _instrument_var._parameters.SWING_dE * 1.1;
  _SWING_mon_src_e_var._parameters.restore_xray = 0;
  _SWING_mon_src_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_SWING_mon_src_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.geometry[0]='\0';
  _SWING_mon_src_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_src_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_src_e_var._parameters.username9[0]='\0';


  /* component SWING_mon_src_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_mon_src_xy_var._rotation_absolute, _SWING_mon_src_e_var._rotation_absolute);
    rot_transpose(_SWING_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_SWING_mon_src_e_var._rotation_absolute, tr1, _SWING_mon_src_e_var._rotation_relative);
    _SWING_mon_src_e_var._rotation_is_identity =  rot_test_identity(_SWING_mon_src_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_mon_src_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_mon_src_e_var._position_absolute = coords_add(_SWING_mon_src_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_mon_src_xy_var._position_absolute, _SWING_mon_src_e_var._position_absolute);
    _SWING_mon_src_e_var._position_relative = rot_apply(_SWING_mon_src_e_var._rotation_absolute, tc1);
  } /* SWING_mon_src_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_mon_src_e", _SWING_mon_src_e_var._position_absolute, _SWING_mon_src_e_var._rotation_absolute);
  instrument->_position_absolute[331] = _SWING_mon_src_e_var._position_absolute;
  instrument->_position_relative[331] = _SWING_mon_src_e_var._position_relative;
    _SWING_mon_src_e_var._position_relative_is_zero =  coords_test_zero(_SWING_mon_src_e_var._position_relative);
  instrument->counter_N[331]  = instrument->counter_P[331] = instrument->counter_P2[331] = 0;
  instrument->counter_AbsorbProp[331]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0330_SWING_mon_src_e", _SWING_mon_src_e_var._position_absolute, _SWING_mon_src_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "min", "-1e40", "_instrument_var._parameters.SWING_E0 - _instrument_var._parameters.SWING_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "max", "1e40", "_instrument_var._parameters.SWING_E0 + _instrument_var._parameters.SWING_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0330_SWING_mon_src_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_mon_src_e_setpos */

/* component SWING_slit=Slit() SETTING, POSITION/ROTATION */
int _SWING_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_slit_setpos] component SWING_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_SWING_slit_var._name, "SWING_slit", 16384);
  stracpy(_SWING_slit_var._type, "Slit", 16384);
  _SWING_slit_var._index=332;
  int current_setpos_index = 332;
  _SWING_slit_var._parameters.xmin = 0;
  _SWING_slit_var._parameters.xmax = 0;
  _SWING_slit_var._parameters.ymin = 0;
  _SWING_slit_var._parameters.ymax = 0;
  _SWING_slit_var._parameters.radius = 0;
  _SWING_slit_var._parameters.xwidth = 1e-3;
  _SWING_slit_var._parameters.yheight = 0.5e-3;
  _SWING_slit_var._parameters.dist = 0;
  _SWING_slit_var._parameters.focus_xw = 0;
  _SWING_slit_var._parameters.focus_yh = 0;
  _SWING_slit_var._parameters.focus_x0 = 0;
  _SWING_slit_var._parameters.focus_y0 = 0;

  /* component SWING_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_mon_src_e_var._rotation_absolute, _SWING_slit_var._rotation_absolute);
    rot_transpose(_SWING_mon_src_e_var._rotation_absolute, tr1);
    rot_mul(_SWING_slit_var._rotation_absolute, tr1, _SWING_slit_var._rotation_relative);
    _SWING_slit_var._rotation_is_identity =  rot_test_identity(_SWING_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_SWING_mon_src_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_slit_var._position_absolute = coords_add(_SWING_mon_src_e_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_mon_src_e_var._position_absolute, _SWING_slit_var._position_absolute);
    _SWING_slit_var._position_relative = rot_apply(_SWING_slit_var._rotation_absolute, tc1);
  } /* SWING_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("SWING_slit", _SWING_slit_var._position_absolute, _SWING_slit_var._rotation_absolute);
  instrument->_position_absolute[332] = _SWING_slit_var._position_absolute;
  instrument->_position_relative[332] = _SWING_slit_var._position_relative;
    _SWING_slit_var._position_relative_is_zero =  coords_test_zero(_SWING_slit_var._position_relative);
  instrument->counter_N[332]  = instrument->counter_P[332] = instrument->counter_P2[332] = 0;
  instrument->counter_AbsorbProp[332]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0331_SWING_slit", _SWING_slit_var._position_absolute, _SWING_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "xwidth", "0.001", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "yheight", "0.001", "0.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0331_SWING_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_slit_setpos */

/* component SWING_slit_mon_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_slit_mon_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_slit_mon_xy_setpos] component SWING_slit_mon_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_slit_mon_xy_var._name, "SWING_slit_mon_xy", 16384);
  stracpy(_SWING_slit_mon_xy_var._type, "Monitor_nD", 16384);
  _SWING_slit_mon_xy_var._index=333;
  int current_setpos_index = 333;
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_slit_mon_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.user9[0]='\0';
  _SWING_slit_mon_xy_var._parameters.xwidth = 2e-3;
  _SWING_slit_mon_xy_var._parameters.yheight = 2e-3;
  _SWING_slit_mon_xy_var._parameters.zdepth = 0;
  _SWING_slit_mon_xy_var._parameters.bins = 128;
  _SWING_slit_mon_xy_var._parameters.min = -1e40;
  _SWING_slit_mon_xy_var._parameters.max = 1e40;
  _SWING_slit_mon_xy_var._parameters.restore_xray = 0;
  _SWING_slit_mon_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_slit_mon_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.geometry[0]='\0';
  _SWING_slit_mon_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_slit_mon_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_slit_mon_xy_var._parameters.username9[0]='\0';


  /* component SWING_slit_mon_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_slit_var._rotation_absolute, _SWING_slit_mon_xy_var._rotation_absolute);
    rot_transpose(_SWING_slit_var._rotation_absolute, tr1);
    rot_mul(_SWING_slit_mon_xy_var._rotation_absolute, tr1, _SWING_slit_mon_xy_var._rotation_relative);
    _SWING_slit_mon_xy_var._rotation_is_identity =  rot_test_identity(_SWING_slit_mon_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_slit_mon_xy_var._position_absolute = coords_add(_SWING_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_slit_var._position_absolute, _SWING_slit_mon_xy_var._position_absolute);
    _SWING_slit_mon_xy_var._position_relative = rot_apply(_SWING_slit_mon_xy_var._rotation_absolute, tc1);
  } /* SWING_slit_mon_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_slit_mon_xy", _SWING_slit_mon_xy_var._position_absolute, _SWING_slit_mon_xy_var._rotation_absolute);
  instrument->_position_absolute[333] = _SWING_slit_mon_xy_var._position_absolute;
  instrument->_position_relative[333] = _SWING_slit_mon_xy_var._position_relative;
    _SWING_slit_mon_xy_var._position_relative_is_zero =  coords_test_zero(_SWING_slit_mon_xy_var._position_relative);
  instrument->counter_N[333]  = instrument->counter_P[333] = instrument->counter_P2[333] = 0;
  instrument->counter_AbsorbProp[333]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0332_SWING_slit_mon_xy", _SWING_slit_mon_xy_var._position_absolute, _SWING_slit_mon_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0332_SWING_slit_mon_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_slit_mon_xy_setpos */

/* component SWING_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _SWING_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_DCM_location_setpos] component SWING_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SWING_DCM_location_var._name, "SWING_DCM_location", 16384);
  stracpy(_SWING_DCM_location_var._type, "Arm", 16384);
  _SWING_DCM_location_var._index=334;
  int current_setpos_index = 334;
  /* component SWING_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_Source_U20_var._rotation_absolute, _SWING_DCM_location_var._rotation_absolute);
    rot_transpose(_SWING_slit_mon_xy_var._rotation_absolute, tr1);
    rot_mul(_SWING_DCM_location_var._rotation_absolute, tr1, _SWING_DCM_location_var._rotation_relative);
    _SWING_DCM_location_var._rotation_is_identity =  rot_test_identity(_SWING_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 20);
    rot_transpose(_SWING_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_DCM_location_var._position_absolute = coords_add(_SWING_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_slit_mon_xy_var._position_absolute, _SWING_DCM_location_var._position_absolute);
    _SWING_DCM_location_var._position_relative = rot_apply(_SWING_DCM_location_var._rotation_absolute, tc1);
  } /* SWING_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("SWING_DCM_location", _SWING_DCM_location_var._position_absolute, _SWING_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[334] = _SWING_DCM_location_var._position_absolute;
  instrument->_position_relative[334] = _SWING_DCM_location_var._position_relative;
    _SWING_DCM_location_var._position_relative_is_zero =  coords_test_zero(_SWING_DCM_location_var._position_relative);
  instrument->counter_N[334]  = instrument->counter_P[334] = instrument->counter_P2[334] = 0;
  instrument->counter_AbsorbProp[334]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0333_SWING_DCM_location", _SWING_DCM_location_var._position_absolute, _SWING_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_DCM_location_setpos */

/* component SWING_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SWING_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_dcm_xtal0_setpos] component SWING_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SWING_dcm_xtal0_var._name, "SWING_dcm_xtal0", 16384);
  stracpy(_SWING_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _SWING_dcm_xtal0_var._index=335;
  int current_setpos_index = 335;
  _SWING_dcm_xtal0_var._parameters.length = 0.04;
  _SWING_dcm_xtal0_var._parameters.width = 0.04;
  _SWING_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SWING_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SWING_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SWING_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SWING_dcm_xtal0_var._parameters.material[0]='\0';
  _SWING_dcm_xtal0_var._parameters.alpha = 0.0;
  _SWING_dcm_xtal0_var._parameters.R0 = 0;
  _SWING_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _SWING_dcm_xtal0_var._parameters.crystal_type = 1;
  _SWING_dcm_xtal0_var._parameters.h = 1;
  _SWING_dcm_xtal0_var._parameters.k = 1;
  _SWING_dcm_xtal0_var._parameters.l = 1;
  _SWING_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _SWING_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component SWING_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SWING_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_DCM_location_var._rotation_absolute, _SWING_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_SWING_slit_mon_xy_var._rotation_absolute, tr1);
    rot_mul(_SWING_dcm_xtal0_var._rotation_absolute, tr1, _SWING_dcm_xtal0_var._rotation_relative);
    _SWING_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_SWING_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_dcm_xtal0_var._position_absolute = coords_add(_SWING_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_slit_mon_xy_var._position_absolute, _SWING_dcm_xtal0_var._position_absolute);
    _SWING_dcm_xtal0_var._position_relative = rot_apply(_SWING_dcm_xtal0_var._rotation_absolute, tc1);
  } /* SWING_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SWING_dcm_xtal0", _SWING_dcm_xtal0_var._position_absolute, _SWING_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[335] = _SWING_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[335] = _SWING_dcm_xtal0_var._position_relative;
    _SWING_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_SWING_dcm_xtal0_var._position_relative);
  instrument->counter_N[335]  = instrument->counter_P[335] = instrument->counter_P2[335] = 0;
  instrument->counter_AbsorbProp[335]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0334_SWING_dcm_xtal0", _SWING_dcm_xtal0_var._position_absolute, _SWING_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0334_SWING_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_dcm_xtal0_setpos */

/* component SWING_dcm0=Arm() SETTING, POSITION/ROTATION */
int _SWING_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_dcm0_setpos] component SWING_dcm0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SWING_dcm0_var._name, "SWING_dcm0", 16384);
  stracpy(_SWING_dcm0_var._type, "Arm", 16384);
  _SWING_dcm0_var._index=336;
  int current_setpos_index = 336;
  /* component SWING_dcm0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SWING_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_dcm_xtal0_var._rotation_absolute, _SWING_dcm0_var._rotation_absolute);
    rot_transpose(_SWING_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_SWING_dcm0_var._rotation_absolute, tr1, _SWING_dcm0_var._rotation_relative);
    _SWING_dcm0_var._rotation_is_identity =  rot_test_identity(_SWING_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_dcm0_var._position_absolute = coords_add(_SWING_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_dcm_xtal0_var._position_absolute, _SWING_dcm0_var._position_absolute);
    _SWING_dcm0_var._position_relative = rot_apply(_SWING_dcm0_var._rotation_absolute, tc1);
  } /* SWING_dcm0=Arm() AT ROTATED */
  DEBUG_COMPONENT("SWING_dcm0", _SWING_dcm0_var._position_absolute, _SWING_dcm0_var._rotation_absolute);
  instrument->_position_absolute[336] = _SWING_dcm0_var._position_absolute;
  instrument->_position_relative[336] = _SWING_dcm0_var._position_relative;
    _SWING_dcm0_var._position_relative_is_zero =  coords_test_zero(_SWING_dcm0_var._position_relative);
  instrument->counter_N[336]  = instrument->counter_P[336] = instrument->counter_P2[336] = 0;
  instrument->counter_AbsorbProp[336]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0335_SWING_dcm0", _SWING_dcm0_var._position_absolute, _SWING_dcm0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_dcm0_setpos */

/* component SWING_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SWING_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_dcm_xtal1_setpos] component SWING_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SWING_dcm_xtal1_var._name, "SWING_dcm_xtal1", 16384);
  stracpy(_SWING_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _SWING_dcm_xtal1_var._index=337;
  int current_setpos_index = 337;
  _SWING_dcm_xtal1_var._parameters.length = 0.04;
  _SWING_dcm_xtal1_var._parameters.width = 0.04;
  _SWING_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SWING_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SWING_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SWING_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SWING_dcm_xtal1_var._parameters.material[0]='\0';
  _SWING_dcm_xtal1_var._parameters.alpha = 0.0;
  _SWING_dcm_xtal1_var._parameters.R0 = 0;
  _SWING_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _SWING_dcm_xtal1_var._parameters.crystal_type = 1;
  _SWING_dcm_xtal1_var._parameters.h = 1;
  _SWING_dcm_xtal1_var._parameters.k = 1;
  _SWING_dcm_xtal1_var._parameters.l = 1;
  _SWING_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _SWING_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component SWING_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SWING_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_dcm0_var._rotation_absolute, _SWING_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_SWING_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_SWING_dcm_xtal1_var._rotation_absolute, tr1, _SWING_dcm_xtal1_var._rotation_relative);
    _SWING_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_SWING_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, SWING_dcm_gap, _instrument_var._parameters.SWING_dcm_theta ? SWING_dcm_gap / tan ( _instrument_var._parameters.SWING_dcm_theta * DEG2RAD ) : 0);
    rot_transpose(_SWING_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_dcm_xtal1_var._position_absolute = coords_add(_SWING_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_dcm_xtal0_var._position_absolute, _SWING_dcm_xtal1_var._position_absolute);
    _SWING_dcm_xtal1_var._position_relative = rot_apply(_SWING_dcm_xtal1_var._rotation_absolute, tc1);
  } /* SWING_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SWING_dcm_xtal1", _SWING_dcm_xtal1_var._position_absolute, _SWING_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[337] = _SWING_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[337] = _SWING_dcm_xtal1_var._position_relative;
    _SWING_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_SWING_dcm_xtal1_var._position_relative);
  instrument->counter_N[337]  = instrument->counter_P[337] = instrument->counter_P2[337] = 0;
  instrument->counter_AbsorbProp[337]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0336_SWING_dcm_xtal1", _SWING_dcm_xtal1_var._position_absolute, _SWING_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0336_SWING_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_dcm_xtal1_setpos */

/* component SWING_dcm1=Arm() SETTING, POSITION/ROTATION */
int _SWING_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_dcm1_setpos] component SWING_dcm1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SWING_dcm1_var._name, "SWING_dcm1", 16384);
  stracpy(_SWING_dcm1_var._type, "Arm", 16384);
  _SWING_dcm1_var._index=338;
  int current_setpos_index = 338;
  /* component SWING_dcm1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SWING_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_dcm_xtal1_var._rotation_absolute, _SWING_dcm1_var._rotation_absolute);
    rot_transpose(_SWING_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_SWING_dcm1_var._rotation_absolute, tr1, _SWING_dcm1_var._rotation_relative);
    _SWING_dcm1_var._rotation_is_identity =  rot_test_identity(_SWING_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_dcm1_var._position_absolute = coords_add(_SWING_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_dcm_xtal1_var._position_absolute, _SWING_dcm1_var._position_absolute);
    _SWING_dcm1_var._position_relative = rot_apply(_SWING_dcm1_var._rotation_absolute, tc1);
  } /* SWING_dcm1=Arm() AT ROTATED */
  DEBUG_COMPONENT("SWING_dcm1", _SWING_dcm1_var._position_absolute, _SWING_dcm1_var._rotation_absolute);
  instrument->_position_absolute[338] = _SWING_dcm1_var._position_absolute;
  instrument->_position_relative[338] = _SWING_dcm1_var._position_relative;
    _SWING_dcm1_var._position_relative_is_zero =  coords_test_zero(_SWING_dcm1_var._position_relative);
  instrument->counter_N[338]  = instrument->counter_P[338] = instrument->counter_P2[338] = 0;
  instrument->counter_AbsorbProp[338]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0337_SWING_dcm1", _SWING_dcm1_var._position_absolute, _SWING_dcm1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_dcm1_setpos */

/* component SWING_mon_dcm_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_mon_dcm_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_mon_dcm_e_setpos] component SWING_mon_dcm_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_mon_dcm_e_var._name, "SWING_mon_dcm_e", 16384);
  stracpy(_SWING_mon_dcm_e_var._type, "Monitor_nD", 16384);
  _SWING_mon_dcm_e_var._index=339;
  int current_setpos_index = 339;
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.user9[0]='\0';
  _SWING_mon_dcm_e_var._parameters.xwidth = 2e-3;
  _SWING_mon_dcm_e_var._parameters.yheight = 2e-3;
  _SWING_mon_dcm_e_var._parameters.zdepth = 0;
  _SWING_mon_dcm_e_var._parameters.bins = 128;
  _SWING_mon_dcm_e_var._parameters.min = _instrument_var._parameters.SWING_E0 - _instrument_var._parameters.SWING_dE * 1.1;
  _SWING_mon_dcm_e_var._parameters.max = _instrument_var._parameters.SWING_E0 + _instrument_var._parameters.SWING_dE * 1.1;
  _SWING_mon_dcm_e_var._parameters.restore_xray = 0;
  _SWING_mon_dcm_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_SWING_mon_dcm_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.geometry[0]='\0';
  _SWING_mon_dcm_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_e_var._parameters.username9[0]='\0';


  /* component SWING_mon_dcm_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_dcm1_var._rotation_absolute, _SWING_mon_dcm_e_var._rotation_absolute);
    rot_transpose(_SWING_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_SWING_mon_dcm_e_var._rotation_absolute, tr1, _SWING_mon_dcm_e_var._rotation_relative);
    _SWING_mon_dcm_e_var._rotation_is_identity =  rot_test_identity(_SWING_mon_dcm_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_SWING_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_mon_dcm_e_var._position_absolute = coords_add(_SWING_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_dcm_xtal1_var._position_absolute, _SWING_mon_dcm_e_var._position_absolute);
    _SWING_mon_dcm_e_var._position_relative = rot_apply(_SWING_mon_dcm_e_var._rotation_absolute, tc1);
  } /* SWING_mon_dcm_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_mon_dcm_e", _SWING_mon_dcm_e_var._position_absolute, _SWING_mon_dcm_e_var._rotation_absolute);
  instrument->_position_absolute[339] = _SWING_mon_dcm_e_var._position_absolute;
  instrument->_position_relative[339] = _SWING_mon_dcm_e_var._position_relative;
    _SWING_mon_dcm_e_var._position_relative_is_zero =  coords_test_zero(_SWING_mon_dcm_e_var._position_relative);
  instrument->counter_N[339]  = instrument->counter_P[339] = instrument->counter_P2[339] = 0;
  instrument->counter_AbsorbProp[339]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0338_SWING_mon_dcm_e", _SWING_mon_dcm_e_var._position_absolute, _SWING_mon_dcm_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "min", "-1e40", "_instrument_var._parameters.SWING_E0 - _instrument_var._parameters.SWING_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "max", "1e40", "_instrument_var._parameters.SWING_E0 + _instrument_var._parameters.SWING_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0338_SWING_mon_dcm_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_mon_dcm_e_setpos */

/* component SWING_mon_dcm_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_mon_dcm_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_mon_dcm_xy_setpos] component SWING_mon_dcm_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_mon_dcm_xy_var._name, "SWING_mon_dcm_xy", 16384);
  stracpy(_SWING_mon_dcm_xy_var._type, "Monitor_nD", 16384);
  _SWING_mon_dcm_xy_var._index=340;
  int current_setpos_index = 340;
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_mon_dcm_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.user9[0]='\0';
  _SWING_mon_dcm_xy_var._parameters.xwidth = 2e-3;
  _SWING_mon_dcm_xy_var._parameters.yheight = 2e-3;
  _SWING_mon_dcm_xy_var._parameters.zdepth = 0;
  _SWING_mon_dcm_xy_var._parameters.bins = 128;
  _SWING_mon_dcm_xy_var._parameters.min = -1e40;
  _SWING_mon_dcm_xy_var._parameters.max = 1e40;
  _SWING_mon_dcm_xy_var._parameters.restore_xray = 0;
  _SWING_mon_dcm_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.geometry[0]='\0';
  _SWING_mon_dcm_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_mon_dcm_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_mon_dcm_xy_var._parameters.username9[0]='\0';


  /* component SWING_mon_dcm_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_mon_dcm_e_var._rotation_absolute, _SWING_mon_dcm_xy_var._rotation_absolute);
    rot_transpose(_SWING_mon_dcm_e_var._rotation_absolute, tr1);
    rot_mul(_SWING_mon_dcm_xy_var._rotation_absolute, tr1, _SWING_mon_dcm_xy_var._rotation_relative);
    _SWING_mon_dcm_xy_var._rotation_is_identity =  rot_test_identity(_SWING_mon_dcm_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_mon_dcm_xy_var._position_absolute = coords_add(_SWING_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_mon_dcm_e_var._position_absolute, _SWING_mon_dcm_xy_var._position_absolute);
    _SWING_mon_dcm_xy_var._position_relative = rot_apply(_SWING_mon_dcm_xy_var._rotation_absolute, tc1);
  } /* SWING_mon_dcm_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_mon_dcm_xy", _SWING_mon_dcm_xy_var._position_absolute, _SWING_mon_dcm_xy_var._rotation_absolute);
  instrument->_position_absolute[340] = _SWING_mon_dcm_xy_var._position_absolute;
  instrument->_position_relative[340] = _SWING_mon_dcm_xy_var._position_relative;
    _SWING_mon_dcm_xy_var._position_relative_is_zero =  coords_test_zero(_SWING_mon_dcm_xy_var._position_relative);
  instrument->counter_N[340]  = instrument->counter_P[340] = instrument->counter_P2[340] = 0;
  instrument->counter_AbsorbProp[340]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0339_SWING_mon_dcm_xy", _SWING_mon_dcm_xy_var._position_absolute, _SWING_mon_dcm_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0339_SWING_mon_dcm_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_mon_dcm_xy_setpos */

/* component SWING_vfm_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_vfm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_vfm_location_setpos] component SWING_vfm_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_vfm_location_var._name, "SWING_vfm_location", 16384);
  stracpy(_SWING_vfm_location_var._type, "Monitor_nD", 16384);
  _SWING_vfm_location_var._index=341;
  int current_setpos_index = 341;
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.user9[0]='\0';
  _SWING_vfm_location_var._parameters.xwidth = 2e-3;
  _SWING_vfm_location_var._parameters.yheight = 2e-3;
  _SWING_vfm_location_var._parameters.zdepth = 0;
  _SWING_vfm_location_var._parameters.bins = 128;
  _SWING_vfm_location_var._parameters.min = -1e40;
  _SWING_vfm_location_var._parameters.max = 1e40;
  _SWING_vfm_location_var._parameters.restore_xray = 0;
  _SWING_vfm_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_vfm_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.geometry[0]='\0';
  _SWING_vfm_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_location_var._parameters.username9[0]='\0';


  /* component SWING_vfm_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_mon_dcm_xy_var._rotation_absolute, _SWING_vfm_location_var._rotation_absolute);
    rot_transpose(_SWING_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_SWING_vfm_location_var._rotation_absolute, tr1, _SWING_vfm_location_var._rotation_relative);
    _SWING_vfm_location_var._rotation_is_identity =  rot_test_identity(_SWING_vfm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 22.5 -20.5);
    rot_transpose(_SWING_mon_dcm_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_vfm_location_var._position_absolute = coords_add(_SWING_mon_dcm_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_mon_dcm_xy_var._position_absolute, _SWING_vfm_location_var._position_absolute);
    _SWING_vfm_location_var._position_relative = rot_apply(_SWING_vfm_location_var._rotation_absolute, tc1);
  } /* SWING_vfm_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_vfm_location", _SWING_vfm_location_var._position_absolute, _SWING_vfm_location_var._rotation_absolute);
  instrument->_position_absolute[341] = _SWING_vfm_location_var._position_absolute;
  instrument->_position_relative[341] = _SWING_vfm_location_var._position_relative;
    _SWING_vfm_location_var._position_relative_is_zero =  coords_test_zero(_SWING_vfm_location_var._position_relative);
  instrument->counter_N[341]  = instrument->counter_P[341] = instrument->counter_P2[341] = 0;
  instrument->counter_AbsorbProp[341]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0340_SWING_vfm_location", _SWING_vfm_location_var._position_absolute, _SWING_vfm_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0340_SWING_vfm_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_vfm_location_setpos */

/* component SWING_vfm_in_xz_plane=Arm() SETTING, POSITION/ROTATION */
int _SWING_vfm_in_xz_plane_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_vfm_in_xz_plane_setpos] component SWING_vfm_in_xz_plane=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SWING_vfm_in_xz_plane_var._name, "SWING_vfm_in_xz_plane", 16384);
  stracpy(_SWING_vfm_in_xz_plane_var._type, "Arm", 16384);
  _SWING_vfm_in_xz_plane_var._index=342;
  int current_setpos_index = 342;
  /* component SWING_vfm_in_xz_plane=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _SWING_vfm_location_var._rotation_absolute, _SWING_vfm_in_xz_plane_var._rotation_absolute);
    rot_transpose(_SWING_vfm_location_var._rotation_absolute, tr1);
    rot_mul(_SWING_vfm_in_xz_plane_var._rotation_absolute, tr1, _SWING_vfm_in_xz_plane_var._rotation_relative);
    _SWING_vfm_in_xz_plane_var._rotation_is_identity =  rot_test_identity(_SWING_vfm_in_xz_plane_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_vfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_vfm_in_xz_plane_var._position_absolute = coords_add(_SWING_vfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_vfm_location_var._position_absolute, _SWING_vfm_in_xz_plane_var._position_absolute);
    _SWING_vfm_in_xz_plane_var._position_relative = rot_apply(_SWING_vfm_in_xz_plane_var._rotation_absolute, tc1);
  } /* SWING_vfm_in_xz_plane=Arm() AT ROTATED */
  DEBUG_COMPONENT("SWING_vfm_in_xz_plane", _SWING_vfm_in_xz_plane_var._position_absolute, _SWING_vfm_in_xz_plane_var._rotation_absolute);
  instrument->_position_absolute[342] = _SWING_vfm_in_xz_plane_var._position_absolute;
  instrument->_position_relative[342] = _SWING_vfm_in_xz_plane_var._position_relative;
    _SWING_vfm_in_xz_plane_var._position_relative_is_zero =  coords_test_zero(_SWING_vfm_in_xz_plane_var._position_relative);
  instrument->counter_N[342]  = instrument->counter_P[342] = instrument->counter_P2[342] = 0;
  instrument->counter_AbsorbProp[342]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0341_SWING_vfm_in_xz_plane", _SWING_vfm_in_xz_plane_var._position_absolute, _SWING_vfm_in_xz_plane_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_vfm_in_xz_plane_setpos */

/* component SWING_vfm=Mirror_curved() SETTING, POSITION/ROTATION */
int _SWING_vfm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_vfm_setpos] component SWING_vfm=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SWING_vfm_var._name, "SWING_vfm", 16384);
  stracpy(_SWING_vfm_var._type, "Mirror_curved", 16384);
  _SWING_vfm_var._index=343;
  int current_setpos_index = 343;
  _SWING_vfm_var._parameters.radius = _instrument_var._parameters.SWING_vfm_radius;
  _SWING_vfm_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_SWING_vfm_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _SWING_vfm_var._parameters.coating[0]='\0';
  _SWING_vfm_var._parameters.zdepth = 0.2;
  _SWING_vfm_var._parameters.yheight = 0.2;
  _SWING_vfm_var._parameters.length = 450e-3;
  _SWING_vfm_var._parameters.width = 0.1;


  /* component SWING_vfm=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.SWING_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_vfm_in_xz_plane_var._rotation_absolute, _SWING_vfm_var._rotation_absolute);
    rot_transpose(_SWING_vfm_location_var._rotation_absolute, tr1);
    rot_mul(_SWING_vfm_var._rotation_absolute, tr1, _SWING_vfm_var._rotation_relative);
    _SWING_vfm_var._rotation_is_identity =  rot_test_identity(_SWING_vfm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_vfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_vfm_var._position_absolute = coords_add(_SWING_vfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_vfm_location_var._position_absolute, _SWING_vfm_var._position_absolute);
    _SWING_vfm_var._position_relative = rot_apply(_SWING_vfm_var._rotation_absolute, tc1);
  } /* SWING_vfm=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SWING_vfm", _SWING_vfm_var._position_absolute, _SWING_vfm_var._rotation_absolute);
  instrument->_position_absolute[343] = _SWING_vfm_var._position_absolute;
  instrument->_position_relative[343] = _SWING_vfm_var._position_relative;
    _SWING_vfm_var._position_relative_is_zero =  coords_test_zero(_SWING_vfm_var._position_relative);
  instrument->counter_N[343]  = instrument->counter_P[343] = instrument->counter_P2[343] = 0;
  instrument->counter_AbsorbProp[343]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0342_SWING_vfm", _SWING_vfm_var._position_absolute, _SWING_vfm_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "radius", "1", "_instrument_var._parameters.SWING_vfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "length", "0", "450e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0342_SWING_vfm", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_vfm_setpos */

/* component SWING_vfm_takeoff=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_vfm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_vfm_takeoff_setpos] component SWING_vfm_takeoff=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_vfm_takeoff_var._name, "SWING_vfm_takeoff", 16384);
  stracpy(_SWING_vfm_takeoff_var._type, "Monitor_nD", 16384);
  _SWING_vfm_takeoff_var._index=344;
  int current_setpos_index = 344;
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_vfm_takeoff_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.user9[0]='\0';
  _SWING_vfm_takeoff_var._parameters.xwidth = 2e-3;
  _SWING_vfm_takeoff_var._parameters.yheight = 2e-3;
  _SWING_vfm_takeoff_var._parameters.zdepth = 0;
  _SWING_vfm_takeoff_var._parameters.bins = 128;
  _SWING_vfm_takeoff_var._parameters.min = -1e40;
  _SWING_vfm_takeoff_var._parameters.max = 1e40;
  _SWING_vfm_takeoff_var._parameters.restore_xray = 0;
  _SWING_vfm_takeoff_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_vfm_takeoff_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.geometry[0]='\0';
  _SWING_vfm_takeoff_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_vfm_takeoff_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_vfm_takeoff_var._parameters.username9[0]='\0';


  /* component SWING_vfm_takeoff=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-2 * _instrument_var._parameters.SWING_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_vfm_location_var._rotation_absolute, _SWING_vfm_takeoff_var._rotation_absolute);
    rot_transpose(_SWING_vfm_var._rotation_absolute, tr1);
    rot_mul(_SWING_vfm_takeoff_var._rotation_absolute, tr1, _SWING_vfm_takeoff_var._rotation_relative);
    _SWING_vfm_takeoff_var._rotation_is_identity =  rot_test_identity(_SWING_vfm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_vfm_in_xz_plane_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_vfm_takeoff_var._position_absolute = coords_add(_SWING_vfm_in_xz_plane_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_vfm_var._position_absolute, _SWING_vfm_takeoff_var._position_absolute);
    _SWING_vfm_takeoff_var._position_relative = rot_apply(_SWING_vfm_takeoff_var._rotation_absolute, tc1);
  } /* SWING_vfm_takeoff=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_vfm_takeoff", _SWING_vfm_takeoff_var._position_absolute, _SWING_vfm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[344] = _SWING_vfm_takeoff_var._position_absolute;
  instrument->_position_relative[344] = _SWING_vfm_takeoff_var._position_relative;
    _SWING_vfm_takeoff_var._position_relative_is_zero =  coords_test_zero(_SWING_vfm_takeoff_var._position_relative);
  instrument->counter_N[344]  = instrument->counter_P[344] = instrument->counter_P2[344] = 0;
  instrument->counter_AbsorbProp[344]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0343_SWING_vfm_takeoff", _SWING_vfm_takeoff_var._position_absolute, _SWING_vfm_takeoff_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0343_SWING_vfm_takeoff", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_vfm_takeoff_setpos */

/* component SWING_hfm_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_hfm_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_hfm_location_setpos] component SWING_hfm_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_hfm_location_var._name, "SWING_hfm_location", 16384);
  stracpy(_SWING_hfm_location_var._type, "Monitor_nD", 16384);
  _SWING_hfm_location_var._index=345;
  int current_setpos_index = 345;
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.user9[0]='\0';
  _SWING_hfm_location_var._parameters.xwidth = 2e-3;
  _SWING_hfm_location_var._parameters.yheight = 2e-3;
  _SWING_hfm_location_var._parameters.zdepth = 0;
  _SWING_hfm_location_var._parameters.bins = 128;
  _SWING_hfm_location_var._parameters.min = -1e40;
  _SWING_hfm_location_var._parameters.max = 1e40;
  _SWING_hfm_location_var._parameters.restore_xray = 0;
  _SWING_hfm_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_hfm_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.geometry[0]='\0';
  _SWING_hfm_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_location_var._parameters.username9[0]='\0';


  /* component SWING_hfm_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_vfm_takeoff_var._rotation_absolute, _SWING_hfm_location_var._rotation_absolute);
    rot_transpose(_SWING_vfm_takeoff_var._rotation_absolute, tr1);
    rot_mul(_SWING_hfm_location_var._rotation_absolute, tr1, _SWING_hfm_location_var._rotation_relative);
    _SWING_hfm_location_var._rotation_is_identity =  rot_test_identity(_SWING_hfm_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 34.5 -33.9);
    rot_transpose(_SWING_vfm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_hfm_location_var._position_absolute = coords_add(_SWING_vfm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_vfm_takeoff_var._position_absolute, _SWING_hfm_location_var._position_absolute);
    _SWING_hfm_location_var._position_relative = rot_apply(_SWING_hfm_location_var._rotation_absolute, tc1);
  } /* SWING_hfm_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_hfm_location", _SWING_hfm_location_var._position_absolute, _SWING_hfm_location_var._rotation_absolute);
  instrument->_position_absolute[345] = _SWING_hfm_location_var._position_absolute;
  instrument->_position_relative[345] = _SWING_hfm_location_var._position_relative;
    _SWING_hfm_location_var._position_relative_is_zero =  coords_test_zero(_SWING_hfm_location_var._position_relative);
  instrument->counter_N[345]  = instrument->counter_P[345] = instrument->counter_P2[345] = 0;
  instrument->counter_AbsorbProp[345]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0344_SWING_hfm_location", _SWING_hfm_location_var._position_absolute, _SWING_hfm_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0344_SWING_hfm_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_hfm_location_setpos */

/* component SWING_hfm=Mirror_curved() SETTING, POSITION/ROTATION */
int _SWING_hfm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_hfm_setpos] component SWING_hfm=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SWING_hfm_var._name, "SWING_hfm", 16384);
  stracpy(_SWING_hfm_var._type, "Mirror_curved", 16384);
  _SWING_hfm_var._index=346;
  int current_setpos_index = 346;
  _SWING_hfm_var._parameters.radius = _instrument_var._parameters.SWING_hfm_radius;
  _SWING_hfm_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_SWING_hfm_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _SWING_hfm_var._parameters.coating[0]='\0';
  _SWING_hfm_var._parameters.zdepth = 0.2;
  _SWING_hfm_var._parameters.yheight = 0.2;
  _SWING_hfm_var._parameters.length = 450e-3;
  _SWING_hfm_var._parameters.width = 0.1;


  /* component SWING_hfm=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.SWING_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_hfm_location_var._rotation_absolute, _SWING_hfm_var._rotation_absolute);
    rot_transpose(_SWING_hfm_location_var._rotation_absolute, tr1);
    rot_mul(_SWING_hfm_var._rotation_absolute, tr1, _SWING_hfm_var._rotation_relative);
    _SWING_hfm_var._rotation_is_identity =  rot_test_identity(_SWING_hfm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_hfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_hfm_var._position_absolute = coords_add(_SWING_hfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_hfm_location_var._position_absolute, _SWING_hfm_var._position_absolute);
    _SWING_hfm_var._position_relative = rot_apply(_SWING_hfm_var._rotation_absolute, tc1);
  } /* SWING_hfm=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SWING_hfm", _SWING_hfm_var._position_absolute, _SWING_hfm_var._rotation_absolute);
  instrument->_position_absolute[346] = _SWING_hfm_var._position_absolute;
  instrument->_position_relative[346] = _SWING_hfm_var._position_relative;
    _SWING_hfm_var._position_relative_is_zero =  coords_test_zero(_SWING_hfm_var._position_relative);
  instrument->counter_N[346]  = instrument->counter_P[346] = instrument->counter_P2[346] = 0;
  instrument->counter_AbsorbProp[346]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0345_SWING_hfm", _SWING_hfm_var._position_absolute, _SWING_hfm_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "radius", "1", "_instrument_var._parameters.SWING_hfm_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "length", "0", "450e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0345_SWING_hfm", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_hfm_setpos */

/* component SWING_hfm_takeoff=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_hfm_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_hfm_takeoff_setpos] component SWING_hfm_takeoff=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_hfm_takeoff_var._name, "SWING_hfm_takeoff", 16384);
  stracpy(_SWING_hfm_takeoff_var._type, "Monitor_nD", 16384);
  _SWING_hfm_takeoff_var._index=347;
  int current_setpos_index = 347;
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_hfm_takeoff_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.user9[0]='\0';
  _SWING_hfm_takeoff_var._parameters.xwidth = 2e-3;
  _SWING_hfm_takeoff_var._parameters.yheight = 2e-3;
  _SWING_hfm_takeoff_var._parameters.zdepth = 0;
  _SWING_hfm_takeoff_var._parameters.bins = 128;
  _SWING_hfm_takeoff_var._parameters.min = -1e40;
  _SWING_hfm_takeoff_var._parameters.max = 1e40;
  _SWING_hfm_takeoff_var._parameters.restore_xray = 0;
  _SWING_hfm_takeoff_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_hfm_takeoff_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.geometry[0]='\0';
  _SWING_hfm_takeoff_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_hfm_takeoff_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_hfm_takeoff_var._parameters.username9[0]='\0';


  /* component SWING_hfm_takeoff=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-2 * _instrument_var._parameters.SWING_mirror_grazing_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SWING_hfm_location_var._rotation_absolute, _SWING_hfm_takeoff_var._rotation_absolute);
    rot_transpose(_SWING_hfm_var._rotation_absolute, tr1);
    rot_mul(_SWING_hfm_takeoff_var._rotation_absolute, tr1, _SWING_hfm_takeoff_var._rotation_relative);
    _SWING_hfm_takeoff_var._rotation_is_identity =  rot_test_identity(_SWING_hfm_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_hfm_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_hfm_takeoff_var._position_absolute = coords_add(_SWING_hfm_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_hfm_var._position_absolute, _SWING_hfm_takeoff_var._position_absolute);
    _SWING_hfm_takeoff_var._position_relative = rot_apply(_SWING_hfm_takeoff_var._rotation_absolute, tc1);
  } /* SWING_hfm_takeoff=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_hfm_takeoff", _SWING_hfm_takeoff_var._position_absolute, _SWING_hfm_takeoff_var._rotation_absolute);
  instrument->_position_absolute[347] = _SWING_hfm_takeoff_var._position_absolute;
  instrument->_position_relative[347] = _SWING_hfm_takeoff_var._position_relative;
    _SWING_hfm_takeoff_var._position_relative_is_zero =  coords_test_zero(_SWING_hfm_takeoff_var._position_relative);
  instrument->counter_N[347]  = instrument->counter_P[347] = instrument->counter_P2[347] = 0;
  instrument->counter_AbsorbProp[347]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0346_SWING_hfm_takeoff", _SWING_hfm_takeoff_var._position_absolute, _SWING_hfm_takeoff_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0346_SWING_hfm_takeoff", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_hfm_takeoff_setpos */

/* component SWING_sample_stage=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_sample_stage_setpos] component SWING_sample_stage=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_sample_stage_var._name, "SWING_sample_stage", 16384);
  stracpy(_SWING_sample_stage_var._type, "Monitor_nD", 16384);
  _SWING_sample_stage_var._index=348;
  int current_setpos_index = 348;
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_sample_stage_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.user9[0]='\0';
  _SWING_sample_stage_var._parameters.xwidth = 0.01;
  _SWING_sample_stage_var._parameters.yheight = 0.01;
  _SWING_sample_stage_var._parameters.zdepth = 0;
  _SWING_sample_stage_var._parameters.bins = 128;
  _SWING_sample_stage_var._parameters.min = -1e40;
  _SWING_sample_stage_var._parameters.max = 1e40;
  _SWING_sample_stage_var._parameters.restore_xray = 1;
  _SWING_sample_stage_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_sample_stage_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.geometry[0]='\0';
  _SWING_sample_stage_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_sample_stage_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_sample_stage_var._parameters.username9[0]='\0';


  /* component SWING_sample_stage=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_hfm_takeoff_var._rotation_absolute, _SWING_sample_stage_var._rotation_absolute);
    rot_transpose(_SWING_hfm_takeoff_var._rotation_absolute, tr1);
    rot_mul(_SWING_sample_stage_var._rotation_absolute, tr1, _SWING_sample_stage_var._rotation_relative);
    _SWING_sample_stage_var._rotation_is_identity =  rot_test_identity(_SWING_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      1e-3, -1.54e-3, 32 -22.5);
    rot_transpose(_SWING_hfm_takeoff_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_sample_stage_var._position_absolute = coords_add(_SWING_hfm_takeoff_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_hfm_takeoff_var._position_absolute, _SWING_sample_stage_var._position_absolute);
    _SWING_sample_stage_var._position_relative = rot_apply(_SWING_sample_stage_var._rotation_absolute, tc1);
  } /* SWING_sample_stage=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_sample_stage", _SWING_sample_stage_var._position_absolute, _SWING_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[348] = _SWING_sample_stage_var._position_absolute;
  instrument->_position_relative[348] = _SWING_sample_stage_var._position_relative;
    _SWING_sample_stage_var._position_relative_is_zero =  coords_test_zero(_SWING_sample_stage_var._position_relative);
  instrument->counter_N[348]  = instrument->counter_P[348] = instrument->counter_P2[348] = 0;
  instrument->counter_AbsorbProp[348]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0347_SWING_sample_stage", _SWING_sample_stage_var._position_absolute, _SWING_sample_stage_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0347_SWING_sample_stage", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_sample_stage_setpos */

/* component SWING_sample_test=Saxs_spheres() SETTING, POSITION/ROTATION */
int _SWING_sample_test_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_sample_test_setpos] component SWING_sample_test=Saxs_spheres() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Saxs_spheres.comp:74]");
  stracpy(_SWING_sample_test_var._name, "SWING_sample_test", 16384);
  stracpy(_SWING_sample_test_var._type, "Saxs_spheres", 16384);
  _SWING_sample_test_var._index=349;
  int current_setpos_index = 349;
  if("Be.txt" && strlen("Be.txt"))
    stracpy(_SWING_sample_test_var._parameters.sphere_mtrl, "Be.txt" ? "Be.txt" : "", 16384);
  else 
  _SWING_sample_test_var._parameters.sphere_mtrl[0]='\0';
  _SWING_sample_test_var._parameters.R = 100;
  _SWING_sample_test_var._parameters.Phi = 0.1;
  _SWING_sample_test_var._parameters.Delta_rho = 1.6;
  _SWING_sample_test_var._parameters.xwidth = 0;
  _SWING_sample_test_var._parameters.yheight = 1e-3;
  _SWING_sample_test_var._parameters.zdepth = 0;
  _SWING_sample_test_var._parameters.radius = 0.25e-3;
  _SWING_sample_test_var._parameters.target_x = 0;
  _SWING_sample_test_var._parameters.target_y = 0;
  _SWING_sample_test_var._parameters.target_z = 6;
  _SWING_sample_test_var._parameters.target_index = 0;
  _SWING_sample_test_var._parameters.focus_xw = 1;
  _SWING_sample_test_var._parameters.focus_yh = 1;
  _SWING_sample_test_var._parameters.focus_aw = 0;
  _SWING_sample_test_var._parameters.focus_ah = 0;
  _SWING_sample_test_var._parameters.focus_r = 0;
  _SWING_sample_test_var._parameters.mu_c = 0;


  /* component SWING_sample_test=Saxs_spheres() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_sample_stage_var._rotation_absolute, _SWING_sample_test_var._rotation_absolute);
    rot_transpose(_SWING_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_SWING_sample_test_var._rotation_absolute, tr1, _SWING_sample_test_var._rotation_relative);
    _SWING_sample_test_var._rotation_is_identity =  rot_test_identity(_SWING_sample_test_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_sample_test_var._position_absolute = coords_add(_SWING_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_sample_stage_var._position_absolute, _SWING_sample_test_var._position_absolute);
    _SWING_sample_test_var._position_relative = rot_apply(_SWING_sample_test_var._rotation_absolute, tc1);
  } /* SWING_sample_test=Saxs_spheres() AT ROTATED */
  DEBUG_COMPONENT("SWING_sample_test", _SWING_sample_test_var._position_absolute, _SWING_sample_test_var._rotation_absolute);
  instrument->_position_absolute[349] = _SWING_sample_test_var._position_absolute;
  instrument->_position_relative[349] = _SWING_sample_test_var._position_relative;
    _SWING_sample_test_var._position_relative_is_zero =  coords_test_zero(_SWING_sample_test_var._position_relative);
  instrument->counter_N[349]  = instrument->counter_P[349] = instrument->counter_P2[349] = 0;
  instrument->counter_AbsorbProp[349]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0348_SWING_sample_test", _SWING_sample_test_var._position_absolute, _SWING_sample_test_var._rotation_absolute, "Saxs_spheres");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "sphere_mtrl", "", "Be.txt", "char*");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "R", "100", "100","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "Phi", "1e-3", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "Delta_rho", "0.6", "1.6","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "yheight", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "radius", "0", "0.25e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "target_z", "6", "6","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "focus_xw", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "focus_yh", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "focus_aw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "focus_ah", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0348_SWING_sample_test", "mu_c", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_sample_test_setpos */

/* component SWING_sample=SAXSPDBFast() SETTING, POSITION/ROTATION */
int _SWING_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_sample_setpos] component SWING_sample=SAXSPDBFast() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSPDBFast.comp:356]");
  stracpy(_SWING_sample_var._name, "SWING_sample", 16384);
  stracpy(_SWING_sample_var._type, "SAXSPDBFast", 16384);
  _SWING_sample_var._index=350;
  int current_setpos_index = 350;
  _SWING_sample_var._parameters.RhoSolvent = 9.4e-14;
  _SWING_sample_var._parameters.Concentration = 0.01;
  _SWING_sample_var._parameters.AbsorptionCrosssection = 0.0;
  _SWING_sample_var._parameters.xwidth = 0.01;
  _SWING_sample_var._parameters.yheight = 0.01;
  _SWING_sample_var._parameters.zdepth = 0.01;
  _SWING_sample_var._parameters.SampleToDetectorDistance = _instrument_var._parameters.SWING_sample_det;
  _SWING_sample_var._parameters.DetectorRadius = 0.16 * 1.41;
  _SWING_sample_var._parameters.qMin = 0.001;
  _SWING_sample_var._parameters.qMax = 0.9;
  _SWING_sample_var._parameters.NumberOfQBins = 2000;
  if(_instrument_var._parameters.SWING_sample && strlen(_instrument_var._parameters.SWING_sample))
    stracpy(_SWING_sample_var._parameters.PDBFilepath, _instrument_var._parameters.SWING_sample ? _instrument_var._parameters.SWING_sample : "", 16384);
  else 
  _SWING_sample_var._parameters.PDBFilepath[0]='\0';


  /* component SWING_sample=SAXSPDBFast() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_sample_stage_var._rotation_absolute, _SWING_sample_var._rotation_absolute);
    rot_transpose(_SWING_sample_test_var._rotation_absolute, tr1);
    rot_mul(_SWING_sample_var._rotation_absolute, tr1, _SWING_sample_var._rotation_relative);
    _SWING_sample_var._rotation_is_identity =  rot_test_identity(_SWING_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_sample_var._position_absolute = coords_add(_SWING_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_sample_test_var._position_absolute, _SWING_sample_var._position_absolute);
    _SWING_sample_var._position_relative = rot_apply(_SWING_sample_var._rotation_absolute, tc1);
  } /* SWING_sample=SAXSPDBFast() AT ROTATED */
  DEBUG_COMPONENT("SWING_sample", _SWING_sample_var._position_absolute, _SWING_sample_var._rotation_absolute);
  instrument->_position_absolute[350] = _SWING_sample_var._position_absolute;
  instrument->_position_relative[350] = _SWING_sample_var._position_relative;
    _SWING_sample_var._position_relative_is_zero =  coords_test_zero(_SWING_sample_var._position_relative);
  instrument->counter_N[350]  = instrument->counter_P[350] = instrument->counter_P2[350] = 0;
  instrument->counter_AbsorbProp[350]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0349_SWING_sample", _SWING_sample_var._position_absolute, _SWING_sample_var._rotation_absolute, "SAXSPDBFast");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "RhoSolvent", "9.4e-14", "9.4e-14","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "Concentration", "0.01", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "AbsorptionCrosssection", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "xwidth", "NONE", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "yheight", "NONE", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "zdepth", "NONE", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "SampleToDetectorDistance", "NONE", "_instrument_var._parameters.SWING_sample_det","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "DetectorRadius", "NONE", "0.16 * 1.41","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "qMin", "0.001", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "qMax", "0.5", "0.9","MCNUM");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "NumberOfQBins", "200", "2000","int");
        mccomp_param_nexus(nxhandle,"0349_SWING_sample", "PDBFilepath", "PDBfile.pdb", _instrument_var._parameters.SWING_sample, "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_sample_setpos */

/* component SWING_sample_out=Arm() SETTING, POSITION/ROTATION */
int _SWING_sample_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_sample_out_setpos] component SWING_sample_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SWING_sample_out_var._name, "SWING_sample_out", 16384);
  stracpy(_SWING_sample_out_var._type, "Arm", 16384);
  _SWING_sample_out_var._index=351;
  int current_setpos_index = 351;
  /* component SWING_sample_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_sample_stage_var._rotation_absolute, _SWING_sample_out_var._rotation_absolute);
    rot_transpose(_SWING_sample_var._rotation_absolute, tr1);
    rot_mul(_SWING_sample_out_var._rotation_absolute, tr1, _SWING_sample_out_var._rotation_relative);
    _SWING_sample_out_var._rotation_is_identity =  rot_test_identity(_SWING_sample_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_sample_out_var._position_absolute = coords_add(_SWING_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_sample_var._position_absolute, _SWING_sample_out_var._position_absolute);
    _SWING_sample_out_var._position_relative = rot_apply(_SWING_sample_out_var._rotation_absolute, tc1);
  } /* SWING_sample_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("SWING_sample_out", _SWING_sample_out_var._position_absolute, _SWING_sample_out_var._rotation_absolute);
  instrument->_position_absolute[351] = _SWING_sample_out_var._position_absolute;
  instrument->_position_relative[351] = _SWING_sample_out_var._position_relative;
    _SWING_sample_out_var._position_relative_is_zero =  coords_test_zero(_SWING_sample_out_var._position_relative);
  instrument->counter_N[351]  = instrument->counter_P[351] = instrument->counter_P2[351] = 0;
  instrument->counter_AbsorbProp[351]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0350_SWING_sample_out", _SWING_sample_out_var._position_absolute, _SWING_sample_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_sample_out_setpos */

/* component SWING_Eiger4M=Monitor_nD() SETTING, POSITION/ROTATION */
int _SWING_Eiger4M_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_Eiger4M_setpos] component SWING_Eiger4M=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SWING_Eiger4M_var._name, "SWING_Eiger4M", 16384);
  stracpy(_SWING_Eiger4M_var._type, "Monitor_nD", 16384);
  _SWING_Eiger4M_var._index=352;
  int current_setpos_index = 352;
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SWING_Eiger4M_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.user9[0]='\0';
  _SWING_Eiger4M_var._parameters.xwidth = 0.5;
  _SWING_Eiger4M_var._parameters.yheight = 0.5;
  _SWING_Eiger4M_var._parameters.zdepth = 0;
  _SWING_Eiger4M_var._parameters.bins = 1024;
  _SWING_Eiger4M_var._parameters.min = -1e40;
  _SWING_Eiger4M_var._parameters.max = 1e40;
  _SWING_Eiger4M_var._parameters.restore_xray = 0;
  _SWING_Eiger4M_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SWING_Eiger4M_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.geometry[0]='\0';
  _SWING_Eiger4M_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SWING_Eiger4M_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SWING_Eiger4M_var._parameters.username9[0]='\0';


  /* component SWING_Eiger4M=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_sample_stage_var._rotation_absolute, _SWING_Eiger4M_var._rotation_absolute);
    rot_transpose(_SWING_sample_var._rotation_absolute, tr1);
    rot_mul(_SWING_Eiger4M_var._rotation_absolute, tr1, _SWING_Eiger4M_var._rotation_relative);
    _SWING_Eiger4M_var._rotation_is_identity =  rot_test_identity(_SWING_Eiger4M_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.SWING_sample_det);
    rot_transpose(_SWING_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_Eiger4M_var._position_absolute = coords_add(_SWING_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_sample_var._position_absolute, _SWING_Eiger4M_var._position_absolute);
    _SWING_Eiger4M_var._position_relative = rot_apply(_SWING_Eiger4M_var._rotation_absolute, tc1);
  } /* SWING_Eiger4M=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SWING_Eiger4M", _SWING_Eiger4M_var._position_absolute, _SWING_Eiger4M_var._rotation_absolute);
  instrument->_position_absolute[352] = _SWING_Eiger4M_var._position_absolute;
  instrument->_position_relative[352] = _SWING_Eiger4M_var._position_relative;
    _SWING_Eiger4M_var._position_relative_is_zero =  coords_test_zero(_SWING_Eiger4M_var._position_relative);
  instrument->counter_N[352]  = instrument->counter_P[352] = instrument->counter_P2[352] = 0;
  instrument->counter_AbsorbProp[352]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0351_SWING_Eiger4M", _SWING_Eiger4M_var._position_absolute, _SWING_Eiger4M_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "xwidth", "0", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "yheight", "0", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "bins", "0", "1024","int");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0351_SWING_Eiger4M", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_Eiger4M_setpos */

/* component SWING_QMonitor=SAXSQMonitor() SETTING, POSITION/ROTATION */
int _SWING_QMonitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SWING_QMonitor_setpos] component SWING_QMonitor=SAXSQMonitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSQMonitor.comp:63]");
  stracpy(_SWING_QMonitor_var._name, "SWING_QMonitor", 16384);
  stracpy(_SWING_QMonitor_var._type, "SAXSQMonitor", 16384);
  _SWING_QMonitor_var._index=353;
  int current_setpos_index = 353;
  if("RDetector" && strlen("RDetector"))
    stracpy(_SWING_QMonitor_var._parameters.RFilename, "RDetector" ? "RDetector" : "", 16384);
  else 
  _SWING_QMonitor_var._parameters.RFilename[0]='\0';
  if("QDetector" && strlen("QDetector"))
    stracpy(_SWING_QMonitor_var._parameters.qFilename, "QDetector" ? "QDetector" : "", 16384);
  else 
  _SWING_QMonitor_var._parameters.qFilename[0]='\0';
  _SWING_QMonitor_var._parameters.NumberOfBins = 2000;
  _SWING_QMonitor_var._parameters.restore_xray = 0;
  _SWING_QMonitor_var._parameters.RadiusDetector = 0.22;
  _SWING_QMonitor_var._parameters.DistanceFromSample = _instrument_var._parameters.SWING_sample_det;
  _SWING_QMonitor_var._parameters.LambdaMin = SWING_Lambda;
  _SWING_QMonitor_var._parameters.Lambda0 = SWING_Lambda;
  _SWING_QMonitor_var._parameters.qMax = 0;


  /* component SWING_QMonitor=SAXSQMonitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_sample_stage_var._rotation_absolute, _SWING_QMonitor_var._rotation_absolute);
    rot_transpose(_SWING_Eiger4M_var._rotation_absolute, tr1);
    rot_mul(_SWING_QMonitor_var._rotation_absolute, tr1, _SWING_QMonitor_var._rotation_relative);
    _SWING_QMonitor_var._rotation_is_identity =  rot_test_identity(_SWING_QMonitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.SWING_sample_det);
    rot_transpose(_SWING_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SWING_QMonitor_var._position_absolute = coords_add(_SWING_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_Eiger4M_var._position_absolute, _SWING_QMonitor_var._position_absolute);
    _SWING_QMonitor_var._position_relative = rot_apply(_SWING_QMonitor_var._rotation_absolute, tc1);
  } /* SWING_QMonitor=SAXSQMonitor() AT ROTATED */
  DEBUG_COMPONENT("SWING_QMonitor", _SWING_QMonitor_var._position_absolute, _SWING_QMonitor_var._rotation_absolute);
  instrument->_position_absolute[353] = _SWING_QMonitor_var._position_absolute;
  instrument->_position_relative[353] = _SWING_QMonitor_var._position_relative;
    _SWING_QMonitor_var._position_relative_is_zero =  coords_test_zero(_SWING_QMonitor_var._position_relative);
  instrument->counter_N[353]  = instrument->counter_P[353] = instrument->counter_P2[353] = 0;
  instrument->counter_AbsorbProp[353]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0352_SWING_QMonitor", _SWING_QMonitor_var._position_absolute, _SWING_QMonitor_var._rotation_absolute, "SAXSQMonitor");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "RFilename", "RDetector", "RDetector", "char*");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "qFilename", "QDetector", "QDetector", "char*");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "NumberOfBins", "100", "2000","int");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "RadiusDetector", "NONE", "0.22","MCNUM");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "DistanceFromSample", "NONE", "_instrument_var._parameters.SWING_sample_det","MCNUM");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "LambdaMin", "1.0", "SWING_Lambda","MCNUM");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "Lambda0", "0.0", "SWING_Lambda","MCNUM");
        mccomp_param_nexus(nxhandle,"0352_SWING_QMonitor", "qMax", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SWING_QMonitor_setpos */

/* component beamdump_364=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_364_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_364_setpos] component beamdump_364=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_364_var._name, "beamdump_364", 16384);
  stracpy(_beamdump_364_var._type, "Beamstop", 16384);
  _beamdump_364_var._index=354;
  int current_setpos_index = 354;
  _beamdump_364_var._parameters.xmin = -0.05;
  _beamdump_364_var._parameters.xmax = 0.05;
  _beamdump_364_var._parameters.ymin = -0.05;
  _beamdump_364_var._parameters.ymax = 0.05;
  _beamdump_364_var._parameters.xwidth = 0;
  _beamdump_364_var._parameters.yheight = 0;
  _beamdump_364_var._parameters.radius = 0;

  /* component beamdump_364=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SWING_QMonitor_var._rotation_absolute, _beamdump_364_var._rotation_absolute);
    rot_transpose(_SWING_QMonitor_var._rotation_absolute, tr1);
    rot_mul(_beamdump_364_var._rotation_absolute, tr1, _beamdump_364_var._rotation_relative);
    _beamdump_364_var._rotation_is_identity =  rot_test_identity(_beamdump_364_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SWING_QMonitor_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_364_var._position_absolute = coords_add(_SWING_QMonitor_var._position_absolute, tc2);
    tc1 = coords_sub(_SWING_QMonitor_var._position_absolute, _beamdump_364_var._position_absolute);
    _beamdump_364_var._position_relative = rot_apply(_beamdump_364_var._rotation_absolute, tc1);
  } /* beamdump_364=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_364", _beamdump_364_var._position_absolute, _beamdump_364_var._rotation_absolute);
  instrument->_position_absolute[354] = _beamdump_364_var._position_absolute;
  instrument->_position_relative[354] = _beamdump_364_var._position_relative;
    _beamdump_364_var._position_relative_is_zero =  coords_test_zero(_beamdump_364_var._position_relative);
  instrument->counter_N[354]  = instrument->counter_P[354] = instrument->counter_P2[354] = 0;
  instrument->counter_AbsorbProp[354]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0353_beamdump_364", _beamdump_364_var._position_absolute, _beamdump_364_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0353_beamdump_364", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_364_setpos */

/* component ANTARES_pos=Text() SETTING, POSITION/ROTATION */
int _ANTARES_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANTARES_pos_setpos] component ANTARES_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_ANTARES_pos_var._name, "ANTARES_pos", 16384);
  stracpy(_ANTARES_pos_var._type, "Text", 16384);
  _ANTARES_pos_var._index=355;
  int current_setpos_index = 355;
  if("ANTARES" && strlen("ANTARES"))
    stracpy(_ANTARES_pos_var._parameters.text, "ANTARES" ? "ANTARES" : "", 16384);
  else 
  _ANTARES_pos_var._parameters.text[0]='\0';
  _ANTARES_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_ANTARES_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _ANTARES_pos_var._parameters.plane[0]='\0';
  _ANTARES_pos_var._parameters.pen_thickness = 0.1;


  /* component ANTARES_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-245.807)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _ANTARES_pos_var._rotation_absolute);
    rot_transpose(_beamdump_364_var._rotation_absolute, tr1);
    rot_mul(_ANTARES_pos_var._rotation_absolute, tr1, _ANTARES_pos_var._rotation_relative);
    _ANTARES_pos_var._rotation_is_identity =  rot_test_identity(_ANTARES_pos_var._rotation_relative);
    tc1 = coords_set(
      -23.089, 0, -51.392);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANTARES_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_364_var._position_absolute, _ANTARES_pos_var._position_absolute);
    _ANTARES_pos_var._position_relative = rot_apply(_ANTARES_pos_var._rotation_absolute, tc1);
  } /* ANTARES_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("ANTARES_pos", _ANTARES_pos_var._position_absolute, _ANTARES_pos_var._rotation_absolute);
  instrument->_position_absolute[355] = _ANTARES_pos_var._position_absolute;
  instrument->_position_relative[355] = _ANTARES_pos_var._position_relative;
    _ANTARES_pos_var._position_relative_is_zero =  coords_test_zero(_ANTARES_pos_var._position_relative);
  instrument->counter_N[355]  = instrument->counter_P[355] = instrument->counter_P2[355] = 0;
  instrument->counter_AbsorbProp[355]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0354_ANTARES_pos", _ANTARES_pos_var._position_absolute, _ANTARES_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0354_ANTARES_pos", "text", "NONE", "ANTARES", "char*");
        mccomp_param_nexus(nxhandle,"0354_ANTARES_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0354_ANTARES_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0354_ANTARES_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANTARES_pos_setpos */

/* component ROCK_pos=Text() SETTING, POSITION/ROTATION */
int _ROCK_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_pos_setpos] component ROCK_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_ROCK_pos_var._name, "ROCK_pos", 16384);
  stracpy(_ROCK_pos_var._type, "Text", 16384);
  _ROCK_pos_var._index=356;
  int current_setpos_index = 356;
  if("ROCK" && strlen("ROCK"))
    stracpy(_ROCK_pos_var._parameters.text, "ROCK" ? "ROCK" : "", 16384);
  else 
  _ROCK_pos_var._parameters.text[0]='\0';
  _ROCK_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_ROCK_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _ROCK_pos_var._parameters.plane[0]='\0';
  _ROCK_pos_var._parameters.pen_thickness = 0.1;


  /* component ROCK_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-259.668)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _ROCK_pos_var._rotation_absolute);
    rot_transpose(_ANTARES_pos_var._rotation_absolute, tr1);
    rot_mul(_ROCK_pos_var._rotation_absolute, tr1, _ROCK_pos_var._rotation_relative);
    _ROCK_pos_var._rotation_is_identity =  rot_test_identity(_ROCK_pos_var._rotation_relative);
    tc1 = coords_set(
      -10.105, 0, -55.426);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_ANTARES_pos_var._position_absolute, _ROCK_pos_var._position_absolute);
    _ROCK_pos_var._position_relative = rot_apply(_ROCK_pos_var._rotation_absolute, tc1);
  } /* ROCK_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("ROCK_pos", _ROCK_pos_var._position_absolute, _ROCK_pos_var._rotation_absolute);
  instrument->_position_absolute[356] = _ROCK_pos_var._position_absolute;
  instrument->_position_relative[356] = _ROCK_pos_var._position_relative;
    _ROCK_pos_var._position_relative_is_zero =  coords_test_zero(_ROCK_pos_var._position_relative);
  instrument->counter_N[356]  = instrument->counter_P[356] = instrument->counter_P2[356] = 0;
  instrument->counter_AbsorbProp[356]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0355_ROCK_pos", _ROCK_pos_var._position_absolute, _ROCK_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0355_ROCK_pos", "text", "NONE", "ROCK", "char*");
        mccomp_param_nexus(nxhandle,"0355_ROCK_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0355_ROCK_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0355_ROCK_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_pos_setpos */

/* component ROCK=Arm() SETTING, POSITION/ROTATION */
int _ROCK_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_setpos] component ROCK=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_var._name, "ROCK", 16384);
  stracpy(_ROCK_var._type, "Arm", 16384);
  _ROCK_var._index=357;
  int current_setpos_index = 357;
  /* component ROCK=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_pos_var._rotation_absolute, _ROCK_var._rotation_absolute);
    rot_transpose(_ROCK_pos_var._rotation_absolute, tr1);
    rot_mul(_ROCK_var._rotation_absolute, tr1, _ROCK_var._rotation_relative);
    _ROCK_var._rotation_is_identity =  rot_test_identity(_ROCK_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_var._position_absolute = coords_add(_ROCK_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_pos_var._position_absolute, _ROCK_var._position_absolute);
    _ROCK_var._position_relative = rot_apply(_ROCK_var._rotation_absolute, tc1);
  } /* ROCK=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK", _ROCK_var._position_absolute, _ROCK_var._rotation_absolute);
  instrument->_position_absolute[357] = _ROCK_var._position_absolute;
  instrument->_position_relative[357] = _ROCK_var._position_relative;
    _ROCK_var._position_relative_is_zero =  coords_test_zero(_ROCK_var._position_relative);
  instrument->counter_N[357]  = instrument->counter_P[357] = instrument->counter_P2[357] = 0;
  instrument->counter_AbsorbProp[357]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0356_ROCK", _ROCK_var._position_absolute, _ROCK_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_setpos */

/* component ROCK_Source=Bending_magnet() SETTING, POSITION/ROTATION */
int _ROCK_Source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_Source_setpos] component ROCK_Source=Bending_magnet() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");
  stracpy(_ROCK_Source_var._name, "ROCK_Source", 16384);
  stracpy(_ROCK_Source_var._type, "Bending_magnet", 16384);
  _ROCK_Source_var._index=358;
  int current_setpos_index = 358;
  _ROCK_Source_var._parameters.E0 = _instrument_var._parameters.ROCK_E0;
  _ROCK_Source_var._parameters.dE = _instrument_var._parameters.ROCK_dE;
  _ROCK_Source_var._parameters.lambda0 = 0;
  _ROCK_Source_var._parameters.dlambda = 0;
  _ROCK_Source_var._parameters.phase = 0;
  _ROCK_Source_var._parameters.randomphase = 1;
  _ROCK_Source_var._parameters.Ee = 2.75;
  _ROCK_Source_var._parameters.Ie = 0.5;
  _ROCK_Source_var._parameters.B = 1.72;
  _ROCK_Source_var._parameters.sigey = 20.2e-6;
  _ROCK_Source_var._parameters.sigex = 54.9e-6;
  _ROCK_Source_var._parameters.focus_xw = 0;
  _ROCK_Source_var._parameters.focus_yh = 0;
  _ROCK_Source_var._parameters.dist = 1;
  _ROCK_Source_var._parameters.gauss_t = 0;


  /* component ROCK_Source=Bending_magnet() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_var._rotation_absolute, _ROCK_Source_var._rotation_absolute);
    rot_transpose(_ROCK_var._rotation_absolute, tr1);
    rot_mul(_ROCK_Source_var._rotation_absolute, tr1, _ROCK_Source_var._rotation_relative);
    _ROCK_Source_var._rotation_is_identity =  rot_test_identity(_ROCK_Source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_Source_var._position_absolute = coords_add(_ROCK_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_var._position_absolute, _ROCK_Source_var._position_absolute);
    _ROCK_Source_var._position_relative = rot_apply(_ROCK_Source_var._rotation_absolute, tc1);
  } /* ROCK_Source=Bending_magnet() AT ROTATED */
  DEBUG_COMPONENT("ROCK_Source", _ROCK_Source_var._position_absolute, _ROCK_Source_var._rotation_absolute);
  instrument->_position_absolute[358] = _ROCK_Source_var._position_absolute;
  instrument->_position_relative[358] = _ROCK_Source_var._position_relative;
    _ROCK_Source_var._position_relative_is_zero =  coords_test_zero(_ROCK_Source_var._position_relative);
  instrument->counter_N[358]  = instrument->counter_P[358] = instrument->counter_P2[358] = 0;
  instrument->counter_AbsorbProp[358]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0357_ROCK_Source", _ROCK_Source_var._position_absolute, _ROCK_Source_var._rotation_absolute, "Bending_magnet");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "E0", "0", "_instrument_var._parameters.ROCK_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "dE", "0", "_instrument_var._parameters.ROCK_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "B", "1.6", "1.72","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "sigey", "0", "20.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "sigex", "0", "54.9e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0357_ROCK_Source", "gauss_t", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_Source_setpos */

/* component ROCK_slit1=Slit() SETTING, POSITION/ROTATION */
int _ROCK_slit1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit1_setpos] component ROCK_slit1=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_ROCK_slit1_var._name, "ROCK_slit1", 16384);
  stracpy(_ROCK_slit1_var._type, "Slit", 16384);
  _ROCK_slit1_var._index=359;
  int current_setpos_index = 359;
  _ROCK_slit1_var._parameters.xmin = 0;
  _ROCK_slit1_var._parameters.xmax = 0;
  _ROCK_slit1_var._parameters.ymin = 0;
  _ROCK_slit1_var._parameters.ymax = 0;
  _ROCK_slit1_var._parameters.radius = 0;
  _ROCK_slit1_var._parameters.xwidth = 0.021;
  _ROCK_slit1_var._parameters.yheight = 0.042;
  _ROCK_slit1_var._parameters.dist = 0;
  _ROCK_slit1_var._parameters.focus_xw = 0;
  _ROCK_slit1_var._parameters.focus_yh = 0;
  _ROCK_slit1_var._parameters.focus_x0 = 0;
  _ROCK_slit1_var._parameters.focus_y0 = 0;

  /* component ROCK_slit1=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_Source_var._rotation_absolute, _ROCK_slit1_var._rotation_absolute);
    rot_transpose(_ROCK_Source_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit1_var._rotation_absolute, tr1, _ROCK_slit1_var._rotation_relative);
    _ROCK_slit1_var._rotation_is_identity =  rot_test_identity(_ROCK_slit1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 8.5336);
    rot_transpose(_ROCK_Source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit1_var._position_absolute = coords_add(_ROCK_Source_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_Source_var._position_absolute, _ROCK_slit1_var._position_absolute);
    _ROCK_slit1_var._position_relative = rot_apply(_ROCK_slit1_var._rotation_absolute, tc1);
  } /* ROCK_slit1=Slit() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit1", _ROCK_slit1_var._position_absolute, _ROCK_slit1_var._rotation_absolute);
  instrument->_position_absolute[359] = _ROCK_slit1_var._position_absolute;
  instrument->_position_relative[359] = _ROCK_slit1_var._position_relative;
    _ROCK_slit1_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit1_var._position_relative);
  instrument->counter_N[359]  = instrument->counter_P[359] = instrument->counter_P2[359] = 0;
  instrument->counter_AbsorbProp[359]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0358_ROCK_slit1", _ROCK_slit1_var._position_absolute, _ROCK_slit1_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "xwidth", "0.001", "0.021","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "yheight", "0.001", "0.042","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0358_ROCK_slit1", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit1_setpos */

/* component ROCK_slit2=Slit() SETTING, POSITION/ROTATION */
int _ROCK_slit2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit2_setpos] component ROCK_slit2=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_ROCK_slit2_var._name, "ROCK_slit2", 16384);
  stracpy(_ROCK_slit2_var._type, "Slit", 16384);
  _ROCK_slit2_var._index=360;
  int current_setpos_index = 360;
  _ROCK_slit2_var._parameters.xmin = 0;
  _ROCK_slit2_var._parameters.xmax = 0;
  _ROCK_slit2_var._parameters.ymin = 0;
  _ROCK_slit2_var._parameters.ymax = 0;
  _ROCK_slit2_var._parameters.radius = 0;
  _ROCK_slit2_var._parameters.xwidth = 0.02;
  _ROCK_slit2_var._parameters.yheight = 0.01;
  _ROCK_slit2_var._parameters.dist = 0;
  _ROCK_slit2_var._parameters.focus_xw = 0;
  _ROCK_slit2_var._parameters.focus_yh = 0;
  _ROCK_slit2_var._parameters.focus_x0 = 0;
  _ROCK_slit2_var._parameters.focus_y0 = 0;

  /* component ROCK_slit2=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit1_var._rotation_absolute, _ROCK_slit2_var._rotation_absolute);
    rot_transpose(_ROCK_slit1_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit2_var._rotation_absolute, tr1, _ROCK_slit2_var._rotation_relative);
    _ROCK_slit2_var._rotation_is_identity =  rot_test_identity(_ROCK_slit2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 8.6486 -8.5336);
    rot_transpose(_ROCK_slit1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit2_var._position_absolute = coords_add(_ROCK_slit1_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit1_var._position_absolute, _ROCK_slit2_var._position_absolute);
    _ROCK_slit2_var._position_relative = rot_apply(_ROCK_slit2_var._rotation_absolute, tc1);
  } /* ROCK_slit2=Slit() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit2", _ROCK_slit2_var._position_absolute, _ROCK_slit2_var._rotation_absolute);
  instrument->_position_absolute[360] = _ROCK_slit2_var._position_absolute;
  instrument->_position_relative[360] = _ROCK_slit2_var._position_relative;
    _ROCK_slit2_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit2_var._position_relative);
  instrument->counter_N[360]  = instrument->counter_P[360] = instrument->counter_P2[360] = 0;
  instrument->counter_AbsorbProp[360]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0359_ROCK_slit2", _ROCK_slit2_var._position_absolute, _ROCK_slit2_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "xwidth", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0359_ROCK_slit2", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit2_setpos */

/* component ROCK_mirror_m1=Mirror_toroid_pothole() SETTING, POSITION/ROTATION */
int _ROCK_mirror_m1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_mirror_m1_setpos] component ROCK_mirror_m1=Mirror_toroid_pothole() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:64]");
  stracpy(_ROCK_mirror_m1_var._name, "ROCK_mirror_m1", 16384);
  stracpy(_ROCK_mirror_m1_var._type, "Mirror_toroid_pothole", 16384);
  _ROCK_mirror_m1_var._index=361;
  int current_setpos_index = 361;
  _ROCK_mirror_m1_var._parameters.zdepth = 1.1;
  _ROCK_mirror_m1_var._parameters.xwidth = 0.015;
  _ROCK_mirror_m1_var._parameters.radius = 0.0317;
  _ROCK_mirror_m1_var._parameters.radius_o = 9.02e3;
  _ROCK_mirror_m1_var._parameters.R0 = 0;
  if(_instrument_var._parameters.ROCK_reflec_material_M1 && strlen(_instrument_var._parameters.ROCK_reflec_material_M1))
    stracpy(_ROCK_mirror_m1_var._parameters.coating, _instrument_var._parameters.ROCK_reflec_material_M1 ? _instrument_var._parameters.ROCK_reflec_material_M1 : "", 16384);
  else 
  _ROCK_mirror_m1_var._parameters.coating[0]='\0';


  /* component ROCK_mirror_m1=Mirror_toroid_pothole() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.ROCK_angle_m1 * RAD2DEG / 2)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit2_var._rotation_absolute, _ROCK_mirror_m1_var._rotation_absolute);
    rot_transpose(_ROCK_slit2_var._rotation_absolute, tr1);
    rot_mul(_ROCK_mirror_m1_var._rotation_absolute, tr1, _ROCK_mirror_m1_var._rotation_relative);
    _ROCK_mirror_m1_var._rotation_is_identity =  rot_test_identity(_ROCK_mirror_m1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 10.15 -8.6486);
    rot_transpose(_ROCK_slit2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_mirror_m1_var._position_absolute = coords_add(_ROCK_slit2_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit2_var._position_absolute, _ROCK_mirror_m1_var._position_absolute);
    _ROCK_mirror_m1_var._position_relative = rot_apply(_ROCK_mirror_m1_var._rotation_absolute, tc1);
  } /* ROCK_mirror_m1=Mirror_toroid_pothole() AT ROTATED */
  DEBUG_COMPONENT("ROCK_mirror_m1", _ROCK_mirror_m1_var._position_absolute, _ROCK_mirror_m1_var._rotation_absolute);
  instrument->_position_absolute[361] = _ROCK_mirror_m1_var._position_absolute;
  instrument->_position_relative[361] = _ROCK_mirror_m1_var._position_relative;
    _ROCK_mirror_m1_var._position_relative_is_zero =  coords_test_zero(_ROCK_mirror_m1_var._position_relative);
  instrument->counter_N[361]  = instrument->counter_P[361] = instrument->counter_P2[361] = 0;
  instrument->counter_AbsorbProp[361]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0360_ROCK_mirror_m1", _ROCK_mirror_m1_var._position_absolute, _ROCK_mirror_m1_var._rotation_absolute, "Mirror_toroid_pothole");
        mccomp_param_nexus(nxhandle,"0360_ROCK_mirror_m1", "zdepth", "0.1", "1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0360_ROCK_mirror_m1", "xwidth", "0.01", "0.015","MCNUM");
        mccomp_param_nexus(nxhandle,"0360_ROCK_mirror_m1", "radius", "NONE", "0.0317","MCNUM");
        mccomp_param_nexus(nxhandle,"0360_ROCK_mirror_m1", "radius_o", "NONE", "9.02e3","MCNUM");
        mccomp_param_nexus(nxhandle,"0360_ROCK_mirror_m1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0360_ROCK_mirror_m1", "coating", "", _instrument_var._parameters.ROCK_reflec_material_M1, "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_mirror_m1_setpos */

/* component ROCK_mirror_m1_out=Arm() SETTING, POSITION/ROTATION */
int _ROCK_mirror_m1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_mirror_m1_out_setpos] component ROCK_mirror_m1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_mirror_m1_out_var._name, "ROCK_mirror_m1_out", 16384);
  stracpy(_ROCK_mirror_m1_out_var._type, "Arm", 16384);
  _ROCK_mirror_m1_out_var._index=362;
  int current_setpos_index = 362;
  /* component ROCK_mirror_m1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.ROCK_angle_m1 * RAD2DEG / 2)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_mirror_m1_var._rotation_absolute, _ROCK_mirror_m1_out_var._rotation_absolute);
    rot_transpose(_ROCK_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_ROCK_mirror_m1_out_var._rotation_absolute, tr1, _ROCK_mirror_m1_out_var._rotation_relative);
    _ROCK_mirror_m1_out_var._rotation_is_identity =  rot_test_identity(_ROCK_mirror_m1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_mirror_m1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_mirror_m1_out_var._position_absolute = coords_add(_ROCK_mirror_m1_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_mirror_m1_var._position_absolute, _ROCK_mirror_m1_out_var._position_absolute);
    _ROCK_mirror_m1_out_var._position_relative = rot_apply(_ROCK_mirror_m1_out_var._rotation_absolute, tc1);
  } /* ROCK_mirror_m1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK_mirror_m1_out", _ROCK_mirror_m1_out_var._position_absolute, _ROCK_mirror_m1_out_var._rotation_absolute);
  instrument->_position_absolute[362] = _ROCK_mirror_m1_out_var._position_absolute;
  instrument->_position_relative[362] = _ROCK_mirror_m1_out_var._position_relative;
    _ROCK_mirror_m1_out_var._position_relative_is_zero =  coords_test_zero(_ROCK_mirror_m1_out_var._position_relative);
  instrument->counter_N[362]  = instrument->counter_P[362] = instrument->counter_P2[362] = 0;
  instrument->counter_AbsorbProp[362]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0361_ROCK_mirror_m1_out", _ROCK_mirror_m1_out_var._position_absolute, _ROCK_mirror_m1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_mirror_m1_out_setpos */

/* component ROCK_slit3_xy=PSD_monitor() SETTING, POSITION/ROTATION */
int _ROCK_slit3_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit3_xy_setpos] component ROCK_slit3_xy=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ROCK_slit3_xy_var._name, "ROCK_slit3_xy", 16384);
  stracpy(_ROCK_slit3_xy_var._type, "PSD_monitor", 16384);
  _ROCK_slit3_xy_var._index=363;
  int current_setpos_index = 363;
  _ROCK_slit3_xy_var._parameters.filename[0]='\0';
  _ROCK_slit3_xy_var._parameters.xwidth = 0.02;
  _ROCK_slit3_xy_var._parameters.yheight = 0.01;
  _ROCK_slit3_xy_var._parameters.radius = 0;
  _ROCK_slit3_xy_var._parameters.restore_xray = 1;
  _ROCK_slit3_xy_var._parameters.nowritefile = 0;
  _ROCK_slit3_xy_var._parameters.nx = 90;
  _ROCK_slit3_xy_var._parameters.ny = 90;
  _ROCK_slit3_xy_var._parameters.nr = 0;


  /* component ROCK_slit3_xy=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_mirror_m1_out_var._rotation_absolute, _ROCK_slit3_xy_var._rotation_absolute);
    rot_transpose(_ROCK_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit3_xy_var._rotation_absolute, tr1, _ROCK_slit3_xy_var._rotation_relative);
    _ROCK_slit3_xy_var._rotation_is_identity =  rot_test_identity(_ROCK_slit3_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 11.6905 -10.15);
    rot_transpose(_ROCK_mirror_m1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit3_xy_var._position_absolute = coords_add(_ROCK_mirror_m1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_mirror_m1_var._position_absolute, _ROCK_slit3_xy_var._position_absolute);
    _ROCK_slit3_xy_var._position_relative = rot_apply(_ROCK_slit3_xy_var._rotation_absolute, tc1);
  } /* ROCK_slit3_xy=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit3_xy", _ROCK_slit3_xy_var._position_absolute, _ROCK_slit3_xy_var._rotation_absolute);
  instrument->_position_absolute[363] = _ROCK_slit3_xy_var._position_absolute;
  instrument->_position_relative[363] = _ROCK_slit3_xy_var._position_relative;
    _ROCK_slit3_xy_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit3_xy_var._position_relative);
  instrument->counter_N[363]  = instrument->counter_P[363] = instrument->counter_P2[363] = 0;
  instrument->counter_AbsorbProp[363]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0362_ROCK_slit3_xy", _ROCK_slit3_xy_var._position_absolute, _ROCK_slit3_xy_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "xwidth", "0.05", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0362_ROCK_slit3_xy", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit3_xy_setpos */

/* component ROCK_slit3_div=Divergence_monitor() SETTING, POSITION/ROTATION */
int _ROCK_slit3_div_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit3_div_setpos] component ROCK_slit3_div=Divergence_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Divergence_monitor.comp:69]");
  stracpy(_ROCK_slit3_div_var._name, "ROCK_slit3_div", 16384);
  stracpy(_ROCK_slit3_div_var._type, "Divergence_monitor", 16384);
  _ROCK_slit3_div_var._index=364;
  int current_setpos_index = 364;
  _ROCK_slit3_div_var._parameters.nh = 128;
  _ROCK_slit3_div_var._parameters.nv = 128;
  _ROCK_slit3_div_var._parameters.rad = 0;
  _ROCK_slit3_div_var._parameters.filename[0]='\0';
  _ROCK_slit3_div_var._parameters.xwidth = 0.1;
  _ROCK_slit3_div_var._parameters.yheight = 0.1;
  _ROCK_slit3_div_var._parameters.maxdiv_h = 0.05;
  _ROCK_slit3_div_var._parameters.maxdiv_v = 0.05;
  _ROCK_slit3_div_var._parameters.restore_xray = 0;
  _ROCK_slit3_div_var._parameters.nx = 0;
  _ROCK_slit3_div_var._parameters.ny = 0;
  _ROCK_slit3_div_var._parameters.nz = 1;
  _ROCK_slit3_div_var._parameters.nowritefile = 0;


  /* component ROCK_slit3_div=Divergence_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit3_xy_var._rotation_absolute, _ROCK_slit3_div_var._rotation_absolute);
    rot_transpose(_ROCK_slit3_xy_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit3_div_var._rotation_absolute, tr1, _ROCK_slit3_div_var._rotation_relative);
    _ROCK_slit3_div_var._rotation_is_identity =  rot_test_identity(_ROCK_slit3_div_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_slit3_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit3_div_var._position_absolute = coords_add(_ROCK_slit3_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit3_xy_var._position_absolute, _ROCK_slit3_div_var._position_absolute);
    _ROCK_slit3_div_var._position_relative = rot_apply(_ROCK_slit3_div_var._rotation_absolute, tc1);
  } /* ROCK_slit3_div=Divergence_monitor() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit3_div", _ROCK_slit3_div_var._position_absolute, _ROCK_slit3_div_var._rotation_absolute);
  instrument->_position_absolute[364] = _ROCK_slit3_div_var._position_absolute;
  instrument->_position_relative[364] = _ROCK_slit3_div_var._position_relative;
    _ROCK_slit3_div_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit3_div_var._position_relative);
  instrument->counter_N[364]  = instrument->counter_P[364] = instrument->counter_P2[364] = 0;
  instrument->counter_AbsorbProp[364]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0363_ROCK_slit3_div", _ROCK_slit3_div_var._position_absolute, _ROCK_slit3_div_var._rotation_absolute, "Divergence_monitor");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "nh", "20", "128","int");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "nv", "20", "128","int");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "rad", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "maxdiv_h", "1", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "maxdiv_v", "1", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "nx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "ny", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "nz", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0363_ROCK_slit3_div", "nowritefile", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit3_div_setpos */

/* component ROCK_slit3=Slit() SETTING, POSITION/ROTATION */
int _ROCK_slit3_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit3_setpos] component ROCK_slit3=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_ROCK_slit3_var._name, "ROCK_slit3", 16384);
  stracpy(_ROCK_slit3_var._type, "Slit", 16384);
  _ROCK_slit3_var._index=365;
  int current_setpos_index = 365;
  _ROCK_slit3_var._parameters.xmin = 0;
  _ROCK_slit3_var._parameters.xmax = 0;
  _ROCK_slit3_var._parameters.ymin = 0;
  _ROCK_slit3_var._parameters.ymax = 0;
  _ROCK_slit3_var._parameters.radius = 0;
  _ROCK_slit3_var._parameters.xwidth = 0.02;
  _ROCK_slit3_var._parameters.yheight = 0.01;
  _ROCK_slit3_var._parameters.dist = 0;
  _ROCK_slit3_var._parameters.focus_xw = 0;
  _ROCK_slit3_var._parameters.focus_yh = 0;
  _ROCK_slit3_var._parameters.focus_x0 = 0;
  _ROCK_slit3_var._parameters.focus_y0 = 0;

  /* component ROCK_slit3=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit3_xy_var._rotation_absolute, _ROCK_slit3_var._rotation_absolute);
    rot_transpose(_ROCK_slit3_div_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit3_var._rotation_absolute, tr1, _ROCK_slit3_var._rotation_relative);
    _ROCK_slit3_var._rotation_is_identity =  rot_test_identity(_ROCK_slit3_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_slit3_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit3_var._position_absolute = coords_add(_ROCK_slit3_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit3_div_var._position_absolute, _ROCK_slit3_var._position_absolute);
    _ROCK_slit3_var._position_relative = rot_apply(_ROCK_slit3_var._rotation_absolute, tc1);
  } /* ROCK_slit3=Slit() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit3", _ROCK_slit3_var._position_absolute, _ROCK_slit3_var._rotation_absolute);
  instrument->_position_absolute[365] = _ROCK_slit3_var._position_absolute;
  instrument->_position_relative[365] = _ROCK_slit3_var._position_relative;
    _ROCK_slit3_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit3_var._position_relative);
  instrument->counter_N[365]  = instrument->counter_P[365] = instrument->counter_P2[365] = 0;
  instrument->counter_AbsorbProp[365]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0364_ROCK_slit3", _ROCK_slit3_var._position_absolute, _ROCK_slit3_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "xwidth", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0364_ROCK_slit3", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit3_setpos */

/* component ROCK_mirror_m2a=Mirror() SETTING, POSITION/ROTATION */
int _ROCK_mirror_m2a_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_mirror_m2a_setpos] component ROCK_mirror_m2a=Mirror() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:69]");
  stracpy(_ROCK_mirror_m2a_var._name, "ROCK_mirror_m2a", 16384);
  stracpy(_ROCK_mirror_m2a_var._type, "Mirror", 16384);
  _ROCK_mirror_m2a_var._index=366;
  int current_setpos_index = 366;
  _ROCK_mirror_m2a_var._parameters.zdepth = 1100e-3;
  _ROCK_mirror_m2a_var._parameters.xwidth = 47e-3;
  _ROCK_mirror_m2a_var._parameters.yheight = 0;
  if(_instrument_var._parameters.ROCK_reflec_material_M2A_M2B && strlen(_instrument_var._parameters.ROCK_reflec_material_M2A_M2B))
    stracpy(_ROCK_mirror_m2a_var._parameters.coating, _instrument_var._parameters.ROCK_reflec_material_M2A_M2B ? _instrument_var._parameters.ROCK_reflec_material_M2A_M2B : "", 16384);
  else 
  _ROCK_mirror_m2a_var._parameters.coating[0]='\0';
  _ROCK_mirror_m2a_var._parameters.R0 = 0;
  if("" && strlen(""))
    stracpy(_ROCK_mirror_m2a_var._parameters.geometry, "" ? "" : "", 16384);
  else 
  _ROCK_mirror_m2a_var._parameters.geometry[0]='\0';


  /* component ROCK_mirror_m2a=Mirror() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.ROCK_angle_m2a_m2b * RAD2DEG / 2)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit3_var._rotation_absolute, _ROCK_mirror_m2a_var._rotation_absolute);
    rot_transpose(_ROCK_slit3_var._rotation_absolute, tr1);
    rot_mul(_ROCK_mirror_m2a_var._rotation_absolute, tr1, _ROCK_mirror_m2a_var._rotation_relative);
    _ROCK_mirror_m2a_var._rotation_is_identity =  rot_test_identity(_ROCK_mirror_m2a_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ( 16.82 -11.6905 ));
    rot_transpose(_ROCK_slit3_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_mirror_m2a_var._position_absolute = coords_add(_ROCK_slit3_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit3_var._position_absolute, _ROCK_mirror_m2a_var._position_absolute);
    _ROCK_mirror_m2a_var._position_relative = rot_apply(_ROCK_mirror_m2a_var._rotation_absolute, tc1);
  } /* ROCK_mirror_m2a=Mirror() AT ROTATED */
  DEBUG_COMPONENT("ROCK_mirror_m2a", _ROCK_mirror_m2a_var._position_absolute, _ROCK_mirror_m2a_var._rotation_absolute);
  instrument->_position_absolute[366] = _ROCK_mirror_m2a_var._position_absolute;
  instrument->_position_relative[366] = _ROCK_mirror_m2a_var._position_relative;
    _ROCK_mirror_m2a_var._position_relative_is_zero =  coords_test_zero(_ROCK_mirror_m2a_var._position_relative);
  instrument->counter_N[366]  = instrument->counter_P[366] = instrument->counter_P2[366] = 0;
  instrument->counter_AbsorbProp[366]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0365_ROCK_mirror_m2a", _ROCK_mirror_m2a_var._position_absolute, _ROCK_mirror_m2a_var._rotation_absolute, "Mirror");
        mccomp_param_nexus(nxhandle,"0365_ROCK_mirror_m2a", "zdepth", "0.1", "1100e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0365_ROCK_mirror_m2a", "xwidth", "0.01", "47e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0365_ROCK_mirror_m2a", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0365_ROCK_mirror_m2a", "coating", "", _instrument_var._parameters.ROCK_reflec_material_M2A_M2B, "char*");
        mccomp_param_nexus(nxhandle,"0365_ROCK_mirror_m2a", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0365_ROCK_mirror_m2a", "geometry", "", "", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_mirror_m2a_setpos */

/* component ROCK_mirror_m2a_out=Arm() SETTING, POSITION/ROTATION */
int _ROCK_mirror_m2a_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_mirror_m2a_out_setpos] component ROCK_mirror_m2a_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_mirror_m2a_out_var._name, "ROCK_mirror_m2a_out", 16384);
  stracpy(_ROCK_mirror_m2a_out_var._type, "Arm", 16384);
  _ROCK_mirror_m2a_out_var._index=367;
  int current_setpos_index = 367;
  /* component ROCK_mirror_m2a_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.ROCK_angle_m2a_m2b * RAD2DEG / 2)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_mirror_m2a_var._rotation_absolute, _ROCK_mirror_m2a_out_var._rotation_absolute);
    rot_transpose(_ROCK_mirror_m2a_var._rotation_absolute, tr1);
    rot_mul(_ROCK_mirror_m2a_out_var._rotation_absolute, tr1, _ROCK_mirror_m2a_out_var._rotation_relative);
    _ROCK_mirror_m2a_out_var._rotation_is_identity =  rot_test_identity(_ROCK_mirror_m2a_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_mirror_m2a_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_mirror_m2a_out_var._position_absolute = coords_add(_ROCK_mirror_m2a_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_mirror_m2a_var._position_absolute, _ROCK_mirror_m2a_out_var._position_absolute);
    _ROCK_mirror_m2a_out_var._position_relative = rot_apply(_ROCK_mirror_m2a_out_var._rotation_absolute, tc1);
  } /* ROCK_mirror_m2a_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK_mirror_m2a_out", _ROCK_mirror_m2a_out_var._position_absolute, _ROCK_mirror_m2a_out_var._rotation_absolute);
  instrument->_position_absolute[367] = _ROCK_mirror_m2a_out_var._position_absolute;
  instrument->_position_relative[367] = _ROCK_mirror_m2a_out_var._position_relative;
    _ROCK_mirror_m2a_out_var._position_relative_is_zero =  coords_test_zero(_ROCK_mirror_m2a_out_var._position_relative);
  instrument->counter_N[367]  = instrument->counter_P[367] = instrument->counter_P2[367] = 0;
  instrument->counter_AbsorbProp[367]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0366_ROCK_mirror_m2a_out", _ROCK_mirror_m2a_out_var._position_absolute, _ROCK_mirror_m2a_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_mirror_m2a_out_setpos */

/* component ROCK_slit4_in=PSD_monitor() SETTING, POSITION/ROTATION */
int _ROCK_slit4_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit4_in_setpos] component ROCK_slit4_in=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ROCK_slit4_in_var._name, "ROCK_slit4_in", 16384);
  stracpy(_ROCK_slit4_in_var._type, "PSD_monitor", 16384);
  _ROCK_slit4_in_var._index=368;
  int current_setpos_index = 368;
  _ROCK_slit4_in_var._parameters.filename[0]='\0';
  _ROCK_slit4_in_var._parameters.xwidth = 0.5;
  _ROCK_slit4_in_var._parameters.yheight = 0.5;
  _ROCK_slit4_in_var._parameters.radius = 0;
  _ROCK_slit4_in_var._parameters.restore_xray = 1;
  _ROCK_slit4_in_var._parameters.nowritefile = 0;
  _ROCK_slit4_in_var._parameters.nx = 90;
  _ROCK_slit4_in_var._parameters.ny = 90;
  _ROCK_slit4_in_var._parameters.nr = 0;


  /* component ROCK_slit4_in=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_mirror_m2a_out_var._rotation_absolute, _ROCK_slit4_in_var._rotation_absolute);
    rot_transpose(_ROCK_mirror_m2a_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit4_in_var._rotation_absolute, tr1, _ROCK_slit4_in_var._rotation_relative);
    _ROCK_slit4_in_var._rotation_is_identity =  rot_test_identity(_ROCK_slit4_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 18.1512 -16.82);
    rot_transpose(_ROCK_mirror_m2a_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit4_in_var._position_absolute = coords_add(_ROCK_mirror_m2a_out_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_mirror_m2a_var._position_absolute, _ROCK_slit4_in_var._position_absolute);
    _ROCK_slit4_in_var._position_relative = rot_apply(_ROCK_slit4_in_var._rotation_absolute, tc1);
  } /* ROCK_slit4_in=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit4_in", _ROCK_slit4_in_var._position_absolute, _ROCK_slit4_in_var._rotation_absolute);
  instrument->_position_absolute[368] = _ROCK_slit4_in_var._position_absolute;
  instrument->_position_relative[368] = _ROCK_slit4_in_var._position_relative;
    _ROCK_slit4_in_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit4_in_var._position_relative);
  instrument->counter_N[368]  = instrument->counter_P[368] = instrument->counter_P2[368] = 0;
  instrument->counter_AbsorbProp[368]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0367_ROCK_slit4_in", _ROCK_slit4_in_var._position_absolute, _ROCK_slit4_in_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "xwidth", "0.05", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "yheight", "0.05", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0367_ROCK_slit4_in", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit4_in_setpos */

/* component ROCK_slit4=Slit() SETTING, POSITION/ROTATION */
int _ROCK_slit4_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit4_setpos] component ROCK_slit4=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_ROCK_slit4_var._name, "ROCK_slit4", 16384);
  stracpy(_ROCK_slit4_var._type, "Slit", 16384);
  _ROCK_slit4_var._index=369;
  int current_setpos_index = 369;
  _ROCK_slit4_var._parameters.xmin = 0;
  _ROCK_slit4_var._parameters.xmax = 0;
  _ROCK_slit4_var._parameters.ymin = 0;
  _ROCK_slit4_var._parameters.ymax = 0;
  _ROCK_slit4_var._parameters.radius = 0;
  _ROCK_slit4_var._parameters.xwidth = 0.02;
  _ROCK_slit4_var._parameters.yheight = 0.02;
  _ROCK_slit4_var._parameters.dist = 0;
  _ROCK_slit4_var._parameters.focus_xw = 0;
  _ROCK_slit4_var._parameters.focus_yh = 0;
  _ROCK_slit4_var._parameters.focus_x0 = 0;
  _ROCK_slit4_var._parameters.focus_y0 = 0;

  /* component ROCK_slit4=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit4_in_var._rotation_absolute, _ROCK_slit4_var._rotation_absolute);
    rot_transpose(_ROCK_slit4_in_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit4_var._rotation_absolute, tr1, _ROCK_slit4_var._rotation_relative);
    _ROCK_slit4_var._rotation_is_identity =  rot_test_identity(_ROCK_slit4_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_slit4_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit4_var._position_absolute = coords_add(_ROCK_slit4_in_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit4_in_var._position_absolute, _ROCK_slit4_var._position_absolute);
    _ROCK_slit4_var._position_relative = rot_apply(_ROCK_slit4_var._rotation_absolute, tc1);
  } /* ROCK_slit4=Slit() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit4", _ROCK_slit4_var._position_absolute, _ROCK_slit4_var._rotation_absolute);
  instrument->_position_absolute[369] = _ROCK_slit4_var._position_absolute;
  instrument->_position_relative[369] = _ROCK_slit4_var._position_relative;
    _ROCK_slit4_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit4_var._position_relative);
  instrument->counter_N[369]  = instrument->counter_P[369] = instrument->counter_P2[369] = 0;
  instrument->counter_AbsorbProp[369]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0368_ROCK_slit4", _ROCK_slit4_var._position_absolute, _ROCK_slit4_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "xwidth", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "yheight", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0368_ROCK_slit4", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit4_setpos */

/* component ROCK_arm_crystal0=Arm() SETTING, POSITION/ROTATION */
int _ROCK_arm_crystal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_arm_crystal0_setpos] component ROCK_arm_crystal0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_arm_crystal0_var._name, "ROCK_arm_crystal0", 16384);
  stracpy(_ROCK_arm_crystal0_var._type, "Arm", 16384);
  _ROCK_arm_crystal0_var._index=370;
  int current_setpos_index = 370;
  /* component ROCK_arm_crystal0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit4_var._rotation_absolute, _ROCK_arm_crystal0_var._rotation_absolute);
    rot_transpose(_ROCK_slit4_var._rotation_absolute, tr1);
    rot_mul(_ROCK_arm_crystal0_var._rotation_absolute, tr1, _ROCK_arm_crystal0_var._rotation_relative);
    _ROCK_arm_crystal0_var._rotation_is_identity =  rot_test_identity(_ROCK_arm_crystal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, ROCK_center_first_crystal -18.1512);
    rot_transpose(_ROCK_slit4_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_arm_crystal0_var._position_absolute = coords_add(_ROCK_slit4_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit4_var._position_absolute, _ROCK_arm_crystal0_var._position_absolute);
    _ROCK_arm_crystal0_var._position_relative = rot_apply(_ROCK_arm_crystal0_var._rotation_absolute, tc1);
  } /* ROCK_arm_crystal0=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK_arm_crystal0", _ROCK_arm_crystal0_var._position_absolute, _ROCK_arm_crystal0_var._rotation_absolute);
  instrument->_position_absolute[370] = _ROCK_arm_crystal0_var._position_absolute;
  instrument->_position_relative[370] = _ROCK_arm_crystal0_var._position_relative;
    _ROCK_arm_crystal0_var._position_relative_is_zero =  coords_test_zero(_ROCK_arm_crystal0_var._position_relative);
  instrument->counter_N[370]  = instrument->counter_P[370] = instrument->counter_P2[370] = 0;
  instrument->counter_AbsorbProp[370]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0369_ROCK_arm_crystal0", _ROCK_arm_crystal0_var._position_absolute, _ROCK_arm_crystal0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_arm_crystal0_setpos */

/* component ROCK_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _ROCK_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_bragg_crystal_setpos] component ROCK_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_ROCK_bragg_crystal_var._name, "ROCK_bragg_crystal", 16384);
  stracpy(_ROCK_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _ROCK_bragg_crystal_var._index=371;
  int current_setpos_index = 371;
  _ROCK_bragg_crystal_var._parameters.length = ROCK_length_first_crystal;
  _ROCK_bragg_crystal_var._parameters.width = 25e-3;
  _ROCK_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_ROCK_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _ROCK_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_ROCK_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _ROCK_bragg_crystal_var._parameters.material[0]='\0';
  _ROCK_bragg_crystal_var._parameters.alpha = 0.0;
  _ROCK_bragg_crystal_var._parameters.R0 = 0;
  _ROCK_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _ROCK_bragg_crystal_var._parameters.crystal_type = 2;
  _ROCK_bragg_crystal_var._parameters.h = ROCK_i_h;
  _ROCK_bragg_crystal_var._parameters.k = ROCK_i_k;
  _ROCK_bragg_crystal_var._parameters.l = ROCK_i_l;
  _ROCK_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _ROCK_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component ROCK_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ROCK_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_arm_crystal0_var._rotation_absolute, _ROCK_bragg_crystal_var._rotation_absolute);
    rot_transpose(_ROCK_slit4_var._rotation_absolute, tr1);
    rot_mul(_ROCK_bragg_crystal_var._rotation_absolute, tr1, _ROCK_bragg_crystal_var._rotation_relative);
    _ROCK_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_ROCK_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_arm_crystal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_bragg_crystal_var._position_absolute = coords_add(_ROCK_arm_crystal0_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit4_var._position_absolute, _ROCK_bragg_crystal_var._position_absolute);
    _ROCK_bragg_crystal_var._position_relative = rot_apply(_ROCK_bragg_crystal_var._rotation_absolute, tc1);
  } /* ROCK_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("ROCK_bragg_crystal", _ROCK_bragg_crystal_var._position_absolute, _ROCK_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[371] = _ROCK_bragg_crystal_var._position_absolute;
  instrument->_position_relative[371] = _ROCK_bragg_crystal_var._position_relative;
    _ROCK_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_ROCK_bragg_crystal_var._position_relative);
  instrument->counter_N[371]  = instrument->counter_P[371] = instrument->counter_P2[371] = 0;
  instrument->counter_AbsorbProp[371]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0370_ROCK_bragg_crystal", _ROCK_bragg_crystal_var._position_absolute, _ROCK_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "length", "0.05", "ROCK_length_first_crystal","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "width", "0.02", "25e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "h", "1", "ROCK_i_h","int");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "k", "1", "ROCK_i_k","int");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "l", "1", "ROCK_i_l","int");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0370_ROCK_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_bragg_crystal_setpos */

/* component ROCK_arm_crystal1=Arm() SETTING, POSITION/ROTATION */
int _ROCK_arm_crystal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_arm_crystal1_setpos] component ROCK_arm_crystal1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_arm_crystal1_var._name, "ROCK_arm_crystal1", 16384);
  stracpy(_ROCK_arm_crystal1_var._type, "Arm", 16384);
  _ROCK_arm_crystal1_var._index=372;
  int current_setpos_index = 372;
  /* component ROCK_arm_crystal1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ROCK_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_bragg_crystal_var._rotation_absolute, _ROCK_arm_crystal1_var._rotation_absolute);
    rot_transpose(_ROCK_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_ROCK_arm_crystal1_var._rotation_absolute, tr1, _ROCK_arm_crystal1_var._rotation_relative);
    _ROCK_arm_crystal1_var._rotation_is_identity =  rot_test_identity(_ROCK_arm_crystal1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_arm_crystal1_var._position_absolute = coords_add(_ROCK_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_bragg_crystal_var._position_absolute, _ROCK_arm_crystal1_var._position_absolute);
    _ROCK_arm_crystal1_var._position_relative = rot_apply(_ROCK_arm_crystal1_var._rotation_absolute, tc1);
  } /* ROCK_arm_crystal1=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK_arm_crystal1", _ROCK_arm_crystal1_var._position_absolute, _ROCK_arm_crystal1_var._rotation_absolute);
  instrument->_position_absolute[372] = _ROCK_arm_crystal1_var._position_absolute;
  instrument->_position_relative[372] = _ROCK_arm_crystal1_var._position_relative;
    _ROCK_arm_crystal1_var._position_relative_is_zero =  coords_test_zero(_ROCK_arm_crystal1_var._position_relative);
  instrument->counter_N[372]  = instrument->counter_P[372] = instrument->counter_P2[372] = 0;
  instrument->counter_AbsorbProp[372]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0371_ROCK_arm_crystal1", _ROCK_arm_crystal1_var._position_absolute, _ROCK_arm_crystal1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_arm_crystal1_setpos */

/* component ROCK_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _ROCK_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_bragg_crystal_two_setpos] component ROCK_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_ROCK_bragg_crystal_two_var._name, "ROCK_bragg_crystal_two", 16384);
  stracpy(_ROCK_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _ROCK_bragg_crystal_two_var._index=373;
  int current_setpos_index = 373;
  _ROCK_bragg_crystal_two_var._parameters.length = ROCK_length_second_crystal;
  _ROCK_bragg_crystal_two_var._parameters.width = 25e-3;
  _ROCK_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_ROCK_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _ROCK_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_ROCK_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _ROCK_bragg_crystal_two_var._parameters.material[0]='\0';
  _ROCK_bragg_crystal_two_var._parameters.alpha = 0.0;
  _ROCK_bragg_crystal_two_var._parameters.R0 = 0;
  _ROCK_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _ROCK_bragg_crystal_two_var._parameters.crystal_type = 2;
  _ROCK_bragg_crystal_two_var._parameters.h = ROCK_i_h;
  _ROCK_bragg_crystal_two_var._parameters.k = ROCK_i_k;
  _ROCK_bragg_crystal_two_var._parameters.l = ROCK_i_l;
  _ROCK_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _ROCK_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component ROCK_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (ROCK_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_arm_crystal1_var._rotation_absolute, _ROCK_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_ROCK_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_ROCK_bragg_crystal_two_var._rotation_absolute, tr1, _ROCK_bragg_crystal_two_var._rotation_relative);
    _ROCK_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_ROCK_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0.01, ROCK_calculated_angle ? 0.01 / tan ( ROCK_calculated_angle * DEG2RAD ) : 0);
    rot_transpose(_ROCK_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_bragg_crystal_two_var._position_absolute = coords_add(_ROCK_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_bragg_crystal_var._position_absolute, _ROCK_bragg_crystal_two_var._position_absolute);
    _ROCK_bragg_crystal_two_var._position_relative = rot_apply(_ROCK_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* ROCK_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("ROCK_bragg_crystal_two", _ROCK_bragg_crystal_two_var._position_absolute, _ROCK_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[373] = _ROCK_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[373] = _ROCK_bragg_crystal_two_var._position_relative;
    _ROCK_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_ROCK_bragg_crystal_two_var._position_relative);
  instrument->counter_N[373]  = instrument->counter_P[373] = instrument->counter_P2[373] = 0;
  instrument->counter_AbsorbProp[373]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", _ROCK_bragg_crystal_two_var._position_absolute, _ROCK_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "length", "0.05", "ROCK_length_second_crystal","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "width", "0.02", "25e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "h", "1", "ROCK_i_h","int");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "k", "1", "ROCK_i_k","int");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "l", "1", "ROCK_i_l","int");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0372_ROCK_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_bragg_crystal_two_setpos */

/* component ROCK_arm_crystal2=Arm() SETTING, POSITION/ROTATION */
int _ROCK_arm_crystal2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_arm_crystal2_setpos] component ROCK_arm_crystal2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_arm_crystal2_var._name, "ROCK_arm_crystal2", 16384);
  stracpy(_ROCK_arm_crystal2_var._type, "Arm", 16384);
  _ROCK_arm_crystal2_var._index=374;
  int current_setpos_index = 374;
  /* component ROCK_arm_crystal2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (ROCK_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_bragg_crystal_two_var._rotation_absolute, _ROCK_arm_crystal2_var._rotation_absolute);
    rot_transpose(_ROCK_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_ROCK_arm_crystal2_var._rotation_absolute, tr1, _ROCK_arm_crystal2_var._rotation_relative);
    _ROCK_arm_crystal2_var._rotation_is_identity =  rot_test_identity(_ROCK_arm_crystal2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_arm_crystal2_var._position_absolute = coords_add(_ROCK_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_bragg_crystal_two_var._position_absolute, _ROCK_arm_crystal2_var._position_absolute);
    _ROCK_arm_crystal2_var._position_relative = rot_apply(_ROCK_arm_crystal2_var._rotation_absolute, tc1);
  } /* ROCK_arm_crystal2=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK_arm_crystal2", _ROCK_arm_crystal2_var._position_absolute, _ROCK_arm_crystal2_var._rotation_absolute);
  instrument->_position_absolute[374] = _ROCK_arm_crystal2_var._position_absolute;
  instrument->_position_relative[374] = _ROCK_arm_crystal2_var._position_relative;
    _ROCK_arm_crystal2_var._position_relative_is_zero =  coords_test_zero(_ROCK_arm_crystal2_var._position_relative);
  instrument->counter_N[374]  = instrument->counter_P[374] = instrument->counter_P2[374] = 0;
  instrument->counter_AbsorbProp[374]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0373_ROCK_arm_crystal2", _ROCK_arm_crystal2_var._position_absolute, _ROCK_arm_crystal2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_arm_crystal2_setpos */

/* component ROCK_bragg_crystal_out=PSD_monitor() SETTING, POSITION/ROTATION */
int _ROCK_bragg_crystal_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_bragg_crystal_out_setpos] component ROCK_bragg_crystal_out=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ROCK_bragg_crystal_out_var._name, "ROCK_bragg_crystal_out", 16384);
  stracpy(_ROCK_bragg_crystal_out_var._type, "PSD_monitor", 16384);
  _ROCK_bragg_crystal_out_var._index=375;
  int current_setpos_index = 375;
  _ROCK_bragg_crystal_out_var._parameters.filename[0]='\0';
  _ROCK_bragg_crystal_out_var._parameters.xwidth = 0.1;
  _ROCK_bragg_crystal_out_var._parameters.yheight = 0.1;
  _ROCK_bragg_crystal_out_var._parameters.radius = 0;
  _ROCK_bragg_crystal_out_var._parameters.restore_xray = 1;
  _ROCK_bragg_crystal_out_var._parameters.nowritefile = 0;
  _ROCK_bragg_crystal_out_var._parameters.nx = 200;
  _ROCK_bragg_crystal_out_var._parameters.ny = 200;
  _ROCK_bragg_crystal_out_var._parameters.nr = 0;


  /* component ROCK_bragg_crystal_out=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_arm_crystal2_var._rotation_absolute, _ROCK_bragg_crystal_out_var._rotation_absolute);
    rot_transpose(_ROCK_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_ROCK_bragg_crystal_out_var._rotation_absolute, tr1, _ROCK_bragg_crystal_out_var._rotation_relative);
    _ROCK_bragg_crystal_out_var._rotation_is_identity =  rot_test_identity(_ROCK_bragg_crystal_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2 * ROCK_length_second_crystal);
    rot_transpose(_ROCK_arm_crystal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_bragg_crystal_out_var._position_absolute = coords_add(_ROCK_arm_crystal2_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_bragg_crystal_two_var._position_absolute, _ROCK_bragg_crystal_out_var._position_absolute);
    _ROCK_bragg_crystal_out_var._position_relative = rot_apply(_ROCK_bragg_crystal_out_var._rotation_absolute, tc1);
  } /* ROCK_bragg_crystal_out=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ROCK_bragg_crystal_out", _ROCK_bragg_crystal_out_var._position_absolute, _ROCK_bragg_crystal_out_var._rotation_absolute);
  instrument->_position_absolute[375] = _ROCK_bragg_crystal_out_var._position_absolute;
  instrument->_position_relative[375] = _ROCK_bragg_crystal_out_var._position_relative;
    _ROCK_bragg_crystal_out_var._position_relative_is_zero =  coords_test_zero(_ROCK_bragg_crystal_out_var._position_relative);
  instrument->counter_N[375]  = instrument->counter_P[375] = instrument->counter_P2[375] = 0;
  instrument->counter_AbsorbProp[375]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", _ROCK_bragg_crystal_out_var._position_absolute, _ROCK_bragg_crystal_out_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "xwidth", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "yheight", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "nx", "90", "200","int");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "ny", "90", "200","int");
        mccomp_param_nexus(nxhandle,"0374_ROCK_bragg_crystal_out", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_bragg_crystal_out_setpos */

/* component ROCK_slit5=Slit() SETTING, POSITION/ROTATION */
int _ROCK_slit5_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit5_setpos] component ROCK_slit5=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_ROCK_slit5_var._name, "ROCK_slit5", 16384);
  stracpy(_ROCK_slit5_var._type, "Slit", 16384);
  _ROCK_slit5_var._index=376;
  int current_setpos_index = 376;
  _ROCK_slit5_var._parameters.xmin = 0;
  _ROCK_slit5_var._parameters.xmax = 0;
  _ROCK_slit5_var._parameters.ymin = 0;
  _ROCK_slit5_var._parameters.ymax = 0;
  _ROCK_slit5_var._parameters.radius = 0;
  _ROCK_slit5_var._parameters.xwidth = 0.02;
  _ROCK_slit5_var._parameters.yheight = 0.01;
  _ROCK_slit5_var._parameters.dist = 0;
  _ROCK_slit5_var._parameters.focus_xw = 0;
  _ROCK_slit5_var._parameters.focus_yh = 0;
  _ROCK_slit5_var._parameters.focus_x0 = 0;
  _ROCK_slit5_var._parameters.focus_y0 = 0;

  /* component ROCK_slit5=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_arm_crystal2_var._rotation_absolute, _ROCK_slit5_var._rotation_absolute);
    rot_transpose(_ROCK_bragg_crystal_out_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit5_var._rotation_absolute, tr1, _ROCK_slit5_var._rotation_relative);
    _ROCK_slit5_var._rotation_is_identity =  rot_test_identity(_ROCK_slit5_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 21.135 - ROCK_center_first_crystal);
    rot_transpose(_ROCK_arm_crystal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit5_var._position_absolute = coords_add(_ROCK_arm_crystal2_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_bragg_crystal_out_var._position_absolute, _ROCK_slit5_var._position_absolute);
    _ROCK_slit5_var._position_relative = rot_apply(_ROCK_slit5_var._rotation_absolute, tc1);
  } /* ROCK_slit5=Slit() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit5", _ROCK_slit5_var._position_absolute, _ROCK_slit5_var._rotation_absolute);
  instrument->_position_absolute[376] = _ROCK_slit5_var._position_absolute;
  instrument->_position_relative[376] = _ROCK_slit5_var._position_relative;
    _ROCK_slit5_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit5_var._position_relative);
  instrument->counter_N[376]  = instrument->counter_P[376] = instrument->counter_P2[376] = 0;
  instrument->counter_AbsorbProp[376]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0375_ROCK_slit5", _ROCK_slit5_var._position_absolute, _ROCK_slit5_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "xwidth", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0375_ROCK_slit5", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit5_setpos */

/* component ROCK_slit6=Slit() SETTING, POSITION/ROTATION */
int _ROCK_slit6_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_slit6_setpos] component ROCK_slit6=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_ROCK_slit6_var._name, "ROCK_slit6", 16384);
  stracpy(_ROCK_slit6_var._type, "Slit", 16384);
  _ROCK_slit6_var._index=377;
  int current_setpos_index = 377;
  _ROCK_slit6_var._parameters.xmin = 0;
  _ROCK_slit6_var._parameters.xmax = 0;
  _ROCK_slit6_var._parameters.ymin = 0;
  _ROCK_slit6_var._parameters.ymax = 0;
  _ROCK_slit6_var._parameters.radius = 0;
  _ROCK_slit6_var._parameters.xwidth = 0.01;
  _ROCK_slit6_var._parameters.yheight = 0.02;
  _ROCK_slit6_var._parameters.dist = 0;
  _ROCK_slit6_var._parameters.focus_xw = 0;
  _ROCK_slit6_var._parameters.focus_yh = 0;
  _ROCK_slit6_var._parameters.focus_x0 = 0;
  _ROCK_slit6_var._parameters.focus_y0 = 0;

  /* component ROCK_slit6=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit5_var._rotation_absolute, _ROCK_slit6_var._rotation_absolute);
    rot_transpose(_ROCK_slit5_var._rotation_absolute, tr1);
    rot_mul(_ROCK_slit6_var._rotation_absolute, tr1, _ROCK_slit6_var._rotation_relative);
    _ROCK_slit6_var._rotation_is_identity =  rot_test_identity(_ROCK_slit6_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 21.25 -21.135);
    rot_transpose(_ROCK_slit5_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_slit6_var._position_absolute = coords_add(_ROCK_slit5_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit5_var._position_absolute, _ROCK_slit6_var._position_absolute);
    _ROCK_slit6_var._position_relative = rot_apply(_ROCK_slit6_var._rotation_absolute, tc1);
  } /* ROCK_slit6=Slit() AT ROTATED */
  DEBUG_COMPONENT("ROCK_slit6", _ROCK_slit6_var._position_absolute, _ROCK_slit6_var._rotation_absolute);
  instrument->_position_absolute[377] = _ROCK_slit6_var._position_absolute;
  instrument->_position_relative[377] = _ROCK_slit6_var._position_relative;
    _ROCK_slit6_var._position_relative_is_zero =  coords_test_zero(_ROCK_slit6_var._position_relative);
  instrument->counter_N[377]  = instrument->counter_P[377] = instrument->counter_P2[377] = 0;
  instrument->counter_AbsorbProp[377]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0376_ROCK_slit6", _ROCK_slit6_var._position_absolute, _ROCK_slit6_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "xwidth", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "yheight", "0.001", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0376_ROCK_slit6", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_slit6_setpos */

/* component ROCK_mirror_m2b=Mirror_curved() SETTING, POSITION/ROTATION */
int _ROCK_mirror_m2b_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_mirror_m2b_setpos] component ROCK_mirror_m2b=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_ROCK_mirror_m2b_var._name, "ROCK_mirror_m2b", 16384);
  stracpy(_ROCK_mirror_m2b_var._type, "Mirror_curved", 16384);
  _ROCK_mirror_m2b_var._index=378;
  int current_setpos_index = 378;
  _ROCK_mirror_m2b_var._parameters.radius = 5e3;
  _ROCK_mirror_m2b_var._parameters.R0 = 1;
  if(_instrument_var._parameters.ROCK_reflec_material_M2A_M2B && strlen(_instrument_var._parameters.ROCK_reflec_material_M2A_M2B))
    stracpy(_ROCK_mirror_m2b_var._parameters.coating, _instrument_var._parameters.ROCK_reflec_material_M2A_M2B ? _instrument_var._parameters.ROCK_reflec_material_M2A_M2B : "", 16384);
  else 
  _ROCK_mirror_m2b_var._parameters.coating[0]='\0';
  _ROCK_mirror_m2b_var._parameters.zdepth = 0.2;
  _ROCK_mirror_m2b_var._parameters.yheight = 0.2;
  _ROCK_mirror_m2b_var._parameters.length = 1100e-3;
  _ROCK_mirror_m2b_var._parameters.width = 47e-3;


  /* component ROCK_mirror_m2b=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.ROCK_angle_m2a_m2b * RAD2DEG / 2)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _ROCK_slit6_var._rotation_absolute, _ROCK_mirror_m2b_var._rotation_absolute);
    rot_transpose(_ROCK_slit6_var._rotation_absolute, tr1);
    rot_mul(_ROCK_mirror_m2b_var._rotation_absolute, tr1, _ROCK_mirror_m2b_var._rotation_relative);
    _ROCK_mirror_m2b_var._rotation_is_identity =  rot_test_identity(_ROCK_mirror_m2b_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 22.44 -21.25);
    rot_transpose(_ROCK_slit6_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_mirror_m2b_var._position_absolute = coords_add(_ROCK_slit6_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_slit6_var._position_absolute, _ROCK_mirror_m2b_var._position_absolute);
    _ROCK_mirror_m2b_var._position_relative = rot_apply(_ROCK_mirror_m2b_var._rotation_absolute, tc1);
  } /* ROCK_mirror_m2b=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("ROCK_mirror_m2b", _ROCK_mirror_m2b_var._position_absolute, _ROCK_mirror_m2b_var._rotation_absolute);
  instrument->_position_absolute[378] = _ROCK_mirror_m2b_var._position_absolute;
  instrument->_position_relative[378] = _ROCK_mirror_m2b_var._position_relative;
    _ROCK_mirror_m2b_var._position_relative_is_zero =  coords_test_zero(_ROCK_mirror_m2b_var._position_relative);
  instrument->counter_N[378]  = instrument->counter_P[378] = instrument->counter_P2[378] = 0;
  instrument->counter_AbsorbProp[378]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0377_ROCK_mirror_m2b", _ROCK_mirror_m2b_var._position_absolute, _ROCK_mirror_m2b_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "radius", "1", "5e3","MCNUM");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "coating", "Be.txt", _instrument_var._parameters.ROCK_reflec_material_M2A_M2B, "char*");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "length", "0", "1100e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0377_ROCK_mirror_m2b", "width", "0", "47e-3","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_mirror_m2b_setpos */

/* component ROCK_mirror_m2b_out=Arm() SETTING, POSITION/ROTATION */
int _ROCK_mirror_m2b_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_mirror_m2b_out_setpos] component ROCK_mirror_m2b_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ROCK_mirror_m2b_out_var._name, "ROCK_mirror_m2b_out", 16384);
  stracpy(_ROCK_mirror_m2b_out_var._type, "Arm", 16384);
  _ROCK_mirror_m2b_out_var._index=379;
  int current_setpos_index = 379;
  /* component ROCK_mirror_m2b_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.ROCK_angle_m2a_m2b * RAD2DEG)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ROCK_arm_crystal2_var._rotation_absolute, _ROCK_mirror_m2b_out_var._rotation_absolute);
    rot_transpose(_ROCK_mirror_m2b_var._rotation_absolute, tr1);
    rot_mul(_ROCK_mirror_m2b_out_var._rotation_absolute, tr1, _ROCK_mirror_m2b_out_var._rotation_relative);
    _ROCK_mirror_m2b_out_var._rotation_is_identity =  rot_test_identity(_ROCK_mirror_m2b_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_mirror_m2b_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_mirror_m2b_out_var._position_absolute = coords_add(_ROCK_mirror_m2b_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_mirror_m2b_var._position_absolute, _ROCK_mirror_m2b_out_var._position_absolute);
    _ROCK_mirror_m2b_out_var._position_relative = rot_apply(_ROCK_mirror_m2b_out_var._rotation_absolute, tc1);
  } /* ROCK_mirror_m2b_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("ROCK_mirror_m2b_out", _ROCK_mirror_m2b_out_var._position_absolute, _ROCK_mirror_m2b_out_var._rotation_absolute);
  instrument->_position_absolute[379] = _ROCK_mirror_m2b_out_var._position_absolute;
  instrument->_position_relative[379] = _ROCK_mirror_m2b_out_var._position_relative;
    _ROCK_mirror_m2b_out_var._position_relative_is_zero =  coords_test_zero(_ROCK_mirror_m2b_out_var._position_relative);
  instrument->counter_N[379]  = instrument->counter_P[379] = instrument->counter_P2[379] = 0;
  instrument->counter_AbsorbProp[379]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0378_ROCK_mirror_m2b_out", _ROCK_mirror_m2b_out_var._position_absolute, _ROCK_mirror_m2b_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_mirror_m2b_out_setpos */

/* component ROCK_EnergyMonitor_before_sample=Monitor_nD() SETTING, POSITION/ROTATION */
int _ROCK_EnergyMonitor_before_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_EnergyMonitor_before_sample_setpos] component ROCK_EnergyMonitor_before_sample=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_ROCK_EnergyMonitor_before_sample_var._name, "ROCK_EnergyMonitor_before_sample", 16384);
  stracpy(_ROCK_EnergyMonitor_before_sample_var._type, "Monitor_nD", 16384);
  _ROCK_EnergyMonitor_before_sample_var._index=380;
  int current_setpos_index = 380;
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.user9[0]='\0';
  _ROCK_EnergyMonitor_before_sample_var._parameters.xwidth = 0.1;
  _ROCK_EnergyMonitor_before_sample_var._parameters.yheight = 0.1;
  _ROCK_EnergyMonitor_before_sample_var._parameters.zdepth = 0;
  _ROCK_EnergyMonitor_before_sample_var._parameters.bins = 500;
  _ROCK_EnergyMonitor_before_sample_var._parameters.min = _instrument_var._parameters.ROCK_E0 - ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr );
  _ROCK_EnergyMonitor_before_sample_var._parameters.max = _instrument_var._parameters.ROCK_E0 + ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr );
  _ROCK_EnergyMonitor_before_sample_var._parameters.restore_xray = 1;
  _ROCK_EnergyMonitor_before_sample_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.options[0]='\0';
  if("ROCK_EnergyMonitor_before_sample" && strlen("ROCK_EnergyMonitor_before_sample"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.filename, "ROCK_EnergyMonitor_before_sample" ? "ROCK_EnergyMonitor_before_sample" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.geometry[0]='\0';
  _ROCK_EnergyMonitor_before_sample_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_before_sample_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_before_sample_var._parameters.username9[0]='\0';


  /* component ROCK_EnergyMonitor_before_sample=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_mirror_m2b_out_var._rotation_absolute, _ROCK_EnergyMonitor_before_sample_var._rotation_absolute);
    rot_transpose(_ROCK_mirror_m2b_var._rotation_absolute, tr1);
    rot_mul(_ROCK_EnergyMonitor_before_sample_var._rotation_absolute, tr1, _ROCK_EnergyMonitor_before_sample_var._rotation_relative);
    _ROCK_EnergyMonitor_before_sample_var._rotation_is_identity =  rot_test_identity(_ROCK_EnergyMonitor_before_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 10);
    rot_transpose(_ROCK_mirror_m2b_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_EnergyMonitor_before_sample_var._position_absolute = coords_add(_ROCK_mirror_m2b_out_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_mirror_m2b_var._position_absolute, _ROCK_EnergyMonitor_before_sample_var._position_absolute);
    _ROCK_EnergyMonitor_before_sample_var._position_relative = rot_apply(_ROCK_EnergyMonitor_before_sample_var._rotation_absolute, tc1);
  } /* ROCK_EnergyMonitor_before_sample=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("ROCK_EnergyMonitor_before_sample", _ROCK_EnergyMonitor_before_sample_var._position_absolute, _ROCK_EnergyMonitor_before_sample_var._rotation_absolute);
  instrument->_position_absolute[380] = _ROCK_EnergyMonitor_before_sample_var._position_absolute;
  instrument->_position_relative[380] = _ROCK_EnergyMonitor_before_sample_var._position_relative;
    _ROCK_EnergyMonitor_before_sample_var._position_relative_is_zero =  coords_test_zero(_ROCK_EnergyMonitor_before_sample_var._position_relative);
  instrument->counter_N[380]  = instrument->counter_P[380] = instrument->counter_P2[380] = 0;
  instrument->counter_AbsorbProp[380]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", _ROCK_EnergyMonitor_before_sample_var._position_absolute, _ROCK_EnergyMonitor_before_sample_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "bins", "0", "500","int");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "min", "-1e40", "_instrument_var._parameters.ROCK_E0 - ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "max", "1e40", "_instrument_var._parameters.ROCK_E0 + ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "filename", "NULL", "ROCK_EnergyMonitor_before_sample", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0379_ROCK_EnergyMonitor_before_sample", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_EnergyMonitor_before_sample_setpos */

/* component ROCK_e_repartition_after_m2b=Monitor_nD() SETTING, POSITION/ROTATION */
int _ROCK_e_repartition_after_m2b_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_e_repartition_after_m2b_setpos] component ROCK_e_repartition_after_m2b=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_ROCK_e_repartition_after_m2b_var._name, "ROCK_e_repartition_after_m2b", 16384);
  stracpy(_ROCK_e_repartition_after_m2b_var._type, "Monitor_nD", 16384);
  _ROCK_e_repartition_after_m2b_var._index=381;
  int current_setpos_index = 381;
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.user9[0]='\0';
  _ROCK_e_repartition_after_m2b_var._parameters.xwidth = 0.02;
  _ROCK_e_repartition_after_m2b_var._parameters.yheight = 0.02;
  _ROCK_e_repartition_after_m2b_var._parameters.zdepth = 0;
  _ROCK_e_repartition_after_m2b_var._parameters.bins = 500;
  _ROCK_e_repartition_after_m2b_var._parameters.min = -1e40;
  _ROCK_e_repartition_after_m2b_var._parameters.max = 1e40;
  _ROCK_e_repartition_after_m2b_var._parameters.restore_xray = 1;
  _ROCK_e_repartition_after_m2b_var._parameters.radius = 0;
  if(ROCK_e_repartition_options && strlen(ROCK_e_repartition_options))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.options, ROCK_e_repartition_options ? ROCK_e_repartition_options : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.options[0]='\0';
  if("ROCK_e_repartition_after_m2b" && strlen("ROCK_e_repartition_after_m2b"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.filename, "ROCK_e_repartition_after_m2b" ? "ROCK_e_repartition_after_m2b" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.geometry[0]='\0';
  _ROCK_e_repartition_after_m2b_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_e_repartition_after_m2b_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_e_repartition_after_m2b_var._parameters.username9[0]='\0';


  /* component ROCK_e_repartition_after_m2b=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_EnergyMonitor_before_sample_var._rotation_absolute, _ROCK_e_repartition_after_m2b_var._rotation_absolute);
    rot_transpose(_ROCK_EnergyMonitor_before_sample_var._rotation_absolute, tr1);
    rot_mul(_ROCK_e_repartition_after_m2b_var._rotation_absolute, tr1, _ROCK_e_repartition_after_m2b_var._rotation_relative);
    _ROCK_e_repartition_after_m2b_var._rotation_is_identity =  rot_test_identity(_ROCK_e_repartition_after_m2b_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_ROCK_EnergyMonitor_before_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_e_repartition_after_m2b_var._position_absolute = coords_add(_ROCK_EnergyMonitor_before_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_EnergyMonitor_before_sample_var._position_absolute, _ROCK_e_repartition_after_m2b_var._position_absolute);
    _ROCK_e_repartition_after_m2b_var._position_relative = rot_apply(_ROCK_e_repartition_after_m2b_var._rotation_absolute, tc1);
  } /* ROCK_e_repartition_after_m2b=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("ROCK_e_repartition_after_m2b", _ROCK_e_repartition_after_m2b_var._position_absolute, _ROCK_e_repartition_after_m2b_var._rotation_absolute);
  instrument->_position_absolute[381] = _ROCK_e_repartition_after_m2b_var._position_absolute;
  instrument->_position_relative[381] = _ROCK_e_repartition_after_m2b_var._position_relative;
    _ROCK_e_repartition_after_m2b_var._position_relative_is_zero =  coords_test_zero(_ROCK_e_repartition_after_m2b_var._position_relative);
  instrument->counter_N[381]  = instrument->counter_P[381] = instrument->counter_P2[381] = 0;
  instrument->counter_AbsorbProp[381]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", _ROCK_e_repartition_after_m2b_var._position_absolute, _ROCK_e_repartition_after_m2b_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "bins", "0", "500","int");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "options", "NULL", ROCK_e_repartition_options, "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "filename", "NULL", "ROCK_e_repartition_after_m2b", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0380_ROCK_e_repartition_after_m2b", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_e_repartition_after_m2b_setpos */

/* component ROCK_sample_in=PSD_monitor() SETTING, POSITION/ROTATION */
int _ROCK_sample_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_sample_in_setpos] component ROCK_sample_in=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ROCK_sample_in_var._name, "ROCK_sample_in", 16384);
  stracpy(_ROCK_sample_in_var._type, "PSD_monitor", 16384);
  _ROCK_sample_in_var._index=382;
  int current_setpos_index = 382;
  _ROCK_sample_in_var._parameters.filename[0]='\0';
  _ROCK_sample_in_var._parameters.xwidth = 0.01;
  _ROCK_sample_in_var._parameters.yheight = 0.01;
  _ROCK_sample_in_var._parameters.radius = 0;
  _ROCK_sample_in_var._parameters.restore_xray = 1;
  _ROCK_sample_in_var._parameters.nowritefile = 0;
  _ROCK_sample_in_var._parameters.nx = 200;
  _ROCK_sample_in_var._parameters.ny = 200;
  _ROCK_sample_in_var._parameters.nr = 0;


  /* component ROCK_sample_in=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_e_repartition_after_m2b_var._rotation_absolute, _ROCK_sample_in_var._rotation_absolute);
    rot_transpose(_ROCK_e_repartition_after_m2b_var._rotation_absolute, tr1);
    rot_mul(_ROCK_sample_in_var._rotation_absolute, tr1, _ROCK_sample_in_var._rotation_relative);
    _ROCK_sample_in_var._rotation_is_identity =  rot_test_identity(_ROCK_sample_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_e_repartition_after_m2b_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_sample_in_var._position_absolute = coords_add(_ROCK_e_repartition_after_m2b_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_e_repartition_after_m2b_var._position_absolute, _ROCK_sample_in_var._position_absolute);
    _ROCK_sample_in_var._position_relative = rot_apply(_ROCK_sample_in_var._rotation_absolute, tc1);
  } /* ROCK_sample_in=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ROCK_sample_in", _ROCK_sample_in_var._position_absolute, _ROCK_sample_in_var._rotation_absolute);
  instrument->_position_absolute[382] = _ROCK_sample_in_var._position_absolute;
  instrument->_position_relative[382] = _ROCK_sample_in_var._position_relative;
    _ROCK_sample_in_var._position_relative_is_zero =  coords_test_zero(_ROCK_sample_in_var._position_relative);
  instrument->counter_N[382]  = instrument->counter_P[382] = instrument->counter_P2[382] = 0;
  instrument->counter_AbsorbProp[382]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0381_ROCK_sample_in", _ROCK_sample_in_var._position_absolute, _ROCK_sample_in_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "xwidth", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "nx", "90", "200","int");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "ny", "90", "200","int");
        mccomp_param_nexus(nxhandle,"0381_ROCK_sample_in", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_sample_in_setpos */

/* component ROCK_absorption_sample=Fluorescence() SETTING, POSITION/ROTATION */
int _ROCK_absorption_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_absorption_sample_setpos] component ROCK_absorption_sample=Fluorescence() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:440]");
  stracpy(_ROCK_absorption_sample_var._name, "ROCK_absorption_sample", 16384);
  stracpy(_ROCK_absorption_sample_var._type, "Fluorescence", 16384);
  _ROCK_absorption_sample_var._index=383;
  int current_setpos_index = 383;
  _ROCK_absorption_sample_var._parameters.geometry[0]='\0';
  _ROCK_absorption_sample_var._parameters.radius = 0;
  _ROCK_absorption_sample_var._parameters.thickness = 0;
  _ROCK_absorption_sample_var._parameters.xwidth = 0.05;
  _ROCK_absorption_sample_var._parameters.yheight = 0.05;
  _ROCK_absorption_sample_var._parameters.zdepth = 0.0001;
  _ROCK_absorption_sample_var._parameters.concentric = 0;
  if(_instrument_var._parameters.ROCK_sample_file && strlen(_instrument_var._parameters.ROCK_sample_file))
    stracpy(_ROCK_absorption_sample_var._parameters.material, _instrument_var._parameters.ROCK_sample_file ? _instrument_var._parameters.ROCK_sample_file : "", 16384);
  else 
  _ROCK_absorption_sample_var._parameters.material[0]='\0';
  _ROCK_absorption_sample_var._parameters.packing_factor = 0;
  _ROCK_absorption_sample_var._parameters.rho = 0;
  _ROCK_absorption_sample_var._parameters.density = 0;
  _ROCK_absorption_sample_var._parameters.weight = 0;
  _ROCK_absorption_sample_var._parameters.p_interact = 0;
  _ROCK_absorption_sample_var._parameters.target_x = 0;
  _ROCK_absorption_sample_var._parameters.target_y = 0;
  _ROCK_absorption_sample_var._parameters.target_z = 0;
  _ROCK_absorption_sample_var._parameters.focus_r = 0;
  _ROCK_absorption_sample_var._parameters.focus_xw = 0;
  _ROCK_absorption_sample_var._parameters.focus_yh = 0;
  _ROCK_absorption_sample_var._parameters.focus_aw = 0;
  _ROCK_absorption_sample_var._parameters.focus_ah = 0;
  _ROCK_absorption_sample_var._parameters.target_index = 0;
  _ROCK_absorption_sample_var._parameters.flag_compton = 1;
  _ROCK_absorption_sample_var._parameters.flag_rayleigh = 1;
  _ROCK_absorption_sample_var._parameters.flag_lorentzian = 0;
  _ROCK_absorption_sample_var._parameters.flag_kissel = 0;
  _ROCK_absorption_sample_var._parameters.flag_low_z = 0;
  _ROCK_absorption_sample_var._parameters.order = 1;


  /* component ROCK_absorption_sample=Fluorescence() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_e_repartition_after_m2b_var._rotation_absolute, _ROCK_absorption_sample_var._rotation_absolute);
    rot_transpose(_ROCK_sample_in_var._rotation_absolute, tr1);
    rot_mul(_ROCK_absorption_sample_var._rotation_absolute, tr1, _ROCK_absorption_sample_var._rotation_relative);
    _ROCK_absorption_sample_var._rotation_is_identity =  rot_test_identity(_ROCK_absorption_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_e_repartition_after_m2b_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_absorption_sample_var._position_absolute = coords_add(_ROCK_e_repartition_after_m2b_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_sample_in_var._position_absolute, _ROCK_absorption_sample_var._position_absolute);
    _ROCK_absorption_sample_var._position_relative = rot_apply(_ROCK_absorption_sample_var._rotation_absolute, tc1);
  } /* ROCK_absorption_sample=Fluorescence() AT ROTATED */
  DEBUG_COMPONENT("ROCK_absorption_sample", _ROCK_absorption_sample_var._position_absolute, _ROCK_absorption_sample_var._rotation_absolute);
  instrument->_position_absolute[383] = _ROCK_absorption_sample_var._position_absolute;
  instrument->_position_relative[383] = _ROCK_absorption_sample_var._position_relative;
    _ROCK_absorption_sample_var._position_relative_is_zero =  coords_test_zero(_ROCK_absorption_sample_var._position_relative);
  instrument->counter_N[383]  = instrument->counter_P[383] = instrument->counter_P2[383] = 0;
  instrument->counter_AbsorbProp[383]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0382_ROCK_absorption_sample", _ROCK_absorption_sample_var._position_absolute, _ROCK_absorption_sample_var._rotation_absolute, "Fluorescence");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "xwidth", "0", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "yheight", "0", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "zdepth", "0", "0.0001","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "material", "LaB6", _instrument_var._parameters.ROCK_sample_file, "char*");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "rho", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "p_interact", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "target_z", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "focus_aw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "focus_ah", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "flag_low_z", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0382_ROCK_absorption_sample", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_absorption_sample_setpos */

/* component ROCK_fluo_monitor=Monitor_nD() SETTING, POSITION/ROTATION */
int _ROCK_fluo_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_fluo_monitor_setpos] component ROCK_fluo_monitor=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_ROCK_fluo_monitor_var._name, "ROCK_fluo_monitor", 16384);
  stracpy(_ROCK_fluo_monitor_var._type, "Monitor_nD", 16384);
  _ROCK_fluo_monitor_var._index=384;
  int current_setpos_index = 384;
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_fluo_monitor_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.user9[0]='\0';
  _ROCK_fluo_monitor_var._parameters.xwidth = 0;
  _ROCK_fluo_monitor_var._parameters.yheight = 0;
  _ROCK_fluo_monitor_var._parameters.zdepth = 0;
  _ROCK_fluo_monitor_var._parameters.bins = 1024;
  _ROCK_fluo_monitor_var._parameters.min = 0;
  _ROCK_fluo_monitor_var._parameters.max = _instrument_var._parameters.ROCK_E0 * 1.2;
  _ROCK_fluo_monitor_var._parameters.restore_xray = 0;
  _ROCK_fluo_monitor_var._parameters.radius = 0.2;
  if("energy" && strlen("energy"))
    stracpy(_ROCK_fluo_monitor_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.geometry[0]='\0';
  _ROCK_fluo_monitor_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_fluo_monitor_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_fluo_monitor_var._parameters.username9[0]='\0';


  /* component ROCK_fluo_monitor=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_absorption_sample_var._rotation_absolute, _ROCK_fluo_monitor_var._rotation_absolute);
    rot_transpose(_ROCK_absorption_sample_var._rotation_absolute, tr1);
    rot_mul(_ROCK_fluo_monitor_var._rotation_absolute, tr1, _ROCK_fluo_monitor_var._rotation_relative);
    _ROCK_fluo_monitor_var._rotation_is_identity =  rot_test_identity(_ROCK_fluo_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_absorption_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_fluo_monitor_var._position_absolute = coords_add(_ROCK_absorption_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_absorption_sample_var._position_absolute, _ROCK_fluo_monitor_var._position_absolute);
    _ROCK_fluo_monitor_var._position_relative = rot_apply(_ROCK_fluo_monitor_var._rotation_absolute, tc1);
  } /* ROCK_fluo_monitor=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("ROCK_fluo_monitor", _ROCK_fluo_monitor_var._position_absolute, _ROCK_fluo_monitor_var._rotation_absolute);
  instrument->_position_absolute[384] = _ROCK_fluo_monitor_var._position_absolute;
  instrument->_position_relative[384] = _ROCK_fluo_monitor_var._position_relative;
    _ROCK_fluo_monitor_var._position_relative_is_zero =  coords_test_zero(_ROCK_fluo_monitor_var._position_relative);
  instrument->counter_N[384]  = instrument->counter_P[384] = instrument->counter_P2[384] = 0;
  instrument->counter_AbsorbProp[384]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0383_ROCK_fluo_monitor", _ROCK_fluo_monitor_var._position_absolute, _ROCK_fluo_monitor_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "bins", "0", "1024","int");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "min", "-1e40", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "max", "1e40", "_instrument_var._parameters.ROCK_E0 * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "radius", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0383_ROCK_fluo_monitor", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_fluo_monitor_setpos */

/* component ROCK_EnergyMonitor_after_sample=Monitor_nD() SETTING, POSITION/ROTATION */
int _ROCK_EnergyMonitor_after_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_EnergyMonitor_after_sample_setpos] component ROCK_EnergyMonitor_after_sample=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_ROCK_EnergyMonitor_after_sample_var._name, "ROCK_EnergyMonitor_after_sample", 16384);
  stracpy(_ROCK_EnergyMonitor_after_sample_var._type, "Monitor_nD", 16384);
  _ROCK_EnergyMonitor_after_sample_var._index=385;
  int current_setpos_index = 385;
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.user9[0]='\0';
  _ROCK_EnergyMonitor_after_sample_var._parameters.xwidth = 0.1;
  _ROCK_EnergyMonitor_after_sample_var._parameters.yheight = 0.1;
  _ROCK_EnergyMonitor_after_sample_var._parameters.zdepth = 0;
  _ROCK_EnergyMonitor_after_sample_var._parameters.bins = 500;
  _ROCK_EnergyMonitor_after_sample_var._parameters.min = _instrument_var._parameters.ROCK_E0 - ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr );
  _ROCK_EnergyMonitor_after_sample_var._parameters.max = _instrument_var._parameters.ROCK_E0 + ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr );
  _ROCK_EnergyMonitor_after_sample_var._parameters.restore_xray = 1;
  _ROCK_EnergyMonitor_after_sample_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.options[0]='\0';
  if("EnergyMonitor_after_sample" && strlen("EnergyMonitor_after_sample"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.filename, "EnergyMonitor_after_sample" ? "EnergyMonitor_after_sample" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.geometry[0]='\0';
  _ROCK_EnergyMonitor_after_sample_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ROCK_EnergyMonitor_after_sample_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _ROCK_EnergyMonitor_after_sample_var._parameters.username9[0]='\0';


  /* component ROCK_EnergyMonitor_after_sample=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_fluo_monitor_var._rotation_absolute, _ROCK_EnergyMonitor_after_sample_var._rotation_absolute);
    rot_transpose(_ROCK_fluo_monitor_var._rotation_absolute, tr1);
    rot_mul(_ROCK_EnergyMonitor_after_sample_var._rotation_absolute, tr1, _ROCK_EnergyMonitor_after_sample_var._rotation_relative);
    _ROCK_EnergyMonitor_after_sample_var._rotation_is_identity =  rot_test_identity(_ROCK_EnergyMonitor_after_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_ROCK_fluo_monitor_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_EnergyMonitor_after_sample_var._position_absolute = coords_add(_ROCK_fluo_monitor_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_fluo_monitor_var._position_absolute, _ROCK_EnergyMonitor_after_sample_var._position_absolute);
    _ROCK_EnergyMonitor_after_sample_var._position_relative = rot_apply(_ROCK_EnergyMonitor_after_sample_var._rotation_absolute, tc1);
  } /* ROCK_EnergyMonitor_after_sample=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("ROCK_EnergyMonitor_after_sample", _ROCK_EnergyMonitor_after_sample_var._position_absolute, _ROCK_EnergyMonitor_after_sample_var._rotation_absolute);
  instrument->_position_absolute[385] = _ROCK_EnergyMonitor_after_sample_var._position_absolute;
  instrument->_position_relative[385] = _ROCK_EnergyMonitor_after_sample_var._position_relative;
    _ROCK_EnergyMonitor_after_sample_var._position_relative_is_zero =  coords_test_zero(_ROCK_EnergyMonitor_after_sample_var._position_relative);
  instrument->counter_N[385]  = instrument->counter_P[385] = instrument->counter_P2[385] = 0;
  instrument->counter_AbsorbProp[385]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", _ROCK_EnergyMonitor_after_sample_var._position_absolute, _ROCK_EnergyMonitor_after_sample_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "bins", "0", "500","int");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "min", "-1e40", "_instrument_var._parameters.ROCK_E0 - ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "max", "1e40", "_instrument_var._parameters.ROCK_E0 + ( 0.005 + ( _instrument_var._parameters.ROCK_E0 - ROCK_Eminkev ) * ROCK_incr )","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "filename", "NULL", "EnergyMonitor_after_sample", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0384_ROCK_EnergyMonitor_after_sample", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_EnergyMonitor_after_sample_setpos */

/* component ROCK_psd_monitor=PSD_monitor() SETTING, POSITION/ROTATION */
int _ROCK_psd_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ROCK_psd_monitor_setpos] component ROCK_psd_monitor=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ROCK_psd_monitor_var._name, "ROCK_psd_monitor", 16384);
  stracpy(_ROCK_psd_monitor_var._type, "PSD_monitor", 16384);
  _ROCK_psd_monitor_var._index=386;
  int current_setpos_index = 386;
  if("ROCK_psd" && strlen("ROCK_psd"))
    stracpy(_ROCK_psd_monitor_var._parameters.filename, "ROCK_psd" ? "ROCK_psd" : "", 16384);
  else 
  _ROCK_psd_monitor_var._parameters.filename[0]='\0';
  _ROCK_psd_monitor_var._parameters.xwidth = 0.004;
  _ROCK_psd_monitor_var._parameters.yheight = 0.004;
  _ROCK_psd_monitor_var._parameters.radius = 0;
  _ROCK_psd_monitor_var._parameters.restore_xray = 1;
  _ROCK_psd_monitor_var._parameters.nowritefile = 0;
  _ROCK_psd_monitor_var._parameters.nx = 100;
  _ROCK_psd_monitor_var._parameters.ny = 100;
  _ROCK_psd_monitor_var._parameters.nr = 0;


  /* component ROCK_psd_monitor=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_EnergyMonitor_after_sample_var._rotation_absolute, _ROCK_psd_monitor_var._rotation_absolute);
    rot_transpose(_ROCK_EnergyMonitor_after_sample_var._rotation_absolute, tr1);
    rot_mul(_ROCK_psd_monitor_var._rotation_absolute, tr1, _ROCK_psd_monitor_var._rotation_relative);
    _ROCK_psd_monitor_var._rotation_is_identity =  rot_test_identity(_ROCK_psd_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_EnergyMonitor_after_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ROCK_psd_monitor_var._position_absolute = coords_add(_ROCK_EnergyMonitor_after_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_EnergyMonitor_after_sample_var._position_absolute, _ROCK_psd_monitor_var._position_absolute);
    _ROCK_psd_monitor_var._position_relative = rot_apply(_ROCK_psd_monitor_var._rotation_absolute, tc1);
  } /* ROCK_psd_monitor=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ROCK_psd_monitor", _ROCK_psd_monitor_var._position_absolute, _ROCK_psd_monitor_var._rotation_absolute);
  instrument->_position_absolute[386] = _ROCK_psd_monitor_var._position_absolute;
  instrument->_position_relative[386] = _ROCK_psd_monitor_var._position_relative;
    _ROCK_psd_monitor_var._position_relative_is_zero =  coords_test_zero(_ROCK_psd_monitor_var._position_relative);
  instrument->counter_N[386]  = instrument->counter_P[386] = instrument->counter_P2[386] = 0;
  instrument->counter_AbsorbProp[386]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0385_ROCK_psd_monitor", _ROCK_psd_monitor_var._position_absolute, _ROCK_psd_monitor_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "filename", 0, "ROCK_psd", "char*");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "xwidth", "0.05", "0.004","MCNUM");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "yheight", "0.05", "0.004","MCNUM");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "nx", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "ny", "90", "100","int");
        mccomp_param_nexus(nxhandle,"0385_ROCK_psd_monitor", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ROCK_psd_monitor_setpos */

/* component beamdump_398=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_398_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_398_setpos] component beamdump_398=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_398_var._name, "beamdump_398", 16384);
  stracpy(_beamdump_398_var._type, "Beamstop", 16384);
  _beamdump_398_var._index=387;
  int current_setpos_index = 387;
  _beamdump_398_var._parameters.xmin = -0.05;
  _beamdump_398_var._parameters.xmax = 0.05;
  _beamdump_398_var._parameters.ymin = -0.05;
  _beamdump_398_var._parameters.ymax = 0.05;
  _beamdump_398_var._parameters.xwidth = 0;
  _beamdump_398_var._parameters.yheight = 0;
  _beamdump_398_var._parameters.radius = 0;

  /* component beamdump_398=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ROCK_psd_monitor_var._rotation_absolute, _beamdump_398_var._rotation_absolute);
    rot_transpose(_ROCK_psd_monitor_var._rotation_absolute, tr1);
    rot_mul(_beamdump_398_var._rotation_absolute, tr1, _beamdump_398_var._rotation_relative);
    _beamdump_398_var._rotation_is_identity =  rot_test_identity(_beamdump_398_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ROCK_psd_monitor_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_398_var._position_absolute = coords_add(_ROCK_psd_monitor_var._position_absolute, tc2);
    tc1 = coords_sub(_ROCK_psd_monitor_var._position_absolute, _beamdump_398_var._position_absolute);
    _beamdump_398_var._position_relative = rot_apply(_beamdump_398_var._rotation_absolute, tc1);
  } /* beamdump_398=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_398", _beamdump_398_var._position_absolute, _beamdump_398_var._rotation_absolute);
  instrument->_position_absolute[387] = _beamdump_398_var._position_absolute;
  instrument->_position_relative[387] = _beamdump_398_var._position_relative;
    _beamdump_398_var._position_relative_is_zero =  coords_test_zero(_beamdump_398_var._position_relative);
  instrument->counter_N[387]  = instrument->counter_P[387] = instrument->counter_P2[387] = 0;
  instrument->counter_AbsorbProp[387]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0386_beamdump_398", _beamdump_398_var._position_absolute, _beamdump_398_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0386_beamdump_398", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_398_setpos */

/* component ANATOMIX_pos=Text() SETTING, POSITION/ROTATION */
int _ANATOMIX_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_pos_setpos] component ANATOMIX_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_ANATOMIX_pos_var._name, "ANATOMIX_pos", 16384);
  stracpy(_ANATOMIX_pos_var._type, "Text", 16384);
  _ANATOMIX_pos_var._index=388;
  int current_setpos_index = 388;
  if("ANATOMIX" && strlen("ANATOMIX"))
    stracpy(_ANATOMIX_pos_var._parameters.text, "ANATOMIX" ? "ANATOMIX" : "", 16384);
  else 
  _ANATOMIX_pos_var._parameters.text[0]='\0';
  _ANATOMIX_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_ANATOMIX_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _ANATOMIX_pos_var._parameters.plane[0]='\0';
  _ANATOMIX_pos_var._parameters.pen_thickness = 0.1;


  /* component ANATOMIX_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-266.6441)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _ANATOMIX_pos_var._rotation_absolute);
    rot_transpose(_beamdump_398_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_pos_var._rotation_absolute, tr1, _ANATOMIX_pos_var._rotation_relative);
    _ANATOMIX_pos_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_pos_var._rotation_relative);
    tc1 = coords_set(
      -3.2981, 0, -56.2434);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_398_var._position_absolute, _ANATOMIX_pos_var._position_absolute);
    _ANATOMIX_pos_var._position_relative = rot_apply(_ANATOMIX_pos_var._rotation_absolute, tc1);
  } /* ANATOMIX_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_pos", _ANATOMIX_pos_var._position_absolute, _ANATOMIX_pos_var._rotation_absolute);
  instrument->_position_absolute[388] = _ANATOMIX_pos_var._position_absolute;
  instrument->_position_relative[388] = _ANATOMIX_pos_var._position_relative;
    _ANATOMIX_pos_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_pos_var._position_relative);
  instrument->counter_N[388]  = instrument->counter_P[388] = instrument->counter_P2[388] = 0;
  instrument->counter_AbsorbProp[388]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0387_ANATOMIX_pos", _ANATOMIX_pos_var._position_absolute, _ANATOMIX_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0387_ANATOMIX_pos", "text", "NONE", "ANATOMIX", "char*");
        mccomp_param_nexus(nxhandle,"0387_ANATOMIX_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0387_ANATOMIX_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0387_ANATOMIX_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_pos_setpos */

/* component ANATOMIX=Arm() SETTING, POSITION/ROTATION */
int _ANATOMIX_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_setpos] component ANATOMIX=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ANATOMIX_var._name, "ANATOMIX", 16384);
  stracpy(_ANATOMIX_var._type, "Arm", 16384);
  _ANATOMIX_var._index=389;
  int current_setpos_index = 389;
  /* component ANATOMIX=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_pos_var._rotation_absolute, _ANATOMIX_var._rotation_absolute);
    rot_transpose(_ANATOMIX_pos_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_var._rotation_absolute, tr1, _ANATOMIX_var._rotation_relative);
    _ANATOMIX_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_var._position_absolute = coords_add(_ANATOMIX_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_pos_var._position_absolute, _ANATOMIX_var._position_absolute);
    _ANATOMIX_var._position_relative = rot_apply(_ANATOMIX_var._rotation_absolute, tc1);
  } /* ANATOMIX=Arm() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX", _ANATOMIX_var._position_absolute, _ANATOMIX_var._rotation_absolute);
  instrument->_position_absolute[389] = _ANATOMIX_var._position_absolute;
  instrument->_position_relative[389] = _ANATOMIX_var._position_relative;
    _ANATOMIX_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_var._position_relative);
  instrument->counter_N[389]  = instrument->counter_P[389] = instrument->counter_P2[389] = 0;
  instrument->counter_AbsorbProp[389]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0388_ANATOMIX", _ANATOMIX_var._position_absolute, _ANATOMIX_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_setpos */

/* component ANATOMIX_source=Undulator() SETTING, POSITION/ROTATION */
int _ANATOMIX_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_source_setpos] component ANATOMIX_source=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_ANATOMIX_source_var._name, "ANATOMIX_source", 16384);
  stracpy(_ANATOMIX_source_var._type, "Undulator", 16384);
  _ANATOMIX_source_var._index=390;
  int current_setpos_index = 390;
  _ANATOMIX_source_var._parameters.E0 = _instrument_var._parameters.ANATOMIX_E0;
  _ANATOMIX_source_var._parameters.dE = _instrument_var._parameters.ANATOMIX_dE;
  _ANATOMIX_source_var._parameters.phase = 0;
  _ANATOMIX_source_var._parameters.randomphase = 1;
  _ANATOMIX_source_var._parameters.Ee = 2.75;
  _ANATOMIX_source_var._parameters.dEe = 0.001;
  _ANATOMIX_source_var._parameters.Ie = 0.5;
  _ANATOMIX_source_var._parameters.B = 0;
  _ANATOMIX_source_var._parameters.K = 1.03118;
  _ANATOMIX_source_var._parameters.Nper = 140;
  _ANATOMIX_source_var._parameters.lu = 3.2e-2;
  _ANATOMIX_source_var._parameters.sigey = 8.4e-6;
  _ANATOMIX_source_var._parameters.sigex = 267.9e-6;
  _ANATOMIX_source_var._parameters.sigepx = 30.1e-6;
  _ANATOMIX_source_var._parameters.sigepy = 3.9e-6;
  _ANATOMIX_source_var._parameters.focus_xw = 0;
  _ANATOMIX_source_var._parameters.focus_yh = 0;
  _ANATOMIX_source_var._parameters.dist = 50;
  _ANATOMIX_source_var._parameters.quick_integ = 0;
  _ANATOMIX_source_var._parameters.E1st = 12.400;
  _ANATOMIX_source_var._parameters.verbose = 0;
  _ANATOMIX_source_var._parameters.Br = 1.35;


  /* component ANATOMIX_source=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_var._rotation_absolute, _ANATOMIX_source_var._rotation_absolute);
    rot_transpose(_ANATOMIX_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_source_var._rotation_absolute, tr1, _ANATOMIX_source_var._rotation_relative);
    _ANATOMIX_source_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_source_var._position_absolute = coords_add(_ANATOMIX_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_var._position_absolute, _ANATOMIX_source_var._position_absolute);
    _ANATOMIX_source_var._position_relative = rot_apply(_ANATOMIX_source_var._rotation_absolute, tc1);
  } /* ANATOMIX_source=Undulator() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_source", _ANATOMIX_source_var._position_absolute, _ANATOMIX_source_var._rotation_absolute);
  instrument->_position_absolute[390] = _ANATOMIX_source_var._position_absolute;
  instrument->_position_relative[390] = _ANATOMIX_source_var._position_relative;
    _ANATOMIX_source_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_source_var._position_relative);
  instrument->counter_N[390]  = instrument->counter_P[390] = instrument->counter_P2[390] = 0;
  instrument->counter_AbsorbProp[390]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0389_ANATOMIX_source", _ANATOMIX_source_var._position_absolute, _ANATOMIX_source_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "E0", "0", "_instrument_var._parameters.ANATOMIX_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "dE", "0", "_instrument_var._parameters.ANATOMIX_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "dEe", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "K", "0", "1.03118","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "Nper", "1", "140","int");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "lu", "16e-3", "3.2e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "sigey", "0", "8.4e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "sigex", "0", "267.9e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "sigepx", "0", "30.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "sigepy", "0", "3.9e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "dist", "1", "50","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "E1st", "0", "12.400","MCNUM");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0389_ANATOMIX_source", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_source_setpos */

/* component ANATOMIX_e_repartition_before_cc=Monitor_nD() SETTING, POSITION/ROTATION */
int _ANATOMIX_e_repartition_before_cc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_e_repartition_before_cc_setpos] component ANATOMIX_e_repartition_before_cc=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_ANATOMIX_e_repartition_before_cc_var._name, "ANATOMIX_e_repartition_before_cc", 16384);
  stracpy(_ANATOMIX_e_repartition_before_cc_var._type, "Monitor_nD", 16384);
  _ANATOMIX_e_repartition_before_cc_var._index=391;
  int current_setpos_index = 391;
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.user9[0]='\0';
  _ANATOMIX_e_repartition_before_cc_var._parameters.xwidth = 0.01;
  _ANATOMIX_e_repartition_before_cc_var._parameters.yheight = 0.01;
  _ANATOMIX_e_repartition_before_cc_var._parameters.zdepth = 0;
  _ANATOMIX_e_repartition_before_cc_var._parameters.bins = 100;
  _ANATOMIX_e_repartition_before_cc_var._parameters.min = -1e40;
  _ANATOMIX_e_repartition_before_cc_var._parameters.max = 1e40;
  _ANATOMIX_e_repartition_before_cc_var._parameters.restore_xray = 1;
  _ANATOMIX_e_repartition_before_cc_var._parameters.radius = 0;
  if(ANATOMIX_emonopts && strlen(ANATOMIX_emonopts))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.options, ANATOMIX_emonopts ? ANATOMIX_emonopts : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.options[0]='\0';
  if("ANATOMIX_e_repartition_before_cc" && strlen("ANATOMIX_e_repartition_before_cc"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.filename, "ANATOMIX_e_repartition_before_cc" ? "ANATOMIX_e_repartition_before_cc" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.geometry[0]='\0';
  _ANATOMIX_e_repartition_before_cc_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_ANATOMIX_e_repartition_before_cc_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _ANATOMIX_e_repartition_before_cc_var._parameters.username9[0]='\0';


  /* component ANATOMIX_e_repartition_before_cc=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_source_var._rotation_absolute, _ANATOMIX_e_repartition_before_cc_var._rotation_absolute);
    rot_transpose(_ANATOMIX_source_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_e_repartition_before_cc_var._rotation_absolute, tr1, _ANATOMIX_e_repartition_before_cc_var._rotation_relative);
    _ANATOMIX_e_repartition_before_cc_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_e_repartition_before_cc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 50);
    rot_transpose(_ANATOMIX_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_e_repartition_before_cc_var._position_absolute = coords_add(_ANATOMIX_source_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_source_var._position_absolute, _ANATOMIX_e_repartition_before_cc_var._position_absolute);
    _ANATOMIX_e_repartition_before_cc_var._position_relative = rot_apply(_ANATOMIX_e_repartition_before_cc_var._rotation_absolute, tc1);
  } /* ANATOMIX_e_repartition_before_cc=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_e_repartition_before_cc", _ANATOMIX_e_repartition_before_cc_var._position_absolute, _ANATOMIX_e_repartition_before_cc_var._rotation_absolute);
  instrument->_position_absolute[391] = _ANATOMIX_e_repartition_before_cc_var._position_absolute;
  instrument->_position_relative[391] = _ANATOMIX_e_repartition_before_cc_var._position_relative;
    _ANATOMIX_e_repartition_before_cc_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_e_repartition_before_cc_var._position_relative);
  instrument->counter_N[391]  = instrument->counter_P[391] = instrument->counter_P2[391] = 0;
  instrument->counter_AbsorbProp[391]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", _ANATOMIX_e_repartition_before_cc_var._position_absolute, _ANATOMIX_e_repartition_before_cc_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "xwidth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "bins", "0", "100","int");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "options", "NULL", ANATOMIX_emonopts, "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "filename", "NULL", "ANATOMIX_e_repartition_before_cc", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0390_ANATOMIX_e_repartition_before_cc", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_e_repartition_before_cc_setpos */

/* component ANATOMIX_psd_monitor_before_cc=PSD_monitor() SETTING, POSITION/ROTATION */
int _ANATOMIX_psd_monitor_before_cc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_psd_monitor_before_cc_setpos] component ANATOMIX_psd_monitor_before_cc=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ANATOMIX_psd_monitor_before_cc_var._name, "ANATOMIX_psd_monitor_before_cc", 16384);
  stracpy(_ANATOMIX_psd_monitor_before_cc_var._type, "PSD_monitor", 16384);
  _ANATOMIX_psd_monitor_before_cc_var._index=392;
  int current_setpos_index = 392;
  if("ANATOMIX_psd_monitor_before_cc.dat" && strlen("ANATOMIX_psd_monitor_before_cc.dat"))
    stracpy(_ANATOMIX_psd_monitor_before_cc_var._parameters.filename, "ANATOMIX_psd_monitor_before_cc.dat" ? "ANATOMIX_psd_monitor_before_cc.dat" : "", 16384);
  else 
  _ANATOMIX_psd_monitor_before_cc_var._parameters.filename[0]='\0';
  _ANATOMIX_psd_monitor_before_cc_var._parameters.xwidth = 0.01;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.yheight = 0.01;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.radius = 0;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.restore_xray = 1;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.nowritefile = 0;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.nx = 90;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.ny = 90;
  _ANATOMIX_psd_monitor_before_cc_var._parameters.nr = 0;


  /* component ANATOMIX_psd_monitor_before_cc=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_e_repartition_before_cc_var._rotation_absolute, _ANATOMIX_psd_monitor_before_cc_var._rotation_absolute);
    rot_transpose(_ANATOMIX_e_repartition_before_cc_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_psd_monitor_before_cc_var._rotation_absolute, tr1, _ANATOMIX_psd_monitor_before_cc_var._rotation_relative);
    _ANATOMIX_psd_monitor_before_cc_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_psd_monitor_before_cc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_e_repartition_before_cc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_psd_monitor_before_cc_var._position_absolute = coords_add(_ANATOMIX_e_repartition_before_cc_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_e_repartition_before_cc_var._position_absolute, _ANATOMIX_psd_monitor_before_cc_var._position_absolute);
    _ANATOMIX_psd_monitor_before_cc_var._position_relative = rot_apply(_ANATOMIX_psd_monitor_before_cc_var._rotation_absolute, tc1);
  } /* ANATOMIX_psd_monitor_before_cc=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_psd_monitor_before_cc", _ANATOMIX_psd_monitor_before_cc_var._position_absolute, _ANATOMIX_psd_monitor_before_cc_var._rotation_absolute);
  instrument->_position_absolute[392] = _ANATOMIX_psd_monitor_before_cc_var._position_absolute;
  instrument->_position_relative[392] = _ANATOMIX_psd_monitor_before_cc_var._position_relative;
    _ANATOMIX_psd_monitor_before_cc_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_psd_monitor_before_cc_var._position_relative);
  instrument->counter_N[392]  = instrument->counter_P[392] = instrument->counter_P2[392] = 0;
  instrument->counter_AbsorbProp[392]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", _ANATOMIX_psd_monitor_before_cc_var._position_absolute, _ANATOMIX_psd_monitor_before_cc_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "filename", 0, "ANATOMIX_psd_monitor_before_cc.dat", "char*");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "xwidth", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "yheight", "0.05", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0391_ANATOMIX_psd_monitor_before_cc", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_psd_monitor_before_cc_setpos */

/* component ANATOMIX_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _ANATOMIX_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_bragg_crystal_setpos] component ANATOMIX_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_ANATOMIX_bragg_crystal_var._name, "ANATOMIX_bragg_crystal", 16384);
  stracpy(_ANATOMIX_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _ANATOMIX_bragg_crystal_var._index=393;
  int current_setpos_index = 393;
  _ANATOMIX_bragg_crystal_var._parameters.length = 0.05;
  _ANATOMIX_bragg_crystal_var._parameters.width = 0.02;
  _ANATOMIX_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_ANATOMIX_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _ANATOMIX_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_ANATOMIX_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _ANATOMIX_bragg_crystal_var._parameters.material[0]='\0';
  _ANATOMIX_bragg_crystal_var._parameters.alpha = 0.0;
  _ANATOMIX_bragg_crystal_var._parameters.R0 = 0;
  _ANATOMIX_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _ANATOMIX_bragg_crystal_var._parameters.crystal_type = 2;
  _ANATOMIX_bragg_crystal_var._parameters.h = 1;
  _ANATOMIX_bragg_crystal_var._parameters.k = 1;
  _ANATOMIX_bragg_crystal_var._parameters.l = 1;
  _ANATOMIX_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _ANATOMIX_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component ANATOMIX_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ANATOMIX_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_psd_monitor_before_cc_var._rotation_absolute, _ANATOMIX_bragg_crystal_var._rotation_absolute);
    rot_transpose(_ANATOMIX_psd_monitor_before_cc_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_bragg_crystal_var._rotation_absolute, tr1, _ANATOMIX_bragg_crystal_var._rotation_relative);
    _ANATOMIX_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_ANATOMIX_psd_monitor_before_cc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_bragg_crystal_var._position_absolute = coords_add(_ANATOMIX_psd_monitor_before_cc_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_psd_monitor_before_cc_var._position_absolute, _ANATOMIX_bragg_crystal_var._position_absolute);
    _ANATOMIX_bragg_crystal_var._position_relative = rot_apply(_ANATOMIX_bragg_crystal_var._rotation_absolute, tc1);
  } /* ANATOMIX_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_bragg_crystal", _ANATOMIX_bragg_crystal_var._position_absolute, _ANATOMIX_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[393] = _ANATOMIX_bragg_crystal_var._position_absolute;
  instrument->_position_relative[393] = _ANATOMIX_bragg_crystal_var._position_relative;
    _ANATOMIX_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_bragg_crystal_var._position_relative);
  instrument->counter_N[393]  = instrument->counter_P[393] = instrument->counter_P2[393] = 0;
  instrument->counter_AbsorbProp[393]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", _ANATOMIX_bragg_crystal_var._position_absolute, _ANATOMIX_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0392_ANATOMIX_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_bragg_crystal_setpos */

/* component ANATOMIX_arm=Arm() SETTING, POSITION/ROTATION */
int _ANATOMIX_arm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_arm_setpos] component ANATOMIX_arm=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ANATOMIX_arm_var._name, "ANATOMIX_arm", 16384);
  stracpy(_ANATOMIX_arm_var._type, "Arm", 16384);
  _ANATOMIX_arm_var._index=394;
  int current_setpos_index = 394;
  /* component ANATOMIX_arm=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- ANATOMIX_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_bragg_crystal_var._rotation_absolute, _ANATOMIX_arm_var._rotation_absolute);
    rot_transpose(_ANATOMIX_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_arm_var._rotation_absolute, tr1, _ANATOMIX_arm_var._rotation_relative);
    _ANATOMIX_arm_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_arm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_arm_var._position_absolute = coords_add(_ANATOMIX_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_bragg_crystal_var._position_absolute, _ANATOMIX_arm_var._position_absolute);
    _ANATOMIX_arm_var._position_relative = rot_apply(_ANATOMIX_arm_var._rotation_absolute, tc1);
  } /* ANATOMIX_arm=Arm() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_arm", _ANATOMIX_arm_var._position_absolute, _ANATOMIX_arm_var._rotation_absolute);
  instrument->_position_absolute[394] = _ANATOMIX_arm_var._position_absolute;
  instrument->_position_relative[394] = _ANATOMIX_arm_var._position_relative;
    _ANATOMIX_arm_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_arm_var._position_relative);
  instrument->counter_N[394]  = instrument->counter_P[394] = instrument->counter_P2[394] = 0;
  instrument->counter_AbsorbProp[394]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0393_ANATOMIX_arm", _ANATOMIX_arm_var._position_absolute, _ANATOMIX_arm_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_arm_setpos */

/* component ANATOMIX_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _ANATOMIX_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_bragg_crystal_two_setpos] component ANATOMIX_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_ANATOMIX_bragg_crystal_two_var._name, "ANATOMIX_bragg_crystal_two", 16384);
  stracpy(_ANATOMIX_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _ANATOMIX_bragg_crystal_two_var._index=395;
  int current_setpos_index = 395;
  _ANATOMIX_bragg_crystal_two_var._parameters.length = 0.05;
  _ANATOMIX_bragg_crystal_two_var._parameters.width = 0.02;
  _ANATOMIX_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_ANATOMIX_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _ANATOMIX_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_ANATOMIX_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _ANATOMIX_bragg_crystal_two_var._parameters.material[0]='\0';
  _ANATOMIX_bragg_crystal_two_var._parameters.alpha = 0.0;
  _ANATOMIX_bragg_crystal_two_var._parameters.R0 = 0;
  _ANATOMIX_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _ANATOMIX_bragg_crystal_two_var._parameters.crystal_type = 2;
  _ANATOMIX_bragg_crystal_two_var._parameters.h = 1;
  _ANATOMIX_bragg_crystal_two_var._parameters.k = 1;
  _ANATOMIX_bragg_crystal_two_var._parameters.l = 1;
  _ANATOMIX_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _ANATOMIX_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component ANATOMIX_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (ANATOMIX_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_arm_var._rotation_absolute, _ANATOMIX_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_ANATOMIX_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_bragg_crystal_two_var._rotation_absolute, tr1, _ANATOMIX_bragg_crystal_two_var._rotation_relative);
    _ANATOMIX_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0.01, ANATOMIX_calculated_angle ? 0.01 / tan ( ANATOMIX_calculated_angle * DEG2RAD ) : 0);
    rot_transpose(_ANATOMIX_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_bragg_crystal_two_var._position_absolute = coords_add(_ANATOMIX_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_bragg_crystal_var._position_absolute, _ANATOMIX_bragg_crystal_two_var._position_absolute);
    _ANATOMIX_bragg_crystal_two_var._position_relative = rot_apply(_ANATOMIX_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* ANATOMIX_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_bragg_crystal_two", _ANATOMIX_bragg_crystal_two_var._position_absolute, _ANATOMIX_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[395] = _ANATOMIX_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[395] = _ANATOMIX_bragg_crystal_two_var._position_relative;
    _ANATOMIX_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_bragg_crystal_two_var._position_relative);
  instrument->counter_N[395]  = instrument->counter_P[395] = instrument->counter_P2[395] = 0;
  instrument->counter_AbsorbProp[395]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", _ANATOMIX_bragg_crystal_two_var._position_absolute, _ANATOMIX_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0394_ANATOMIX_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_bragg_crystal_two_setpos */

/* component ANATOMIX_arm_two=Arm() SETTING, POSITION/ROTATION */
int _ANATOMIX_arm_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_arm_two_setpos] component ANATOMIX_arm_two=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ANATOMIX_arm_two_var._name, "ANATOMIX_arm_two", 16384);
  stracpy(_ANATOMIX_arm_two_var._type, "Arm", 16384);
  _ANATOMIX_arm_two_var._index=396;
  int current_setpos_index = 396;
  /* component ANATOMIX_arm_two=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (ANATOMIX_calculated_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_bragg_crystal_two_var._rotation_absolute, _ANATOMIX_arm_two_var._rotation_absolute);
    rot_transpose(_ANATOMIX_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_arm_two_var._rotation_absolute, tr1, _ANATOMIX_arm_two_var._rotation_relative);
    _ANATOMIX_arm_two_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_arm_two_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_arm_two_var._position_absolute = coords_add(_ANATOMIX_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_bragg_crystal_two_var._position_absolute, _ANATOMIX_arm_two_var._position_absolute);
    _ANATOMIX_arm_two_var._position_relative = rot_apply(_ANATOMIX_arm_two_var._rotation_absolute, tc1);
  } /* ANATOMIX_arm_two=Arm() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_arm_two", _ANATOMIX_arm_two_var._position_absolute, _ANATOMIX_arm_two_var._rotation_absolute);
  instrument->_position_absolute[396] = _ANATOMIX_arm_two_var._position_absolute;
  instrument->_position_relative[396] = _ANATOMIX_arm_two_var._position_relative;
    _ANATOMIX_arm_two_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_arm_two_var._position_relative);
  instrument->counter_N[396]  = instrument->counter_P[396] = instrument->counter_P2[396] = 0;
  instrument->counter_AbsorbProp[396]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0395_ANATOMIX_arm_two", _ANATOMIX_arm_two_var._position_absolute, _ANATOMIX_arm_two_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_arm_two_setpos */

/* component ANATOMIX_psd_after_cc=PSD_monitor() SETTING, POSITION/ROTATION */
int _ANATOMIX_psd_after_cc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_psd_after_cc_setpos] component ANATOMIX_psd_after_cc=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ANATOMIX_psd_after_cc_var._name, "ANATOMIX_psd_after_cc", 16384);
  stracpy(_ANATOMIX_psd_after_cc_var._type, "PSD_monitor", 16384);
  _ANATOMIX_psd_after_cc_var._index=397;
  int current_setpos_index = 397;
  if("ANATOMIX_psd_after_cc2" && strlen("ANATOMIX_psd_after_cc2"))
    stracpy(_ANATOMIX_psd_after_cc_var._parameters.filename, "ANATOMIX_psd_after_cc2" ? "ANATOMIX_psd_after_cc2" : "", 16384);
  else 
  _ANATOMIX_psd_after_cc_var._parameters.filename[0]='\0';
  _ANATOMIX_psd_after_cc_var._parameters.xwidth = 0.1;
  _ANATOMIX_psd_after_cc_var._parameters.yheight = 0.1;
  _ANATOMIX_psd_after_cc_var._parameters.radius = 0;
  _ANATOMIX_psd_after_cc_var._parameters.restore_xray = 1;
  _ANATOMIX_psd_after_cc_var._parameters.nowritefile = 0;
  _ANATOMIX_psd_after_cc_var._parameters.nx = 90;
  _ANATOMIX_psd_after_cc_var._parameters.ny = 90;
  _ANATOMIX_psd_after_cc_var._parameters.nr = 0;


  /* component ANATOMIX_psd_after_cc=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_arm_two_var._rotation_absolute, _ANATOMIX_psd_after_cc_var._rotation_absolute);
    rot_transpose(_ANATOMIX_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_psd_after_cc_var._rotation_absolute, tr1, _ANATOMIX_psd_after_cc_var._rotation_relative);
    _ANATOMIX_psd_after_cc_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_psd_after_cc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1);
    rot_transpose(_ANATOMIX_arm_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_psd_after_cc_var._position_absolute = coords_add(_ANATOMIX_arm_two_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_bragg_crystal_two_var._position_absolute, _ANATOMIX_psd_after_cc_var._position_absolute);
    _ANATOMIX_psd_after_cc_var._position_relative = rot_apply(_ANATOMIX_psd_after_cc_var._rotation_absolute, tc1);
  } /* ANATOMIX_psd_after_cc=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_psd_after_cc", _ANATOMIX_psd_after_cc_var._position_absolute, _ANATOMIX_psd_after_cc_var._rotation_absolute);
  instrument->_position_absolute[397] = _ANATOMIX_psd_after_cc_var._position_absolute;
  instrument->_position_relative[397] = _ANATOMIX_psd_after_cc_var._position_relative;
    _ANATOMIX_psd_after_cc_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_psd_after_cc_var._position_relative);
  instrument->counter_N[397]  = instrument->counter_P[397] = instrument->counter_P2[397] = 0;
  instrument->counter_AbsorbProp[397]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", _ANATOMIX_psd_after_cc_var._position_absolute, _ANATOMIX_psd_after_cc_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "filename", 0, "ANATOMIX_psd_after_cc2", "char*");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "xwidth", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "yheight", "0.05", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0396_ANATOMIX_psd_after_cc", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_psd_after_cc_setpos */

/* component ANATOMIX_e_monitor_before_sample=E_monitor() SETTING, POSITION/ROTATION */
int _ANATOMIX_e_monitor_before_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_e_monitor_before_sample_setpos] component ANATOMIX_e_monitor_before_sample=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_ANATOMIX_e_monitor_before_sample_var._name, "ANATOMIX_e_monitor_before_sample", 16384);
  stracpy(_ANATOMIX_e_monitor_before_sample_var._type, "E_monitor", 16384);
  _ANATOMIX_e_monitor_before_sample_var._index=398;
  int current_setpos_index = 398;
  _ANATOMIX_e_monitor_before_sample_var._parameters.nE = 500;
  if("ANATOMIX_e_monitor_before_sample.dat" && strlen("ANATOMIX_e_monitor_before_sample.dat"))
    stracpy(_ANATOMIX_e_monitor_before_sample_var._parameters.filename, "ANATOMIX_e_monitor_before_sample.dat" ? "ANATOMIX_e_monitor_before_sample.dat" : "", 16384);
  else 
  _ANATOMIX_e_monitor_before_sample_var._parameters.filename[0]='\0';
  _ANATOMIX_e_monitor_before_sample_var._parameters.xwidth = 1;
  _ANATOMIX_e_monitor_before_sample_var._parameters.yheight = 1;
  _ANATOMIX_e_monitor_before_sample_var._parameters.Emin = _instrument_var._parameters.ANATOMIX_E0 - _instrument_var._parameters.ANATOMIX_dE;
  _ANATOMIX_e_monitor_before_sample_var._parameters.Emax = _instrument_var._parameters.ANATOMIX_E0 + _instrument_var._parameters.ANATOMIX_dE;
  _ANATOMIX_e_monitor_before_sample_var._parameters.restore_xray = 1;


  /* component ANATOMIX_e_monitor_before_sample=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_psd_after_cc_var._rotation_absolute, _ANATOMIX_e_monitor_before_sample_var._rotation_absolute);
    rot_transpose(_ANATOMIX_psd_after_cc_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_e_monitor_before_sample_var._rotation_absolute, tr1, _ANATOMIX_e_monitor_before_sample_var._rotation_relative);
    _ANATOMIX_e_monitor_before_sample_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_e_monitor_before_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1);
    rot_transpose(_ANATOMIX_psd_after_cc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_e_monitor_before_sample_var._position_absolute = coords_add(_ANATOMIX_psd_after_cc_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_psd_after_cc_var._position_absolute, _ANATOMIX_e_monitor_before_sample_var._position_absolute);
    _ANATOMIX_e_monitor_before_sample_var._position_relative = rot_apply(_ANATOMIX_e_monitor_before_sample_var._rotation_absolute, tc1);
  } /* ANATOMIX_e_monitor_before_sample=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_e_monitor_before_sample", _ANATOMIX_e_monitor_before_sample_var._position_absolute, _ANATOMIX_e_monitor_before_sample_var._rotation_absolute);
  instrument->_position_absolute[398] = _ANATOMIX_e_monitor_before_sample_var._position_absolute;
  instrument->_position_relative[398] = _ANATOMIX_e_monitor_before_sample_var._position_relative;
    _ANATOMIX_e_monitor_before_sample_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_e_monitor_before_sample_var._position_relative);
  instrument->counter_N[398]  = instrument->counter_P[398] = instrument->counter_P2[398] = 0;
  instrument->counter_AbsorbProp[398]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", _ANATOMIX_e_monitor_before_sample_var._position_absolute, _ANATOMIX_e_monitor_before_sample_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "nE", "20", "500","MCNUM");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "filename", 0, "ANATOMIX_e_monitor_before_sample.dat", "char*");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "xwidth", "0.1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "yheight", "0.1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "Emin", "NONE", "_instrument_var._parameters.ANATOMIX_E0 - _instrument_var._parameters.ANATOMIX_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "Emax", "NONE", "_instrument_var._parameters.ANATOMIX_E0 + _instrument_var._parameters.ANATOMIX_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0397_ANATOMIX_e_monitor_before_sample", "restore_xray", "0", "1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_e_monitor_before_sample_setpos */

/* component ANATOMIX_psd_repartition_after_cc=PSD_monitor() SETTING, POSITION/ROTATION */
int _ANATOMIX_psd_repartition_after_cc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_psd_repartition_after_cc_setpos] component ANATOMIX_psd_repartition_after_cc=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ANATOMIX_psd_repartition_after_cc_var._name, "ANATOMIX_psd_repartition_after_cc", 16384);
  stracpy(_ANATOMIX_psd_repartition_after_cc_var._type, "PSD_monitor", 16384);
  _ANATOMIX_psd_repartition_after_cc_var._index=399;
  int current_setpos_index = 399;
  if("ANATOMIX_psd_repartition_after_cc" && strlen("ANATOMIX_psd_repartition_after_cc"))
    stracpy(_ANATOMIX_psd_repartition_after_cc_var._parameters.filename, "ANATOMIX_psd_repartition_after_cc" ? "ANATOMIX_psd_repartition_after_cc" : "", 16384);
  else 
  _ANATOMIX_psd_repartition_after_cc_var._parameters.filename[0]='\0';
  _ANATOMIX_psd_repartition_after_cc_var._parameters.xwidth = .1;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.yheight = .1;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.radius = 0;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.restore_xray = 1;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.nowritefile = 0;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.nx = 90;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.ny = 90;
  _ANATOMIX_psd_repartition_after_cc_var._parameters.nr = 0;


  /* component ANATOMIX_psd_repartition_after_cc=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_e_monitor_before_sample_var._rotation_absolute, _ANATOMIX_psd_repartition_after_cc_var._rotation_absolute);
    rot_transpose(_ANATOMIX_e_monitor_before_sample_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, tr1, _ANATOMIX_psd_repartition_after_cc_var._rotation_relative);
    _ANATOMIX_psd_repartition_after_cc_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_psd_repartition_after_cc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_e_monitor_before_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_psd_repartition_after_cc_var._position_absolute = coords_add(_ANATOMIX_e_monitor_before_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_e_monitor_before_sample_var._position_absolute, _ANATOMIX_psd_repartition_after_cc_var._position_absolute);
    _ANATOMIX_psd_repartition_after_cc_var._position_relative = rot_apply(_ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, tc1);
  } /* ANATOMIX_psd_repartition_after_cc=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_psd_repartition_after_cc", _ANATOMIX_psd_repartition_after_cc_var._position_absolute, _ANATOMIX_psd_repartition_after_cc_var._rotation_absolute);
  instrument->_position_absolute[399] = _ANATOMIX_psd_repartition_after_cc_var._position_absolute;
  instrument->_position_relative[399] = _ANATOMIX_psd_repartition_after_cc_var._position_relative;
    _ANATOMIX_psd_repartition_after_cc_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_psd_repartition_after_cc_var._position_relative);
  instrument->counter_N[399]  = instrument->counter_P[399] = instrument->counter_P2[399] = 0;
  instrument->counter_AbsorbProp[399]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", _ANATOMIX_psd_repartition_after_cc_var._position_absolute, _ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "filename", 0, "ANATOMIX_psd_repartition_after_cc", "char*");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "xwidth", "0.05", ".1","MCNUM");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "yheight", "0.05", ".1","MCNUM");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0398_ANATOMIX_psd_repartition_after_cc", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_psd_repartition_after_cc_setpos */

/* component ANATOMIX_sample_rotation_stage=Arm() SETTING, POSITION/ROTATION */
int _ANATOMIX_sample_rotation_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_sample_rotation_stage_setpos] component ANATOMIX_sample_rotation_stage=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_ANATOMIX_sample_rotation_stage_var._name, "ANATOMIX_sample_rotation_stage", 16384);
  stracpy(_ANATOMIX_sample_rotation_stage_var._type, "Arm", 16384);
  _ANATOMIX_sample_rotation_stage_var._index=400;
  int current_setpos_index = 400;
  /* component ANATOMIX_sample_rotation_stage=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, _ANATOMIX_sample_rotation_stage_var._rotation_absolute);
    rot_transpose(_ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_sample_rotation_stage_var._rotation_absolute, tr1, _ANATOMIX_sample_rotation_stage_var._rotation_relative);
    _ANATOMIX_sample_rotation_stage_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_sample_rotation_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 150);
    rot_transpose(_ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_sample_rotation_stage_var._position_absolute = coords_add(_ANATOMIX_psd_repartition_after_cc_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_psd_repartition_after_cc_var._position_absolute, _ANATOMIX_sample_rotation_stage_var._position_absolute);
    _ANATOMIX_sample_rotation_stage_var._position_relative = rot_apply(_ANATOMIX_sample_rotation_stage_var._rotation_absolute, tc1);
  } /* ANATOMIX_sample_rotation_stage=Arm() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_sample_rotation_stage", _ANATOMIX_sample_rotation_stage_var._position_absolute, _ANATOMIX_sample_rotation_stage_var._rotation_absolute);
  instrument->_position_absolute[400] = _ANATOMIX_sample_rotation_stage_var._position_absolute;
  instrument->_position_relative[400] = _ANATOMIX_sample_rotation_stage_var._position_relative;
    _ANATOMIX_sample_rotation_stage_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_sample_rotation_stage_var._position_relative);
  instrument->counter_N[400]  = instrument->counter_P[400] = instrument->counter_P2[400] = 0;
  instrument->counter_AbsorbProp[400]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0399_ANATOMIX_sample_rotation_stage", _ANATOMIX_sample_rotation_stage_var._position_absolute, _ANATOMIX_sample_rotation_stage_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_sample_rotation_stage_setpos */

/* component ANATOMIX_sample=Filter() SETTING, POSITION/ROTATION */
int _ANATOMIX_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_sample_setpos] component ANATOMIX_sample=Filter() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Filter.comp:126]");
  stracpy(_ANATOMIX_sample_var._name, "ANATOMIX_sample", 16384);
  stracpy(_ANATOMIX_sample_var._type, "Filter", 16384);
  _ANATOMIX_sample_var._index=401;
  int current_setpos_index = 401;
  _ANATOMIX_sample_var._parameters.refraction = 0;
  _ANATOMIX_sample_var._parameters.fixed_delta = 0;
  if("Ge.txt" && strlen("Ge.txt"))
    stracpy(_ANATOMIX_sample_var._parameters.material_datafile, "Ge.txt" ? "Ge.txt" : "", 16384);
  else 
  _ANATOMIX_sample_var._parameters.material_datafile[0]='\0';
  if(_instrument_var._parameters.ANATOMIX_sample && strlen(_instrument_var._parameters.ANATOMIX_sample))
    stracpy(_ANATOMIX_sample_var._parameters.geometry, _instrument_var._parameters.ANATOMIX_sample ? _instrument_var._parameters.ANATOMIX_sample : "", 16384);
  else 
  _ANATOMIX_sample_var._parameters.geometry[0]='\0';
  _ANATOMIX_sample_var._parameters.xwidth = 0.02;
  _ANATOMIX_sample_var._parameters.yheight = 0;
  _ANATOMIX_sample_var._parameters.zdepth = 0;
  _ANATOMIX_sample_var._parameters.radius = 0;
  _ANATOMIX_sample_var._parameters.mu_col = -1;


  /* component ANATOMIX_sample=Filter() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.ANATOMIX_ANGLE)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_sample_rotation_stage_var._rotation_absolute, _ANATOMIX_sample_var._rotation_absolute);
    rot_transpose(_ANATOMIX_psd_repartition_after_cc_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_sample_var._rotation_absolute, tr1, _ANATOMIX_sample_var._rotation_relative);
    _ANATOMIX_sample_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_sample_rotation_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_sample_var._position_absolute = coords_add(_ANATOMIX_sample_rotation_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_psd_repartition_after_cc_var._position_absolute, _ANATOMIX_sample_var._position_absolute);
    _ANATOMIX_sample_var._position_relative = rot_apply(_ANATOMIX_sample_var._rotation_absolute, tc1);
  } /* ANATOMIX_sample=Filter() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_sample", _ANATOMIX_sample_var._position_absolute, _ANATOMIX_sample_var._rotation_absolute);
  instrument->_position_absolute[401] = _ANATOMIX_sample_var._position_absolute;
  instrument->_position_relative[401] = _ANATOMIX_sample_var._position_relative;
    _ANATOMIX_sample_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_sample_var._position_relative);
  instrument->counter_N[401]  = instrument->counter_P[401] = instrument->counter_P2[401] = 0;
  instrument->counter_AbsorbProp[401]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0400_ANATOMIX_sample", _ANATOMIX_sample_var._position_absolute, _ANATOMIX_sample_var._rotation_absolute, "Filter");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "refraction", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "fixed_delta", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "material_datafile", "Be.txt", "Ge.txt", "char*");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "geometry", 0, _instrument_var._parameters.ANATOMIX_sample, "char*");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0400_ANATOMIX_sample", "mu_col", "-1", "-1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_sample_setpos */

/* component ANATOMIX_e_monitor_after_sample=E_monitor() SETTING, POSITION/ROTATION */
int _ANATOMIX_e_monitor_after_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_e_monitor_after_sample_setpos] component ANATOMIX_e_monitor_after_sample=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_ANATOMIX_e_monitor_after_sample_var._name, "ANATOMIX_e_monitor_after_sample", 16384);
  stracpy(_ANATOMIX_e_monitor_after_sample_var._type, "E_monitor", 16384);
  _ANATOMIX_e_monitor_after_sample_var._index=402;
  int current_setpos_index = 402;
  _ANATOMIX_e_monitor_after_sample_var._parameters.nE = 500;
  if("ANATOMIX_e_monitor_after_sample.dat" && strlen("ANATOMIX_e_monitor_after_sample.dat"))
    stracpy(_ANATOMIX_e_monitor_after_sample_var._parameters.filename, "ANATOMIX_e_monitor_after_sample.dat" ? "ANATOMIX_e_monitor_after_sample.dat" : "", 16384);
  else 
  _ANATOMIX_e_monitor_after_sample_var._parameters.filename[0]='\0';
  _ANATOMIX_e_monitor_after_sample_var._parameters.xwidth = 1;
  _ANATOMIX_e_monitor_after_sample_var._parameters.yheight = 1;
  _ANATOMIX_e_monitor_after_sample_var._parameters.Emin = _instrument_var._parameters.ANATOMIX_E0 - _instrument_var._parameters.ANATOMIX_E0 * 0.1;
  _ANATOMIX_e_monitor_after_sample_var._parameters.Emax = _instrument_var._parameters.ANATOMIX_E0 + _instrument_var._parameters.ANATOMIX_E0 * 0.1;
  _ANATOMIX_e_monitor_after_sample_var._parameters.restore_xray = 1;


  /* component ANATOMIX_e_monitor_after_sample=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_sample_rotation_stage_var._rotation_absolute, _ANATOMIX_e_monitor_after_sample_var._rotation_absolute);
    rot_transpose(_ANATOMIX_sample_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_e_monitor_after_sample_var._rotation_absolute, tr1, _ANATOMIX_e_monitor_after_sample_var._rotation_relative);
    _ANATOMIX_e_monitor_after_sample_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_e_monitor_after_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_ANATOMIX_sample_rotation_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_e_monitor_after_sample_var._position_absolute = coords_add(_ANATOMIX_sample_rotation_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_sample_var._position_absolute, _ANATOMIX_e_monitor_after_sample_var._position_absolute);
    _ANATOMIX_e_monitor_after_sample_var._position_relative = rot_apply(_ANATOMIX_e_monitor_after_sample_var._rotation_absolute, tc1);
  } /* ANATOMIX_e_monitor_after_sample=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_e_monitor_after_sample", _ANATOMIX_e_monitor_after_sample_var._position_absolute, _ANATOMIX_e_monitor_after_sample_var._rotation_absolute);
  instrument->_position_absolute[402] = _ANATOMIX_e_monitor_after_sample_var._position_absolute;
  instrument->_position_relative[402] = _ANATOMIX_e_monitor_after_sample_var._position_relative;
    _ANATOMIX_e_monitor_after_sample_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_e_monitor_after_sample_var._position_relative);
  instrument->counter_N[402]  = instrument->counter_P[402] = instrument->counter_P2[402] = 0;
  instrument->counter_AbsorbProp[402]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", _ANATOMIX_e_monitor_after_sample_var._position_absolute, _ANATOMIX_e_monitor_after_sample_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "nE", "20", "500","MCNUM");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "filename", 0, "ANATOMIX_e_monitor_after_sample.dat", "char*");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "xwidth", "0.1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "yheight", "0.1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "Emin", "NONE", "_instrument_var._parameters.ANATOMIX_E0 - _instrument_var._parameters.ANATOMIX_E0 * 0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "Emax", "NONE", "_instrument_var._parameters.ANATOMIX_E0 + _instrument_var._parameters.ANATOMIX_E0 * 0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0401_ANATOMIX_e_monitor_after_sample", "restore_xray", "0", "1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_e_monitor_after_sample_setpos */

/* component ANATOMIX_psd_monitor_after_cc=PSD_monitor() SETTING, POSITION/ROTATION */
int _ANATOMIX_psd_monitor_after_cc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_psd_monitor_after_cc_setpos] component ANATOMIX_psd_monitor_after_cc=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_ANATOMIX_psd_monitor_after_cc_var._name, "ANATOMIX_psd_monitor_after_cc", 16384);
  stracpy(_ANATOMIX_psd_monitor_after_cc_var._type, "PSD_monitor", 16384);
  _ANATOMIX_psd_monitor_after_cc_var._index=403;
  int current_setpos_index = 403;
  if("ANATOMIX_psd_monitor_after_sample.dat" && strlen("ANATOMIX_psd_monitor_after_sample.dat"))
    stracpy(_ANATOMIX_psd_monitor_after_cc_var._parameters.filename, "ANATOMIX_psd_monitor_after_sample.dat" ? "ANATOMIX_psd_monitor_after_sample.dat" : "", 16384);
  else 
  _ANATOMIX_psd_monitor_after_cc_var._parameters.filename[0]='\0';
  _ANATOMIX_psd_monitor_after_cc_var._parameters.xwidth = .02;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.yheight = .02;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.radius = 0;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.restore_xray = 1;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.nowritefile = 0;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.nx = 512;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.ny = 512;
  _ANATOMIX_psd_monitor_after_cc_var._parameters.nr = 0;


  /* component ANATOMIX_psd_monitor_after_cc=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_e_monitor_after_sample_var._rotation_absolute, _ANATOMIX_psd_monitor_after_cc_var._rotation_absolute);
    rot_transpose(_ANATOMIX_e_monitor_after_sample_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_psd_monitor_after_cc_var._rotation_absolute, tr1, _ANATOMIX_psd_monitor_after_cc_var._rotation_relative);
    _ANATOMIX_psd_monitor_after_cc_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_psd_monitor_after_cc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_e_monitor_after_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_psd_monitor_after_cc_var._position_absolute = coords_add(_ANATOMIX_e_monitor_after_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_e_monitor_after_sample_var._position_absolute, _ANATOMIX_psd_monitor_after_cc_var._position_absolute);
    _ANATOMIX_psd_monitor_after_cc_var._position_relative = rot_apply(_ANATOMIX_psd_monitor_after_cc_var._rotation_absolute, tc1);
  } /* ANATOMIX_psd_monitor_after_cc=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_psd_monitor_after_cc", _ANATOMIX_psd_monitor_after_cc_var._position_absolute, _ANATOMIX_psd_monitor_after_cc_var._rotation_absolute);
  instrument->_position_absolute[403] = _ANATOMIX_psd_monitor_after_cc_var._position_absolute;
  instrument->_position_relative[403] = _ANATOMIX_psd_monitor_after_cc_var._position_relative;
    _ANATOMIX_psd_monitor_after_cc_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_psd_monitor_after_cc_var._position_relative);
  instrument->counter_N[403]  = instrument->counter_P[403] = instrument->counter_P2[403] = 0;
  instrument->counter_AbsorbProp[403]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", _ANATOMIX_psd_monitor_after_cc_var._position_absolute, _ANATOMIX_psd_monitor_after_cc_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "filename", 0, "ANATOMIX_psd_monitor_after_sample.dat", "char*");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "xwidth", "0.05", ".02","MCNUM");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "yheight", "0.05", ".02","MCNUM");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "nx", "90", "512","int");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "ny", "90", "512","int");
        mccomp_param_nexus(nxhandle,"0402_ANATOMIX_psd_monitor_after_cc", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_psd_monitor_after_cc_setpos */

/* component beamdump_416=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_416_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_416_setpos] component beamdump_416=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_416_var._name, "beamdump_416", 16384);
  stracpy(_beamdump_416_var._type, "Beamstop", 16384);
  _beamdump_416_var._index=404;
  int current_setpos_index = 404;
  _beamdump_416_var._parameters.xmin = -0.05;
  _beamdump_416_var._parameters.xmax = 0.05;
  _beamdump_416_var._parameters.ymin = -0.05;
  _beamdump_416_var._parameters.ymax = 0.05;
  _beamdump_416_var._parameters.xwidth = 0;
  _beamdump_416_var._parameters.yheight = 0;
  _beamdump_416_var._parameters.radius = 0;

  /* component beamdump_416=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_psd_monitor_after_cc_var._rotation_absolute, _beamdump_416_var._rotation_absolute);
    rot_transpose(_ANATOMIX_psd_monitor_after_cc_var._rotation_absolute, tr1);
    rot_mul(_beamdump_416_var._rotation_absolute, tr1, _beamdump_416_var._rotation_relative);
    _beamdump_416_var._rotation_is_identity =  rot_test_identity(_beamdump_416_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_ANATOMIX_psd_monitor_after_cc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_416_var._position_absolute = coords_add(_ANATOMIX_psd_monitor_after_cc_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_psd_monitor_after_cc_var._position_absolute, _beamdump_416_var._position_absolute);
    _beamdump_416_var._position_relative = rot_apply(_beamdump_416_var._rotation_absolute, tc1);
  } /* beamdump_416=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_416", _beamdump_416_var._position_absolute, _beamdump_416_var._rotation_absolute);
  instrument->_position_absolute[404] = _beamdump_416_var._position_absolute;
  instrument->_position_relative[404] = _beamdump_416_var._position_relative;
    _beamdump_416_var._position_relative_is_zero =  coords_test_zero(_beamdump_416_var._position_relative);
  instrument->counter_N[404]  = instrument->counter_P[404] = instrument->counter_P2[404] = 0;
  instrument->counter_AbsorbProp[404]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0403_beamdump_416", _beamdump_416_var._position_absolute, _beamdump_416_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0403_beamdump_416", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_416_setpos */

/* component NANOSCOPIUM_pos=Text() SETTING, POSITION/ROTATION */
int _NANOSCOPIUM_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANOSCOPIUM_pos_setpos] component NANOSCOPIUM_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_NANOSCOPIUM_pos_var._name, "NANOSCOPIUM_pos", 16384);
  stracpy(_NANOSCOPIUM_pos_var._type, "Text", 16384);
  _NANOSCOPIUM_pos_var._index=405;
  int current_setpos_index = 405;
  if("NANOSCOPIUM" && strlen("NANOSCOPIUM"))
    stracpy(_NANOSCOPIUM_pos_var._parameters.text, "NANOSCOPIUM" ? "NANOSCOPIUM" : "", 16384);
  else 
  _NANOSCOPIUM_pos_var._parameters.text[0]='\0';
  _NANOSCOPIUM_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_NANOSCOPIUM_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _NANOSCOPIUM_pos_var._parameters.plane[0]='\0';
  _NANOSCOPIUM_pos_var._parameters.pen_thickness = 0.1;


  /* component NANOSCOPIUM_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-273.5085)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _NANOSCOPIUM_pos_var._rotation_absolute);
    rot_transpose(_beamdump_416_var._rotation_absolute, tr1);
    rot_mul(_NANOSCOPIUM_pos_var._rotation_absolute, tr1, _NANOSCOPIUM_pos_var._rotation_relative);
    _NANOSCOPIUM_pos_var._rotation_is_identity =  rot_test_identity(_NANOSCOPIUM_pos_var._rotation_relative);
    tc1 = coords_set(
      3.4478, 0, -56.2344);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANOSCOPIUM_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_416_var._position_absolute, _NANOSCOPIUM_pos_var._position_absolute);
    _NANOSCOPIUM_pos_var._position_relative = rot_apply(_NANOSCOPIUM_pos_var._rotation_absolute, tc1);
  } /* NANOSCOPIUM_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("NANOSCOPIUM_pos", _NANOSCOPIUM_pos_var._position_absolute, _NANOSCOPIUM_pos_var._rotation_absolute);
  instrument->_position_absolute[405] = _NANOSCOPIUM_pos_var._position_absolute;
  instrument->_position_relative[405] = _NANOSCOPIUM_pos_var._position_relative;
    _NANOSCOPIUM_pos_var._position_relative_is_zero =  coords_test_zero(_NANOSCOPIUM_pos_var._position_relative);
  instrument->counter_N[405]  = instrument->counter_P[405] = instrument->counter_P2[405] = 0;
  instrument->counter_AbsorbProp[405]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0404_NANOSCOPIUM_pos", _NANOSCOPIUM_pos_var._position_absolute, _NANOSCOPIUM_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0404_NANOSCOPIUM_pos", "text", "NONE", "NANOSCOPIUM", "char*");
        mccomp_param_nexus(nxhandle,"0404_NANOSCOPIUM_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0404_NANOSCOPIUM_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0404_NANOSCOPIUM_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANOSCOPIUM_pos_setpos */

/* component NANOSCOPIUM=Arm() SETTING, POSITION/ROTATION */
int _NANOSCOPIUM_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANOSCOPIUM_setpos] component NANOSCOPIUM=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANOSCOPIUM_var._name, "NANOSCOPIUM", 16384);
  stracpy(_NANOSCOPIUM_var._type, "Arm", 16384);
  _NANOSCOPIUM_var._index=406;
  int current_setpos_index = 406;
  /* component NANOSCOPIUM=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANOSCOPIUM_pos_var._rotation_absolute, _NANOSCOPIUM_var._rotation_absolute);
    rot_transpose(_NANOSCOPIUM_pos_var._rotation_absolute, tr1);
    rot_mul(_NANOSCOPIUM_var._rotation_absolute, tr1, _NANOSCOPIUM_var._rotation_relative);
    _NANOSCOPIUM_var._rotation_is_identity =  rot_test_identity(_NANOSCOPIUM_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANOSCOPIUM_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANOSCOPIUM_var._position_absolute = coords_add(_NANOSCOPIUM_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_NANOSCOPIUM_pos_var._position_absolute, _NANOSCOPIUM_var._position_absolute);
    _NANOSCOPIUM_var._position_relative = rot_apply(_NANOSCOPIUM_var._rotation_absolute, tc1);
  } /* NANOSCOPIUM=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANOSCOPIUM", _NANOSCOPIUM_var._position_absolute, _NANOSCOPIUM_var._rotation_absolute);
  instrument->_position_absolute[406] = _NANOSCOPIUM_var._position_absolute;
  instrument->_position_relative[406] = _NANOSCOPIUM_var._position_relative;
    _NANOSCOPIUM_var._position_relative_is_zero =  coords_test_zero(_NANOSCOPIUM_var._position_relative);
  instrument->counter_N[406]  = instrument->counter_P[406] = instrument->counter_P2[406] = 0;
  instrument->counter_AbsorbProp[406]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0405_NANOSCOPIUM", _NANOSCOPIUM_var._position_absolute, _NANOSCOPIUM_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANOSCOPIUM_setpos */

/* component NANO_source=Undulator() SETTING, POSITION/ROTATION */
int _NANO_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_source_setpos] component NANO_source=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_NANO_source_var._name, "NANO_source", 16384);
  stracpy(_NANO_source_var._type, "Undulator", 16384);
  _NANO_source_var._index=407;
  int current_setpos_index = 407;
  _NANO_source_var._parameters.E0 = _instrument_var._parameters.NANO_E0;
  _NANO_source_var._parameters.dE = _instrument_var._parameters.NANO_dE;
  _NANO_source_var._parameters.phase = 0;
  _NANO_source_var._parameters.randomphase = 0;
  _NANO_source_var._parameters.Ee = 2.75;
  _NANO_source_var._parameters.dEe = 0.001;
  _NANO_source_var._parameters.Ie = 0.5;
  _NANO_source_var._parameters.B = 0;
  _NANO_source_var._parameters.K = 0;
  _NANO_source_var._parameters.Nper = 106;
  _NANO_source_var._parameters.lu = 1.8e-2;
  _NANO_source_var._parameters.sigey = 8.8e-6;
  _NANO_source_var._parameters.sigex = 258.6e-6;
  _NANO_source_var._parameters.sigepx = 31.2e-6;
  _NANO_source_var._parameters.sigepy = 3.5e-6;
  _NANO_source_var._parameters.focus_xw = 100e-6;
  _NANO_source_var._parameters.focus_yh = 100e-6;
  _NANO_source_var._parameters.dist = 22.655;
  _NANO_source_var._parameters.quick_integ = 0;
  _NANO_source_var._parameters.E1st = NANO_E1_target;
  _NANO_source_var._parameters.verbose = 0;
  _NANO_source_var._parameters.Br = 1.35;


  /* component NANO_source=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANOSCOPIUM_var._rotation_absolute, _NANO_source_var._rotation_absolute);
    rot_transpose(_NANOSCOPIUM_var._rotation_absolute, tr1);
    rot_mul(_NANO_source_var._rotation_absolute, tr1, _NANO_source_var._rotation_relative);
    _NANO_source_var._rotation_is_identity =  rot_test_identity(_NANO_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANOSCOPIUM_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_source_var._position_absolute = coords_add(_NANOSCOPIUM_var._position_absolute, tc2);
    tc1 = coords_sub(_NANOSCOPIUM_var._position_absolute, _NANO_source_var._position_absolute);
    _NANO_source_var._position_relative = rot_apply(_NANO_source_var._rotation_absolute, tc1);
  } /* NANO_source=Undulator() AT ROTATED */
  DEBUG_COMPONENT("NANO_source", _NANO_source_var._position_absolute, _NANO_source_var._rotation_absolute);
  instrument->_position_absolute[407] = _NANO_source_var._position_absolute;
  instrument->_position_relative[407] = _NANO_source_var._position_relative;
    _NANO_source_var._position_relative_is_zero =  coords_test_zero(_NANO_source_var._position_relative);
  instrument->counter_N[407]  = instrument->counter_P[407] = instrument->counter_P2[407] = 0;
  instrument->counter_AbsorbProp[407]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0406_NANO_source", _NANO_source_var._position_absolute, _NANO_source_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "E0", "0", "_instrument_var._parameters.NANO_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "dE", "0", "_instrument_var._parameters.NANO_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "randomphase", "1", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "dEe", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "K", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "Nper", "1", "106","int");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "lu", "16e-3", "1.8e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "sigey", "0", "8.8e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "sigex", "0", "258.6e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "sigepx", "0", "31.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "sigepy", "0", "3.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "focus_xw", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "focus_yh", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "dist", "1", "22.655","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "E1st", "0", "NANO_E1_target","MCNUM");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0406_NANO_source", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_source_setpos */

/* component NANO_e_monitor_source=E_monitor() SETTING, POSITION/ROTATION */
int _NANO_e_monitor_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_e_monitor_source_setpos] component NANO_e_monitor_source=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_NANO_e_monitor_source_var._name, "NANO_e_monitor_source", 16384);
  stracpy(_NANO_e_monitor_source_var._type, "E_monitor", 16384);
  _NANO_e_monitor_source_var._index=408;
  int current_setpos_index = 408;
  _NANO_e_monitor_source_var._parameters.nE = 500;
  if("e_monitor_source.dat" && strlen("e_monitor_source.dat"))
    stracpy(_NANO_e_monitor_source_var._parameters.filename, "e_monitor_source.dat" ? "e_monitor_source.dat" : "", 16384);
  else 
  _NANO_e_monitor_source_var._parameters.filename[0]='\0';
  _NANO_e_monitor_source_var._parameters.xwidth = 0.1;
  _NANO_e_monitor_source_var._parameters.yheight = 0.1;
  _NANO_e_monitor_source_var._parameters.Emin = _instrument_var._parameters.NANO_E0 - _instrument_var._parameters.NANO_dE;
  _NANO_e_monitor_source_var._parameters.Emax = _instrument_var._parameters.NANO_E0 + _instrument_var._parameters.NANO_dE;
  _NANO_e_monitor_source_var._parameters.restore_xray = 1;


  /* component NANO_e_monitor_source=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_source_var._rotation_absolute, _NANO_e_monitor_source_var._rotation_absolute);
    rot_transpose(_NANO_source_var._rotation_absolute, tr1);
    rot_mul(_NANO_e_monitor_source_var._rotation_absolute, tr1, _NANO_e_monitor_source_var._rotation_relative);
    _NANO_e_monitor_source_var._rotation_is_identity =  rot_test_identity(_NANO_e_monitor_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_e_monitor_source_var._position_absolute = coords_add(_NANO_source_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_source_var._position_absolute, _NANO_e_monitor_source_var._position_absolute);
    _NANO_e_monitor_source_var._position_relative = rot_apply(_NANO_e_monitor_source_var._rotation_absolute, tc1);
  } /* NANO_e_monitor_source=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("NANO_e_monitor_source", _NANO_e_monitor_source_var._position_absolute, _NANO_e_monitor_source_var._rotation_absolute);
  instrument->_position_absolute[408] = _NANO_e_monitor_source_var._position_absolute;
  instrument->_position_relative[408] = _NANO_e_monitor_source_var._position_relative;
    _NANO_e_monitor_source_var._position_relative_is_zero =  coords_test_zero(_NANO_e_monitor_source_var._position_relative);
  instrument->counter_N[408]  = instrument->counter_P[408] = instrument->counter_P2[408] = 0;
  instrument->counter_AbsorbProp[408]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0407_NANO_e_monitor_source", _NANO_e_monitor_source_var._position_absolute, _NANO_e_monitor_source_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "nE", "20", "500","MCNUM");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "filename", 0, "e_monitor_source.dat", "char*");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "Emin", "NONE", "_instrument_var._parameters.NANO_E0 - _instrument_var._parameters.NANO_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "Emax", "NONE", "_instrument_var._parameters.NANO_E0 + _instrument_var._parameters.NANO_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0407_NANO_e_monitor_source", "restore_xray", "0", "1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_e_monitor_source_setpos */

/* component NANO_psd_source=PSD_monitor_coh() SETTING, POSITION/ROTATION */
int _NANO_psd_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_psd_source_setpos] component NANO_psd_source=PSD_monitor_coh() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_coh.comp:77]");
  stracpy(_NANO_psd_source_var._name, "NANO_psd_source", 16384);
  stracpy(_NANO_psd_source_var._type, "PSD_monitor_coh", 16384);
  _NANO_psd_source_var._index=409;
  int current_setpos_index = 409;
  _NANO_psd_source_var._parameters.nx = 90;
  _NANO_psd_source_var._parameters.ny = 90;
  if("psd_source.dat" && strlen("psd_source.dat"))
    stracpy(_NANO_psd_source_var._parameters.filename, "psd_source.dat" ? "psd_source.dat" : "", 16384);
  else 
  _NANO_psd_source_var._parameters.filename[0]='\0';
  _NANO_psd_source_var._parameters.restore_xray = 1;
  _NANO_psd_source_var._parameters.xwidth = 0.05;
  _NANO_psd_source_var._parameters.yheight = 0.05;
  _NANO_psd_source_var._parameters.ratio = 1;
  _NANO_psd_source_var._parameters.centering = 0;
  _NANO_psd_source_var._parameters.nowritefile = 0;


  /* component NANO_psd_source=PSD_monitor_coh() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_e_monitor_source_var._rotation_absolute, _NANO_psd_source_var._rotation_absolute);
    rot_transpose(_NANO_e_monitor_source_var._rotation_absolute, tr1);
    rot_mul(_NANO_psd_source_var._rotation_absolute, tr1, _NANO_psd_source_var._rotation_relative);
    _NANO_psd_source_var._rotation_is_identity =  rot_test_identity(_NANO_psd_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_e_monitor_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_psd_source_var._position_absolute = coords_add(_NANO_e_monitor_source_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_e_monitor_source_var._position_absolute, _NANO_psd_source_var._position_absolute);
    _NANO_psd_source_var._position_relative = rot_apply(_NANO_psd_source_var._rotation_absolute, tc1);
  } /* NANO_psd_source=PSD_monitor_coh() AT ROTATED */
  DEBUG_COMPONENT("NANO_psd_source", _NANO_psd_source_var._position_absolute, _NANO_psd_source_var._rotation_absolute);
  instrument->_position_absolute[409] = _NANO_psd_source_var._position_absolute;
  instrument->_position_relative[409] = _NANO_psd_source_var._position_relative;
    _NANO_psd_source_var._position_relative_is_zero =  coords_test_zero(_NANO_psd_source_var._position_relative);
  instrument->counter_N[409]  = instrument->counter_P[409] = instrument->counter_P2[409] = 0;
  instrument->counter_AbsorbProp[409]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0408_NANO_psd_source", _NANO_psd_source_var._position_absolute, _NANO_psd_source_var._rotation_absolute, "PSD_monitor_coh");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "filename", 0, "psd_source.dat", "char*");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "xwidth", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "yheight", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "ratio", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "centering", "1", "0","int");
        mccomp_param_nexus(nxhandle,"0408_NANO_psd_source", "nowritefile", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_psd_source_setpos */

/* component NANO_slit_1=Slit() SETTING, POSITION/ROTATION */
int _NANO_slit_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_slit_1_setpos] component NANO_slit_1=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_NANO_slit_1_var._name, "NANO_slit_1", 16384);
  stracpy(_NANO_slit_1_var._type, "Slit", 16384);
  _NANO_slit_1_var._index=410;
  int current_setpos_index = 410;
  _NANO_slit_1_var._parameters.xmin = 0;
  _NANO_slit_1_var._parameters.xmax = 0;
  _NANO_slit_1_var._parameters.ymin = 0;
  _NANO_slit_1_var._parameters.ymax = 0;
  _NANO_slit_1_var._parameters.radius = 0;
  _NANO_slit_1_var._parameters.xwidth = 0.0008;
  _NANO_slit_1_var._parameters.yheight = 0.0008;
  _NANO_slit_1_var._parameters.dist = 0;
  _NANO_slit_1_var._parameters.focus_xw = 0;
  _NANO_slit_1_var._parameters.focus_yh = 0;
  _NANO_slit_1_var._parameters.focus_x0 = 0;
  _NANO_slit_1_var._parameters.focus_y0 = 0;

  /* component NANO_slit_1=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_psd_source_var._rotation_absolute, _NANO_slit_1_var._rotation_absolute);
    rot_transpose(_NANO_psd_source_var._rotation_absolute, tr1);
    rot_mul(_NANO_slit_1_var._rotation_absolute, tr1, _NANO_slit_1_var._rotation_relative);
    _NANO_slit_1_var._rotation_is_identity =  rot_test_identity(_NANO_slit_1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 18.109);
    rot_transpose(_NANO_psd_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_slit_1_var._position_absolute = coords_add(_NANO_psd_source_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_psd_source_var._position_absolute, _NANO_slit_1_var._position_absolute);
    _NANO_slit_1_var._position_relative = rot_apply(_NANO_slit_1_var._rotation_absolute, tc1);
  } /* NANO_slit_1=Slit() AT ROTATED */
  DEBUG_COMPONENT("NANO_slit_1", _NANO_slit_1_var._position_absolute, _NANO_slit_1_var._rotation_absolute);
  instrument->_position_absolute[410] = _NANO_slit_1_var._position_absolute;
  instrument->_position_relative[410] = _NANO_slit_1_var._position_relative;
    _NANO_slit_1_var._position_relative_is_zero =  coords_test_zero(_NANO_slit_1_var._position_relative);
  instrument->counter_N[410]  = instrument->counter_P[410] = instrument->counter_P2[410] = 0;
  instrument->counter_AbsorbProp[410]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0409_NANO_slit_1", _NANO_slit_1_var._position_absolute, _NANO_slit_1_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "xwidth", "0.001", "0.0008","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "yheight", "0.001", "0.0008","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0409_NANO_slit_1", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_slit_1_setpos */

/* component NANO_m1_in=Arm() SETTING, POSITION/ROTATION */
int _NANO_m1_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_m1_in_setpos] component NANO_m1_in=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_m1_in_var._name, "NANO_m1_in", 16384);
  stracpy(_NANO_m1_in_var._type, "Arm", 16384);
  _NANO_m1_in_var._index=411;
  int current_setpos_index = 411;
  /* component NANO_m1_in=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_slit_1_var._rotation_absolute, _NANO_m1_in_var._rotation_absolute);
    rot_transpose(_NANO_slit_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_m1_in_var._rotation_absolute, tr1, _NANO_m1_in_var._rotation_relative);
    _NANO_m1_in_var._rotation_is_identity =  rot_test_identity(_NANO_m1_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 4.546);
    rot_transpose(_NANO_slit_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_m1_in_var._position_absolute = coords_add(_NANO_slit_1_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_1_var._position_absolute, _NANO_m1_in_var._position_absolute);
    _NANO_m1_in_var._position_relative = rot_apply(_NANO_m1_in_var._rotation_absolute, tc1);
  } /* NANO_m1_in=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_m1_in", _NANO_m1_in_var._position_absolute, _NANO_m1_in_var._rotation_absolute);
  instrument->_position_absolute[411] = _NANO_m1_in_var._position_absolute;
  instrument->_position_relative[411] = _NANO_m1_in_var._position_relative;
    _NANO_m1_in_var._position_relative_is_zero =  coords_test_zero(_NANO_m1_in_var._position_relative);
  instrument->counter_N[411]  = instrument->counter_P[411] = instrument->counter_P2[411] = 0;
  instrument->counter_AbsorbProp[411]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0410_NANO_m1_in", _NANO_m1_in_var._position_absolute, _NANO_m1_in_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_m1_in_setpos */

/* component NANO_m1_roll=Arm() SETTING, POSITION/ROTATION */
int _NANO_m1_roll_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_m1_roll_setpos] component NANO_m1_roll=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_m1_roll_var._name, "NANO_m1_roll", 16384);
  stracpy(_NANO_m1_roll_var._type, "Arm", 16384);
  _NANO_m1_roll_var._index=412;
  int current_setpos_index = 412;
  /* component NANO_m1_roll=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (-90)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_m1_in_var._rotation_absolute, _NANO_m1_roll_var._rotation_absolute);
    rot_transpose(_NANO_slit_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_m1_roll_var._rotation_absolute, tr1, _NANO_m1_roll_var._rotation_relative);
    _NANO_m1_roll_var._rotation_is_identity =  rot_test_identity(_NANO_m1_roll_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_m1_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_m1_roll_var._position_absolute = coords_add(_NANO_m1_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_1_var._position_absolute, _NANO_m1_roll_var._position_absolute);
    _NANO_m1_roll_var._position_relative = rot_apply(_NANO_m1_roll_var._rotation_absolute, tc1);
  } /* NANO_m1_roll=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_m1_roll", _NANO_m1_roll_var._position_absolute, _NANO_m1_roll_var._rotation_absolute);
  instrument->_position_absolute[412] = _NANO_m1_roll_var._position_absolute;
  instrument->_position_relative[412] = _NANO_m1_roll_var._position_relative;
    _NANO_m1_roll_var._position_relative_is_zero =  coords_test_zero(_NANO_m1_roll_var._position_relative);
  instrument->counter_N[412]  = instrument->counter_P[412] = instrument->counter_P2[412] = 0;
  instrument->counter_AbsorbProp[412]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0411_NANO_m1_roll", _NANO_m1_roll_var._position_absolute, _NANO_m1_roll_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_m1_roll_setpos */

/* component NANO_mirror_m1=Mirror_curved() SETTING, POSITION/ROTATION */
int _NANO_mirror_m1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_mirror_m1_setpos] component NANO_mirror_m1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_NANO_mirror_m1_var._name, "NANO_mirror_m1", 16384);
  stracpy(_NANO_mirror_m1_var._type, "Mirror_curved", 16384);
  _NANO_mirror_m1_var._index=413;
  int current_setpos_index = 413;
  _NANO_mirror_m1_var._parameters.radius = -82e-3;
  _NANO_mirror_m1_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_NANO_mirror_m1_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _NANO_mirror_m1_var._parameters.coating[0]='\0';
  _NANO_mirror_m1_var._parameters.zdepth = 0.029;
  _NANO_mirror_m1_var._parameters.yheight = 0.351;
  _NANO_mirror_m1_var._parameters.length = 0;
  _NANO_mirror_m1_var._parameters.width = 0;


  /* component NANO_mirror_m1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (- _instrument_var._parameters.NANO_angle_m1_m2 * RAD2DEG)*DEG2RAD);
    rot_mul(tr1, _NANO_m1_roll_var._rotation_absolute, _NANO_mirror_m1_var._rotation_absolute);
    rot_transpose(_NANO_slit_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_mirror_m1_var._rotation_absolute, tr1, _NANO_mirror_m1_var._rotation_relative);
    _NANO_mirror_m1_var._rotation_is_identity =  rot_test_identity(_NANO_mirror_m1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_m1_roll_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_mirror_m1_var._position_absolute = coords_add(_NANO_m1_roll_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_1_var._position_absolute, _NANO_mirror_m1_var._position_absolute);
    _NANO_mirror_m1_var._position_relative = rot_apply(_NANO_mirror_m1_var._rotation_absolute, tc1);
  } /* NANO_mirror_m1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("NANO_mirror_m1", _NANO_mirror_m1_var._position_absolute, _NANO_mirror_m1_var._rotation_absolute);
  instrument->_position_absolute[413] = _NANO_mirror_m1_var._position_absolute;
  instrument->_position_relative[413] = _NANO_mirror_m1_var._position_relative;
    _NANO_mirror_m1_var._position_relative_is_zero =  coords_test_zero(_NANO_mirror_m1_var._position_relative);
  instrument->counter_N[413]  = instrument->counter_P[413] = instrument->counter_P2[413] = 0;
  instrument->counter_AbsorbProp[413]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0412_NANO_mirror_m1", _NANO_mirror_m1_var._position_absolute, _NANO_mirror_m1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "radius", "1", "-82e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "zdepth", "0.2", "0.029","MCNUM");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "yheight", "0.2", "0.351","MCNUM");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "length", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0412_NANO_mirror_m1", "width", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_mirror_m1_setpos */

/* component NANO_beam_deviation=Arm() SETTING, POSITION/ROTATION */
int _NANO_beam_deviation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_beam_deviation_setpos] component NANO_beam_deviation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_beam_deviation_var._name, "NANO_beam_deviation", 16384);
  stracpy(_NANO_beam_deviation_var._type, "Arm", 16384);
  _NANO_beam_deviation_var._index=414;
  int current_setpos_index = 414;
  /* component NANO_beam_deviation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-2.0 * _instrument_var._parameters.NANO_angle_m1_m2 * RAD2DEG)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_m1_in_var._rotation_absolute, _NANO_beam_deviation_var._rotation_absolute);
    rot_transpose(_NANO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_NANO_beam_deviation_var._rotation_absolute, tr1, _NANO_beam_deviation_var._rotation_relative);
    _NANO_beam_deviation_var._rotation_is_identity =  rot_test_identity(_NANO_beam_deviation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_m1_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_beam_deviation_var._position_absolute = coords_add(_NANO_m1_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_mirror_m1_var._position_absolute, _NANO_beam_deviation_var._position_absolute);
    _NANO_beam_deviation_var._position_relative = rot_apply(_NANO_beam_deviation_var._rotation_absolute, tc1);
  } /* NANO_beam_deviation=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_beam_deviation", _NANO_beam_deviation_var._position_absolute, _NANO_beam_deviation_var._rotation_absolute);
  instrument->_position_absolute[414] = _NANO_beam_deviation_var._position_absolute;
  instrument->_position_relative[414] = _NANO_beam_deviation_var._position_relative;
    _NANO_beam_deviation_var._position_relative_is_zero =  coords_test_zero(_NANO_beam_deviation_var._position_relative);
  instrument->counter_N[414]  = instrument->counter_P[414] = instrument->counter_P2[414] = 0;
  instrument->counter_AbsorbProp[414]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0413_NANO_beam_deviation", _NANO_beam_deviation_var._position_absolute, _NANO_beam_deviation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_beam_deviation_setpos */

/* component NANO_m2_in=Arm() SETTING, POSITION/ROTATION */
int _NANO_m2_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_m2_in_setpos] component NANO_m2_in=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_m2_in_var._name, "NANO_m2_in", 16384);
  stracpy(_NANO_m2_in_var._type, "Arm", 16384);
  _NANO_m2_in_var._index=415;
  int current_setpos_index = 415;
  /* component NANO_m2_in=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_beam_deviation_var._rotation_absolute, _NANO_m2_in_var._rotation_absolute);
    rot_transpose(_NANO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_NANO_m2_in_var._rotation_absolute, tr1, _NANO_m2_in_var._rotation_relative);
    _NANO_m2_in_var._rotation_is_identity =  rot_test_identity(_NANO_m2_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.816);
    rot_transpose(_NANO_beam_deviation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_m2_in_var._position_absolute = coords_add(_NANO_beam_deviation_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_mirror_m1_var._position_absolute, _NANO_m2_in_var._position_absolute);
    _NANO_m2_in_var._position_relative = rot_apply(_NANO_m2_in_var._rotation_absolute, tc1);
  } /* NANO_m2_in=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_m2_in", _NANO_m2_in_var._position_absolute, _NANO_m2_in_var._rotation_absolute);
  instrument->_position_absolute[415] = _NANO_m2_in_var._position_absolute;
  instrument->_position_relative[415] = _NANO_m2_in_var._position_relative;
    _NANO_m2_in_var._position_relative_is_zero =  coords_test_zero(_NANO_m2_in_var._position_relative);
  instrument->counter_N[415]  = instrument->counter_P[415] = instrument->counter_P2[415] = 0;
  instrument->counter_AbsorbProp[415]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0414_NANO_m2_in", _NANO_m2_in_var._position_absolute, _NANO_m2_in_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_m2_in_setpos */

/* component NANO_mirror_m2=Mirror_curved() SETTING, POSITION/ROTATION */
int _NANO_mirror_m2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_mirror_m2_setpos] component NANO_mirror_m2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_NANO_mirror_m2_var._name, "NANO_mirror_m2", 16384);
  stracpy(_NANO_mirror_m2_var._type, "Mirror_curved", 16384);
  _NANO_mirror_m2_var._index=416;
  int current_setpos_index = 416;
  _NANO_mirror_m2_var._parameters.radius = -13739;
  _NANO_mirror_m2_var._parameters.R0 = 1;
  if(NANO_material_coating_m2 && strlen(NANO_material_coating_m2))
    stracpy(_NANO_mirror_m2_var._parameters.coating, NANO_material_coating_m2 ? NANO_material_coating_m2 : "", 16384);
  else 
  _NANO_mirror_m2_var._parameters.coating[0]='\0';
  _NANO_mirror_m2_var._parameters.zdepth = 0.351;
  _NANO_mirror_m2_var._parameters.yheight = 0.029;
  _NANO_mirror_m2_var._parameters.length = 0;
  _NANO_mirror_m2_var._parameters.width = 0;


  /* component NANO_mirror_m2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.NANO_angle_m1_m2 * RAD2DEG)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_m2_in_var._rotation_absolute, _NANO_mirror_m2_var._rotation_absolute);
    rot_transpose(_NANO_mirror_m1_var._rotation_absolute, tr1);
    rot_mul(_NANO_mirror_m2_var._rotation_absolute, tr1, _NANO_mirror_m2_var._rotation_relative);
    _NANO_mirror_m2_var._rotation_is_identity =  rot_test_identity(_NANO_mirror_m2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_m2_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_mirror_m2_var._position_absolute = coords_add(_NANO_m2_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_mirror_m1_var._position_absolute, _NANO_mirror_m2_var._position_absolute);
    _NANO_mirror_m2_var._position_relative = rot_apply(_NANO_mirror_m2_var._rotation_absolute, tc1);
  } /* NANO_mirror_m2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("NANO_mirror_m2", _NANO_mirror_m2_var._position_absolute, _NANO_mirror_m2_var._rotation_absolute);
  instrument->_position_absolute[416] = _NANO_mirror_m2_var._position_absolute;
  instrument->_position_relative[416] = _NANO_mirror_m2_var._position_relative;
    _NANO_mirror_m2_var._position_relative_is_zero =  coords_test_zero(_NANO_mirror_m2_var._position_relative);
  instrument->counter_N[416]  = instrument->counter_P[416] = instrument->counter_P2[416] = 0;
  instrument->counter_AbsorbProp[416]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0415_NANO_mirror_m2", _NANO_mirror_m2_var._position_absolute, _NANO_mirror_m2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "radius", "1", "-13739","MCNUM");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "coating", "Be.txt", NANO_material_coating_m2, "char*");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "zdepth", "0.2", "0.351","MCNUM");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "yheight", "0.2", "0.029","MCNUM");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "length", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0415_NANO_mirror_m2", "width", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_mirror_m2_setpos */

/* component NANO_mirror_m2_out=Arm() SETTING, POSITION/ROTATION */
int _NANO_mirror_m2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_mirror_m2_out_setpos] component NANO_mirror_m2_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_mirror_m2_out_var._name, "NANO_mirror_m2_out", 16384);
  stracpy(_NANO_mirror_m2_out_var._type, "Arm", 16384);
  _NANO_mirror_m2_out_var._index=417;
  int current_setpos_index = 417;
  /* component NANO_mirror_m2_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.NANO_angle_m1_m2 * RAD2DEG)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_mirror_m2_var._rotation_absolute, _NANO_mirror_m2_out_var._rotation_absolute);
    rot_transpose(_NANO_mirror_m2_var._rotation_absolute, tr1);
    rot_mul(_NANO_mirror_m2_out_var._rotation_absolute, tr1, _NANO_mirror_m2_out_var._rotation_relative);
    _NANO_mirror_m2_out_var._rotation_is_identity =  rot_test_identity(_NANO_mirror_m2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_mirror_m2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_mirror_m2_out_var._position_absolute = coords_add(_NANO_mirror_m2_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_mirror_m2_var._position_absolute, _NANO_mirror_m2_out_var._position_absolute);
    _NANO_mirror_m2_out_var._position_relative = rot_apply(_NANO_mirror_m2_out_var._rotation_absolute, tc1);
  } /* NANO_mirror_m2_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_mirror_m2_out", _NANO_mirror_m2_out_var._position_absolute, _NANO_mirror_m2_out_var._rotation_absolute);
  instrument->_position_absolute[417] = _NANO_mirror_m2_out_var._position_absolute;
  instrument->_position_relative[417] = _NANO_mirror_m2_out_var._position_relative;
    _NANO_mirror_m2_out_var._position_relative_is_zero =  coords_test_zero(_NANO_mirror_m2_out_var._position_relative);
  instrument->counter_N[417]  = instrument->counter_P[417] = instrument->counter_P2[417] = 0;
  instrument->counter_AbsorbProp[417]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0416_NANO_mirror_m2_out", _NANO_mirror_m2_out_var._position_absolute, _NANO_mirror_m2_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_mirror_m2_out_setpos */

/* component NANO_slit_2=Slit() SETTING, POSITION/ROTATION */
int _NANO_slit_2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_slit_2_setpos] component NANO_slit_2=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_NANO_slit_2_var._name, "NANO_slit_2", 16384);
  stracpy(_NANO_slit_2_var._type, "Slit", 16384);
  _NANO_slit_2_var._index=418;
  int current_setpos_index = 418;
  _NANO_slit_2_var._parameters.xmin = 0;
  _NANO_slit_2_var._parameters.xmax = 0;
  _NANO_slit_2_var._parameters.ymin = 0;
  _NANO_slit_2_var._parameters.ymax = 0;
  _NANO_slit_2_var._parameters.radius = 0;
  _NANO_slit_2_var._parameters.xwidth = 2e-3;
  _NANO_slit_2_var._parameters.yheight = 5e-4;
  _NANO_slit_2_var._parameters.dist = 0;
  _NANO_slit_2_var._parameters.focus_xw = 0;
  _NANO_slit_2_var._parameters.focus_yh = 0;
  _NANO_slit_2_var._parameters.focus_x0 = 0;
  _NANO_slit_2_var._parameters.focus_y0 = 0;

  /* component NANO_slit_2=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_mirror_m2_out_var._rotation_absolute, _NANO_slit_2_var._rotation_absolute);
    rot_transpose(_NANO_mirror_m2_var._rotation_absolute, tr1);
    rot_mul(_NANO_slit_2_var._rotation_absolute, tr1, _NANO_slit_2_var._rotation_relative);
    _NANO_slit_2_var._rotation_is_identity =  rot_test_identity(_NANO_slit_2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 51.287);
    rot_transpose(_NANO_mirror_m2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_slit_2_var._position_absolute = coords_add(_NANO_mirror_m2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_mirror_m2_var._position_absolute, _NANO_slit_2_var._position_absolute);
    _NANO_slit_2_var._position_relative = rot_apply(_NANO_slit_2_var._rotation_absolute, tc1);
  } /* NANO_slit_2=Slit() AT ROTATED */
  DEBUG_COMPONENT("NANO_slit_2", _NANO_slit_2_var._position_absolute, _NANO_slit_2_var._rotation_absolute);
  instrument->_position_absolute[418] = _NANO_slit_2_var._position_absolute;
  instrument->_position_relative[418] = _NANO_slit_2_var._position_relative;
    _NANO_slit_2_var._position_relative_is_zero =  coords_test_zero(_NANO_slit_2_var._position_relative);
  instrument->counter_N[418]  = instrument->counter_P[418] = instrument->counter_P2[418] = 0;
  instrument->counter_AbsorbProp[418]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0417_NANO_slit_2", _NANO_slit_2_var._position_absolute, _NANO_slit_2_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "xwidth", "0.001", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "yheight", "0.001", "5e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0417_NANO_slit_2", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_slit_2_setpos */

/* component NANO_dcm_in=Arm() SETTING, POSITION/ROTATION */
int _NANO_dcm_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_dcm_in_setpos] component NANO_dcm_in=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_dcm_in_var._name, "NANO_dcm_in", 16384);
  stracpy(_NANO_dcm_in_var._type, "Arm", 16384);
  _NANO_dcm_in_var._index=419;
  int current_setpos_index = 419;
  /* component NANO_dcm_in=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_slit_2_var._rotation_absolute, _NANO_dcm_in_var._rotation_absolute);
    rot_transpose(_NANO_slit_2_var._rotation_absolute, tr1);
    rot_mul(_NANO_dcm_in_var._rotation_absolute, tr1, _NANO_dcm_in_var._rotation_relative);
    _NANO_dcm_in_var._rotation_is_identity =  rot_test_identity(_NANO_dcm_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.466);
    rot_transpose(_NANO_slit_2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_dcm_in_var._position_absolute = coords_add(_NANO_slit_2_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_2_var._position_absolute, _NANO_dcm_in_var._position_absolute);
    _NANO_dcm_in_var._position_relative = rot_apply(_NANO_dcm_in_var._rotation_absolute, tc1);
  } /* NANO_dcm_in=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_dcm_in", _NANO_dcm_in_var._position_absolute, _NANO_dcm_in_var._rotation_absolute);
  instrument->_position_absolute[419] = _NANO_dcm_in_var._position_absolute;
  instrument->_position_relative[419] = _NANO_dcm_in_var._position_relative;
    _NANO_dcm_in_var._position_relative_is_zero =  coords_test_zero(_NANO_dcm_in_var._position_relative);
  instrument->counter_N[419]  = instrument->counter_P[419] = instrument->counter_P2[419] = 0;
  instrument->counter_AbsorbProp[419]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0418_NANO_dcm_in", _NANO_dcm_in_var._position_absolute, _NANO_dcm_in_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_dcm_in_setpos */

/* component NANO_PSD_dcm_in=PSD_monitor() SETTING, POSITION/ROTATION */
int _NANO_PSD_dcm_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_PSD_dcm_in_setpos] component NANO_PSD_dcm_in=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_NANO_PSD_dcm_in_var._name, "NANO_PSD_dcm_in", 16384);
  stracpy(_NANO_PSD_dcm_in_var._type, "PSD_monitor", 16384);
  _NANO_PSD_dcm_in_var._index=420;
  int current_setpos_index = 420;
  if("psd_dcm_in.dat" && strlen("psd_dcm_in.dat"))
    stracpy(_NANO_PSD_dcm_in_var._parameters.filename, "psd_dcm_in.dat" ? "psd_dcm_in.dat" : "", 16384);
  else 
  _NANO_PSD_dcm_in_var._parameters.filename[0]='\0';
  _NANO_PSD_dcm_in_var._parameters.xwidth = 3e-3;
  _NANO_PSD_dcm_in_var._parameters.yheight = 10e-4;
  _NANO_PSD_dcm_in_var._parameters.radius = 0;
  _NANO_PSD_dcm_in_var._parameters.restore_xray = 1;
  _NANO_PSD_dcm_in_var._parameters.nowritefile = 0;
  _NANO_PSD_dcm_in_var._parameters.nx = 90;
  _NANO_PSD_dcm_in_var._parameters.ny = 90;
  _NANO_PSD_dcm_in_var._parameters.nr = 0;


  /* component NANO_PSD_dcm_in=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_dcm_in_var._rotation_absolute, _NANO_PSD_dcm_in_var._rotation_absolute);
    rot_transpose(_NANO_slit_2_var._rotation_absolute, tr1);
    rot_mul(_NANO_PSD_dcm_in_var._rotation_absolute, tr1, _NANO_PSD_dcm_in_var._rotation_relative);
    _NANO_PSD_dcm_in_var._rotation_is_identity =  rot_test_identity(_NANO_PSD_dcm_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_dcm_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_PSD_dcm_in_var._position_absolute = coords_add(_NANO_dcm_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_2_var._position_absolute, _NANO_PSD_dcm_in_var._position_absolute);
    _NANO_PSD_dcm_in_var._position_relative = rot_apply(_NANO_PSD_dcm_in_var._rotation_absolute, tc1);
  } /* NANO_PSD_dcm_in=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("NANO_PSD_dcm_in", _NANO_PSD_dcm_in_var._position_absolute, _NANO_PSD_dcm_in_var._rotation_absolute);
  instrument->_position_absolute[420] = _NANO_PSD_dcm_in_var._position_absolute;
  instrument->_position_relative[420] = _NANO_PSD_dcm_in_var._position_relative;
    _NANO_PSD_dcm_in_var._position_relative_is_zero =  coords_test_zero(_NANO_PSD_dcm_in_var._position_relative);
  instrument->counter_N[420]  = instrument->counter_P[420] = instrument->counter_P2[420] = 0;
  instrument->counter_AbsorbProp[420]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0419_NANO_PSD_dcm_in", _NANO_PSD_dcm_in_var._position_absolute, _NANO_PSD_dcm_in_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "filename", 0, "psd_dcm_in.dat", "char*");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "xwidth", "0.05", "3e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "yheight", "0.05", "10e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0419_NANO_PSD_dcm_in", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_PSD_dcm_in_setpos */

/* component NANO_bragg_roll=Arm() SETTING, POSITION/ROTATION */
int _NANO_bragg_roll_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_bragg_roll_setpos] component NANO_bragg_roll=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_bragg_roll_var._name, "NANO_bragg_roll", 16384);
  stracpy(_NANO_bragg_roll_var._type, "Arm", 16384);
  _NANO_bragg_roll_var._index=421;
  int current_setpos_index = 421;
  /* component NANO_bragg_roll=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _NANO_PSD_dcm_in_var._rotation_absolute, _NANO_bragg_roll_var._rotation_absolute);
    rot_transpose(_NANO_PSD_dcm_in_var._rotation_absolute, tr1);
    rot_mul(_NANO_bragg_roll_var._rotation_absolute, tr1, _NANO_bragg_roll_var._rotation_relative);
    _NANO_bragg_roll_var._rotation_is_identity =  rot_test_identity(_NANO_bragg_roll_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_PSD_dcm_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_bragg_roll_var._position_absolute = coords_add(_NANO_PSD_dcm_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_PSD_dcm_in_var._position_absolute, _NANO_bragg_roll_var._position_absolute);
    _NANO_bragg_roll_var._position_relative = rot_apply(_NANO_bragg_roll_var._rotation_absolute, tc1);
  } /* NANO_bragg_roll=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_bragg_roll", _NANO_bragg_roll_var._position_absolute, _NANO_bragg_roll_var._rotation_absolute);
  instrument->_position_absolute[421] = _NANO_bragg_roll_var._position_absolute;
  instrument->_position_relative[421] = _NANO_bragg_roll_var._position_relative;
    _NANO_bragg_roll_var._position_relative_is_zero =  coords_test_zero(_NANO_bragg_roll_var._position_relative);
  instrument->counter_N[421]  = instrument->counter_P[421] = instrument->counter_P2[421] = 0;
  instrument->counter_AbsorbProp[421]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0420_NANO_bragg_roll", _NANO_bragg_roll_var._position_absolute, _NANO_bragg_roll_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_bragg_roll_setpos */

/* component NANO_bragg_crystal_1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _NANO_bragg_crystal_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_bragg_crystal_1_setpos] component NANO_bragg_crystal_1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_NANO_bragg_crystal_1_var._name, "NANO_bragg_crystal_1", 16384);
  stracpy(_NANO_bragg_crystal_1_var._type, "Bragg_crystal", 16384);
  _NANO_bragg_crystal_1_var._index=422;
  int current_setpos_index = 422;
  _NANO_bragg_crystal_1_var._parameters.length = 0.05;
  _NANO_bragg_crystal_1_var._parameters.width = 0.02;
  _NANO_bragg_crystal_1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_NANO_bragg_crystal_1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _NANO_bragg_crystal_1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_NANO_bragg_crystal_1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _NANO_bragg_crystal_1_var._parameters.material[0]='\0';
  _NANO_bragg_crystal_1_var._parameters.alpha = 0.0;
  _NANO_bragg_crystal_1_var._parameters.R0 = 0;
  _NANO_bragg_crystal_1_var._parameters.debye_waller_B = 0.4632;
  _NANO_bragg_crystal_1_var._parameters.crystal_type = 2;
  _NANO_bragg_crystal_1_var._parameters.h = 1;
  _NANO_bragg_crystal_1_var._parameters.k = 1;
  _NANO_bragg_crystal_1_var._parameters.l = 1;
  _NANO_bragg_crystal_1_var._parameters.structure_factor_scale_r = 0.0;
  _NANO_bragg_crystal_1_var._parameters.structure_factor_scale_i = 0.0;


  /* component NANO_bragg_crystal_1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- NANO_angle_dcm)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_bragg_roll_var._rotation_absolute, _NANO_bragg_crystal_1_var._rotation_absolute);
    rot_transpose(_NANO_PSD_dcm_in_var._rotation_absolute, tr1);
    rot_mul(_NANO_bragg_crystal_1_var._rotation_absolute, tr1, _NANO_bragg_crystal_1_var._rotation_relative);
    _NANO_bragg_crystal_1_var._rotation_is_identity =  rot_test_identity(_NANO_bragg_crystal_1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_bragg_roll_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_bragg_crystal_1_var._position_absolute = coords_add(_NANO_bragg_roll_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_PSD_dcm_in_var._position_absolute, _NANO_bragg_crystal_1_var._position_absolute);
    _NANO_bragg_crystal_1_var._position_relative = rot_apply(_NANO_bragg_crystal_1_var._rotation_absolute, tc1);
  } /* NANO_bragg_crystal_1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("NANO_bragg_crystal_1", _NANO_bragg_crystal_1_var._position_absolute, _NANO_bragg_crystal_1_var._rotation_absolute);
  instrument->_position_absolute[422] = _NANO_bragg_crystal_1_var._position_absolute;
  instrument->_position_relative[422] = _NANO_bragg_crystal_1_var._position_relative;
    _NANO_bragg_crystal_1_var._position_relative_is_zero =  coords_test_zero(_NANO_bragg_crystal_1_var._position_relative);
  instrument->counter_N[422]  = instrument->counter_P[422] = instrument->counter_P2[422] = 0;
  instrument->counter_AbsorbProp[422]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0421_NANO_bragg_crystal_1", _NANO_bragg_crystal_1_var._position_absolute, _NANO_bragg_crystal_1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "length", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0421_NANO_bragg_crystal_1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_bragg_crystal_1_setpos */

/* component NANO_dcm2_rot=Arm() SETTING, POSITION/ROTATION */
int _NANO_dcm2_rot_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_dcm2_rot_setpos] component NANO_dcm2_rot=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_dcm2_rot_var._name, "NANO_dcm2_rot", 16384);
  stracpy(_NANO_dcm2_rot_var._type, "Arm", 16384);
  _NANO_dcm2_rot_var._index=423;
  int current_setpos_index = 423;
  /* component NANO_dcm2_rot=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- NANO_angle_dcm)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_bragg_crystal_1_var._rotation_absolute, _NANO_dcm2_rot_var._rotation_absolute);
    rot_transpose(_NANO_bragg_crystal_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_dcm2_rot_var._rotation_absolute, tr1, _NANO_dcm2_rot_var._rotation_relative);
    _NANO_dcm2_rot_var._rotation_is_identity =  rot_test_identity(_NANO_dcm2_rot_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_bragg_crystal_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_dcm2_rot_var._position_absolute = coords_add(_NANO_bragg_crystal_1_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_bragg_crystal_1_var._position_absolute, _NANO_dcm2_rot_var._position_absolute);
    _NANO_dcm2_rot_var._position_relative = rot_apply(_NANO_dcm2_rot_var._rotation_absolute, tc1);
  } /* NANO_dcm2_rot=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_dcm2_rot", _NANO_dcm2_rot_var._position_absolute, _NANO_dcm2_rot_var._rotation_absolute);
  instrument->_position_absolute[423] = _NANO_dcm2_rot_var._position_absolute;
  instrument->_position_relative[423] = _NANO_dcm2_rot_var._position_relative;
    _NANO_dcm2_rot_var._position_relative_is_zero =  coords_test_zero(_NANO_dcm2_rot_var._position_relative);
  instrument->counter_N[423]  = instrument->counter_P[423] = instrument->counter_P2[423] = 0;
  instrument->counter_AbsorbProp[423]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0422_NANO_dcm2_rot", _NANO_dcm2_rot_var._position_absolute, _NANO_dcm2_rot_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_dcm2_rot_setpos */

/* component NANO_dcm_transl=Arm() SETTING, POSITION/ROTATION */
int _NANO_dcm_transl_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_dcm_transl_setpos] component NANO_dcm_transl=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_dcm_transl_var._name, "NANO_dcm_transl", 16384);
  stracpy(_NANO_dcm_transl_var._type, "Arm", 16384);
  _NANO_dcm_transl_var._index=424;
  int current_setpos_index = 424;
  /* component NANO_dcm_transl=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_dcm_in_var._rotation_absolute, _NANO_dcm_transl_var._rotation_absolute);
    rot_transpose(_NANO_bragg_crystal_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_dcm_transl_var._rotation_absolute, tr1, _NANO_dcm_transl_var._rotation_relative);
    _NANO_dcm_transl_var._rotation_is_identity =  rot_test_identity(_NANO_dcm_transl_var._rotation_relative);
    tc1 = coords_set(
      -0.02, 0, NANO_delta_dcm);
    rot_transpose(_NANO_dcm_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_dcm_transl_var._position_absolute = coords_add(_NANO_dcm_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_bragg_crystal_1_var._position_absolute, _NANO_dcm_transl_var._position_absolute);
    _NANO_dcm_transl_var._position_relative = rot_apply(_NANO_dcm_transl_var._rotation_absolute, tc1);
  } /* NANO_dcm_transl=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_dcm_transl", _NANO_dcm_transl_var._position_absolute, _NANO_dcm_transl_var._rotation_absolute);
  instrument->_position_absolute[424] = _NANO_dcm_transl_var._position_absolute;
  instrument->_position_relative[424] = _NANO_dcm_transl_var._position_relative;
    _NANO_dcm_transl_var._position_relative_is_zero =  coords_test_zero(_NANO_dcm_transl_var._position_relative);
  instrument->counter_N[424]  = instrument->counter_P[424] = instrument->counter_P2[424] = 0;
  instrument->counter_AbsorbProp[424]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0423_NANO_dcm_transl", _NANO_dcm_transl_var._position_absolute, _NANO_dcm_transl_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_dcm_transl_setpos */

/* component NANO_bragg_crystal_2=Bragg_crystal() SETTING, POSITION/ROTATION */
int _NANO_bragg_crystal_2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_bragg_crystal_2_setpos] component NANO_bragg_crystal_2=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_NANO_bragg_crystal_2_var._name, "NANO_bragg_crystal_2", 16384);
  stracpy(_NANO_bragg_crystal_2_var._type, "Bragg_crystal", 16384);
  _NANO_bragg_crystal_2_var._index=425;
  int current_setpos_index = 425;
  _NANO_bragg_crystal_2_var._parameters.length = 0.115;
  _NANO_bragg_crystal_2_var._parameters.width = 0.02;
  _NANO_bragg_crystal_2_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_NANO_bragg_crystal_2_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _NANO_bragg_crystal_2_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_NANO_bragg_crystal_2_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _NANO_bragg_crystal_2_var._parameters.material[0]='\0';
  _NANO_bragg_crystal_2_var._parameters.alpha = 0.0;
  _NANO_bragg_crystal_2_var._parameters.R0 = 0;
  _NANO_bragg_crystal_2_var._parameters.debye_waller_B = 0.4632;
  _NANO_bragg_crystal_2_var._parameters.crystal_type = 2;
  _NANO_bragg_crystal_2_var._parameters.h = 1;
  _NANO_bragg_crystal_2_var._parameters.k = 1;
  _NANO_bragg_crystal_2_var._parameters.l = 1;
  _NANO_bragg_crystal_2_var._parameters.structure_factor_scale_r = 0.0;
  _NANO_bragg_crystal_2_var._parameters.structure_factor_scale_i = 0.0;


  /* component NANO_bragg_crystal_2=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (NANO_angle_dcm)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_dcm2_rot_var._rotation_absolute, _NANO_bragg_crystal_2_var._rotation_absolute);
    rot_transpose(_NANO_bragg_crystal_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_bragg_crystal_2_var._rotation_absolute, tr1, _NANO_bragg_crystal_2_var._rotation_relative);
    _NANO_bragg_crystal_2_var._rotation_is_identity =  rot_test_identity(_NANO_bragg_crystal_2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_dcm_transl_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_bragg_crystal_2_var._position_absolute = coords_add(_NANO_dcm_transl_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_bragg_crystal_1_var._position_absolute, _NANO_bragg_crystal_2_var._position_absolute);
    _NANO_bragg_crystal_2_var._position_relative = rot_apply(_NANO_bragg_crystal_2_var._rotation_absolute, tc1);
  } /* NANO_bragg_crystal_2=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("NANO_bragg_crystal_2", _NANO_bragg_crystal_2_var._position_absolute, _NANO_bragg_crystal_2_var._rotation_absolute);
  instrument->_position_absolute[425] = _NANO_bragg_crystal_2_var._position_absolute;
  instrument->_position_relative[425] = _NANO_bragg_crystal_2_var._position_relative;
    _NANO_bragg_crystal_2_var._position_relative_is_zero =  coords_test_zero(_NANO_bragg_crystal_2_var._position_relative);
  instrument->counter_N[425]  = instrument->counter_P[425] = instrument->counter_P2[425] = 0;
  instrument->counter_AbsorbProp[425]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0424_NANO_bragg_crystal_2", _NANO_bragg_crystal_2_var._position_absolute, _NANO_bragg_crystal_2_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "length", "0.05", "0.115","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "width", "0.02", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0424_NANO_bragg_crystal_2", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_bragg_crystal_2_setpos */

/* component NANO_bragg2_out=Arm() SETTING, POSITION/ROTATION */
int _NANO_bragg2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_bragg2_out_setpos] component NANO_bragg2_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_bragg2_out_var._name, "NANO_bragg2_out", 16384);
  stracpy(_NANO_bragg2_out_var._type, "Arm", 16384);
  _NANO_bragg2_out_var._index=426;
  int current_setpos_index = 426;
  /* component NANO_bragg2_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (NANO_angle_dcm)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_bragg_crystal_2_var._rotation_absolute, _NANO_bragg2_out_var._rotation_absolute);
    rot_transpose(_NANO_bragg_crystal_2_var._rotation_absolute, tr1);
    rot_mul(_NANO_bragg2_out_var._rotation_absolute, tr1, _NANO_bragg2_out_var._rotation_relative);
    _NANO_bragg2_out_var._rotation_is_identity =  rot_test_identity(_NANO_bragg2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_bragg_crystal_2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_bragg2_out_var._position_absolute = coords_add(_NANO_bragg_crystal_2_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_bragg_crystal_2_var._position_absolute, _NANO_bragg2_out_var._position_absolute);
    _NANO_bragg2_out_var._position_relative = rot_apply(_NANO_bragg2_out_var._rotation_absolute, tc1);
  } /* NANO_bragg2_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_bragg2_out", _NANO_bragg2_out_var._position_absolute, _NANO_bragg2_out_var._rotation_absolute);
  instrument->_position_absolute[426] = _NANO_bragg2_out_var._position_absolute;
  instrument->_position_relative[426] = _NANO_bragg2_out_var._position_relative;
    _NANO_bragg2_out_var._position_relative_is_zero =  coords_test_zero(_NANO_bragg2_out_var._position_relative);
  instrument->counter_N[426]  = instrument->counter_P[426] = instrument->counter_P2[426] = 0;
  instrument->counter_AbsorbProp[426]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0425_NANO_bragg2_out", _NANO_bragg2_out_var._position_absolute, _NANO_bragg2_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_bragg2_out_setpos */

/* component NANO_dcm_out=Arm() SETTING, POSITION/ROTATION */
int _NANO_dcm_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_dcm_out_setpos] component NANO_dcm_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_dcm_out_var._name, "NANO_dcm_out", 16384);
  stracpy(_NANO_dcm_out_var._type, "Arm", 16384);
  _NANO_dcm_out_var._index=427;
  int current_setpos_index = 427;
  /* component NANO_dcm_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_dcm_in_var._rotation_absolute, _NANO_dcm_out_var._rotation_absolute);
    rot_transpose(_NANO_bragg_crystal_2_var._rotation_absolute, tr1);
    rot_mul(_NANO_dcm_out_var._rotation_absolute, tr1, _NANO_dcm_out_var._rotation_relative);
    _NANO_dcm_out_var._rotation_is_identity =  rot_test_identity(_NANO_dcm_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_bragg2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_dcm_out_var._position_absolute = coords_add(_NANO_bragg2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_bragg_crystal_2_var._position_absolute, _NANO_dcm_out_var._position_absolute);
    _NANO_dcm_out_var._position_relative = rot_apply(_NANO_dcm_out_var._rotation_absolute, tc1);
  } /* NANO_dcm_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_dcm_out", _NANO_dcm_out_var._position_absolute, _NANO_dcm_out_var._rotation_absolute);
  instrument->_position_absolute[427] = _NANO_dcm_out_var._position_absolute;
  instrument->_position_relative[427] = _NANO_dcm_out_var._position_relative;
    _NANO_dcm_out_var._position_relative_is_zero =  coords_test_zero(_NANO_dcm_out_var._position_relative);
  instrument->counter_N[427]  = instrument->counter_P[427] = instrument->counter_P2[427] = 0;
  instrument->counter_AbsorbProp[427]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0426_NANO_dcm_out", _NANO_dcm_out_var._position_absolute, _NANO_dcm_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_dcm_out_setpos */

/* component NANO_e_dcm_out=E_monitor() SETTING, POSITION/ROTATION */
int _NANO_e_dcm_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_e_dcm_out_setpos] component NANO_e_dcm_out=E_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");
  stracpy(_NANO_e_dcm_out_var._name, "NANO_e_dcm_out", 16384);
  stracpy(_NANO_e_dcm_out_var._type, "E_monitor", 16384);
  _NANO_e_dcm_out_var._index=428;
  int current_setpos_index = 428;
  _NANO_e_dcm_out_var._parameters.nE = 500;
  if("e_dcm_out.dat" && strlen("e_dcm_out.dat"))
    stracpy(_NANO_e_dcm_out_var._parameters.filename, "e_dcm_out.dat" ? "e_dcm_out.dat" : "", 16384);
  else 
  _NANO_e_dcm_out_var._parameters.filename[0]='\0';
  _NANO_e_dcm_out_var._parameters.xwidth = 0.1;
  _NANO_e_dcm_out_var._parameters.yheight = 0.1;
  _NANO_e_dcm_out_var._parameters.Emin = _instrument_var._parameters.NANO_E0 - _instrument_var._parameters.NANO_dE;
  _NANO_e_dcm_out_var._parameters.Emax = _instrument_var._parameters.NANO_E0 + _instrument_var._parameters.NANO_dE;
  _NANO_e_dcm_out_var._parameters.restore_xray = 1;


  /* component NANO_e_dcm_out=E_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_dcm_out_var._rotation_absolute, _NANO_e_dcm_out_var._rotation_absolute);
    rot_transpose(_NANO_bragg_crystal_2_var._rotation_absolute, tr1);
    rot_mul(_NANO_e_dcm_out_var._rotation_absolute, tr1, _NANO_e_dcm_out_var._rotation_relative);
    _NANO_e_dcm_out_var._rotation_is_identity =  rot_test_identity(_NANO_e_dcm_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1);
    rot_transpose(_NANO_dcm_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_e_dcm_out_var._position_absolute = coords_add(_NANO_dcm_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_bragg_crystal_2_var._position_absolute, _NANO_e_dcm_out_var._position_absolute);
    _NANO_e_dcm_out_var._position_relative = rot_apply(_NANO_e_dcm_out_var._rotation_absolute, tc1);
  } /* NANO_e_dcm_out=E_monitor() AT ROTATED */
  DEBUG_COMPONENT("NANO_e_dcm_out", _NANO_e_dcm_out_var._position_absolute, _NANO_e_dcm_out_var._rotation_absolute);
  instrument->_position_absolute[428] = _NANO_e_dcm_out_var._position_absolute;
  instrument->_position_relative[428] = _NANO_e_dcm_out_var._position_relative;
    _NANO_e_dcm_out_var._position_relative_is_zero =  coords_test_zero(_NANO_e_dcm_out_var._position_relative);
  instrument->counter_N[428]  = instrument->counter_P[428] = instrument->counter_P2[428] = 0;
  instrument->counter_AbsorbProp[428]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0427_NANO_e_dcm_out", _NANO_e_dcm_out_var._position_absolute, _NANO_e_dcm_out_var._rotation_absolute, "E_monitor");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "nE", "20", "500","MCNUM");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "filename", 0, "e_dcm_out.dat", "char*");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "xwidth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "yheight", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "Emin", "NONE", "_instrument_var._parameters.NANO_E0 - _instrument_var._parameters.NANO_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "Emax", "NONE", "_instrument_var._parameters.NANO_E0 + _instrument_var._parameters.NANO_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0427_NANO_e_dcm_out", "restore_xray", "0", "1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_e_dcm_out_setpos */

/* component NANO_secondary_source_slits=Arm() SETTING, POSITION/ROTATION */
int _NANO_secondary_source_slits_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_secondary_source_slits_setpos] component NANO_secondary_source_slits=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_secondary_source_slits_var._name, "NANO_secondary_source_slits", 16384);
  stracpy(_NANO_secondary_source_slits_var._type, "Arm", 16384);
  _NANO_secondary_source_slits_var._index=429;
  int current_setpos_index = 429;
  /* component NANO_secondary_source_slits=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_dcm_out_var._rotation_absolute, _NANO_secondary_source_slits_var._rotation_absolute);
    rot_transpose(_NANO_e_dcm_out_var._rotation_absolute, tr1);
    rot_mul(_NANO_secondary_source_slits_var._rotation_absolute, tr1, _NANO_secondary_source_slits_var._rotation_relative);
    _NANO_secondary_source_slits_var._rotation_is_identity =  rot_test_identity(_NANO_secondary_source_slits_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 4.84);
    rot_transpose(_NANO_dcm_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_secondary_source_slits_var._position_absolute = coords_add(_NANO_dcm_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_e_dcm_out_var._position_absolute, _NANO_secondary_source_slits_var._position_absolute);
    _NANO_secondary_source_slits_var._position_relative = rot_apply(_NANO_secondary_source_slits_var._rotation_absolute, tc1);
  } /* NANO_secondary_source_slits=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_secondary_source_slits", _NANO_secondary_source_slits_var._position_absolute, _NANO_secondary_source_slits_var._rotation_absolute);
  instrument->_position_absolute[429] = _NANO_secondary_source_slits_var._position_absolute;
  instrument->_position_relative[429] = _NANO_secondary_source_slits_var._position_relative;
    _NANO_secondary_source_slits_var._position_relative_is_zero =  coords_test_zero(_NANO_secondary_source_slits_var._position_relative);
  instrument->counter_N[429]  = instrument->counter_P[429] = instrument->counter_P2[429] = 0;
  instrument->counter_AbsorbProp[429]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0428_NANO_secondary_source_slits", _NANO_secondary_source_slits_var._position_absolute, _NANO_secondary_source_slits_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_secondary_source_slits_setpos */

/* component NANO_psd_ss_in=PSD_monitor() SETTING, POSITION/ROTATION */
int _NANO_psd_ss_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_psd_ss_in_setpos] component NANO_psd_ss_in=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_NANO_psd_ss_in_var._name, "NANO_psd_ss_in", 16384);
  stracpy(_NANO_psd_ss_in_var._type, "PSD_monitor", 16384);
  _NANO_psd_ss_in_var._index=430;
  int current_setpos_index = 430;
  if("psd_ss_in.dat" && strlen("psd_ss_in.dat"))
    stracpy(_NANO_psd_ss_in_var._parameters.filename, "psd_ss_in.dat" ? "psd_ss_in.dat" : "", 16384);
  else 
  _NANO_psd_ss_in_var._parameters.filename[0]='\0';
  _NANO_psd_ss_in_var._parameters.xwidth = 0.002;
  _NANO_psd_ss_in_var._parameters.yheight = 0.002;
  _NANO_psd_ss_in_var._parameters.radius = 0;
  _NANO_psd_ss_in_var._parameters.restore_xray = 1;
  _NANO_psd_ss_in_var._parameters.nowritefile = 0;
  _NANO_psd_ss_in_var._parameters.nx = 90;
  _NANO_psd_ss_in_var._parameters.ny = 90;
  _NANO_psd_ss_in_var._parameters.nr = 0;


  /* component NANO_psd_ss_in=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_secondary_source_slits_var._rotation_absolute, _NANO_psd_ss_in_var._rotation_absolute);
    rot_transpose(_NANO_e_dcm_out_var._rotation_absolute, tr1);
    rot_mul(_NANO_psd_ss_in_var._rotation_absolute, tr1, _NANO_psd_ss_in_var._rotation_relative);
    _NANO_psd_ss_in_var._rotation_is_identity =  rot_test_identity(_NANO_psd_ss_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_secondary_source_slits_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_psd_ss_in_var._position_absolute = coords_add(_NANO_secondary_source_slits_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_e_dcm_out_var._position_absolute, _NANO_psd_ss_in_var._position_absolute);
    _NANO_psd_ss_in_var._position_relative = rot_apply(_NANO_psd_ss_in_var._rotation_absolute, tc1);
  } /* NANO_psd_ss_in=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("NANO_psd_ss_in", _NANO_psd_ss_in_var._position_absolute, _NANO_psd_ss_in_var._rotation_absolute);
  instrument->_position_absolute[430] = _NANO_psd_ss_in_var._position_absolute;
  instrument->_position_relative[430] = _NANO_psd_ss_in_var._position_relative;
    _NANO_psd_ss_in_var._position_relative_is_zero =  coords_test_zero(_NANO_psd_ss_in_var._position_relative);
  instrument->counter_N[430]  = instrument->counter_P[430] = instrument->counter_P2[430] = 0;
  instrument->counter_AbsorbProp[430]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0429_NANO_psd_ss_in", _NANO_psd_ss_in_var._position_absolute, _NANO_psd_ss_in_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "filename", 0, "psd_ss_in.dat", "char*");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "xwidth", "0.05", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "yheight", "0.05", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0429_NANO_psd_ss_in", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_psd_ss_in_setpos */

/* component NANO_slit_3=Slit() SETTING, POSITION/ROTATION */
int _NANO_slit_3_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_slit_3_setpos] component NANO_slit_3=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_NANO_slit_3_var._name, "NANO_slit_3", 16384);
  stracpy(_NANO_slit_3_var._type, "Slit", 16384);
  _NANO_slit_3_var._index=431;
  int current_setpos_index = 431;
  _NANO_slit_3_var._parameters.xmin = 0;
  _NANO_slit_3_var._parameters.xmax = 0;
  _NANO_slit_3_var._parameters.ymin = 0;
  _NANO_slit_3_var._parameters.ymax = 0;
  _NANO_slit_3_var._parameters.radius = 0;
  _NANO_slit_3_var._parameters.xwidth = 50e-6;
  _NANO_slit_3_var._parameters.yheight = 50e-6;
  _NANO_slit_3_var._parameters.dist = 0;
  _NANO_slit_3_var._parameters.focus_xw = 0;
  _NANO_slit_3_var._parameters.focus_yh = 0;
  _NANO_slit_3_var._parameters.focus_x0 = 0;
  _NANO_slit_3_var._parameters.focus_y0 = 0;

  /* component NANO_slit_3=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_psd_ss_in_var._rotation_absolute, _NANO_slit_3_var._rotation_absolute);
    rot_transpose(_NANO_psd_ss_in_var._rotation_absolute, tr1);
    rot_mul(_NANO_slit_3_var._rotation_absolute, tr1, _NANO_slit_3_var._rotation_relative);
    _NANO_slit_3_var._rotation_is_identity =  rot_test_identity(_NANO_slit_3_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_psd_ss_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_slit_3_var._position_absolute = coords_add(_NANO_psd_ss_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_psd_ss_in_var._position_absolute, _NANO_slit_3_var._position_absolute);
    _NANO_slit_3_var._position_relative = rot_apply(_NANO_slit_3_var._rotation_absolute, tc1);
  } /* NANO_slit_3=Slit() AT ROTATED */
  DEBUG_COMPONENT("NANO_slit_3", _NANO_slit_3_var._position_absolute, _NANO_slit_3_var._rotation_absolute);
  instrument->_position_absolute[431] = _NANO_slit_3_var._position_absolute;
  instrument->_position_relative[431] = _NANO_slit_3_var._position_relative;
    _NANO_slit_3_var._position_relative_is_zero =  coords_test_zero(_NANO_slit_3_var._position_relative);
  instrument->counter_N[431]  = instrument->counter_P[431] = instrument->counter_P2[431] = 0;
  instrument->counter_AbsorbProp[431]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0430_NANO_slit_3", _NANO_slit_3_var._position_absolute, _NANO_slit_3_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "xwidth", "0.001", "50e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "yheight", "0.001", "50e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0430_NANO_slit_3", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_slit_3_setpos */

/* component NANO_psd_ss_out=PSD_monitor() SETTING, POSITION/ROTATION */
int _NANO_psd_ss_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_psd_ss_out_setpos] component NANO_psd_ss_out=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_NANO_psd_ss_out_var._name, "NANO_psd_ss_out", 16384);
  stracpy(_NANO_psd_ss_out_var._type, "PSD_monitor", 16384);
  _NANO_psd_ss_out_var._index=432;
  int current_setpos_index = 432;
  if("psd_ss_out.dat" && strlen("psd_ss_out.dat"))
    stracpy(_NANO_psd_ss_out_var._parameters.filename, "psd_ss_out.dat" ? "psd_ss_out.dat" : "", 16384);
  else 
  _NANO_psd_ss_out_var._parameters.filename[0]='\0';
  _NANO_psd_ss_out_var._parameters.xwidth = 1e-3;
  _NANO_psd_ss_out_var._parameters.yheight = 1e-3;
  _NANO_psd_ss_out_var._parameters.radius = 0;
  _NANO_psd_ss_out_var._parameters.restore_xray = 1;
  _NANO_psd_ss_out_var._parameters.nowritefile = 0;
  _NANO_psd_ss_out_var._parameters.nx = 90;
  _NANO_psd_ss_out_var._parameters.ny = 90;
  _NANO_psd_ss_out_var._parameters.nr = 0;


  /* component NANO_psd_ss_out=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_slit_3_var._rotation_absolute, _NANO_psd_ss_out_var._rotation_absolute);
    rot_transpose(_NANO_slit_3_var._rotation_absolute, tr1);
    rot_mul(_NANO_psd_ss_out_var._rotation_absolute, tr1, _NANO_psd_ss_out_var._rotation_relative);
    _NANO_psd_ss_out_var._rotation_is_identity =  rot_test_identity(_NANO_psd_ss_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 5);
    rot_transpose(_NANO_slit_3_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_psd_ss_out_var._position_absolute = coords_add(_NANO_slit_3_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_3_var._position_absolute, _NANO_psd_ss_out_var._position_absolute);
    _NANO_psd_ss_out_var._position_relative = rot_apply(_NANO_psd_ss_out_var._rotation_absolute, tc1);
  } /* NANO_psd_ss_out=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("NANO_psd_ss_out", _NANO_psd_ss_out_var._position_absolute, _NANO_psd_ss_out_var._rotation_absolute);
  instrument->_position_absolute[432] = _NANO_psd_ss_out_var._position_absolute;
  instrument->_position_relative[432] = _NANO_psd_ss_out_var._position_relative;
    _NANO_psd_ss_out_var._position_relative_is_zero =  coords_test_zero(_NANO_psd_ss_out_var._position_relative);
  instrument->counter_N[432]  = instrument->counter_P[432] = instrument->counter_P2[432] = 0;
  instrument->counter_AbsorbProp[432]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0431_NANO_psd_ss_out", _NANO_psd_ss_out_var._position_absolute, _NANO_psd_ss_out_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "filename", 0, "psd_ss_out.dat", "char*");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "xwidth", "0.05", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "yheight", "0.05", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0431_NANO_psd_ss_out", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_psd_ss_out_setpos */

/* component NANO_jjxray2_slits=Arm() SETTING, POSITION/ROTATION */
int _NANO_jjxray2_slits_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_jjxray2_slits_setpos] component NANO_jjxray2_slits=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_jjxray2_slits_var._name, "NANO_jjxray2_slits", 16384);
  stracpy(_NANO_jjxray2_slits_var._type, "Arm", 16384);
  _NANO_jjxray2_slits_var._index=433;
  int current_setpos_index = 433;
  /* component NANO_jjxray2_slits=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_secondary_source_slits_var._rotation_absolute, _NANO_jjxray2_slits_var._rotation_absolute);
    rot_transpose(_NANO_psd_ss_out_var._rotation_absolute, tr1);
    rot_mul(_NANO_jjxray2_slits_var._rotation_absolute, tr1, _NANO_jjxray2_slits_var._rotation_relative);
    _NANO_jjxray2_slits_var._rotation_is_identity =  rot_test_identity(_NANO_jjxray2_slits_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 72.289);
    rot_transpose(_NANO_secondary_source_slits_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_jjxray2_slits_var._position_absolute = coords_add(_NANO_secondary_source_slits_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_psd_ss_out_var._position_absolute, _NANO_jjxray2_slits_var._position_absolute);
    _NANO_jjxray2_slits_var._position_relative = rot_apply(_NANO_jjxray2_slits_var._rotation_absolute, tc1);
  } /* NANO_jjxray2_slits=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_jjxray2_slits", _NANO_jjxray2_slits_var._position_absolute, _NANO_jjxray2_slits_var._rotation_absolute);
  instrument->_position_absolute[433] = _NANO_jjxray2_slits_var._position_absolute;
  instrument->_position_relative[433] = _NANO_jjxray2_slits_var._position_relative;
    _NANO_jjxray2_slits_var._position_relative_is_zero =  coords_test_zero(_NANO_jjxray2_slits_var._position_relative);
  instrument->counter_N[433]  = instrument->counter_P[433] = instrument->counter_P2[433] = 0;
  instrument->counter_AbsorbProp[433]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0432_NANO_jjxray2_slits", _NANO_jjxray2_slits_var._position_absolute, _NANO_jjxray2_slits_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_jjxray2_slits_setpos */

/* component NANO_slit_5=Slit() SETTING, POSITION/ROTATION */
int _NANO_slit_5_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_slit_5_setpos] component NANO_slit_5=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_NANO_slit_5_var._name, "NANO_slit_5", 16384);
  stracpy(_NANO_slit_5_var._type, "Slit", 16384);
  _NANO_slit_5_var._index=434;
  int current_setpos_index = 434;
  _NANO_slit_5_var._parameters.xmin = 0;
  _NANO_slit_5_var._parameters.xmax = 0;
  _NANO_slit_5_var._parameters.ymin = 0;
  _NANO_slit_5_var._parameters.ymax = 0;
  _NANO_slit_5_var._parameters.radius = 0;
  _NANO_slit_5_var._parameters.xwidth = 50e-6;
  _NANO_slit_5_var._parameters.yheight = 50e-6;
  _NANO_slit_5_var._parameters.dist = 0;
  _NANO_slit_5_var._parameters.focus_xw = 0;
  _NANO_slit_5_var._parameters.focus_yh = 0;
  _NANO_slit_5_var._parameters.focus_x0 = 0;
  _NANO_slit_5_var._parameters.focus_y0 = 0;

  /* component NANO_slit_5=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_jjxray2_slits_var._rotation_absolute, _NANO_slit_5_var._rotation_absolute);
    rot_transpose(_NANO_psd_ss_out_var._rotation_absolute, tr1);
    rot_mul(_NANO_slit_5_var._rotation_absolute, tr1, _NANO_slit_5_var._rotation_relative);
    _NANO_slit_5_var._rotation_is_identity =  rot_test_identity(_NANO_slit_5_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_jjxray2_slits_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_slit_5_var._position_absolute = coords_add(_NANO_jjxray2_slits_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_psd_ss_out_var._position_absolute, _NANO_slit_5_var._position_absolute);
    _NANO_slit_5_var._position_relative = rot_apply(_NANO_slit_5_var._rotation_absolute, tc1);
  } /* NANO_slit_5=Slit() AT ROTATED */
  DEBUG_COMPONENT("NANO_slit_5", _NANO_slit_5_var._position_absolute, _NANO_slit_5_var._rotation_absolute);
  instrument->_position_absolute[434] = _NANO_slit_5_var._position_absolute;
  instrument->_position_relative[434] = _NANO_slit_5_var._position_relative;
    _NANO_slit_5_var._position_relative_is_zero =  coords_test_zero(_NANO_slit_5_var._position_relative);
  instrument->counter_N[434]  = instrument->counter_P[434] = instrument->counter_P2[434] = 0;
  instrument->counter_AbsorbProp[434]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0433_NANO_slit_5", _NANO_slit_5_var._position_absolute, _NANO_slit_5_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "xwidth", "0.001", "50e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "yheight", "0.001", "50e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0433_NANO_slit_5", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_slit_5_setpos */

/* component NANO_kb_in=Arm() SETTING, POSITION/ROTATION */
int _NANO_kb_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_kb_in_setpos] component NANO_kb_in=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_kb_in_var._name, "NANO_kb_in", 16384);
  stracpy(_NANO_kb_in_var._type, "Arm", 16384);
  _NANO_kb_in_var._index=435;
  int current_setpos_index = 435;
  /* component NANO_kb_in=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _NANO_slit_5_var._rotation_absolute, _NANO_kb_in_var._rotation_absolute);
    rot_transpose(_NANO_slit_5_var._rotation_absolute, tr1);
    rot_mul(_NANO_kb_in_var._rotation_absolute, tr1, _NANO_kb_in_var._rotation_relative);
    _NANO_kb_in_var._rotation_is_identity =  rot_test_identity(_NANO_kb_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.503);
    rot_transpose(_NANO_slit_5_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_kb_in_var._position_absolute = coords_add(_NANO_slit_5_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_5_var._position_absolute, _NANO_kb_in_var._position_absolute);
    _NANO_kb_in_var._position_relative = rot_apply(_NANO_kb_in_var._rotation_absolute, tc1);
  } /* NANO_kb_in=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_kb_in", _NANO_kb_in_var._position_absolute, _NANO_kb_in_var._rotation_absolute);
  instrument->_position_absolute[435] = _NANO_kb_in_var._position_absolute;
  instrument->_position_relative[435] = _NANO_kb_in_var._position_relative;
    _NANO_kb_in_var._position_relative_is_zero =  coords_test_zero(_NANO_kb_in_var._position_relative);
  instrument->counter_N[435]  = instrument->counter_P[435] = instrument->counter_P2[435] = 0;
  instrument->counter_AbsorbProp[435]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0434_NANO_kb_in", _NANO_kb_in_var._position_absolute, _NANO_kb_in_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_kb_in_setpos */

/* component NANO_kb_1=Mirror_curved() SETTING, POSITION/ROTATION */
int _NANO_kb_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_kb_1_setpos] component NANO_kb_1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_NANO_kb_1_var._name, "NANO_kb_1", 16384);
  stracpy(_NANO_kb_1_var._type, "Mirror_curved", 16384);
  _NANO_kb_1_var._index=436;
  int current_setpos_index = 436;
  _NANO_kb_1_var._parameters.radius = 189.259;
  _NANO_kb_1_var._parameters.R0 = 1;
  if("Be.txt" && strlen("Be.txt"))
    stracpy(_NANO_kb_1_var._parameters.coating, "Be.txt" ? "Be.txt" : "", 16384);
  else 
  _NANO_kb_1_var._parameters.coating[0]='\0';
  _NANO_kb_1_var._parameters.zdepth = 0.2;
  _NANO_kb_1_var._parameters.yheight = 0.2;
  _NANO_kb_1_var._parameters.length = 0.1;
  _NANO_kb_1_var._parameters.width = 0.04;


  /* component NANO_kb_1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (RAD2DEG * _instrument_var._parameters.NANO_angle_kb1)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_kb_in_var._rotation_absolute, _NANO_kb_1_var._rotation_absolute);
    rot_transpose(_NANO_slit_5_var._rotation_absolute, tr1);
    rot_mul(_NANO_kb_1_var._rotation_absolute, tr1, _NANO_kb_1_var._rotation_relative);
    _NANO_kb_1_var._rotation_is_identity =  rot_test_identity(_NANO_kb_1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_kb_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_kb_1_var._position_absolute = coords_add(_NANO_kb_in_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_5_var._position_absolute, _NANO_kb_1_var._position_absolute);
    _NANO_kb_1_var._position_relative = rot_apply(_NANO_kb_1_var._rotation_absolute, tc1);
  } /* NANO_kb_1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("NANO_kb_1", _NANO_kb_1_var._position_absolute, _NANO_kb_1_var._rotation_absolute);
  instrument->_position_absolute[436] = _NANO_kb_1_var._position_absolute;
  instrument->_position_relative[436] = _NANO_kb_1_var._position_relative;
    _NANO_kb_1_var._position_relative_is_zero =  coords_test_zero(_NANO_kb_1_var._position_relative);
  instrument->counter_N[436]  = instrument->counter_P[436] = instrument->counter_P2[436] = 0;
  instrument->counter_AbsorbProp[436]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0435_NANO_kb_1", _NANO_kb_1_var._position_absolute, _NANO_kb_1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "radius", "1", "189.259","MCNUM");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "coating", "Be.txt", "Be.txt", "char*");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "length", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0435_NANO_kb_1", "width", "0", "0.04","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_kb_1_setpos */

/* component NANO_kb_beam_deviation=Arm() SETTING, POSITION/ROTATION */
int _NANO_kb_beam_deviation_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_kb_beam_deviation_setpos] component NANO_kb_beam_deviation=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_kb_beam_deviation_var._name, "NANO_kb_beam_deviation", 16384);
  stracpy(_NANO_kb_beam_deviation_var._type, "Arm", 16384);
  _NANO_kb_beam_deviation_var._index=437;
  int current_setpos_index = 437;
  /* component NANO_kb_beam_deviation=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (RAD2DEG * _instrument_var._parameters.NANO_angle_kb1)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_kb_1_var._rotation_absolute, _NANO_kb_beam_deviation_var._rotation_absolute);
    rot_transpose(_NANO_kb_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_kb_beam_deviation_var._rotation_absolute, tr1, _NANO_kb_beam_deviation_var._rotation_relative);
    _NANO_kb_beam_deviation_var._rotation_is_identity =  rot_test_identity(_NANO_kb_beam_deviation_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_kb_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_kb_beam_deviation_var._position_absolute = coords_add(_NANO_kb_1_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_kb_1_var._position_absolute, _NANO_kb_beam_deviation_var._position_absolute);
    _NANO_kb_beam_deviation_var._position_relative = rot_apply(_NANO_kb_beam_deviation_var._rotation_absolute, tc1);
  } /* NANO_kb_beam_deviation=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_kb_beam_deviation", _NANO_kb_beam_deviation_var._position_absolute, _NANO_kb_beam_deviation_var._rotation_absolute);
  instrument->_position_absolute[437] = _NANO_kb_beam_deviation_var._position_absolute;
  instrument->_position_relative[437] = _NANO_kb_beam_deviation_var._position_relative;
    _NANO_kb_beam_deviation_var._position_relative_is_zero =  coords_test_zero(_NANO_kb_beam_deviation_var._position_relative);
  instrument->counter_N[437]  = instrument->counter_P[437] = instrument->counter_P2[437] = 0;
  instrument->counter_AbsorbProp[437]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0436_NANO_kb_beam_deviation", _NANO_kb_beam_deviation_var._position_absolute, _NANO_kb_beam_deviation_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_kb_beam_deviation_setpos */

/* component NANO_kb1_out=Arm() SETTING, POSITION/ROTATION */
int _NANO_kb1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_kb1_out_setpos] component NANO_kb1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_kb1_out_var._name, "NANO_kb1_out", 16384);
  stracpy(_NANO_kb1_out_var._type, "Arm", 16384);
  _NANO_kb1_out_var._index=438;
  int current_setpos_index = 438;
  /* component NANO_kb1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _NANO_kb_beam_deviation_var._rotation_absolute, _NANO_kb1_out_var._rotation_absolute);
    rot_transpose(_NANO_kb_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_kb1_out_var._rotation_absolute, tr1, _NANO_kb1_out_var._rotation_relative);
    _NANO_kb1_out_var._rotation_is_identity =  rot_test_identity(_NANO_kb1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_kb_beam_deviation_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_kb1_out_var._position_absolute = coords_add(_NANO_kb_beam_deviation_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_kb_1_var._position_absolute, _NANO_kb1_out_var._position_absolute);
    _NANO_kb1_out_var._position_relative = rot_apply(_NANO_kb1_out_var._rotation_absolute, tc1);
  } /* NANO_kb1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_kb1_out", _NANO_kb1_out_var._position_absolute, _NANO_kb1_out_var._rotation_absolute);
  instrument->_position_absolute[438] = _NANO_kb1_out_var._position_absolute;
  instrument->_position_relative[438] = _NANO_kb1_out_var._position_relative;
    _NANO_kb1_out_var._position_relative_is_zero =  coords_test_zero(_NANO_kb1_out_var._position_relative);
  instrument->counter_N[438]  = instrument->counter_P[438] = instrument->counter_P2[438] = 0;
  instrument->counter_AbsorbProp[438]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0437_NANO_kb1_out", _NANO_kb1_out_var._position_absolute, _NANO_kb1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_kb1_out_setpos */

/* component NANO_kb2=Mirror_curved() SETTING, POSITION/ROTATION */
int _NANO_kb2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_kb2_setpos] component NANO_kb2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_NANO_kb2_var._name, "NANO_kb2", 16384);
  stracpy(_NANO_kb2_var._type, "Mirror_curved", 16384);
  _NANO_kb2_var._index=439;
  int current_setpos_index = 439;
  _NANO_kb2_var._parameters.radius = -143.645;
  _NANO_kb2_var._parameters.R0 = 1;
  if("Be.txt" && strlen("Be.txt"))
    stracpy(_NANO_kb2_var._parameters.coating, "Be.txt" ? "Be.txt" : "", 16384);
  else 
  _NANO_kb2_var._parameters.coating[0]='\0';
  _NANO_kb2_var._parameters.zdepth = 0.2;
  _NANO_kb2_var._parameters.yheight = 0.2;
  _NANO_kb2_var._parameters.length = 0.1;
  _NANO_kb2_var._parameters.width = 0.04;


  /* component NANO_kb2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- RAD2DEG * _instrument_var._parameters.NANO_angle_kb2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_kb1_out_var._rotation_absolute, _NANO_kb2_var._rotation_absolute);
    rot_transpose(_NANO_kb_1_var._rotation_absolute, tr1);
    rot_mul(_NANO_kb2_var._rotation_absolute, tr1, _NANO_kb2_var._rotation_relative);
    _NANO_kb2_var._rotation_is_identity =  rot_test_identity(_NANO_kb2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.105);
    rot_transpose(_NANO_kb1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_kb2_var._position_absolute = coords_add(_NANO_kb1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_kb_1_var._position_absolute, _NANO_kb2_var._position_absolute);
    _NANO_kb2_var._position_relative = rot_apply(_NANO_kb2_var._rotation_absolute, tc1);
  } /* NANO_kb2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("NANO_kb2", _NANO_kb2_var._position_absolute, _NANO_kb2_var._rotation_absolute);
  instrument->_position_absolute[439] = _NANO_kb2_var._position_absolute;
  instrument->_position_relative[439] = _NANO_kb2_var._position_relative;
    _NANO_kb2_var._position_relative_is_zero =  coords_test_zero(_NANO_kb2_var._position_relative);
  instrument->counter_N[439]  = instrument->counter_P[439] = instrument->counter_P2[439] = 0;
  instrument->counter_AbsorbProp[439]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0438_NANO_kb2", _NANO_kb2_var._position_absolute, _NANO_kb2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "radius", "1", "-143.645","MCNUM");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "coating", "Be.txt", "Be.txt", "char*");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "length", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0438_NANO_kb2", "width", "0", "0.04","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_kb2_setpos */

/* component NANO_kb_out=Arm() SETTING, POSITION/ROTATION */
int _NANO_kb_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_kb_out_setpos] component NANO_kb_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_NANO_kb_out_var._name, "NANO_kb_out", 16384);
  stracpy(_NANO_kb_out_var._type, "Arm", 16384);
  _NANO_kb_out_var._index=440;
  int current_setpos_index = 440;
  /* component NANO_kb_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- RAD2DEG * _instrument_var._parameters.NANO_angle_kb2)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _NANO_kb2_var._rotation_absolute, _NANO_kb_out_var._rotation_absolute);
    rot_transpose(_NANO_kb2_var._rotation_absolute, tr1);
    rot_mul(_NANO_kb_out_var._rotation_absolute, tr1, _NANO_kb_out_var._rotation_relative);
    _NANO_kb_out_var._rotation_is_identity =  rot_test_identity(_NANO_kb_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_kb2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_kb_out_var._position_absolute = coords_add(_NANO_kb2_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_kb2_var._position_absolute, _NANO_kb_out_var._position_absolute);
    _NANO_kb_out_var._position_relative = rot_apply(_NANO_kb_out_var._rotation_absolute, tc1);
  } /* NANO_kb_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("NANO_kb_out", _NANO_kb_out_var._position_absolute, _NANO_kb_out_var._rotation_absolute);
  instrument->_position_absolute[440] = _NANO_kb_out_var._position_absolute;
  instrument->_position_relative[440] = _NANO_kb_out_var._position_relative;
    _NANO_kb_out_var._position_relative_is_zero =  coords_test_zero(_NANO_kb_out_var._position_relative);
  instrument->counter_N[440]  = instrument->counter_P[440] = instrument->counter_P2[440] = 0;
  instrument->counter_AbsorbProp[440]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0439_NANO_kb_out", _NANO_kb_out_var._position_absolute, _NANO_kb_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_kb_out_setpos */

/* component NANO_slit=Slit() SETTING, POSITION/ROTATION */
int _NANO_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_slit_setpos] component NANO_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_NANO_slit_var._name, "NANO_slit", 16384);
  stracpy(_NANO_slit_var._type, "Slit", 16384);
  _NANO_slit_var._index=441;
  int current_setpos_index = 441;
  _NANO_slit_var._parameters.xmin = 0;
  _NANO_slit_var._parameters.xmax = 0;
  _NANO_slit_var._parameters.ymin = 0;
  _NANO_slit_var._parameters.ymax = 0;
  _NANO_slit_var._parameters.radius = 0;
  _NANO_slit_var._parameters.xwidth = 20e-6;
  _NANO_slit_var._parameters.yheight = 20e-6;
  _NANO_slit_var._parameters.dist = 0;
  _NANO_slit_var._parameters.focus_xw = 0;
  _NANO_slit_var._parameters.focus_yh = 0;
  _NANO_slit_var._parameters.focus_x0 = 0;
  _NANO_slit_var._parameters.focus_y0 = 0;

  /* component NANO_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_kb_out_var._rotation_absolute, _NANO_slit_var._rotation_absolute);
    rot_transpose(_NANO_kb2_var._rotation_absolute, tr1);
    rot_mul(_NANO_slit_var._rotation_absolute, tr1, _NANO_slit_var._rotation_relative);
    _NANO_slit_var._rotation_is_identity =  rot_test_identity(_NANO_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.18 * 0.5);
    rot_transpose(_NANO_kb_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_slit_var._position_absolute = coords_add(_NANO_kb_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_kb2_var._position_absolute, _NANO_slit_var._position_absolute);
    _NANO_slit_var._position_relative = rot_apply(_NANO_slit_var._rotation_absolute, tc1);
  } /* NANO_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("NANO_slit", _NANO_slit_var._position_absolute, _NANO_slit_var._rotation_absolute);
  instrument->_position_absolute[441] = _NANO_slit_var._position_absolute;
  instrument->_position_relative[441] = _NANO_slit_var._position_relative;
    _NANO_slit_var._position_relative_is_zero =  coords_test_zero(_NANO_slit_var._position_relative);
  instrument->counter_N[441]  = instrument->counter_P[441] = instrument->counter_P2[441] = 0;
  instrument->counter_AbsorbProp[441]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0440_NANO_slit", _NANO_slit_var._position_absolute, _NANO_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "xwidth", "0.001", "20e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "yheight", "0.001", "20e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0440_NANO_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_slit_setpos */

/* component NANO_psd_sample_stage=PSD_monitor() SETTING, POSITION/ROTATION */
int _NANO_psd_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_NANO_psd_sample_stage_setpos] component NANO_psd_sample_stage=PSD_monitor() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");
  stracpy(_NANO_psd_sample_stage_var._name, "NANO_psd_sample_stage", 16384);
  stracpy(_NANO_psd_sample_stage_var._type, "PSD_monitor", 16384);
  _NANO_psd_sample_stage_var._index=442;
  int current_setpos_index = 442;
  _NANO_psd_sample_stage_var._parameters.filename[0]='\0';
  _NANO_psd_sample_stage_var._parameters.xwidth = 0.000005;
  _NANO_psd_sample_stage_var._parameters.yheight = 0.000005;
  _NANO_psd_sample_stage_var._parameters.radius = 0;
  _NANO_psd_sample_stage_var._parameters.restore_xray = 1;
  _NANO_psd_sample_stage_var._parameters.nowritefile = 0;
  _NANO_psd_sample_stage_var._parameters.nx = 90;
  _NANO_psd_sample_stage_var._parameters.ny = 90;
  _NANO_psd_sample_stage_var._parameters.nr = 0;


  /* component NANO_psd_sample_stage=PSD_monitor() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_kb_out_var._rotation_absolute, _NANO_psd_sample_stage_var._rotation_absolute);
    rot_transpose(_NANO_slit_var._rotation_absolute, tr1);
    rot_mul(_NANO_psd_sample_stage_var._rotation_absolute, tr1, _NANO_psd_sample_stage_var._rotation_relative);
    _NANO_psd_sample_stage_var._rotation_is_identity =  rot_test_identity(_NANO_psd_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.18);
    rot_transpose(_NANO_kb_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _NANO_psd_sample_stage_var._position_absolute = coords_add(_NANO_kb_out_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_slit_var._position_absolute, _NANO_psd_sample_stage_var._position_absolute);
    _NANO_psd_sample_stage_var._position_relative = rot_apply(_NANO_psd_sample_stage_var._rotation_absolute, tc1);
  } /* NANO_psd_sample_stage=PSD_monitor() AT ROTATED */
  DEBUG_COMPONENT("NANO_psd_sample_stage", _NANO_psd_sample_stage_var._position_absolute, _NANO_psd_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[442] = _NANO_psd_sample_stage_var._position_absolute;
  instrument->_position_relative[442] = _NANO_psd_sample_stage_var._position_relative;
    _NANO_psd_sample_stage_var._position_relative_is_zero =  coords_test_zero(_NANO_psd_sample_stage_var._position_relative);
  instrument->counter_N[442]  = instrument->counter_P[442] = instrument->counter_P2[442] = 0;
  instrument->counter_AbsorbProp[442]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0441_NANO_psd_sample_stage", _NANO_psd_sample_stage_var._position_absolute, _NANO_psd_sample_stage_var._rotation_absolute, "PSD_monitor");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "xwidth", "0.05", "0.000005","MCNUM");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "yheight", "0.05", "0.000005","MCNUM");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "restore_xray", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "nx", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "ny", "90", "90","int");
        mccomp_param_nexus(nxhandle,"0441_NANO_psd_sample_stage", "nr", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _NANO_psd_sample_stage_setpos */

/* component beamdump_456=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_456_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_456_setpos] component beamdump_456=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_456_var._name, "beamdump_456", 16384);
  stracpy(_beamdump_456_var._type, "Beamstop", 16384);
  _beamdump_456_var._index=443;
  int current_setpos_index = 443;
  _beamdump_456_var._parameters.xmin = -0.05;
  _beamdump_456_var._parameters.xmax = 0.05;
  _beamdump_456_var._parameters.ymin = -0.05;
  _beamdump_456_var._parameters.ymax = 0.05;
  _beamdump_456_var._parameters.xwidth = 0;
  _beamdump_456_var._parameters.yheight = 0;
  _beamdump_456_var._parameters.radius = 0;

  /* component beamdump_456=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _NANO_psd_sample_stage_var._rotation_absolute, _beamdump_456_var._rotation_absolute);
    rot_transpose(_NANO_psd_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_beamdump_456_var._rotation_absolute, tr1, _beamdump_456_var._rotation_relative);
    _beamdump_456_var._rotation_is_identity =  rot_test_identity(_beamdump_456_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_NANO_psd_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_456_var._position_absolute = coords_add(_NANO_psd_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_NANO_psd_sample_stage_var._position_absolute, _beamdump_456_var._position_absolute);
    _beamdump_456_var._position_relative = rot_apply(_beamdump_456_var._rotation_absolute, tc1);
  } /* beamdump_456=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_456", _beamdump_456_var._position_absolute, _beamdump_456_var._rotation_absolute);
  instrument->_position_absolute[443] = _beamdump_456_var._position_absolute;
  instrument->_position_relative[443] = _beamdump_456_var._position_relative;
    _beamdump_456_var._position_relative_is_zero =  coords_test_zero(_beamdump_456_var._position_relative);
  instrument->counter_N[443]  = instrument->counter_P[443] = instrument->counter_P2[443] = 0;
  instrument->counter_AbsorbProp[443]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0442_beamdump_456", _beamdump_456_var._position_absolute, _beamdump_456_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0442_beamdump_456", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_456_setpos */

/* component DIFFABS_pos=Text() SETTING, POSITION/ROTATION */
int _DIFFABS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_pos_setpos] component DIFFABS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_DIFFABS_pos_var._name, "DIFFABS_pos", 16384);
  stracpy(_DIFFABS_pos_var._type, "Text", 16384);
  _DIFFABS_pos_var._index=444;
  int current_setpos_index = 444;
  if("DIFFABS" && strlen("DIFFABS"))
    stracpy(_DIFFABS_pos_var._parameters.text, "DIFFABS" ? "DIFFABS" : "", 16384);
  else 
  _DIFFABS_pos_var._parameters.text[0]='\0';
  _DIFFABS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_DIFFABS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _DIFFABS_pos_var._parameters.plane[0]='\0';
  _DIFFABS_pos_var._parameters.pen_thickness = 0.1;


  /* component DIFFABS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-285.193)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _DIFFABS_pos_var._rotation_absolute);
    rot_transpose(_beamdump_456_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_pos_var._rotation_absolute, tr1, _DIFFABS_pos_var._rotation_relative);
    _DIFFABS_pos_var._rotation_is_identity =  rot_test_identity(_DIFFABS_pos_var._rotation_relative);
    tc1 = coords_set(
      14.765, 0, -54.371);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_456_var._position_absolute, _DIFFABS_pos_var._position_absolute);
    _DIFFABS_pos_var._position_relative = rot_apply(_DIFFABS_pos_var._rotation_absolute, tc1);
  } /* DIFFABS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_pos", _DIFFABS_pos_var._position_absolute, _DIFFABS_pos_var._rotation_absolute);
  instrument->_position_absolute[444] = _DIFFABS_pos_var._position_absolute;
  instrument->_position_relative[444] = _DIFFABS_pos_var._position_relative;
    _DIFFABS_pos_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_pos_var._position_relative);
  instrument->counter_N[444]  = instrument->counter_P[444] = instrument->counter_P2[444] = 0;
  instrument->counter_AbsorbProp[444]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0443_DIFFABS_pos", _DIFFABS_pos_var._position_absolute, _DIFFABS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0443_DIFFABS_pos", "text", "NONE", "DIFFABS", "char*");
        mccomp_param_nexus(nxhandle,"0443_DIFFABS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0443_DIFFABS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0443_DIFFABS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_pos_setpos */

/* component DIFFABS=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_setpos] component DIFFABS=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_var._name, "DIFFABS", 16384);
  stracpy(_DIFFABS_var._type, "Arm", 16384);
  _DIFFABS_var._index=445;
  int current_setpos_index = 445;
  /* component DIFFABS=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_pos_var._rotation_absolute, _DIFFABS_var._rotation_absolute);
    rot_transpose(_DIFFABS_pos_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_var._rotation_absolute, tr1, _DIFFABS_var._rotation_relative);
    _DIFFABS_var._rotation_is_identity =  rot_test_identity(_DIFFABS_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_var._position_absolute = coords_add(_DIFFABS_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_pos_var._position_absolute, _DIFFABS_var._position_absolute);
    _DIFFABS_var._position_relative = rot_apply(_DIFFABS_var._rotation_absolute, tc1);
  } /* DIFFABS=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS", _DIFFABS_var._position_absolute, _DIFFABS_var._rotation_absolute);
  instrument->_position_absolute[445] = _DIFFABS_var._position_absolute;
  instrument->_position_relative[445] = _DIFFABS_var._position_relative;
    _DIFFABS_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_var._position_relative);
  instrument->counter_N[445]  = instrument->counter_P[445] = instrument->counter_P2[445] = 0;
  instrument->counter_AbsorbProp[445]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0444_DIFFABS", _DIFFABS_var._position_absolute, _DIFFABS_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_setpos */

/* component DIFFABS_BM_D13_1=Bending_magnet() SETTING, POSITION/ROTATION */
int _DIFFABS_BM_D13_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_BM_D13_1_setpos] component DIFFABS_BM_D13_1=Bending_magnet() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");
  stracpy(_DIFFABS_BM_D13_1_var._name, "DIFFABS_BM_D13_1", 16384);
  stracpy(_DIFFABS_BM_D13_1_var._type, "Bending_magnet", 16384);
  _DIFFABS_BM_D13_1_var._index=446;
  int current_setpos_index = 446;
  _DIFFABS_BM_D13_1_var._parameters.E0 = _instrument_var._parameters.DIFFABS_E0;
  _DIFFABS_BM_D13_1_var._parameters.dE = _instrument_var._parameters.DIFFABS_dE;
  _DIFFABS_BM_D13_1_var._parameters.lambda0 = 0;
  _DIFFABS_BM_D13_1_var._parameters.dlambda = 0;
  _DIFFABS_BM_D13_1_var._parameters.phase = 0;
  _DIFFABS_BM_D13_1_var._parameters.randomphase = 1;
  _DIFFABS_BM_D13_1_var._parameters.Ee = 2.75;
  _DIFFABS_BM_D13_1_var._parameters.Ie = 0.5;
  _DIFFABS_BM_D13_1_var._parameters.B = 1.71;
  _DIFFABS_BM_D13_1_var._parameters.sigey = 24.9e-6;
  _DIFFABS_BM_D13_1_var._parameters.sigex = 60.1e-6;
  _DIFFABS_BM_D13_1_var._parameters.focus_xw = 0;
  _DIFFABS_BM_D13_1_var._parameters.focus_yh = 0;
  _DIFFABS_BM_D13_1_var._parameters.dist = 1;
  _DIFFABS_BM_D13_1_var._parameters.gauss_t = 0;


  /* component DIFFABS_BM_D13_1=Bending_magnet() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_var._rotation_absolute, _DIFFABS_BM_D13_1_var._rotation_absolute);
    rot_transpose(_DIFFABS_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_BM_D13_1_var._rotation_absolute, tr1, _DIFFABS_BM_D13_1_var._rotation_relative);
    _DIFFABS_BM_D13_1_var._rotation_is_identity =  rot_test_identity(_DIFFABS_BM_D13_1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_BM_D13_1_var._position_absolute = coords_add(_DIFFABS_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_var._position_absolute, _DIFFABS_BM_D13_1_var._position_absolute);
    _DIFFABS_BM_D13_1_var._position_relative = rot_apply(_DIFFABS_BM_D13_1_var._rotation_absolute, tc1);
  } /* DIFFABS_BM_D13_1=Bending_magnet() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_BM_D13_1", _DIFFABS_BM_D13_1_var._position_absolute, _DIFFABS_BM_D13_1_var._rotation_absolute);
  instrument->_position_absolute[446] = _DIFFABS_BM_D13_1_var._position_absolute;
  instrument->_position_relative[446] = _DIFFABS_BM_D13_1_var._position_relative;
    _DIFFABS_BM_D13_1_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_BM_D13_1_var._position_relative);
  instrument->counter_N[446]  = instrument->counter_P[446] = instrument->counter_P2[446] = 0;
  instrument->counter_AbsorbProp[446]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", _DIFFABS_BM_D13_1_var._position_absolute, _DIFFABS_BM_D13_1_var._rotation_absolute, "Bending_magnet");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "E0", "0", "_instrument_var._parameters.DIFFABS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "dE", "0", "_instrument_var._parameters.DIFFABS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "B", "1.6", "1.71","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "sigey", "0", "24.9e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "sigex", "0", "60.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0445_DIFFABS_BM_D13_1", "gauss_t", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_BM_D13_1_setpos */

/* component DIFFABS_primary_slit=Slit() SETTING, POSITION/ROTATION */
int _DIFFABS_primary_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_primary_slit_setpos] component DIFFABS_primary_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_DIFFABS_primary_slit_var._name, "DIFFABS_primary_slit", 16384);
  stracpy(_DIFFABS_primary_slit_var._type, "Slit", 16384);
  _DIFFABS_primary_slit_var._index=447;
  int current_setpos_index = 447;
  _DIFFABS_primary_slit_var._parameters.xmin = 0;
  _DIFFABS_primary_slit_var._parameters.xmax = 0;
  _DIFFABS_primary_slit_var._parameters.ymin = 0;
  _DIFFABS_primary_slit_var._parameters.ymax = 0;
  _DIFFABS_primary_slit_var._parameters.radius = 0;
  _DIFFABS_primary_slit_var._parameters.xwidth = 0.03;
  _DIFFABS_primary_slit_var._parameters.yheight = 0.01;
  _DIFFABS_primary_slit_var._parameters.dist = 0;
  _DIFFABS_primary_slit_var._parameters.focus_xw = 0;
  _DIFFABS_primary_slit_var._parameters.focus_yh = 0;
  _DIFFABS_primary_slit_var._parameters.focus_x0 = 0;
  _DIFFABS_primary_slit_var._parameters.focus_y0 = 0;

  /* component DIFFABS_primary_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_BM_D13_1_var._rotation_absolute, _DIFFABS_primary_slit_var._rotation_absolute);
    rot_transpose(_DIFFABS_BM_D13_1_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_primary_slit_var._rotation_absolute, tr1, _DIFFABS_primary_slit_var._rotation_relative);
    _DIFFABS_primary_slit_var._rotation_is_identity =  rot_test_identity(_DIFFABS_primary_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 11.85);
    rot_transpose(_DIFFABS_BM_D13_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_primary_slit_var._position_absolute = coords_add(_DIFFABS_BM_D13_1_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_BM_D13_1_var._position_absolute, _DIFFABS_primary_slit_var._position_absolute);
    _DIFFABS_primary_slit_var._position_relative = rot_apply(_DIFFABS_primary_slit_var._rotation_absolute, tc1);
  } /* DIFFABS_primary_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_primary_slit", _DIFFABS_primary_slit_var._position_absolute, _DIFFABS_primary_slit_var._rotation_absolute);
  instrument->_position_absolute[447] = _DIFFABS_primary_slit_var._position_absolute;
  instrument->_position_relative[447] = _DIFFABS_primary_slit_var._position_relative;
    _DIFFABS_primary_slit_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_primary_slit_var._position_relative);
  instrument->counter_N[447]  = instrument->counter_P[447] = instrument->counter_P2[447] = 0;
  instrument->counter_AbsorbProp[447]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0446_DIFFABS_primary_slit", _DIFFABS_primary_slit_var._position_absolute, _DIFFABS_primary_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "xwidth", "0.001", "0.03","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0446_DIFFABS_primary_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_primary_slit_setpos */

/* component DIFFABS_M1_location=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_M1_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M1_location_setpos] component DIFFABS_M1_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_M1_location_var._name, "DIFFABS_M1_location", 16384);
  stracpy(_DIFFABS_M1_location_var._type, "Arm", 16384);
  _DIFFABS_M1_location_var._index=448;
  int current_setpos_index = 448;
  /* component DIFFABS_M1_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_BM_D13_1_var._rotation_absolute, _DIFFABS_M1_location_var._rotation_absolute);
    rot_transpose(_DIFFABS_primary_slit_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M1_location_var._rotation_absolute, tr1, _DIFFABS_M1_location_var._rotation_relative);
    _DIFFABS_M1_location_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M1_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 14.92);
    rot_transpose(_DIFFABS_BM_D13_1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M1_location_var._position_absolute = coords_add(_DIFFABS_BM_D13_1_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_primary_slit_var._position_absolute, _DIFFABS_M1_location_var._position_absolute);
    _DIFFABS_M1_location_var._position_relative = rot_apply(_DIFFABS_M1_location_var._rotation_absolute, tc1);
  } /* DIFFABS_M1_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M1_location", _DIFFABS_M1_location_var._position_absolute, _DIFFABS_M1_location_var._rotation_absolute);
  instrument->_position_absolute[448] = _DIFFABS_M1_location_var._position_absolute;
  instrument->_position_relative[448] = _DIFFABS_M1_location_var._position_relative;
    _DIFFABS_M1_location_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M1_location_var._position_relative);
  instrument->counter_N[448]  = instrument->counter_P[448] = instrument->counter_P2[448] = 0;
  instrument->counter_AbsorbProp[448]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0447_DIFFABS_M1_location", _DIFFABS_M1_location_var._position_absolute, _DIFFABS_M1_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M1_location_setpos */

/* component DIFFABS_M1_rotated=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_M1_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M1_rotated_setpos] component DIFFABS_M1_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_M1_rotated_var._name, "DIFFABS_M1_rotated", 16384);
  stracpy(_DIFFABS_M1_rotated_var._type, "Arm", 16384);
  _DIFFABS_M1_rotated_var._index=449;
  int current_setpos_index = 449;
  /* component DIFFABS_M1_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DIFFABS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M1_location_var._rotation_absolute, _DIFFABS_M1_rotated_var._rotation_absolute);
    rot_transpose(_DIFFABS_primary_slit_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M1_rotated_var._rotation_absolute, tr1, _DIFFABS_M1_rotated_var._rotation_relative);
    _DIFFABS_M1_rotated_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M1_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_M1_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M1_rotated_var._position_absolute = coords_add(_DIFFABS_M1_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_primary_slit_var._position_absolute, _DIFFABS_M1_rotated_var._position_absolute);
    _DIFFABS_M1_rotated_var._position_relative = rot_apply(_DIFFABS_M1_rotated_var._rotation_absolute, tc1);
  } /* DIFFABS_M1_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M1_rotated", _DIFFABS_M1_rotated_var._position_absolute, _DIFFABS_M1_rotated_var._rotation_absolute);
  instrument->_position_absolute[449] = _DIFFABS_M1_rotated_var._position_absolute;
  instrument->_position_relative[449] = _DIFFABS_M1_rotated_var._position_relative;
    _DIFFABS_M1_rotated_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M1_rotated_var._position_relative);
  instrument->counter_N[449]  = instrument->counter_P[449] = instrument->counter_P2[449] = 0;
  instrument->counter_AbsorbProp[449]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0448_DIFFABS_M1_rotated", _DIFFABS_M1_rotated_var._position_absolute, _DIFFABS_M1_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M1_rotated_setpos */

/* component DIFFABS_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _DIFFABS_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M1_setpos] component DIFFABS_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_DIFFABS_M1_var._name, "DIFFABS_M1", 16384);
  stracpy(_DIFFABS_M1_var._type, "Mirror_curved", 16384);
  _DIFFABS_M1_var._index=450;
  int current_setpos_index = 450;
  _DIFFABS_M1_var._parameters.radius = _instrument_var._parameters.DIFFABS_M1_radius;
  _DIFFABS_M1_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_DIFFABS_M1_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _DIFFABS_M1_var._parameters.coating[0]='\0';
  _DIFFABS_M1_var._parameters.zdepth = 0.2;
  _DIFFABS_M1_var._parameters.yheight = 0.2;
  _DIFFABS_M1_var._parameters.length = 1.3;
  _DIFFABS_M1_var._parameters.width = 0.1;


  /* component DIFFABS_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M1_rotated_var._rotation_absolute, _DIFFABS_M1_var._rotation_absolute);
    rot_transpose(_DIFFABS_primary_slit_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M1_var._rotation_absolute, tr1, _DIFFABS_M1_var._rotation_relative);
    _DIFFABS_M1_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M1_var._position_absolute = coords_add(_DIFFABS_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_primary_slit_var._position_absolute, _DIFFABS_M1_var._position_absolute);
    _DIFFABS_M1_var._position_relative = rot_apply(_DIFFABS_M1_var._rotation_absolute, tc1);
  } /* DIFFABS_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M1", _DIFFABS_M1_var._position_absolute, _DIFFABS_M1_var._rotation_absolute);
  instrument->_position_absolute[450] = _DIFFABS_M1_var._position_absolute;
  instrument->_position_relative[450] = _DIFFABS_M1_var._position_relative;
    _DIFFABS_M1_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M1_var._position_relative);
  instrument->counter_N[450]  = instrument->counter_P[450] = instrument->counter_P2[450] = 0;
  instrument->counter_AbsorbProp[450]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0449_DIFFABS_M1", _DIFFABS_M1_var._position_absolute, _DIFFABS_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "radius", "1", "_instrument_var._parameters.DIFFABS_M1_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "length", "0", "1.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0449_DIFFABS_M1", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M1_setpos */

/* component DIFFABS_M1_out=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_M1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M1_out_setpos] component DIFFABS_M1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_M1_out_var._name, "DIFFABS_M1_out", 16384);
  stracpy(_DIFFABS_M1_out_var._type, "Arm", 16384);
  _DIFFABS_M1_out_var._index=451;
  int current_setpos_index = 451;
  /* component DIFFABS_M1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DIFFABS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M1_rotated_var._rotation_absolute, _DIFFABS_M1_out_var._rotation_absolute);
    rot_transpose(_DIFFABS_M1_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M1_out_var._rotation_absolute, tr1, _DIFFABS_M1_out_var._rotation_relative);
    _DIFFABS_M1_out_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M1_out_var._position_absolute = coords_add(_DIFFABS_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_M1_var._position_absolute, _DIFFABS_M1_out_var._position_absolute);
    _DIFFABS_M1_out_var._position_relative = rot_apply(_DIFFABS_M1_out_var._rotation_absolute, tc1);
  } /* DIFFABS_M1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M1_out", _DIFFABS_M1_out_var._position_absolute, _DIFFABS_M1_out_var._rotation_absolute);
  instrument->_position_absolute[451] = _DIFFABS_M1_out_var._position_absolute;
  instrument->_position_relative[451] = _DIFFABS_M1_out_var._position_relative;
    _DIFFABS_M1_out_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M1_out_var._position_relative);
  instrument->counter_N[451]  = instrument->counter_P[451] = instrument->counter_P2[451] = 0;
  instrument->counter_AbsorbProp[451]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0450_DIFFABS_M1_out", _DIFFABS_M1_out_var._position_absolute, _DIFFABS_M1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M1_out_setpos */

/* component DIFFABS_DCM_slit_in=Slit() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_slit_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_slit_in_setpos] component DIFFABS_DCM_slit_in=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_DIFFABS_DCM_slit_in_var._name, "DIFFABS_DCM_slit_in", 16384);
  stracpy(_DIFFABS_DCM_slit_in_var._type, "Slit", 16384);
  _DIFFABS_DCM_slit_in_var._index=452;
  int current_setpos_index = 452;
  _DIFFABS_DCM_slit_in_var._parameters.xmin = 0;
  _DIFFABS_DCM_slit_in_var._parameters.xmax = 0;
  _DIFFABS_DCM_slit_in_var._parameters.ymin = 0;
  _DIFFABS_DCM_slit_in_var._parameters.ymax = 0;
  _DIFFABS_DCM_slit_in_var._parameters.radius = 0;
  _DIFFABS_DCM_slit_in_var._parameters.xwidth = 0.03;
  _DIFFABS_DCM_slit_in_var._parameters.yheight = 0.01;
  _DIFFABS_DCM_slit_in_var._parameters.dist = 0;
  _DIFFABS_DCM_slit_in_var._parameters.focus_xw = 0;
  _DIFFABS_DCM_slit_in_var._parameters.focus_yh = 0;
  _DIFFABS_DCM_slit_in_var._parameters.focus_x0 = 0;
  _DIFFABS_DCM_slit_in_var._parameters.focus_y0 = 0;

  /* component DIFFABS_DCM_slit_in=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M1_out_var._rotation_absolute, _DIFFABS_DCM_slit_in_var._rotation_absolute);
    rot_transpose(_DIFFABS_M1_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_slit_in_var._rotation_absolute, tr1, _DIFFABS_DCM_slit_in_var._rotation_relative);
    _DIFFABS_DCM_slit_in_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_slit_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2.3);
    rot_transpose(_DIFFABS_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_slit_in_var._position_absolute = coords_add(_DIFFABS_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_M1_var._position_absolute, _DIFFABS_DCM_slit_in_var._position_absolute);
    _DIFFABS_DCM_slit_in_var._position_relative = rot_apply(_DIFFABS_DCM_slit_in_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_slit_in=Slit() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_slit_in", _DIFFABS_DCM_slit_in_var._position_absolute, _DIFFABS_DCM_slit_in_var._rotation_absolute);
  instrument->_position_absolute[452] = _DIFFABS_DCM_slit_in_var._position_absolute;
  instrument->_position_relative[452] = _DIFFABS_DCM_slit_in_var._position_relative;
    _DIFFABS_DCM_slit_in_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_slit_in_var._position_relative);
  instrument->counter_N[452]  = instrument->counter_P[452] = instrument->counter_P2[452] = 0;
  instrument->counter_AbsorbProp[452]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", _DIFFABS_DCM_slit_in_var._position_absolute, _DIFFABS_DCM_slit_in_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "xwidth", "0.001", "0.03","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "yheight", "0.001", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0451_DIFFABS_DCM_slit_in", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_slit_in_setpos */

/* component DIFFABS_DCM_in=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_in_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_in_setpos] component DIFFABS_DCM_in=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_DCM_in_var._name, "DIFFABS_DCM_in", 16384);
  stracpy(_DIFFABS_DCM_in_var._type, "Monitor_nD", 16384);
  _DIFFABS_DCM_in_var._index=453;
  int current_setpos_index = 453;
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.user9[0]='\0';
  _DIFFABS_DCM_in_var._parameters.xwidth = 5e-2;
  _DIFFABS_DCM_in_var._parameters.yheight = 5e-2;
  _DIFFABS_DCM_in_var._parameters.zdepth = 0;
  _DIFFABS_DCM_in_var._parameters.bins = 128;
  _DIFFABS_DCM_in_var._parameters.min = -1e40;
  _DIFFABS_DCM_in_var._parameters.max = 1e40;
  _DIFFABS_DCM_in_var._parameters.restore_xray = 1;
  _DIFFABS_DCM_in_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_DIFFABS_DCM_in_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.geometry[0]='\0';
  _DIFFABS_DCM_in_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_var._parameters.username9[0]='\0';


  /* component DIFFABS_DCM_in=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_DCM_slit_in_var._rotation_absolute, _DIFFABS_DCM_in_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_slit_in_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_in_var._rotation_absolute, tr1, _DIFFABS_DCM_in_var._rotation_relative);
    _DIFFABS_DCM_in_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_in_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.001);
    rot_transpose(_DIFFABS_DCM_slit_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_in_var._position_absolute = coords_add(_DIFFABS_DCM_slit_in_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_slit_in_var._position_absolute, _DIFFABS_DCM_in_var._position_absolute);
    _DIFFABS_DCM_in_var._position_relative = rot_apply(_DIFFABS_DCM_in_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_in=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_in", _DIFFABS_DCM_in_var._position_absolute, _DIFFABS_DCM_in_var._rotation_absolute);
  instrument->_position_absolute[453] = _DIFFABS_DCM_in_var._position_absolute;
  instrument->_position_relative[453] = _DIFFABS_DCM_in_var._position_relative;
    _DIFFABS_DCM_in_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_in_var._position_relative);
  instrument->counter_N[453]  = instrument->counter_P[453] = instrument->counter_P2[453] = 0;
  instrument->counter_AbsorbProp[453]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0452_DIFFABS_DCM_in", _DIFFABS_DCM_in_var._position_absolute, _DIFFABS_DCM_in_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "xwidth", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "yheight", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0452_DIFFABS_DCM_in", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_in_setpos */

/* component DIFFABS_DCM_in_div=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_in_div_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_in_div_setpos] component DIFFABS_DCM_in_div=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_DCM_in_div_var._name, "DIFFABS_DCM_in_div", 16384);
  stracpy(_DIFFABS_DCM_in_div_var._type, "Monitor_nD", 16384);
  _DIFFABS_DCM_in_div_var._index=454;
  int current_setpos_index = 454;
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.user9[0]='\0';
  _DIFFABS_DCM_in_div_var._parameters.xwidth = 5e-2;
  _DIFFABS_DCM_in_div_var._parameters.yheight = 5e-2;
  _DIFFABS_DCM_in_div_var._parameters.zdepth = 0;
  _DIFFABS_DCM_in_div_var._parameters.bins = 128;
  _DIFFABS_DCM_in_div_var._parameters.min = -1e40;
  _DIFFABS_DCM_in_div_var._parameters.max = 1e40;
  _DIFFABS_DCM_in_div_var._parameters.restore_xray = 1;
  _DIFFABS_DCM_in_div_var._parameters.radius = 0;
  if("dx limits=[-0.05 0.05], dy limits=[-0.5 0.5]" && strlen("dx limits=[-0.05 0.05], dy limits=[-0.5 0.5]"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.options, "dx limits=[-0.05 0.05], dy limits=[-0.5 0.5]" ? "dx limits=[-0.05 0.05], dy limits=[-0.5 0.5]" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.geometry[0]='\0';
  _DIFFABS_DCM_in_div_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_in_div_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_in_div_var._parameters.username9[0]='\0';


  /* component DIFFABS_DCM_in_div=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_DCM_in_var._rotation_absolute, _DIFFABS_DCM_in_div_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_in_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_in_div_var._rotation_absolute, tr1, _DIFFABS_DCM_in_div_var._rotation_relative);
    _DIFFABS_DCM_in_div_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_in_div_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_DCM_in_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_in_div_var._position_absolute = coords_add(_DIFFABS_DCM_in_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_in_var._position_absolute, _DIFFABS_DCM_in_div_var._position_absolute);
    _DIFFABS_DCM_in_div_var._position_relative = rot_apply(_DIFFABS_DCM_in_div_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_in_div=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_in_div", _DIFFABS_DCM_in_div_var._position_absolute, _DIFFABS_DCM_in_div_var._rotation_absolute);
  instrument->_position_absolute[454] = _DIFFABS_DCM_in_div_var._position_absolute;
  instrument->_position_relative[454] = _DIFFABS_DCM_in_div_var._position_relative;
    _DIFFABS_DCM_in_div_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_in_div_var._position_relative);
  instrument->counter_N[454]  = instrument->counter_P[454] = instrument->counter_P2[454] = 0;
  instrument->counter_AbsorbProp[454]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", _DIFFABS_DCM_in_div_var._position_absolute, _DIFFABS_DCM_in_div_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "xwidth", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "yheight", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "options", "NULL", "dx limits=[-0.05 0.05], dy limits=[-0.5 0.5]", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0453_DIFFABS_DCM_in_div", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_in_div_setpos */

/* component DIFFABS_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_location_setpos] component DIFFABS_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_DCM_location_var._name, "DIFFABS_DCM_location", 16384);
  stracpy(_DIFFABS_DCM_location_var._type, "Arm", 16384);
  _DIFFABS_DCM_location_var._index=455;
  int current_setpos_index = 455;
  /* component DIFFABS_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M1_out_var._rotation_absolute, _DIFFABS_DCM_location_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_in_div_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_location_var._rotation_absolute, tr1, _DIFFABS_DCM_location_var._rotation_relative);
    _DIFFABS_DCM_location_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2.54);
    rot_transpose(_DIFFABS_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_location_var._position_absolute = coords_add(_DIFFABS_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_in_div_var._position_absolute, _DIFFABS_DCM_location_var._position_absolute);
    _DIFFABS_DCM_location_var._position_relative = rot_apply(_DIFFABS_DCM_location_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_location", _DIFFABS_DCM_location_var._position_absolute, _DIFFABS_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[455] = _DIFFABS_DCM_location_var._position_absolute;
  instrument->_position_relative[455] = _DIFFABS_DCM_location_var._position_relative;
    _DIFFABS_DCM_location_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_location_var._position_relative);
  instrument->counter_N[455]  = instrument->counter_P[455] = instrument->counter_P2[455] = 0;
  instrument->counter_AbsorbProp[455]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0454_DIFFABS_DCM_location", _DIFFABS_DCM_location_var._position_absolute, _DIFFABS_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_location_setpos */

/* component DIFFABS_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _DIFFABS_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_bragg_crystal_setpos] component DIFFABS_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_DIFFABS_bragg_crystal_var._name, "DIFFABS_bragg_crystal", 16384);
  stracpy(_DIFFABS_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _DIFFABS_bragg_crystal_var._index=456;
  int current_setpos_index = 456;
  _DIFFABS_bragg_crystal_var._parameters.length = 0.2;
  _DIFFABS_bragg_crystal_var._parameters.width = 0.1;
  _DIFFABS_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_DIFFABS_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _DIFFABS_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_DIFFABS_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _DIFFABS_bragg_crystal_var._parameters.material[0]='\0';
  _DIFFABS_bragg_crystal_var._parameters.alpha = 0.0;
  _DIFFABS_bragg_crystal_var._parameters.R0 = 0;
  _DIFFABS_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _DIFFABS_bragg_crystal_var._parameters.crystal_type = 2;
  _DIFFABS_bragg_crystal_var._parameters.h = 1;
  _DIFFABS_bragg_crystal_var._parameters.k = 1;
  _DIFFABS_bragg_crystal_var._parameters.l = 1;
  _DIFFABS_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _DIFFABS_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component DIFFABS_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DIFFABS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_DCM_location_var._rotation_absolute, _DIFFABS_bragg_crystal_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_in_div_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_bragg_crystal_var._rotation_absolute, tr1, _DIFFABS_bragg_crystal_var._rotation_relative);
    _DIFFABS_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_DIFFABS_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_bragg_crystal_var._position_absolute = coords_add(_DIFFABS_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_in_div_var._position_absolute, _DIFFABS_bragg_crystal_var._position_absolute);
    _DIFFABS_bragg_crystal_var._position_relative = rot_apply(_DIFFABS_bragg_crystal_var._rotation_absolute, tc1);
  } /* DIFFABS_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_bragg_crystal", _DIFFABS_bragg_crystal_var._position_absolute, _DIFFABS_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[456] = _DIFFABS_bragg_crystal_var._position_absolute;
  instrument->_position_relative[456] = _DIFFABS_bragg_crystal_var._position_relative;
    _DIFFABS_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_bragg_crystal_var._position_relative);
  instrument->counter_N[456]  = instrument->counter_P[456] = instrument->counter_P2[456] = 0;
  instrument->counter_AbsorbProp[456]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", _DIFFABS_bragg_crystal_var._position_absolute, _DIFFABS_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "length", "0.05", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "width", "0.02", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0455_DIFFABS_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_bragg_crystal_setpos */

/* component DIFFABS_arm_crystal1=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_arm_crystal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_arm_crystal1_setpos] component DIFFABS_arm_crystal1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_arm_crystal1_var._name, "DIFFABS_arm_crystal1", 16384);
  stracpy(_DIFFABS_arm_crystal1_var._type, "Arm", 16384);
  _DIFFABS_arm_crystal1_var._index=457;
  int current_setpos_index = 457;
  /* component DIFFABS_arm_crystal1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.DIFFABS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_bragg_crystal_var._rotation_absolute, _DIFFABS_arm_crystal1_var._rotation_absolute);
    rot_transpose(_DIFFABS_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_arm_crystal1_var._rotation_absolute, tr1, _DIFFABS_arm_crystal1_var._rotation_relative);
    _DIFFABS_arm_crystal1_var._rotation_is_identity =  rot_test_identity(_DIFFABS_arm_crystal1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_arm_crystal1_var._position_absolute = coords_add(_DIFFABS_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_bragg_crystal_var._position_absolute, _DIFFABS_arm_crystal1_var._position_absolute);
    _DIFFABS_arm_crystal1_var._position_relative = rot_apply(_DIFFABS_arm_crystal1_var._rotation_absolute, tc1);
  } /* DIFFABS_arm_crystal1=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_arm_crystal1", _DIFFABS_arm_crystal1_var._position_absolute, _DIFFABS_arm_crystal1_var._rotation_absolute);
  instrument->_position_absolute[457] = _DIFFABS_arm_crystal1_var._position_absolute;
  instrument->_position_relative[457] = _DIFFABS_arm_crystal1_var._position_relative;
    _DIFFABS_arm_crystal1_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_arm_crystal1_var._position_relative);
  instrument->counter_N[457]  = instrument->counter_P[457] = instrument->counter_P2[457] = 0;
  instrument->counter_AbsorbProp[457]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0456_DIFFABS_arm_crystal1", _DIFFABS_arm_crystal1_var._position_absolute, _DIFFABS_arm_crystal1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_arm_crystal1_setpos */

/* component DIFFABS_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _DIFFABS_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_bragg_crystal_two_setpos] component DIFFABS_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_DIFFABS_bragg_crystal_two_var._name, "DIFFABS_bragg_crystal_two", 16384);
  stracpy(_DIFFABS_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _DIFFABS_bragg_crystal_two_var._index=458;
  int current_setpos_index = 458;
  _DIFFABS_bragg_crystal_two_var._parameters.length = 0.2;
  _DIFFABS_bragg_crystal_two_var._parameters.width = 0.1;
  _DIFFABS_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_DIFFABS_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _DIFFABS_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_DIFFABS_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _DIFFABS_bragg_crystal_two_var._parameters.material[0]='\0';
  _DIFFABS_bragg_crystal_two_var._parameters.alpha = 0.0;
  _DIFFABS_bragg_crystal_two_var._parameters.R0 = 0;
  _DIFFABS_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _DIFFABS_bragg_crystal_two_var._parameters.crystal_type = 2;
  _DIFFABS_bragg_crystal_two_var._parameters.h = 1;
  _DIFFABS_bragg_crystal_two_var._parameters.k = 1;
  _DIFFABS_bragg_crystal_two_var._parameters.l = 1;
  _DIFFABS_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _DIFFABS_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component DIFFABS_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DIFFABS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_arm_crystal1_var._rotation_absolute, _DIFFABS_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_DIFFABS_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_bragg_crystal_two_var._rotation_absolute, tr1, _DIFFABS_bragg_crystal_two_var._rotation_relative);
    _DIFFABS_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_DIFFABS_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, DIFFABS_dcm_gap, _instrument_var._parameters.DIFFABS_DCM_theta ? DIFFABS_dcm_gap / tan ( _instrument_var._parameters.DIFFABS_DCM_theta * DEG2RAD ) : 0);
    rot_transpose(_DIFFABS_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_bragg_crystal_two_var._position_absolute = coords_add(_DIFFABS_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_bragg_crystal_var._position_absolute, _DIFFABS_bragg_crystal_two_var._position_absolute);
    _DIFFABS_bragg_crystal_two_var._position_relative = rot_apply(_DIFFABS_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* DIFFABS_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_bragg_crystal_two", _DIFFABS_bragg_crystal_two_var._position_absolute, _DIFFABS_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[458] = _DIFFABS_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[458] = _DIFFABS_bragg_crystal_two_var._position_relative;
    _DIFFABS_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_bragg_crystal_two_var._position_relative);
  instrument->counter_N[458]  = instrument->counter_P[458] = instrument->counter_P2[458] = 0;
  instrument->counter_AbsorbProp[458]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", _DIFFABS_bragg_crystal_two_var._position_absolute, _DIFFABS_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "length", "0.05", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "width", "0.02", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0457_DIFFABS_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_bragg_crystal_two_setpos */

/* component DIFFABS_arm_crystal2=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_arm_crystal2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_arm_crystal2_setpos] component DIFFABS_arm_crystal2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_arm_crystal2_var._name, "DIFFABS_arm_crystal2", 16384);
  stracpy(_DIFFABS_arm_crystal2_var._type, "Arm", 16384);
  _DIFFABS_arm_crystal2_var._index=459;
  int current_setpos_index = 459;
  /* component DIFFABS_arm_crystal2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DIFFABS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_bragg_crystal_two_var._rotation_absolute, _DIFFABS_arm_crystal2_var._rotation_absolute);
    rot_transpose(_DIFFABS_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_arm_crystal2_var._rotation_absolute, tr1, _DIFFABS_arm_crystal2_var._rotation_relative);
    _DIFFABS_arm_crystal2_var._rotation_is_identity =  rot_test_identity(_DIFFABS_arm_crystal2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_arm_crystal2_var._position_absolute = coords_add(_DIFFABS_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_bragg_crystal_two_var._position_absolute, _DIFFABS_arm_crystal2_var._position_absolute);
    _DIFFABS_arm_crystal2_var._position_relative = rot_apply(_DIFFABS_arm_crystal2_var._rotation_absolute, tc1);
  } /* DIFFABS_arm_crystal2=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_arm_crystal2", _DIFFABS_arm_crystal2_var._position_absolute, _DIFFABS_arm_crystal2_var._rotation_absolute);
  instrument->_position_absolute[459] = _DIFFABS_arm_crystal2_var._position_absolute;
  instrument->_position_relative[459] = _DIFFABS_arm_crystal2_var._position_relative;
    _DIFFABS_arm_crystal2_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_arm_crystal2_var._position_relative);
  instrument->counter_N[459]  = instrument->counter_P[459] = instrument->counter_P2[459] = 0;
  instrument->counter_AbsorbProp[459]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0458_DIFFABS_arm_crystal2", _DIFFABS_arm_crystal2_var._position_absolute, _DIFFABS_arm_crystal2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_arm_crystal2_setpos */

/* component DIFFABS_DCM_out=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_out_setpos] component DIFFABS_DCM_out=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_DCM_out_var._name, "DIFFABS_DCM_out", 16384);
  stracpy(_DIFFABS_DCM_out_var._type, "Monitor_nD", 16384);
  _DIFFABS_DCM_out_var._index=460;
  int current_setpos_index = 460;
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.user9[0]='\0';
  _DIFFABS_DCM_out_var._parameters.xwidth = 5e-2;
  _DIFFABS_DCM_out_var._parameters.yheight = 0.02;
  _DIFFABS_DCM_out_var._parameters.zdepth = 0;
  _DIFFABS_DCM_out_var._parameters.bins = 128;
  _DIFFABS_DCM_out_var._parameters.min = -1e40;
  _DIFFABS_DCM_out_var._parameters.max = 1e40;
  _DIFFABS_DCM_out_var._parameters.restore_xray = 1;
  _DIFFABS_DCM_out_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_DIFFABS_DCM_out_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.geometry[0]='\0';
  _DIFFABS_DCM_out_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_var._parameters.username9[0]='\0';


  /* component DIFFABS_DCM_out=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_arm_crystal2_var._rotation_absolute, _DIFFABS_DCM_out_var._rotation_absolute);
    rot_transpose(_DIFFABS_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_out_var._rotation_absolute, tr1, _DIFFABS_DCM_out_var._rotation_relative);
    _DIFFABS_DCM_out_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_DIFFABS_arm_crystal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_out_var._position_absolute = coords_add(_DIFFABS_arm_crystal2_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_bragg_crystal_two_var._position_absolute, _DIFFABS_DCM_out_var._position_absolute);
    _DIFFABS_DCM_out_var._position_relative = rot_apply(_DIFFABS_DCM_out_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_out=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_out", _DIFFABS_DCM_out_var._position_absolute, _DIFFABS_DCM_out_var._rotation_absolute);
  instrument->_position_absolute[460] = _DIFFABS_DCM_out_var._position_absolute;
  instrument->_position_relative[460] = _DIFFABS_DCM_out_var._position_relative;
    _DIFFABS_DCM_out_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_out_var._position_relative);
  instrument->counter_N[460]  = instrument->counter_P[460] = instrument->counter_P2[460] = 0;
  instrument->counter_AbsorbProp[460]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0459_DIFFABS_DCM_out", _DIFFABS_DCM_out_var._position_absolute, _DIFFABS_DCM_out_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "xwidth", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0459_DIFFABS_DCM_out", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_out_setpos */

/* component DIFFABS_DCM_out_div=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_out_div_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_out_div_setpos] component DIFFABS_DCM_out_div=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_DCM_out_div_var._name, "DIFFABS_DCM_out_div", 16384);
  stracpy(_DIFFABS_DCM_out_div_var._type, "Monitor_nD", 16384);
  _DIFFABS_DCM_out_div_var._index=461;
  int current_setpos_index = 461;
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.user9[0]='\0';
  _DIFFABS_DCM_out_div_var._parameters.xwidth = 5e-2;
  _DIFFABS_DCM_out_div_var._parameters.yheight = 0.2;
  _DIFFABS_DCM_out_div_var._parameters.zdepth = 0;
  _DIFFABS_DCM_out_div_var._parameters.bins = 128;
  _DIFFABS_DCM_out_div_var._parameters.min = -1e40;
  _DIFFABS_DCM_out_div_var._parameters.max = 1e40;
  _DIFFABS_DCM_out_div_var._parameters.restore_xray = 1;
  _DIFFABS_DCM_out_div_var._parameters.radius = 0;
  if("dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" && strlen("dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.options, "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" ? "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.geometry[0]='\0';
  _DIFFABS_DCM_out_div_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_div_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_div_var._parameters.username9[0]='\0';


  /* component DIFFABS_DCM_out_div=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_DCM_out_var._rotation_absolute, _DIFFABS_DCM_out_div_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_out_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_out_div_var._rotation_absolute, tr1, _DIFFABS_DCM_out_div_var._rotation_relative);
    _DIFFABS_DCM_out_div_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_out_div_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_out_div_var._position_absolute = coords_add(_DIFFABS_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_out_var._position_absolute, _DIFFABS_DCM_out_div_var._position_absolute);
    _DIFFABS_DCM_out_div_var._position_relative = rot_apply(_DIFFABS_DCM_out_div_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_out_div=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_out_div", _DIFFABS_DCM_out_div_var._position_absolute, _DIFFABS_DCM_out_div_var._rotation_absolute);
  instrument->_position_absolute[461] = _DIFFABS_DCM_out_div_var._position_absolute;
  instrument->_position_relative[461] = _DIFFABS_DCM_out_div_var._position_relative;
    _DIFFABS_DCM_out_div_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_out_div_var._position_relative);
  instrument->counter_N[461]  = instrument->counter_P[461] = instrument->counter_P2[461] = 0;
  instrument->counter_AbsorbProp[461]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", _DIFFABS_DCM_out_div_var._position_absolute, _DIFFABS_DCM_out_div_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "xwidth", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "yheight", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "options", "NULL", "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0460_DIFFABS_DCM_out_div", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_out_div_setpos */

/* component DIFFABS_DCM_out_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_out_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_out_e_setpos] component DIFFABS_DCM_out_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_DCM_out_e_var._name, "DIFFABS_DCM_out_e", 16384);
  stracpy(_DIFFABS_DCM_out_e_var._type, "Monitor_nD", 16384);
  _DIFFABS_DCM_out_e_var._index=462;
  int current_setpos_index = 462;
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.user9[0]='\0';
  _DIFFABS_DCM_out_e_var._parameters.xwidth = 0.1;
  _DIFFABS_DCM_out_e_var._parameters.yheight = 0.2;
  _DIFFABS_DCM_out_e_var._parameters.zdepth = 0;
  _DIFFABS_DCM_out_e_var._parameters.bins = 512;
  _DIFFABS_DCM_out_e_var._parameters.min = _instrument_var._parameters.DIFFABS_E0 - _instrument_var._parameters.DIFFABS_dE;
  _DIFFABS_DCM_out_e_var._parameters.max = _instrument_var._parameters.DIFFABS_E0 + _instrument_var._parameters.DIFFABS_dE;
  _DIFFABS_DCM_out_e_var._parameters.restore_xray = 0;
  _DIFFABS_DCM_out_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.geometry[0]='\0';
  _DIFFABS_DCM_out_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_DCM_out_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_DCM_out_e_var._parameters.username9[0]='\0';


  /* component DIFFABS_DCM_out_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_DCM_out_var._rotation_absolute, _DIFFABS_DCM_out_e_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_out_div_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_out_e_var._rotation_absolute, tr1, _DIFFABS_DCM_out_e_var._rotation_relative);
    _DIFFABS_DCM_out_e_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_out_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_out_e_var._position_absolute = coords_add(_DIFFABS_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_out_div_var._position_absolute, _DIFFABS_DCM_out_e_var._position_absolute);
    _DIFFABS_DCM_out_e_var._position_relative = rot_apply(_DIFFABS_DCM_out_e_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_out_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_out_e", _DIFFABS_DCM_out_e_var._position_absolute, _DIFFABS_DCM_out_e_var._rotation_absolute);
  instrument->_position_absolute[462] = _DIFFABS_DCM_out_e_var._position_absolute;
  instrument->_position_relative[462] = _DIFFABS_DCM_out_e_var._position_relative;
    _DIFFABS_DCM_out_e_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_out_e_var._position_relative);
  instrument->counter_N[462]  = instrument->counter_P[462] = instrument->counter_P2[462] = 0;
  instrument->counter_AbsorbProp[462]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", _DIFFABS_DCM_out_e_var._position_absolute, _DIFFABS_DCM_out_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "yheight", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "min", "-1e40", "_instrument_var._parameters.DIFFABS_E0 - _instrument_var._parameters.DIFFABS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "max", "1e40", "_instrument_var._parameters.DIFFABS_E0 + _instrument_var._parameters.DIFFABS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0461_DIFFABS_DCM_out_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_out_e_setpos */

/* component DIFFABS_DCM_slit_out=Slit() SETTING, POSITION/ROTATION */
int _DIFFABS_DCM_slit_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_DCM_slit_out_setpos] component DIFFABS_DCM_slit_out=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_DIFFABS_DCM_slit_out_var._name, "DIFFABS_DCM_slit_out", 16384);
  stracpy(_DIFFABS_DCM_slit_out_var._type, "Slit", 16384);
  _DIFFABS_DCM_slit_out_var._index=463;
  int current_setpos_index = 463;
  _DIFFABS_DCM_slit_out_var._parameters.xmin = 0;
  _DIFFABS_DCM_slit_out_var._parameters.xmax = 0;
  _DIFFABS_DCM_slit_out_var._parameters.ymin = 0;
  _DIFFABS_DCM_slit_out_var._parameters.ymax = 0;
  _DIFFABS_DCM_slit_out_var._parameters.radius = 0;
  _DIFFABS_DCM_slit_out_var._parameters.xwidth = 0.1;
  _DIFFABS_DCM_slit_out_var._parameters.yheight = 0.2 * sin ( _instrument_var._parameters.DIFFABS_DCM_theta * DEG2RAD );
  _DIFFABS_DCM_slit_out_var._parameters.dist = 0;
  _DIFFABS_DCM_slit_out_var._parameters.focus_xw = 0;
  _DIFFABS_DCM_slit_out_var._parameters.focus_yh = 0;
  _DIFFABS_DCM_slit_out_var._parameters.focus_x0 = 0;
  _DIFFABS_DCM_slit_out_var._parameters.focus_y0 = 0;

  /* component DIFFABS_DCM_slit_out=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_DCM_out_e_var._rotation_absolute, _DIFFABS_DCM_slit_out_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_out_e_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_DCM_slit_out_var._rotation_absolute, tr1, _DIFFABS_DCM_slit_out_var._rotation_relative);
    _DIFFABS_DCM_slit_out_var._rotation_is_identity =  rot_test_identity(_DIFFABS_DCM_slit_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_DCM_out_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_DCM_slit_out_var._position_absolute = coords_add(_DIFFABS_DCM_out_e_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_out_e_var._position_absolute, _DIFFABS_DCM_slit_out_var._position_absolute);
    _DIFFABS_DCM_slit_out_var._position_relative = rot_apply(_DIFFABS_DCM_slit_out_var._rotation_absolute, tc1);
  } /* DIFFABS_DCM_slit_out=Slit() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_DCM_slit_out", _DIFFABS_DCM_slit_out_var._position_absolute, _DIFFABS_DCM_slit_out_var._rotation_absolute);
  instrument->_position_absolute[463] = _DIFFABS_DCM_slit_out_var._position_absolute;
  instrument->_position_relative[463] = _DIFFABS_DCM_slit_out_var._position_relative;
    _DIFFABS_DCM_slit_out_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_DCM_slit_out_var._position_relative);
  instrument->counter_N[463]  = instrument->counter_P[463] = instrument->counter_P2[463] = 0;
  instrument->counter_AbsorbProp[463]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", _DIFFABS_DCM_slit_out_var._position_absolute, _DIFFABS_DCM_slit_out_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "xwidth", "0.001", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "yheight", "0.001", "0.2 * sin ( _instrument_var._parameters.DIFFABS_DCM_theta * DEG2RAD )","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0462_DIFFABS_DCM_slit_out", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_DCM_slit_out_setpos */

/* component DIFFABS_M2_location=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_M2_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M2_location_setpos] component DIFFABS_M2_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_M2_location_var._name, "DIFFABS_M2_location", 16384);
  stracpy(_DIFFABS_M2_location_var._type, "Arm", 16384);
  _DIFFABS_M2_location_var._index=464;
  int current_setpos_index = 464;
  /* component DIFFABS_M2_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_arm_crystal2_var._rotation_absolute, _DIFFABS_M2_location_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_slit_out_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M2_location_var._rotation_absolute, tr1, _DIFFABS_M2_location_var._rotation_relative);
    _DIFFABS_M2_location_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M2_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.818);
    rot_transpose(_DIFFABS_arm_crystal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M2_location_var._position_absolute = coords_add(_DIFFABS_arm_crystal2_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_slit_out_var._position_absolute, _DIFFABS_M2_location_var._position_absolute);
    _DIFFABS_M2_location_var._position_relative = rot_apply(_DIFFABS_M2_location_var._rotation_absolute, tc1);
  } /* DIFFABS_M2_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M2_location", _DIFFABS_M2_location_var._position_absolute, _DIFFABS_M2_location_var._rotation_absolute);
  instrument->_position_absolute[464] = _DIFFABS_M2_location_var._position_absolute;
  instrument->_position_relative[464] = _DIFFABS_M2_location_var._position_relative;
    _DIFFABS_M2_location_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M2_location_var._position_relative);
  instrument->counter_N[464]  = instrument->counter_P[464] = instrument->counter_P2[464] = 0;
  instrument->counter_AbsorbProp[464]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0463_DIFFABS_M2_location", _DIFFABS_M2_location_var._position_absolute, _DIFFABS_M2_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M2_location_setpos */

/* component DIFFABS_M2_rotated=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_M2_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M2_rotated_setpos] component DIFFABS_M2_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_M2_rotated_var._name, "DIFFABS_M2_rotated", 16384);
  stracpy(_DIFFABS_M2_rotated_var._type, "Arm", 16384);
  _DIFFABS_M2_rotated_var._index=465;
  int current_setpos_index = 465;
  /* component DIFFABS_M2_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DIFFABS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M2_location_var._rotation_absolute, _DIFFABS_M2_rotated_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_slit_out_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M2_rotated_var._rotation_absolute, tr1, _DIFFABS_M2_rotated_var._rotation_relative);
    _DIFFABS_M2_rotated_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M2_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_M2_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M2_rotated_var._position_absolute = coords_add(_DIFFABS_M2_location_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_slit_out_var._position_absolute, _DIFFABS_M2_rotated_var._position_absolute);
    _DIFFABS_M2_rotated_var._position_relative = rot_apply(_DIFFABS_M2_rotated_var._rotation_absolute, tc1);
  } /* DIFFABS_M2_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M2_rotated", _DIFFABS_M2_rotated_var._position_absolute, _DIFFABS_M2_rotated_var._rotation_absolute);
  instrument->_position_absolute[465] = _DIFFABS_M2_rotated_var._position_absolute;
  instrument->_position_relative[465] = _DIFFABS_M2_rotated_var._position_relative;
    _DIFFABS_M2_rotated_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M2_rotated_var._position_relative);
  instrument->counter_N[465]  = instrument->counter_P[465] = instrument->counter_P2[465] = 0;
  instrument->counter_AbsorbProp[465]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0464_DIFFABS_M2_rotated", _DIFFABS_M2_rotated_var._position_absolute, _DIFFABS_M2_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M2_rotated_setpos */

/* component DIFFABS_M2=Mirror_curved() SETTING, POSITION/ROTATION */
int _DIFFABS_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M2_setpos] component DIFFABS_M2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_DIFFABS_M2_var._name, "DIFFABS_M2", 16384);
  stracpy(_DIFFABS_M2_var._type, "Mirror_curved", 16384);
  _DIFFABS_M2_var._index=466;
  int current_setpos_index = 466;
  _DIFFABS_M2_var._parameters.radius = _instrument_var._parameters.DIFFABS_M2_radius;
  _DIFFABS_M2_var._parameters.R0 = 1;
  if("Rh.txt" && strlen("Rh.txt"))
    stracpy(_DIFFABS_M2_var._parameters.coating, "Rh.txt" ? "Rh.txt" : "", 16384);
  else 
  _DIFFABS_M2_var._parameters.coating[0]='\0';
  _DIFFABS_M2_var._parameters.zdepth = 0.2;
  _DIFFABS_M2_var._parameters.yheight = 0.2;
  _DIFFABS_M2_var._parameters.length = 1.3;
  _DIFFABS_M2_var._parameters.width = .1;


  /* component DIFFABS_M2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M2_rotated_var._rotation_absolute, _DIFFABS_M2_var._rotation_absolute);
    rot_transpose(_DIFFABS_DCM_slit_out_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M2_var._rotation_absolute, tr1, _DIFFABS_M2_var._rotation_relative);
    _DIFFABS_M2_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M2_var._position_absolute = coords_add(_DIFFABS_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_DCM_slit_out_var._position_absolute, _DIFFABS_M2_var._position_absolute);
    _DIFFABS_M2_var._position_relative = rot_apply(_DIFFABS_M2_var._rotation_absolute, tc1);
  } /* DIFFABS_M2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M2", _DIFFABS_M2_var._position_absolute, _DIFFABS_M2_var._rotation_absolute);
  instrument->_position_absolute[466] = _DIFFABS_M2_var._position_absolute;
  instrument->_position_relative[466] = _DIFFABS_M2_var._position_relative;
    _DIFFABS_M2_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M2_var._position_relative);
  instrument->counter_N[466]  = instrument->counter_P[466] = instrument->counter_P2[466] = 0;
  instrument->counter_AbsorbProp[466]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0465_DIFFABS_M2", _DIFFABS_M2_var._position_absolute, _DIFFABS_M2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "radius", "1", "_instrument_var._parameters.DIFFABS_M2_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "coating", "Be.txt", "Rh.txt", "char*");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "length", "0", "1.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0465_DIFFABS_M2", "width", "0", ".1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M2_setpos */

/* component DIFFABS_M2_out=Arm() SETTING, POSITION/ROTATION */
int _DIFFABS_M2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_M2_out_setpos] component DIFFABS_M2_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_DIFFABS_M2_out_var._name, "DIFFABS_M2_out", 16384);
  stracpy(_DIFFABS_M2_out_var._type, "Arm", 16384);
  _DIFFABS_M2_out_var._index=467;
  int current_setpos_index = 467;
  /* component DIFFABS_M2_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.DIFFABS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M2_rotated_var._rotation_absolute, _DIFFABS_M2_out_var._rotation_absolute);
    rot_transpose(_DIFFABS_M2_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_M2_out_var._rotation_absolute, tr1, _DIFFABS_M2_out_var._rotation_relative);
    _DIFFABS_M2_out_var._rotation_is_identity =  rot_test_identity(_DIFFABS_M2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_M2_out_var._position_absolute = coords_add(_DIFFABS_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_M2_var._position_absolute, _DIFFABS_M2_out_var._position_absolute);
    _DIFFABS_M2_out_var._position_relative = rot_apply(_DIFFABS_M2_out_var._rotation_absolute, tc1);
  } /* DIFFABS_M2_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_M2_out", _DIFFABS_M2_out_var._position_absolute, _DIFFABS_M2_out_var._rotation_absolute);
  instrument->_position_absolute[467] = _DIFFABS_M2_out_var._position_absolute;
  instrument->_position_relative[467] = _DIFFABS_M2_out_var._position_relative;
    _DIFFABS_M2_out_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_M2_out_var._position_relative);
  instrument->counter_N[467]  = instrument->counter_P[467] = instrument->counter_P2[467] = 0;
  instrument->counter_AbsorbProp[467]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0466_DIFFABS_M2_out", _DIFFABS_M2_out_var._position_absolute, _DIFFABS_M2_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_M2_out_setpos */

/* component DIFFABS_sample_stage=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_sample_stage_setpos] component DIFFABS_sample_stage=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_sample_stage_var._name, "DIFFABS_sample_stage", 16384);
  stracpy(_DIFFABS_sample_stage_var._type, "Monitor_nD", 16384);
  _DIFFABS_sample_stage_var._index=468;
  int current_setpos_index = 468;
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_sample_stage_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.user9[0]='\0';
  _DIFFABS_sample_stage_var._parameters.xwidth = 5e-2;
  _DIFFABS_sample_stage_var._parameters.yheight = 5e-2;
  _DIFFABS_sample_stage_var._parameters.zdepth = 0;
  _DIFFABS_sample_stage_var._parameters.bins = 128;
  _DIFFABS_sample_stage_var._parameters.min = -1e40;
  _DIFFABS_sample_stage_var._parameters.max = 1e40;
  _DIFFABS_sample_stage_var._parameters.restore_xray = 1;
  _DIFFABS_sample_stage_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_DIFFABS_sample_stage_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.geometry[0]='\0';
  _DIFFABS_sample_stage_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_sample_stage_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_sample_stage_var._parameters.username9[0]='\0';


  /* component DIFFABS_sample_stage=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_M2_out_var._rotation_absolute, _DIFFABS_sample_stage_var._rotation_absolute);
    rot_transpose(_DIFFABS_M2_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_sample_stage_var._rotation_absolute, tr1, _DIFFABS_sample_stage_var._rotation_relative);
    _DIFFABS_sample_stage_var._rotation_is_identity =  rot_test_identity(_DIFFABS_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 12.17);
    rot_transpose(_DIFFABS_M2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_sample_stage_var._position_absolute = coords_add(_DIFFABS_M2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_M2_var._position_absolute, _DIFFABS_sample_stage_var._position_absolute);
    _DIFFABS_sample_stage_var._position_relative = rot_apply(_DIFFABS_sample_stage_var._rotation_absolute, tc1);
  } /* DIFFABS_sample_stage=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_sample_stage", _DIFFABS_sample_stage_var._position_absolute, _DIFFABS_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[468] = _DIFFABS_sample_stage_var._position_absolute;
  instrument->_position_relative[468] = _DIFFABS_sample_stage_var._position_relative;
    _DIFFABS_sample_stage_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_sample_stage_var._position_relative);
  instrument->counter_N[468]  = instrument->counter_P[468] = instrument->counter_P2[468] = 0;
  instrument->counter_AbsorbProp[468]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0467_DIFFABS_sample_stage", _DIFFABS_sample_stage_var._position_absolute, _DIFFABS_sample_stage_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "xwidth", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "yheight", "0", "5e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0467_DIFFABS_sample_stage", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_sample_stage_setpos */

/* component DIFFABS_fluo=FluoPowder() SETTING, POSITION/ROTATION */
int _DIFFABS_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_fluo_setpos] component DIFFABS_fluo=FluoPowder() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");
  stracpy(_DIFFABS_fluo_var._name, "DIFFABS_fluo", 16384);
  stracpy(_DIFFABS_fluo_var._type, "FluoPowder", 16384);
  _DIFFABS_fluo_var._index=469;
  int current_setpos_index = 469;
  _DIFFABS_fluo_var._parameters.geometry[0]='\0';
  _DIFFABS_fluo_var._parameters.radius = 0;
  _DIFFABS_fluo_var._parameters.thickness = 0;
  _DIFFABS_fluo_var._parameters.xwidth = 0.001;
  _DIFFABS_fluo_var._parameters.yheight = 0.01;
  _DIFFABS_fluo_var._parameters.zdepth = 5e-6;
  _DIFFABS_fluo_var._parameters.concentric = 0;
  if(_instrument_var._parameters.DIFFABS_sample && strlen(_instrument_var._parameters.DIFFABS_sample))
    stracpy(_DIFFABS_fluo_var._parameters.material, _instrument_var._parameters.DIFFABS_sample ? _instrument_var._parameters.DIFFABS_sample : "", 16384);
  else 
  _DIFFABS_fluo_var._parameters.material[0]='\0';
  _DIFFABS_fluo_var._parameters.packing_factor = 0;
  _DIFFABS_fluo_var._parameters.density = 0;
  _DIFFABS_fluo_var._parameters.weight = 0;
  _DIFFABS_fluo_var._parameters.p_interact = 1;
  _DIFFABS_fluo_var._parameters.target_x = 0;
  _DIFFABS_fluo_var._parameters.target_y = 0;
  _DIFFABS_fluo_var._parameters.target_z = 1;
  _DIFFABS_fluo_var._parameters.focus_r = 0;
  _DIFFABS_fluo_var._parameters.focus_xw = 0;
  _DIFFABS_fluo_var._parameters.focus_yh = 0;
  _DIFFABS_fluo_var._parameters.focus_aw = 180;
  _DIFFABS_fluo_var._parameters.focus_ah = 5;
  _DIFFABS_fluo_var._parameters.target_index = 0;
  _DIFFABS_fluo_var._parameters.flag_compton = 1;
  _DIFFABS_fluo_var._parameters.flag_rayleigh = 1;
  _DIFFABS_fluo_var._parameters.flag_lorentzian = 0;
  _DIFFABS_fluo_var._parameters.flag_powder = 1;
  _DIFFABS_fluo_var._parameters.flag_kissel = 0;
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_var._parameters.powder_refl, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_var._parameters.powder_refl[0]='\0';
  _DIFFABS_fluo_var._parameters.powder_format[0] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[1] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[2] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[3] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[4] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[5] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[6] = 0;
  _DIFFABS_fluo_var._parameters.powder_format[7] = 0;
  _DIFFABS_fluo_var._parameters.Vc = 0;
  _DIFFABS_fluo_var._parameters.delta_d_d = 0;
  _DIFFABS_fluo_var._parameters.DW = 0;
  _DIFFABS_fluo_var._parameters.d_phi = 5;
  _DIFFABS_fluo_var._parameters.nb_atoms = 1;
  _DIFFABS_fluo_var._parameters.barns = 1;
  _DIFFABS_fluo_var._parameters.tth_sign = 0;
  _DIFFABS_fluo_var._parameters.order = 1;


  /* component DIFFABS_fluo=FluoPowder() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_sample_stage_var._rotation_absolute, _DIFFABS_fluo_var._rotation_absolute);
    rot_transpose(_DIFFABS_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_fluo_var._rotation_absolute, tr1, _DIFFABS_fluo_var._rotation_relative);
    _DIFFABS_fluo_var._rotation_is_identity =  rot_test_identity(_DIFFABS_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_fluo_var._position_absolute = coords_add(_DIFFABS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_sample_stage_var._position_absolute, _DIFFABS_fluo_var._position_absolute);
    _DIFFABS_fluo_var._position_relative = rot_apply(_DIFFABS_fluo_var._rotation_absolute, tc1);
  } /* DIFFABS_fluo=FluoPowder() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_fluo", _DIFFABS_fluo_var._position_absolute, _DIFFABS_fluo_var._rotation_absolute);
  instrument->_position_absolute[469] = _DIFFABS_fluo_var._position_absolute;
  instrument->_position_relative[469] = _DIFFABS_fluo_var._position_relative;
    _DIFFABS_fluo_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_fluo_var._position_relative);
  instrument->counter_N[469]  = instrument->counter_P[469] = instrument->counter_P2[469] = 0;
  instrument->counter_AbsorbProp[469]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0468_DIFFABS_fluo", _DIFFABS_fluo_var._position_absolute, _DIFFABS_fluo_var._rotation_absolute, "FluoPowder");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "xwidth", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "zdepth", "0", "5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "material", "LaB6.cif", _instrument_var._parameters.DIFFABS_sample, "char*");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "p_interact", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "target_z", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "focus_aw", "0", "180","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "focus_ah", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "flag_powder", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "powder_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "powder_format", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "Vc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "delta_d_d", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "DW", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "d_phi", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "nb_atoms", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "tth_sign", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0468_DIFFABS_fluo", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_fluo_setpos */

/* component DIFFABS_fluo_monitor=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_fluo_monitor_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_fluo_monitor_setpos] component DIFFABS_fluo_monitor=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_fluo_monitor_var._name, "DIFFABS_fluo_monitor", 16384);
  stracpy(_DIFFABS_fluo_monitor_var._type, "Monitor_nD", 16384);
  _DIFFABS_fluo_monitor_var._index=470;
  int current_setpos_index = 470;
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.user9[0]='\0';
  _DIFFABS_fluo_monitor_var._parameters.xwidth = 0;
  _DIFFABS_fluo_monitor_var._parameters.yheight = 0;
  _DIFFABS_fluo_monitor_var._parameters.zdepth = 0;
  _DIFFABS_fluo_monitor_var._parameters.bins = 1024;
  _DIFFABS_fluo_monitor_var._parameters.min = 0;
  _DIFFABS_fluo_monitor_var._parameters.max = _instrument_var._parameters.DIFFABS_E0 * 1.2;
  _DIFFABS_fluo_monitor_var._parameters.restore_xray = 0;
  _DIFFABS_fluo_monitor_var._parameters.radius = 0.2;
  if("energy" && strlen("energy"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.geometry[0]='\0';
  _DIFFABS_fluo_monitor_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_fluo_monitor_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_fluo_monitor_var._parameters.username9[0]='\0';


  /* component DIFFABS_fluo_monitor=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_fluo_var._rotation_absolute, _DIFFABS_fluo_monitor_var._rotation_absolute);
    rot_transpose(_DIFFABS_fluo_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_fluo_monitor_var._rotation_absolute, tr1, _DIFFABS_fluo_monitor_var._rotation_relative);
    _DIFFABS_fluo_monitor_var._rotation_is_identity =  rot_test_identity(_DIFFABS_fluo_monitor_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_fluo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_fluo_monitor_var._position_absolute = coords_add(_DIFFABS_fluo_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_fluo_var._position_absolute, _DIFFABS_fluo_monitor_var._position_absolute);
    _DIFFABS_fluo_monitor_var._position_relative = rot_apply(_DIFFABS_fluo_monitor_var._rotation_absolute, tc1);
  } /* DIFFABS_fluo_monitor=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_fluo_monitor", _DIFFABS_fluo_monitor_var._position_absolute, _DIFFABS_fluo_monitor_var._rotation_absolute);
  instrument->_position_absolute[470] = _DIFFABS_fluo_monitor_var._position_absolute;
  instrument->_position_relative[470] = _DIFFABS_fluo_monitor_var._position_relative;
    _DIFFABS_fluo_monitor_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_fluo_monitor_var._position_relative);
  instrument->counter_N[470]  = instrument->counter_P[470] = instrument->counter_P2[470] = 0;
  instrument->counter_AbsorbProp[470]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", _DIFFABS_fluo_monitor_var._position_absolute, _DIFFABS_fluo_monitor_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "bins", "0", "1024","int");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "min", "-1e40", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "max", "1e40", "_instrument_var._parameters.DIFFABS_E0 * 1.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "radius", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0469_DIFFABS_fluo_monitor", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_fluo_monitor_setpos */

/* component DIFFABS_det_angle=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_det_angle_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_det_angle_setpos] component DIFFABS_det_angle=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_det_angle_var._name, "DIFFABS_det_angle", 16384);
  stracpy(_DIFFABS_det_angle_var._type, "Monitor_nD", 16384);
  _DIFFABS_det_angle_var._index=471;
  int current_setpos_index = 471;
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_det_angle_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.user9[0]='\0';
  _DIFFABS_det_angle_var._parameters.xwidth = 0;
  _DIFFABS_det_angle_var._parameters.yheight = 1e-2;
  _DIFFABS_det_angle_var._parameters.zdepth = 0;
  _DIFFABS_det_angle_var._parameters.bins = 10000;
  _DIFFABS_det_angle_var._parameters.min = -1e40;
  _DIFFABS_det_angle_var._parameters.max = 1e40;
  _DIFFABS_det_angle_var._parameters.restore_xray = 0;
  _DIFFABS_det_angle_var._parameters.radius = 0.6;
  if("abs theta limits=[2 90]" && strlen("abs theta limits=[2 90]"))
    stracpy(_DIFFABS_det_angle_var._parameters.options, "abs theta limits=[2 90]" ? "abs theta limits=[2 90]" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.geometry[0]='\0';
  _DIFFABS_det_angle_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_det_angle_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_det_angle_var._parameters.username9[0]='\0';


  /* component DIFFABS_det_angle=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_sample_stage_var._rotation_absolute, _DIFFABS_det_angle_var._rotation_absolute);
    rot_transpose(_DIFFABS_fluo_monitor_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_det_angle_var._rotation_absolute, tr1, _DIFFABS_det_angle_var._rotation_relative);
    _DIFFABS_det_angle_var._rotation_is_identity =  rot_test_identity(_DIFFABS_det_angle_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_det_angle_var._position_absolute = coords_add(_DIFFABS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_fluo_monitor_var._position_absolute, _DIFFABS_det_angle_var._position_absolute);
    _DIFFABS_det_angle_var._position_relative = rot_apply(_DIFFABS_det_angle_var._rotation_absolute, tc1);
  } /* DIFFABS_det_angle=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_det_angle", _DIFFABS_det_angle_var._position_absolute, _DIFFABS_det_angle_var._rotation_absolute);
  instrument->_position_absolute[471] = _DIFFABS_det_angle_var._position_absolute;
  instrument->_position_relative[471] = _DIFFABS_det_angle_var._position_relative;
    _DIFFABS_det_angle_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_det_angle_var._position_relative);
  instrument->counter_N[471]  = instrument->counter_P[471] = instrument->counter_P2[471] = 0;
  instrument->counter_AbsorbProp[471]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0470_DIFFABS_det_angle", _DIFFABS_det_angle_var._position_absolute, _DIFFABS_det_angle_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "bins", "0", "10000","int");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "radius", "0", "0.6","MCNUM");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "options", "NULL", "abs theta limits=[2 90]", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0470_DIFFABS_det_angle", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_det_angle_setpos */

/* component DIFFABS_xpad=Monitor_nD() SETTING, POSITION/ROTATION */
int _DIFFABS_xpad_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_DIFFABS_xpad_setpos] component DIFFABS_xpad=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_DIFFABS_xpad_var._name, "DIFFABS_xpad", 16384);
  stracpy(_DIFFABS_xpad_var._type, "Monitor_nD", 16384);
  _DIFFABS_xpad_var._index=472;
  int current_setpos_index = 472;
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_DIFFABS_xpad_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.user9[0]='\0';
  _DIFFABS_xpad_var._parameters.xwidth = 0;
  _DIFFABS_xpad_var._parameters.yheight = 0.05;
  _DIFFABS_xpad_var._parameters.zdepth = 0;
  _DIFFABS_xpad_var._parameters.bins = 0;
  _DIFFABS_xpad_var._parameters.min = -1e40;
  _DIFFABS_xpad_var._parameters.max = 1e40;
  _DIFFABS_xpad_var._parameters.restore_xray = 0;
  _DIFFABS_xpad_var._parameters.radius = .645;
  if("theta bins=512 limits=[-8 120], y bins=128" && strlen("theta bins=512 limits=[-8 120], y bins=128"))
    stracpy(_DIFFABS_xpad_var._parameters.options, "theta bins=512 limits=[-8 120], y bins=128" ? "theta bins=512 limits=[-8 120], y bins=128" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.geometry[0]='\0';
  _DIFFABS_xpad_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_DIFFABS_xpad_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _DIFFABS_xpad_var._parameters.username9[0]='\0';


  /* component DIFFABS_xpad=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_sample_stage_var._rotation_absolute, _DIFFABS_xpad_var._rotation_absolute);
    rot_transpose(_DIFFABS_det_angle_var._rotation_absolute, tr1);
    rot_mul(_DIFFABS_xpad_var._rotation_absolute, tr1, _DIFFABS_xpad_var._rotation_relative);
    _DIFFABS_xpad_var._rotation_is_identity =  rot_test_identity(_DIFFABS_xpad_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _DIFFABS_xpad_var._position_absolute = coords_add(_DIFFABS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_det_angle_var._position_absolute, _DIFFABS_xpad_var._position_absolute);
    _DIFFABS_xpad_var._position_relative = rot_apply(_DIFFABS_xpad_var._rotation_absolute, tc1);
  } /* DIFFABS_xpad=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("DIFFABS_xpad", _DIFFABS_xpad_var._position_absolute, _DIFFABS_xpad_var._rotation_absolute);
  instrument->_position_absolute[472] = _DIFFABS_xpad_var._position_absolute;
  instrument->_position_relative[472] = _DIFFABS_xpad_var._position_relative;
    _DIFFABS_xpad_var._position_relative_is_zero =  coords_test_zero(_DIFFABS_xpad_var._position_relative);
  instrument->counter_N[472]  = instrument->counter_P[472] = instrument->counter_P2[472] = 0;
  instrument->counter_AbsorbProp[472]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0471_DIFFABS_xpad", _DIFFABS_xpad_var._position_absolute, _DIFFABS_xpad_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "yheight", "0", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "radius", "0", ".645","MCNUM");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "options", "NULL", "theta bins=512 limits=[-8 120], y bins=128", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0471_DIFFABS_xpad", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _DIFFABS_xpad_setpos */

/* component beamdump_487=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_487_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_487_setpos] component beamdump_487=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_487_var._name, "beamdump_487", 16384);
  stracpy(_beamdump_487_var._type, "Beamstop", 16384);
  _beamdump_487_var._index=473;
  int current_setpos_index = 473;
  _beamdump_487_var._parameters.xmin = -0.05;
  _beamdump_487_var._parameters.xmax = 0.05;
  _beamdump_487_var._parameters.ymin = -0.05;
  _beamdump_487_var._parameters.ymax = 0.05;
  _beamdump_487_var._parameters.xwidth = 0;
  _beamdump_487_var._parameters.yheight = 0;
  _beamdump_487_var._parameters.radius = 0;

  /* component beamdump_487=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _DIFFABS_xpad_var._rotation_absolute, _beamdump_487_var._rotation_absolute);
    rot_transpose(_DIFFABS_xpad_var._rotation_absolute, tr1);
    rot_mul(_beamdump_487_var._rotation_absolute, tr1, _beamdump_487_var._rotation_relative);
    _beamdump_487_var._rotation_is_identity =  rot_test_identity(_beamdump_487_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_DIFFABS_xpad_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_487_var._position_absolute = coords_add(_DIFFABS_xpad_var._position_absolute, tc2);
    tc1 = coords_sub(_DIFFABS_xpad_var._position_absolute, _beamdump_487_var._position_absolute);
    _beamdump_487_var._position_relative = rot_apply(_beamdump_487_var._rotation_absolute, tc1);
  } /* beamdump_487=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_487", _beamdump_487_var._position_absolute, _beamdump_487_var._rotation_absolute);
  instrument->_position_absolute[473] = _beamdump_487_var._position_absolute;
  instrument->_position_relative[473] = _beamdump_487_var._position_relative;
    _beamdump_487_var._position_relative_is_zero =  coords_test_zero(_beamdump_487_var._position_relative);
  instrument->counter_N[473]  = instrument->counter_P[473] = instrument->counter_P2[473] = 0;
  instrument->counter_AbsorbProp[473]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0472_beamdump_487", _beamdump_487_var._position_absolute, _beamdump_487_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0472_beamdump_487", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_487_setpos */

/* component SEXTANTS=Text() SETTING, POSITION/ROTATION */
int _SEXTANTS_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SEXTANTS_setpos] component SEXTANTS=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_SEXTANTS_var._name, "SEXTANTS", 16384);
  stracpy(_SEXTANTS_var._type, "Text", 16384);
  _SEXTANTS_var._index=474;
  int current_setpos_index = 474;
  if("SEXTANTS" && strlen("SEXTANTS"))
    stracpy(_SEXTANTS_var._parameters.text, "SEXTANTS" ? "SEXTANTS" : "", 16384);
  else 
  _SEXTANTS_var._parameters.text[0]='\0';
  _SEXTANTS_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_SEXTANTS_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _SEXTANTS_var._parameters.plane[0]='\0';
  _SEXTANTS_var._parameters.pen_thickness = 0.1;


  /* component SEXTANTS=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-292.475)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _SEXTANTS_var._rotation_absolute);
    rot_transpose(_beamdump_487_var._rotation_absolute, tr1);
    rot_mul(_SEXTANTS_var._rotation_absolute, tr1, _SEXTANTS_var._rotation_relative);
    _SEXTANTS_var._rotation_is_identity =  rot_test_identity(_SEXTANTS_var._rotation_relative);
    tc1 = coords_set(
      21.537, 0, -52.061);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SEXTANTS_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_487_var._position_absolute, _SEXTANTS_var._position_absolute);
    _SEXTANTS_var._position_relative = rot_apply(_SEXTANTS_var._rotation_absolute, tc1);
  } /* SEXTANTS=Text() AT ROTATED */
  DEBUG_COMPONENT("SEXTANTS", _SEXTANTS_var._position_absolute, _SEXTANTS_var._rotation_absolute);
  instrument->_position_absolute[474] = _SEXTANTS_var._position_absolute;
  instrument->_position_relative[474] = _SEXTANTS_var._position_relative;
    _SEXTANTS_var._position_relative_is_zero =  coords_test_zero(_SEXTANTS_var._position_relative);
  instrument->counter_N[474]  = instrument->counter_P[474] = instrument->counter_P2[474] = 0;
  instrument->counter_AbsorbProp[474]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0473_SEXTANTS", _SEXTANTS_var._position_absolute, _SEXTANTS_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0473_SEXTANTS", "text", "NONE", "SEXTANTS", "char*");
        mccomp_param_nexus(nxhandle,"0473_SEXTANTS", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0473_SEXTANTS", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0473_SEXTANTS", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SEXTANTS_setpos */

/* component SIXS_pos=Text() SETTING, POSITION/ROTATION */
int _SIXS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_pos_setpos] component SIXS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_SIXS_pos_var._name, "SIXS_pos", 16384);
  stracpy(_SIXS_pos_var._type, "Text", 16384);
  _SIXS_pos_var._index=475;
  int current_setpos_index = 475;
  if("SIXS" && strlen("SIXS"))
    stracpy(_SIXS_pos_var._parameters.text, "SIXS" ? "SIXS" : "", 16384);
  else 
  _SIXS_pos_var._parameters.text[0]='\0';
  _SIXS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_SIXS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _SIXS_pos_var._parameters.plane[0]='\0';
  _SIXS_pos_var._parameters.pen_thickness = 0.1;


  /* component SIXS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-303.864)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _SIXS_pos_var._rotation_absolute);
    rot_transpose(_SEXTANTS_var._rotation_absolute, tr1);
    rot_mul(_SIXS_pos_var._rotation_absolute, tr1, _SIXS_pos_var._rotation_relative);
    _SIXS_pos_var._rotation_is_identity =  rot_test_identity(_SIXS_pos_var._rotation_relative);
    tc1 = coords_set(
      31.394, 0, -46.782);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_SEXTANTS_var._position_absolute, _SIXS_pos_var._position_absolute);
    _SIXS_pos_var._position_relative = rot_apply(_SIXS_pos_var._rotation_absolute, tc1);
  } /* SIXS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("SIXS_pos", _SIXS_pos_var._position_absolute, _SIXS_pos_var._rotation_absolute);
  instrument->_position_absolute[475] = _SIXS_pos_var._position_absolute;
  instrument->_position_relative[475] = _SIXS_pos_var._position_relative;
    _SIXS_pos_var._position_relative_is_zero =  coords_test_zero(_SIXS_pos_var._position_relative);
  instrument->counter_N[475]  = instrument->counter_P[475] = instrument->counter_P2[475] = 0;
  instrument->counter_AbsorbProp[475]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0474_SIXS_pos", _SIXS_pos_var._position_absolute, _SIXS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0474_SIXS_pos", "text", "NONE", "SIXS", "char*");
        mccomp_param_nexus(nxhandle,"0474_SIXS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0474_SIXS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0474_SIXS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_pos_setpos */

/* component SIXS=Arm() SETTING, POSITION/ROTATION */
int _SIXS_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_setpos] component SIXS=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_var._name, "SIXS", 16384);
  stracpy(_SIXS_var._type, "Arm", 16384);
  _SIXS_var._index=476;
  int current_setpos_index = 476;
  /* component SIXS=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_pos_var._rotation_absolute, _SIXS_var._rotation_absolute);
    rot_transpose(_SIXS_pos_var._rotation_absolute, tr1);
    rot_mul(_SIXS_var._rotation_absolute, tr1, _SIXS_var._rotation_relative);
    _SIXS_var._rotation_is_identity =  rot_test_identity(_SIXS_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_var._position_absolute = coords_add(_SIXS_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_pos_var._position_absolute, _SIXS_var._position_absolute);
    _SIXS_var._position_relative = rot_apply(_SIXS_var._rotation_absolute, tc1);
  } /* SIXS=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS", _SIXS_var._position_absolute, _SIXS_var._rotation_absolute);
  instrument->_position_absolute[476] = _SIXS_var._position_absolute;
  instrument->_position_relative[476] = _SIXS_var._position_relative;
    _SIXS_var._position_relative_is_zero =  coords_test_zero(_SIXS_var._position_relative);
  instrument->counter_N[476]  = instrument->counter_P[476] = instrument->counter_P2[476] = 0;
  instrument->counter_AbsorbProp[476]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0475_SIXS", _SIXS_var._position_absolute, _SIXS_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_setpos */

/* component SIXS_Source_U20=Undulator() SETTING, POSITION/ROTATION */
int _SIXS_Source_U20_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_Source_U20_setpos] component SIXS_Source_U20=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_SIXS_Source_U20_var._name, "SIXS_Source_U20", 16384);
  stracpy(_SIXS_Source_U20_var._type, "Undulator", 16384);
  _SIXS_Source_U20_var._index=477;
  int current_setpos_index = 477;
  _SIXS_Source_U20_var._parameters.E0 = _instrument_var._parameters.SIXS_E0;
  _SIXS_Source_U20_var._parameters.dE = _instrument_var._parameters.SIXS_dE;
  _SIXS_Source_U20_var._parameters.phase = 0;
  _SIXS_Source_U20_var._parameters.randomphase = 1;
  _SIXS_Source_U20_var._parameters.Ee = 2.75;
  _SIXS_Source_U20_var._parameters.dEe = 0;
  _SIXS_Source_U20_var._parameters.Ie = 0.5;
  _SIXS_Source_U20_var._parameters.B = 0;
  _SIXS_Source_U20_var._parameters.K = 5;
  _SIXS_Source_U20_var._parameters.Nper = 1;
  _SIXS_Source_U20_var._parameters.lu = 16e-3;
  _SIXS_Source_U20_var._parameters.sigey = 8.1e-6;
  _SIXS_Source_U20_var._parameters.sigex = 388e-6;
  _SIXS_Source_U20_var._parameters.sigepx = 14.5e-6;
  _SIXS_Source_U20_var._parameters.sigepy = 4.61e-6;
  _SIXS_Source_U20_var._parameters.focus_xw = 0;
  _SIXS_Source_U20_var._parameters.focus_yh = 0;
  _SIXS_Source_U20_var._parameters.dist = 1;
  _SIXS_Source_U20_var._parameters.quick_integ = 0;
  _SIXS_Source_U20_var._parameters.E1st = 0;
  _SIXS_Source_U20_var._parameters.verbose = 0;
  _SIXS_Source_U20_var._parameters.Br = 1.35;


  /* component SIXS_Source_U20=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_var._rotation_absolute, _SIXS_Source_U20_var._rotation_absolute);
    rot_transpose(_SIXS_var._rotation_absolute, tr1);
    rot_mul(_SIXS_Source_U20_var._rotation_absolute, tr1, _SIXS_Source_U20_var._rotation_relative);
    _SIXS_Source_U20_var._rotation_is_identity =  rot_test_identity(_SIXS_Source_U20_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_Source_U20_var._position_absolute = coords_add(_SIXS_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_var._position_absolute, _SIXS_Source_U20_var._position_absolute);
    _SIXS_Source_U20_var._position_relative = rot_apply(_SIXS_Source_U20_var._rotation_absolute, tc1);
  } /* SIXS_Source_U20=Undulator() AT ROTATED */
  DEBUG_COMPONENT("SIXS_Source_U20", _SIXS_Source_U20_var._position_absolute, _SIXS_Source_U20_var._rotation_absolute);
  instrument->_position_absolute[477] = _SIXS_Source_U20_var._position_absolute;
  instrument->_position_relative[477] = _SIXS_Source_U20_var._position_relative;
    _SIXS_Source_U20_var._position_relative_is_zero =  coords_test_zero(_SIXS_Source_U20_var._position_relative);
  instrument->counter_N[477]  = instrument->counter_P[477] = instrument->counter_P2[477] = 0;
  instrument->counter_AbsorbProp[477]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0476_SIXS_Source_U20", _SIXS_Source_U20_var._position_absolute, _SIXS_Source_U20_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "E0", "0", "_instrument_var._parameters.SIXS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "dE", "0", "_instrument_var._parameters.SIXS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "dEe", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "K", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "Nper", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "lu", "16e-3", "16e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "sigey", "0", "8.1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "sigex", "0", "388e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "sigepx", "0", "14.5e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "sigepy", "0", "4.61e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0476_SIXS_Source_U20", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_Source_U20_setpos */

/* component SIXS_mon_src_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_mon_src_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_mon_src_xy_setpos] component SIXS_mon_src_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_mon_src_xy_var._name, "SIXS_mon_src_xy", 16384);
  stracpy(_SIXS_mon_src_xy_var._type, "Monitor_nD", 16384);
  _SIXS_mon_src_xy_var._index=478;
  int current_setpos_index = 478;
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.user9[0]='\0';
  _SIXS_mon_src_xy_var._parameters.xwidth = 2e-3;
  _SIXS_mon_src_xy_var._parameters.yheight = 2e-3;
  _SIXS_mon_src_xy_var._parameters.zdepth = 0;
  _SIXS_mon_src_xy_var._parameters.bins = 128;
  _SIXS_mon_src_xy_var._parameters.min = -1e40;
  _SIXS_mon_src_xy_var._parameters.max = 1e40;
  _SIXS_mon_src_xy_var._parameters.restore_xray = 0;
  _SIXS_mon_src_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIXS_mon_src_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.geometry[0]='\0';
  _SIXS_mon_src_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_xy_var._parameters.username9[0]='\0';


  /* component SIXS_mon_src_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_Source_U20_var._rotation_absolute, _SIXS_mon_src_xy_var._rotation_absolute);
    rot_transpose(_SIXS_Source_U20_var._rotation_absolute, tr1);
    rot_mul(_SIXS_mon_src_xy_var._rotation_absolute, tr1, _SIXS_mon_src_xy_var._rotation_relative);
    _SIXS_mon_src_xy_var._rotation_is_identity =  rot_test_identity(_SIXS_mon_src_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 14.9);
    rot_transpose(_SIXS_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_mon_src_xy_var._position_absolute = coords_add(_SIXS_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_Source_U20_var._position_absolute, _SIXS_mon_src_xy_var._position_absolute);
    _SIXS_mon_src_xy_var._position_relative = rot_apply(_SIXS_mon_src_xy_var._rotation_absolute, tc1);
  } /* SIXS_mon_src_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_mon_src_xy", _SIXS_mon_src_xy_var._position_absolute, _SIXS_mon_src_xy_var._rotation_absolute);
  instrument->_position_absolute[478] = _SIXS_mon_src_xy_var._position_absolute;
  instrument->_position_relative[478] = _SIXS_mon_src_xy_var._position_relative;
    _SIXS_mon_src_xy_var._position_relative_is_zero =  coords_test_zero(_SIXS_mon_src_xy_var._position_relative);
  instrument->counter_N[478]  = instrument->counter_P[478] = instrument->counter_P2[478] = 0;
  instrument->counter_AbsorbProp[478]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0477_SIXS_mon_src_xy", _SIXS_mon_src_xy_var._position_absolute, _SIXS_mon_src_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0477_SIXS_mon_src_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_mon_src_xy_setpos */

/* component SIXS_mon_src_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_mon_src_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_mon_src_e_setpos] component SIXS_mon_src_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_mon_src_e_var._name, "SIXS_mon_src_e", 16384);
  stracpy(_SIXS_mon_src_e_var._type, "Monitor_nD", 16384);
  _SIXS_mon_src_e_var._index=479;
  int current_setpos_index = 479;
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_src_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.user9[0]='\0';
  _SIXS_mon_src_e_var._parameters.xwidth = 2e-3;
  _SIXS_mon_src_e_var._parameters.yheight = 2e-3;
  _SIXS_mon_src_e_var._parameters.zdepth = 0;
  _SIXS_mon_src_e_var._parameters.bins = 128;
  _SIXS_mon_src_e_var._parameters.min = _instrument_var._parameters.SIXS_E0 - _instrument_var._parameters.SIXS_dE * 1.1;
  _SIXS_mon_src_e_var._parameters.max = _instrument_var._parameters.SIXS_E0 + _instrument_var._parameters.SIXS_dE * 1.1;
  _SIXS_mon_src_e_var._parameters.restore_xray = 0;
  _SIXS_mon_src_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_SIXS_mon_src_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.geometry[0]='\0';
  _SIXS_mon_src_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_src_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_src_e_var._parameters.username9[0]='\0';


  /* component SIXS_mon_src_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_mon_src_xy_var._rotation_absolute, _SIXS_mon_src_e_var._rotation_absolute);
    rot_transpose(_SIXS_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_SIXS_mon_src_e_var._rotation_absolute, tr1, _SIXS_mon_src_e_var._rotation_relative);
    _SIXS_mon_src_e_var._rotation_is_identity =  rot_test_identity(_SIXS_mon_src_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_mon_src_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_mon_src_e_var._position_absolute = coords_add(_SIXS_mon_src_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_mon_src_xy_var._position_absolute, _SIXS_mon_src_e_var._position_absolute);
    _SIXS_mon_src_e_var._position_relative = rot_apply(_SIXS_mon_src_e_var._rotation_absolute, tc1);
  } /* SIXS_mon_src_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_mon_src_e", _SIXS_mon_src_e_var._position_absolute, _SIXS_mon_src_e_var._rotation_absolute);
  instrument->_position_absolute[479] = _SIXS_mon_src_e_var._position_absolute;
  instrument->_position_relative[479] = _SIXS_mon_src_e_var._position_relative;
    _SIXS_mon_src_e_var._position_relative_is_zero =  coords_test_zero(_SIXS_mon_src_e_var._position_relative);
  instrument->counter_N[479]  = instrument->counter_P[479] = instrument->counter_P2[479] = 0;
  instrument->counter_AbsorbProp[479]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0478_SIXS_mon_src_e", _SIXS_mon_src_e_var._position_absolute, _SIXS_mon_src_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "min", "-1e40", "_instrument_var._parameters.SIXS_E0 - _instrument_var._parameters.SIXS_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "max", "1e40", "_instrument_var._parameters.SIXS_E0 + _instrument_var._parameters.SIXS_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0478_SIXS_mon_src_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_mon_src_e_setpos */

/* component SIXS_slit=Slit() SETTING, POSITION/ROTATION */
int _SIXS_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_slit_setpos] component SIXS_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_SIXS_slit_var._name, "SIXS_slit", 16384);
  stracpy(_SIXS_slit_var._type, "Slit", 16384);
  _SIXS_slit_var._index=480;
  int current_setpos_index = 480;
  _SIXS_slit_var._parameters.xmin = 0;
  _SIXS_slit_var._parameters.xmax = 0;
  _SIXS_slit_var._parameters.ymin = 0;
  _SIXS_slit_var._parameters.ymax = 0;
  _SIXS_slit_var._parameters.radius = 0;
  _SIXS_slit_var._parameters.xwidth = 2e-3;
  _SIXS_slit_var._parameters.yheight = 0.7e-3;
  _SIXS_slit_var._parameters.dist = 0;
  _SIXS_slit_var._parameters.focus_xw = 0;
  _SIXS_slit_var._parameters.focus_yh = 0;
  _SIXS_slit_var._parameters.focus_x0 = 0;
  _SIXS_slit_var._parameters.focus_y0 = 0;

  /* component SIXS_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_mon_src_e_var._rotation_absolute, _SIXS_slit_var._rotation_absolute);
    rot_transpose(_SIXS_mon_src_e_var._rotation_absolute, tr1);
    rot_mul(_SIXS_slit_var._rotation_absolute, tr1, _SIXS_slit_var._rotation_relative);
    _SIXS_slit_var._rotation_is_identity =  rot_test_identity(_SIXS_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_SIXS_mon_src_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_slit_var._position_absolute = coords_add(_SIXS_mon_src_e_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_mon_src_e_var._position_absolute, _SIXS_slit_var._position_absolute);
    _SIXS_slit_var._position_relative = rot_apply(_SIXS_slit_var._rotation_absolute, tc1);
  } /* SIXS_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("SIXS_slit", _SIXS_slit_var._position_absolute, _SIXS_slit_var._rotation_absolute);
  instrument->_position_absolute[480] = _SIXS_slit_var._position_absolute;
  instrument->_position_relative[480] = _SIXS_slit_var._position_relative;
    _SIXS_slit_var._position_relative_is_zero =  coords_test_zero(_SIXS_slit_var._position_relative);
  instrument->counter_N[480]  = instrument->counter_P[480] = instrument->counter_P2[480] = 0;
  instrument->counter_AbsorbProp[480]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0479_SIXS_slit", _SIXS_slit_var._position_absolute, _SIXS_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "xwidth", "0.001", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "yheight", "0.001", "0.7e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0479_SIXS_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_slit_setpos */

/* component SIXS_slit_mon_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_slit_mon_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_slit_mon_xy_setpos] component SIXS_slit_mon_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_slit_mon_xy_var._name, "SIXS_slit_mon_xy", 16384);
  stracpy(_SIXS_slit_mon_xy_var._type, "Monitor_nD", 16384);
  _SIXS_slit_mon_xy_var._index=481;
  int current_setpos_index = 481;
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_slit_mon_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.user9[0]='\0';
  _SIXS_slit_mon_xy_var._parameters.xwidth = 2e-3;
  _SIXS_slit_mon_xy_var._parameters.yheight = 2e-3;
  _SIXS_slit_mon_xy_var._parameters.zdepth = 0;
  _SIXS_slit_mon_xy_var._parameters.bins = 128;
  _SIXS_slit_mon_xy_var._parameters.min = -1e40;
  _SIXS_slit_mon_xy_var._parameters.max = 1e40;
  _SIXS_slit_mon_xy_var._parameters.restore_xray = 0;
  _SIXS_slit_mon_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.geometry[0]='\0';
  _SIXS_slit_mon_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_slit_mon_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_slit_mon_xy_var._parameters.username9[0]='\0';


  /* component SIXS_slit_mon_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_slit_var._rotation_absolute, _SIXS_slit_mon_xy_var._rotation_absolute);
    rot_transpose(_SIXS_slit_var._rotation_absolute, tr1);
    rot_mul(_SIXS_slit_mon_xy_var._rotation_absolute, tr1, _SIXS_slit_mon_xy_var._rotation_relative);
    _SIXS_slit_mon_xy_var._rotation_is_identity =  rot_test_identity(_SIXS_slit_mon_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_slit_mon_xy_var._position_absolute = coords_add(_SIXS_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_slit_var._position_absolute, _SIXS_slit_mon_xy_var._position_absolute);
    _SIXS_slit_mon_xy_var._position_relative = rot_apply(_SIXS_slit_mon_xy_var._rotation_absolute, tc1);
  } /* SIXS_slit_mon_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_slit_mon_xy", _SIXS_slit_mon_xy_var._position_absolute, _SIXS_slit_mon_xy_var._rotation_absolute);
  instrument->_position_absolute[481] = _SIXS_slit_mon_xy_var._position_absolute;
  instrument->_position_relative[481] = _SIXS_slit_mon_xy_var._position_relative;
    _SIXS_slit_mon_xy_var._position_relative_is_zero =  coords_test_zero(_SIXS_slit_mon_xy_var._position_relative);
  instrument->counter_N[481]  = instrument->counter_P[481] = instrument->counter_P2[481] = 0;
  instrument->counter_AbsorbProp[481]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0480_SIXS_slit_mon_xy", _SIXS_slit_mon_xy_var._position_absolute, _SIXS_slit_mon_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0480_SIXS_slit_mon_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_slit_mon_xy_setpos */

/* component SIXS_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _SIXS_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_DCM_location_setpos] component SIXS_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_DCM_location_var._name, "SIXS_DCM_location", 16384);
  stracpy(_SIXS_DCM_location_var._type, "Arm", 16384);
  _SIXS_DCM_location_var._index=482;
  int current_setpos_index = 482;
  /* component SIXS_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_Source_U20_var._rotation_absolute, _SIXS_DCM_location_var._rotation_absolute);
    rot_transpose(_SIXS_slit_mon_xy_var._rotation_absolute, tr1);
    rot_mul(_SIXS_DCM_location_var._rotation_absolute, tr1, _SIXS_DCM_location_var._rotation_relative);
    _SIXS_DCM_location_var._rotation_is_identity =  rot_test_identity(_SIXS_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 16.5);
    rot_transpose(_SIXS_Source_U20_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_DCM_location_var._position_absolute = coords_add(_SIXS_Source_U20_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_slit_mon_xy_var._position_absolute, _SIXS_DCM_location_var._position_absolute);
    _SIXS_DCM_location_var._position_relative = rot_apply(_SIXS_DCM_location_var._rotation_absolute, tc1);
  } /* SIXS_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_DCM_location", _SIXS_DCM_location_var._position_absolute, _SIXS_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[482] = _SIXS_DCM_location_var._position_absolute;
  instrument->_position_relative[482] = _SIXS_DCM_location_var._position_relative;
    _SIXS_DCM_location_var._position_relative_is_zero =  coords_test_zero(_SIXS_DCM_location_var._position_relative);
  instrument->counter_N[482]  = instrument->counter_P[482] = instrument->counter_P2[482] = 0;
  instrument->counter_AbsorbProp[482]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0481_SIXS_DCM_location", _SIXS_DCM_location_var._position_absolute, _SIXS_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_DCM_location_setpos */

/* component SIXS_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SIXS_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_dcm_xtal0_setpos] component SIXS_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SIXS_dcm_xtal0_var._name, "SIXS_dcm_xtal0", 16384);
  stracpy(_SIXS_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _SIXS_dcm_xtal0_var._index=483;
  int current_setpos_index = 483;
  _SIXS_dcm_xtal0_var._parameters.length = 0.04;
  _SIXS_dcm_xtal0_var._parameters.width = 0.04;
  _SIXS_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SIXS_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SIXS_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SIXS_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SIXS_dcm_xtal0_var._parameters.material[0]='\0';
  _SIXS_dcm_xtal0_var._parameters.alpha = 0.0;
  _SIXS_dcm_xtal0_var._parameters.R0 = 0;
  _SIXS_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _SIXS_dcm_xtal0_var._parameters.crystal_type = 1;
  _SIXS_dcm_xtal0_var._parameters.h = 1;
  _SIXS_dcm_xtal0_var._parameters.k = 1;
  _SIXS_dcm_xtal0_var._parameters.l = 1;
  _SIXS_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _SIXS_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component SIXS_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIXS_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_DCM_location_var._rotation_absolute, _SIXS_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_SIXS_slit_mon_xy_var._rotation_absolute, tr1);
    rot_mul(_SIXS_dcm_xtal0_var._rotation_absolute, tr1, _SIXS_dcm_xtal0_var._rotation_relative);
    _SIXS_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_SIXS_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_dcm_xtal0_var._position_absolute = coords_add(_SIXS_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_slit_mon_xy_var._position_absolute, _SIXS_dcm_xtal0_var._position_absolute);
    _SIXS_dcm_xtal0_var._position_relative = rot_apply(_SIXS_dcm_xtal0_var._rotation_absolute, tc1);
  } /* SIXS_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SIXS_dcm_xtal0", _SIXS_dcm_xtal0_var._position_absolute, _SIXS_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[483] = _SIXS_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[483] = _SIXS_dcm_xtal0_var._position_relative;
    _SIXS_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_SIXS_dcm_xtal0_var._position_relative);
  instrument->counter_N[483]  = instrument->counter_P[483] = instrument->counter_P2[483] = 0;
  instrument->counter_AbsorbProp[483]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0482_SIXS_dcm_xtal0", _SIXS_dcm_xtal0_var._position_absolute, _SIXS_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0482_SIXS_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_dcm_xtal0_setpos */

/* component SIXS_dcm0=Arm() SETTING, POSITION/ROTATION */
int _SIXS_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_dcm0_setpos] component SIXS_dcm0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_dcm0_var._name, "SIXS_dcm0", 16384);
  stracpy(_SIXS_dcm0_var._type, "Arm", 16384);
  _SIXS_dcm0_var._index=484;
  int current_setpos_index = 484;
  /* component SIXS_dcm0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIXS_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_dcm_xtal0_var._rotation_absolute, _SIXS_dcm0_var._rotation_absolute);
    rot_transpose(_SIXS_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_SIXS_dcm0_var._rotation_absolute, tr1, _SIXS_dcm0_var._rotation_relative);
    _SIXS_dcm0_var._rotation_is_identity =  rot_test_identity(_SIXS_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_dcm0_var._position_absolute = coords_add(_SIXS_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_dcm_xtal0_var._position_absolute, _SIXS_dcm0_var._position_absolute);
    _SIXS_dcm0_var._position_relative = rot_apply(_SIXS_dcm0_var._rotation_absolute, tc1);
  } /* SIXS_dcm0=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_dcm0", _SIXS_dcm0_var._position_absolute, _SIXS_dcm0_var._rotation_absolute);
  instrument->_position_absolute[484] = _SIXS_dcm0_var._position_absolute;
  instrument->_position_relative[484] = _SIXS_dcm0_var._position_relative;
    _SIXS_dcm0_var._position_relative_is_zero =  coords_test_zero(_SIXS_dcm0_var._position_relative);
  instrument->counter_N[484]  = instrument->counter_P[484] = instrument->counter_P2[484] = 0;
  instrument->counter_AbsorbProp[484]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0483_SIXS_dcm0", _SIXS_dcm0_var._position_absolute, _SIXS_dcm0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_dcm0_setpos */

/* component SIXS_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SIXS_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_dcm_xtal1_setpos] component SIXS_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SIXS_dcm_xtal1_var._name, "SIXS_dcm_xtal1", 16384);
  stracpy(_SIXS_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _SIXS_dcm_xtal1_var._index=485;
  int current_setpos_index = 485;
  _SIXS_dcm_xtal1_var._parameters.length = 0.04;
  _SIXS_dcm_xtal1_var._parameters.width = 0.04;
  _SIXS_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SIXS_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SIXS_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SIXS_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SIXS_dcm_xtal1_var._parameters.material[0]='\0';
  _SIXS_dcm_xtal1_var._parameters.alpha = 0.0;
  _SIXS_dcm_xtal1_var._parameters.R0 = 0;
  _SIXS_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _SIXS_dcm_xtal1_var._parameters.crystal_type = 1;
  _SIXS_dcm_xtal1_var._parameters.h = 1;
  _SIXS_dcm_xtal1_var._parameters.k = 1;
  _SIXS_dcm_xtal1_var._parameters.l = 1;
  _SIXS_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _SIXS_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component SIXS_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SIXS_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_dcm0_var._rotation_absolute, _SIXS_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_SIXS_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_SIXS_dcm_xtal1_var._rotation_absolute, tr1, _SIXS_dcm_xtal1_var._rotation_relative);
    _SIXS_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_SIXS_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, SIXS_dcm_gap, _instrument_var._parameters.SIXS_dcm_theta ? SIXS_dcm_gap / tan ( _instrument_var._parameters.SIXS_dcm_theta * DEG2RAD ) : 0);
    rot_transpose(_SIXS_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_dcm_xtal1_var._position_absolute = coords_add(_SIXS_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_dcm_xtal0_var._position_absolute, _SIXS_dcm_xtal1_var._position_absolute);
    _SIXS_dcm_xtal1_var._position_relative = rot_apply(_SIXS_dcm_xtal1_var._rotation_absolute, tc1);
  } /* SIXS_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SIXS_dcm_xtal1", _SIXS_dcm_xtal1_var._position_absolute, _SIXS_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[485] = _SIXS_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[485] = _SIXS_dcm_xtal1_var._position_relative;
    _SIXS_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_SIXS_dcm_xtal1_var._position_relative);
  instrument->counter_N[485]  = instrument->counter_P[485] = instrument->counter_P2[485] = 0;
  instrument->counter_AbsorbProp[485]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0484_SIXS_dcm_xtal1", _SIXS_dcm_xtal1_var._position_absolute, _SIXS_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0484_SIXS_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_dcm_xtal1_setpos */

/* component SIXS_dcm1=Arm() SETTING, POSITION/ROTATION */
int _SIXS_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_dcm1_setpos] component SIXS_dcm1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_dcm1_var._name, "SIXS_dcm1", 16384);
  stracpy(_SIXS_dcm1_var._type, "Arm", 16384);
  _SIXS_dcm1_var._index=486;
  int current_setpos_index = 486;
  /* component SIXS_dcm1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SIXS_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_dcm_xtal1_var._rotation_absolute, _SIXS_dcm1_var._rotation_absolute);
    rot_transpose(_SIXS_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_SIXS_dcm1_var._rotation_absolute, tr1, _SIXS_dcm1_var._rotation_relative);
    _SIXS_dcm1_var._rotation_is_identity =  rot_test_identity(_SIXS_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_dcm1_var._position_absolute = coords_add(_SIXS_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_dcm_xtal1_var._position_absolute, _SIXS_dcm1_var._position_absolute);
    _SIXS_dcm1_var._position_relative = rot_apply(_SIXS_dcm1_var._rotation_absolute, tc1);
  } /* SIXS_dcm1=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_dcm1", _SIXS_dcm1_var._position_absolute, _SIXS_dcm1_var._rotation_absolute);
  instrument->_position_absolute[486] = _SIXS_dcm1_var._position_absolute;
  instrument->_position_relative[486] = _SIXS_dcm1_var._position_relative;
    _SIXS_dcm1_var._position_relative_is_zero =  coords_test_zero(_SIXS_dcm1_var._position_relative);
  instrument->counter_N[486]  = instrument->counter_P[486] = instrument->counter_P2[486] = 0;
  instrument->counter_AbsorbProp[486]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0485_SIXS_dcm1", _SIXS_dcm1_var._position_absolute, _SIXS_dcm1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_dcm1_setpos */

/* component SIXS_mon_dcm_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_mon_dcm_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_mon_dcm_e_setpos] component SIXS_mon_dcm_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_mon_dcm_e_var._name, "SIXS_mon_dcm_e", 16384);
  stracpy(_SIXS_mon_dcm_e_var._type, "Monitor_nD", 16384);
  _SIXS_mon_dcm_e_var._index=487;
  int current_setpos_index = 487;
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.user9[0]='\0';
  _SIXS_mon_dcm_e_var._parameters.xwidth = 2e-3;
  _SIXS_mon_dcm_e_var._parameters.yheight = 2e-3;
  _SIXS_mon_dcm_e_var._parameters.zdepth = 0;
  _SIXS_mon_dcm_e_var._parameters.bins = 128;
  _SIXS_mon_dcm_e_var._parameters.min = _instrument_var._parameters.SIXS_E0 - _instrument_var._parameters.SIXS_dE * 1.1;
  _SIXS_mon_dcm_e_var._parameters.max = _instrument_var._parameters.SIXS_E0 + _instrument_var._parameters.SIXS_dE * 1.1;
  _SIXS_mon_dcm_e_var._parameters.restore_xray = 0;
  _SIXS_mon_dcm_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.geometry[0]='\0';
  _SIXS_mon_dcm_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_e_var._parameters.username9[0]='\0';


  /* component SIXS_mon_dcm_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_dcm1_var._rotation_absolute, _SIXS_mon_dcm_e_var._rotation_absolute);
    rot_transpose(_SIXS_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_SIXS_mon_dcm_e_var._rotation_absolute, tr1, _SIXS_mon_dcm_e_var._rotation_relative);
    _SIXS_mon_dcm_e_var._rotation_is_identity =  rot_test_identity(_SIXS_mon_dcm_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_SIXS_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_mon_dcm_e_var._position_absolute = coords_add(_SIXS_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_dcm_xtal1_var._position_absolute, _SIXS_mon_dcm_e_var._position_absolute);
    _SIXS_mon_dcm_e_var._position_relative = rot_apply(_SIXS_mon_dcm_e_var._rotation_absolute, tc1);
  } /* SIXS_mon_dcm_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_mon_dcm_e", _SIXS_mon_dcm_e_var._position_absolute, _SIXS_mon_dcm_e_var._rotation_absolute);
  instrument->_position_absolute[487] = _SIXS_mon_dcm_e_var._position_absolute;
  instrument->_position_relative[487] = _SIXS_mon_dcm_e_var._position_relative;
    _SIXS_mon_dcm_e_var._position_relative_is_zero =  coords_test_zero(_SIXS_mon_dcm_e_var._position_relative);
  instrument->counter_N[487]  = instrument->counter_P[487] = instrument->counter_P2[487] = 0;
  instrument->counter_AbsorbProp[487]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0486_SIXS_mon_dcm_e", _SIXS_mon_dcm_e_var._position_absolute, _SIXS_mon_dcm_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "min", "-1e40", "_instrument_var._parameters.SIXS_E0 - _instrument_var._parameters.SIXS_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "max", "1e40", "_instrument_var._parameters.SIXS_E0 + _instrument_var._parameters.SIXS_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0486_SIXS_mon_dcm_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_mon_dcm_e_setpos */

/* component SIXS_mon_dcm_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_mon_dcm_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_mon_dcm_xy_setpos] component SIXS_mon_dcm_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_mon_dcm_xy_var._name, "SIXS_mon_dcm_xy", 16384);
  stracpy(_SIXS_mon_dcm_xy_var._type, "Monitor_nD", 16384);
  _SIXS_mon_dcm_xy_var._index=488;
  int current_setpos_index = 488;
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.user9[0]='\0';
  _SIXS_mon_dcm_xy_var._parameters.xwidth = 2e-3;
  _SIXS_mon_dcm_xy_var._parameters.yheight = 2e-3;
  _SIXS_mon_dcm_xy_var._parameters.zdepth = 0;
  _SIXS_mon_dcm_xy_var._parameters.bins = 128;
  _SIXS_mon_dcm_xy_var._parameters.min = -1e40;
  _SIXS_mon_dcm_xy_var._parameters.max = 1e40;
  _SIXS_mon_dcm_xy_var._parameters.restore_xray = 0;
  _SIXS_mon_dcm_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.geometry[0]='\0';
  _SIXS_mon_dcm_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_mon_dcm_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_mon_dcm_xy_var._parameters.username9[0]='\0';


  /* component SIXS_mon_dcm_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_mon_dcm_e_var._rotation_absolute, _SIXS_mon_dcm_xy_var._rotation_absolute);
    rot_transpose(_SIXS_mon_dcm_e_var._rotation_absolute, tr1);
    rot_mul(_SIXS_mon_dcm_xy_var._rotation_absolute, tr1, _SIXS_mon_dcm_xy_var._rotation_relative);
    _SIXS_mon_dcm_xy_var._rotation_is_identity =  rot_test_identity(_SIXS_mon_dcm_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_mon_dcm_xy_var._position_absolute = coords_add(_SIXS_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_mon_dcm_e_var._position_absolute, _SIXS_mon_dcm_xy_var._position_absolute);
    _SIXS_mon_dcm_xy_var._position_relative = rot_apply(_SIXS_mon_dcm_xy_var._rotation_absolute, tc1);
  } /* SIXS_mon_dcm_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_mon_dcm_xy", _SIXS_mon_dcm_xy_var._position_absolute, _SIXS_mon_dcm_xy_var._rotation_absolute);
  instrument->_position_absolute[488] = _SIXS_mon_dcm_xy_var._position_absolute;
  instrument->_position_relative[488] = _SIXS_mon_dcm_xy_var._position_relative;
    _SIXS_mon_dcm_xy_var._position_relative_is_zero =  coords_test_zero(_SIXS_mon_dcm_xy_var._position_relative);
  instrument->counter_N[488]  = instrument->counter_P[488] = instrument->counter_P2[488] = 0;
  instrument->counter_AbsorbProp[488]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", _SIXS_mon_dcm_xy_var._position_absolute, _SIXS_mon_dcm_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0487_SIXS_mon_dcm_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_mon_dcm_xy_setpos */

/* component SIXS_M1_location=Arm() SETTING, POSITION/ROTATION */
int _SIXS_M1_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M1_location_setpos] component SIXS_M1_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_M1_location_var._name, "SIXS_M1_location", 16384);
  stracpy(_SIXS_M1_location_var._type, "Arm", 16384);
  _SIXS_M1_location_var._index=489;
  int current_setpos_index = 489;
  /* component SIXS_M1_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_mon_dcm_e_var._rotation_absolute, _SIXS_M1_location_var._rotation_absolute);
    rot_transpose(_SIXS_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M1_location_var._rotation_absolute, tr1, _SIXS_M1_location_var._rotation_relative);
    _SIXS_M1_location_var._rotation_is_identity =  rot_test_identity(_SIXS_M1_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 26 -16.5 -0.5);
    rot_transpose(_SIXS_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M1_location_var._position_absolute = coords_add(_SIXS_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_mon_dcm_xy_var._position_absolute, _SIXS_M1_location_var._position_absolute);
    _SIXS_M1_location_var._position_relative = rot_apply(_SIXS_M1_location_var._rotation_absolute, tc1);
  } /* SIXS_M1_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M1_location", _SIXS_M1_location_var._position_absolute, _SIXS_M1_location_var._rotation_absolute);
  instrument->_position_absolute[489] = _SIXS_M1_location_var._position_absolute;
  instrument->_position_relative[489] = _SIXS_M1_location_var._position_relative;
    _SIXS_M1_location_var._position_relative_is_zero =  coords_test_zero(_SIXS_M1_location_var._position_relative);
  instrument->counter_N[489]  = instrument->counter_P[489] = instrument->counter_P2[489] = 0;
  instrument->counter_AbsorbProp[489]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0488_SIXS_M1_location", _SIXS_M1_location_var._position_absolute, _SIXS_M1_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M1_location_setpos */

/* component SIXS_M1_rotated=Arm() SETTING, POSITION/ROTATION */
int _SIXS_M1_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M1_rotated_setpos] component SIXS_M1_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_M1_rotated_var._name, "SIXS_M1_rotated", 16384);
  stracpy(_SIXS_M1_rotated_var._type, "Arm", 16384);
  _SIXS_M1_rotated_var._index=490;
  int current_setpos_index = 490;
  /* component SIXS_M1_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIXS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_M1_location_var._rotation_absolute, _SIXS_M1_rotated_var._rotation_absolute);
    rot_transpose(_SIXS_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M1_rotated_var._rotation_absolute, tr1, _SIXS_M1_rotated_var._rotation_relative);
    _SIXS_M1_rotated_var._rotation_is_identity =  rot_test_identity(_SIXS_M1_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_M1_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M1_rotated_var._position_absolute = coords_add(_SIXS_M1_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_mon_dcm_xy_var._position_absolute, _SIXS_M1_rotated_var._position_absolute);
    _SIXS_M1_rotated_var._position_relative = rot_apply(_SIXS_M1_rotated_var._rotation_absolute, tc1);
  } /* SIXS_M1_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M1_rotated", _SIXS_M1_rotated_var._position_absolute, _SIXS_M1_rotated_var._rotation_absolute);
  instrument->_position_absolute[490] = _SIXS_M1_rotated_var._position_absolute;
  instrument->_position_relative[490] = _SIXS_M1_rotated_var._position_relative;
    _SIXS_M1_rotated_var._position_relative_is_zero =  coords_test_zero(_SIXS_M1_rotated_var._position_relative);
  instrument->counter_N[490]  = instrument->counter_P[490] = instrument->counter_P2[490] = 0;
  instrument->counter_AbsorbProp[490]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0489_SIXS_M1_rotated", _SIXS_M1_rotated_var._position_absolute, _SIXS_M1_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M1_rotated_setpos */

/* component SIXS_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _SIXS_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M1_setpos] component SIXS_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SIXS_M1_var._name, "SIXS_M1", 16384);
  stracpy(_SIXS_M1_var._type, "Mirror_curved", 16384);
  _SIXS_M1_var._index=491;
  int current_setpos_index = 491;
  _SIXS_M1_var._parameters.radius = _instrument_var._parameters.SIXS_M1_radius;
  _SIXS_M1_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_SIXS_M1_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _SIXS_M1_var._parameters.coating[0]='\0';
  _SIXS_M1_var._parameters.zdepth = 0.2;
  _SIXS_M1_var._parameters.yheight = 0.2;
  _SIXS_M1_var._parameters.length = .350;
  _SIXS_M1_var._parameters.width = 0.2;


  /* component SIXS_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _SIXS_M1_rotated_var._rotation_absolute, _SIXS_M1_var._rotation_absolute);
    rot_transpose(_SIXS_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M1_var._rotation_absolute, tr1, _SIXS_M1_var._rotation_relative);
    _SIXS_M1_var._rotation_is_identity =  rot_test_identity(_SIXS_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M1_var._position_absolute = coords_add(_SIXS_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_mon_dcm_xy_var._position_absolute, _SIXS_M1_var._position_absolute);
    _SIXS_M1_var._position_relative = rot_apply(_SIXS_M1_var._rotation_absolute, tc1);
  } /* SIXS_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M1", _SIXS_M1_var._position_absolute, _SIXS_M1_var._rotation_absolute);
  instrument->_position_absolute[491] = _SIXS_M1_var._position_absolute;
  instrument->_position_relative[491] = _SIXS_M1_var._position_relative;
    _SIXS_M1_var._position_relative_is_zero =  coords_test_zero(_SIXS_M1_var._position_relative);
  instrument->counter_N[491]  = instrument->counter_P[491] = instrument->counter_P2[491] = 0;
  instrument->counter_AbsorbProp[491]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0490_SIXS_M1", _SIXS_M1_var._position_absolute, _SIXS_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "radius", "1", "_instrument_var._parameters.SIXS_M1_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "length", "0", ".350","MCNUM");
        mccomp_param_nexus(nxhandle,"0490_SIXS_M1", "width", "0", "0.2","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M1_setpos */

/* component SIXS_M1_out=Arm() SETTING, POSITION/ROTATION */
int _SIXS_M1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M1_out_setpos] component SIXS_M1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_M1_out_var._name, "SIXS_M1_out", 16384);
  stracpy(_SIXS_M1_out_var._type, "Arm", 16384);
  _SIXS_M1_out_var._index=492;
  int current_setpos_index = 492;
  /* component SIXS_M1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIXS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_M1_rotated_var._rotation_absolute, _SIXS_M1_out_var._rotation_absolute);
    rot_transpose(_SIXS_M1_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M1_out_var._rotation_absolute, tr1, _SIXS_M1_out_var._rotation_relative);
    _SIXS_M1_out_var._rotation_is_identity =  rot_test_identity(_SIXS_M1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_M1_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M1_out_var._position_absolute = coords_add(_SIXS_M1_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_M1_var._position_absolute, _SIXS_M1_out_var._position_absolute);
    _SIXS_M1_out_var._position_relative = rot_apply(_SIXS_M1_out_var._rotation_absolute, tc1);
  } /* SIXS_M1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M1_out", _SIXS_M1_out_var._position_absolute, _SIXS_M1_out_var._rotation_absolute);
  instrument->_position_absolute[492] = _SIXS_M1_out_var._position_absolute;
  instrument->_position_relative[492] = _SIXS_M1_out_var._position_relative;
    _SIXS_M1_out_var._position_relative_is_zero =  coords_test_zero(_SIXS_M1_out_var._position_relative);
  instrument->counter_N[492]  = instrument->counter_P[492] = instrument->counter_P2[492] = 0;
  instrument->counter_AbsorbProp[492]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0491_SIXS_M1_out", _SIXS_M1_out_var._position_absolute, _SIXS_M1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M1_out_setpos */

/* component SIXS_M2_location=Arm() SETTING, POSITION/ROTATION */
int _SIXS_M2_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M2_location_setpos] component SIXS_M2_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_M2_location_var._name, "SIXS_M2_location", 16384);
  stracpy(_SIXS_M2_location_var._type, "Arm", 16384);
  _SIXS_M2_location_var._index=493;
  int current_setpos_index = 493;
  /* component SIXS_M2_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_M1_out_var._rotation_absolute, _SIXS_M2_location_var._rotation_absolute);
    rot_transpose(_SIXS_M1_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M2_location_var._rotation_absolute, tr1, _SIXS_M2_location_var._rotation_relative);
    _SIXS_M2_location_var._rotation_is_identity =  rot_test_identity(_SIXS_M2_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 28 -26);
    rot_transpose(_SIXS_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M2_location_var._position_absolute = coords_add(_SIXS_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_M1_var._position_absolute, _SIXS_M2_location_var._position_absolute);
    _SIXS_M2_location_var._position_relative = rot_apply(_SIXS_M2_location_var._rotation_absolute, tc1);
  } /* SIXS_M2_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M2_location", _SIXS_M2_location_var._position_absolute, _SIXS_M2_location_var._rotation_absolute);
  instrument->_position_absolute[493] = _SIXS_M2_location_var._position_absolute;
  instrument->_position_relative[493] = _SIXS_M2_location_var._position_relative;
    _SIXS_M2_location_var._position_relative_is_zero =  coords_test_zero(_SIXS_M2_location_var._position_relative);
  instrument->counter_N[493]  = instrument->counter_P[493] = instrument->counter_P2[493] = 0;
  instrument->counter_AbsorbProp[493]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0492_SIXS_M2_location", _SIXS_M2_location_var._position_absolute, _SIXS_M2_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M2_location_setpos */

/* component SIXS_M2_rotated=Arm() SETTING, POSITION/ROTATION */
int _SIXS_M2_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M2_rotated_setpos] component SIXS_M2_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_M2_rotated_var._name, "SIXS_M2_rotated", 16384);
  stracpy(_SIXS_M2_rotated_var._type, "Arm", 16384);
  _SIXS_M2_rotated_var._index=494;
  int current_setpos_index = 494;
  /* component SIXS_M2_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SIXS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_M2_location_var._rotation_absolute, _SIXS_M2_rotated_var._rotation_absolute);
    rot_transpose(_SIXS_M1_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M2_rotated_var._rotation_absolute, tr1, _SIXS_M2_rotated_var._rotation_relative);
    _SIXS_M2_rotated_var._rotation_is_identity =  rot_test_identity(_SIXS_M2_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_M2_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M2_rotated_var._position_absolute = coords_add(_SIXS_M2_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_M1_var._position_absolute, _SIXS_M2_rotated_var._position_absolute);
    _SIXS_M2_rotated_var._position_relative = rot_apply(_SIXS_M2_rotated_var._rotation_absolute, tc1);
  } /* SIXS_M2_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M2_rotated", _SIXS_M2_rotated_var._position_absolute, _SIXS_M2_rotated_var._rotation_absolute);
  instrument->_position_absolute[494] = _SIXS_M2_rotated_var._position_absolute;
  instrument->_position_relative[494] = _SIXS_M2_rotated_var._position_relative;
    _SIXS_M2_rotated_var._position_relative_is_zero =  coords_test_zero(_SIXS_M2_rotated_var._position_relative);
  instrument->counter_N[494]  = instrument->counter_P[494] = instrument->counter_P2[494] = 0;
  instrument->counter_AbsorbProp[494]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0493_SIXS_M2_rotated", _SIXS_M2_rotated_var._position_absolute, _SIXS_M2_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M2_rotated_setpos */

/* component SIXS_M2=Mirror_curved() SETTING, POSITION/ROTATION */
int _SIXS_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M2_setpos] component SIXS_M2=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SIXS_M2_var._name, "SIXS_M2", 16384);
  stracpy(_SIXS_M2_var._type, "Mirror_curved", 16384);
  _SIXS_M2_var._index=495;
  int current_setpos_index = 495;
  _SIXS_M2_var._parameters.radius = _instrument_var._parameters.SIXS_M2_radius;
  _SIXS_M2_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_SIXS_M2_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _SIXS_M2_var._parameters.coating[0]='\0';
  _SIXS_M2_var._parameters.zdepth = 0.2;
  _SIXS_M2_var._parameters.yheight = 0.2;
  _SIXS_M2_var._parameters.length = 0.550;
  _SIXS_M2_var._parameters.width = .2;


  /* component SIXS_M2=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (-90)*DEG2RAD);
    rot_mul(tr1, _SIXS_M2_rotated_var._rotation_absolute, _SIXS_M2_var._rotation_absolute);
    rot_transpose(_SIXS_M1_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M2_var._rotation_absolute, tr1, _SIXS_M2_var._rotation_relative);
    _SIXS_M2_var._rotation_is_identity =  rot_test_identity(_SIXS_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M2_var._position_absolute = coords_add(_SIXS_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_M1_var._position_absolute, _SIXS_M2_var._position_absolute);
    _SIXS_M2_var._position_relative = rot_apply(_SIXS_M2_var._rotation_absolute, tc1);
  } /* SIXS_M2=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M2", _SIXS_M2_var._position_absolute, _SIXS_M2_var._rotation_absolute);
  instrument->_position_absolute[495] = _SIXS_M2_var._position_absolute;
  instrument->_position_relative[495] = _SIXS_M2_var._position_relative;
    _SIXS_M2_var._position_relative_is_zero =  coords_test_zero(_SIXS_M2_var._position_relative);
  instrument->counter_N[495]  = instrument->counter_P[495] = instrument->counter_P2[495] = 0;
  instrument->counter_AbsorbProp[495]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0494_SIXS_M2", _SIXS_M2_var._position_absolute, _SIXS_M2_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "radius", "1", "_instrument_var._parameters.SIXS_M2_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "length", "0", "0.550","MCNUM");
        mccomp_param_nexus(nxhandle,"0494_SIXS_M2", "width", "0", ".2","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M2_setpos */

/* component SIXS_M2_out=Arm() SETTING, POSITION/ROTATION */
int _SIXS_M2_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_M2_out_setpos] component SIXS_M2_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_M2_out_var._name, "SIXS_M2_out", 16384);
  stracpy(_SIXS_M2_out_var._type, "Arm", 16384);
  _SIXS_M2_out_var._index=496;
  int current_setpos_index = 496;
  /* component SIXS_M2_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SIXS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_M2_rotated_var._rotation_absolute, _SIXS_M2_out_var._rotation_absolute);
    rot_transpose(_SIXS_M2_var._rotation_absolute, tr1);
    rot_mul(_SIXS_M2_out_var._rotation_absolute, tr1, _SIXS_M2_out_var._rotation_relative);
    _SIXS_M2_out_var._rotation_is_identity =  rot_test_identity(_SIXS_M2_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_M2_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_M2_out_var._position_absolute = coords_add(_SIXS_M2_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_M2_var._position_absolute, _SIXS_M2_out_var._position_absolute);
    _SIXS_M2_out_var._position_relative = rot_apply(_SIXS_M2_out_var._rotation_absolute, tc1);
  } /* SIXS_M2_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_M2_out", _SIXS_M2_out_var._position_absolute, _SIXS_M2_out_var._rotation_absolute);
  instrument->_position_absolute[496] = _SIXS_M2_out_var._position_absolute;
  instrument->_position_relative[496] = _SIXS_M2_out_var._position_relative;
    _SIXS_M2_out_var._position_relative_is_zero =  coords_test_zero(_SIXS_M2_out_var._position_relative);
  instrument->counter_N[496]  = instrument->counter_P[496] = instrument->counter_P2[496] = 0;
  instrument->counter_AbsorbProp[496]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0495_SIXS_M2_out", _SIXS_M2_out_var._position_absolute, _SIXS_M2_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_M2_out_setpos */

/* component SIXS_sample_stage=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_sample_stage_setpos] component SIXS_sample_stage=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_sample_stage_var._name, "SIXS_sample_stage", 16384);
  stracpy(_SIXS_sample_stage_var._type, "Monitor_nD", 16384);
  _SIXS_sample_stage_var._index=497;
  int current_setpos_index = 497;
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_sample_stage_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.user9[0]='\0';
  _SIXS_sample_stage_var._parameters.xwidth = 2e-3;
  _SIXS_sample_stage_var._parameters.yheight = 2e-3;
  _SIXS_sample_stage_var._parameters.zdepth = 0;
  _SIXS_sample_stage_var._parameters.bins = 128;
  _SIXS_sample_stage_var._parameters.min = -1e40;
  _SIXS_sample_stage_var._parameters.max = 1e40;
  _SIXS_sample_stage_var._parameters.restore_xray = 0;
  _SIXS_sample_stage_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIXS_sample_stage_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.geometry[0]='\0';
  _SIXS_sample_stage_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_sample_stage_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_sample_stage_var._parameters.username9[0]='\0';


  /* component SIXS_sample_stage=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_M2_out_var._rotation_absolute, _SIXS_sample_stage_var._rotation_absolute);
    rot_transpose(_SIXS_M2_var._rotation_absolute, tr1);
    rot_mul(_SIXS_sample_stage_var._rotation_absolute, tr1, _SIXS_sample_stage_var._rotation_relative);
    _SIXS_sample_stage_var._rotation_is_identity =  rot_test_identity(_SIXS_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 33 -28);
    rot_transpose(_SIXS_M2_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_sample_stage_var._position_absolute = coords_add(_SIXS_M2_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_M2_var._position_absolute, _SIXS_sample_stage_var._position_absolute);
    _SIXS_sample_stage_var._position_relative = rot_apply(_SIXS_sample_stage_var._rotation_absolute, tc1);
  } /* SIXS_sample_stage=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_sample_stage", _SIXS_sample_stage_var._position_absolute, _SIXS_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[497] = _SIXS_sample_stage_var._position_absolute;
  instrument->_position_relative[497] = _SIXS_sample_stage_var._position_relative;
    _SIXS_sample_stage_var._position_relative_is_zero =  coords_test_zero(_SIXS_sample_stage_var._position_relative);
  instrument->counter_N[497]  = instrument->counter_P[497] = instrument->counter_P2[497] = 0;
  instrument->counter_AbsorbProp[497]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0496_SIXS_sample_stage", _SIXS_sample_stage_var._position_absolute, _SIXS_sample_stage_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0496_SIXS_sample_stage", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_sample_stage_setpos */

/* component SIXS_sx_layer=Single_crystal() SETTING, POSITION/ROTATION */
int _SIXS_sx_layer_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_sx_layer_setpos] component SIXS_sx_layer=Single_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1265]");
  stracpy(_SIXS_sx_layer_var._name, "SIXS_sx_layer", 16384);
  stracpy(_SIXS_sx_layer_var._type, "Single_crystal", 16384);
  _SIXS_sx_layer_var._index=498;
  int current_setpos_index = 498;
  if(_instrument_var._parameters.SIXS_sample_coating && strlen(_instrument_var._parameters.SIXS_sample_coating))
    stracpy(_SIXS_sx_layer_var._parameters.reflections, _instrument_var._parameters.SIXS_sample_coating ? _instrument_var._parameters.SIXS_sample_coating : "", 16384);
  else 
  _SIXS_sx_layer_var._parameters.reflections[0]='\0';
  _SIXS_sx_layer_var._parameters.geometry[0]='\0';
  _SIXS_sx_layer_var._parameters.mosaic_AB[0] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[1] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[2] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[3] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[4] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[5] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[6] = 0;
  _SIXS_sx_layer_var._parameters.mosaic_AB[7] = 0;
  _SIXS_sx_layer_var._parameters.xwidth = 2e-3;
  _SIXS_sx_layer_var._parameters.yheight = _instrument_var._parameters.SIXS_sample_thickness;
  _SIXS_sx_layer_var._parameters.zdepth = 0.01;
  _SIXS_sx_layer_var._parameters.radius = 0;
  _SIXS_sx_layer_var._parameters.delta_d_d = 1e-3;
  _SIXS_sx_layer_var._parameters.mosaic = 1e-4;
  _SIXS_sx_layer_var._parameters.mosaic_a = -1;
  _SIXS_sx_layer_var._parameters.mosaic_b = -1;
  _SIXS_sx_layer_var._parameters.mosaic_c = -1;
  _SIXS_sx_layer_var._parameters.recip_cell = 0;
  _SIXS_sx_layer_var._parameters.barns = 0;
  _SIXS_sx_layer_var._parameters.ax = 0;
  _SIXS_sx_layer_var._parameters.ay = 0;
  _SIXS_sx_layer_var._parameters.az = 0;
  _SIXS_sx_layer_var._parameters.bx = 0;
  _SIXS_sx_layer_var._parameters.by = 0;
  _SIXS_sx_layer_var._parameters.bz = 0;
  _SIXS_sx_layer_var._parameters.cx = 0;
  _SIXS_sx_layer_var._parameters.cy = 0;
  _SIXS_sx_layer_var._parameters.cz = 0;
  _SIXS_sx_layer_var._parameters.p_transmit = 0.1;
  _SIXS_sx_layer_var._parameters.sigma_inc = 0;
  _SIXS_sx_layer_var._parameters.aa = 0;
  _SIXS_sx_layer_var._parameters.bb = 0;
  _SIXS_sx_layer_var._parameters.cc = 0;
  _SIXS_sx_layer_var._parameters.order = 1;
  _SIXS_sx_layer_var._parameters.extra_order = 0;
  _SIXS_sx_layer_var._parameters.RX = 0;
  _SIXS_sx_layer_var._parameters.RY = 0;
  _SIXS_sx_layer_var._parameters.powder = 0;
  _SIXS_sx_layer_var._parameters.deltak = 1e-6;
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SIXS_sx_layer_var._parameters.material_datafile, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SIXS_sx_layer_var._parameters.material_datafile[0]='\0';
  _SIXS_sx_layer_var._parameters.surf_size = -1;
  _SIXS_sx_layer_var._parameters.surf_k = NULL; // default pointer allocation
  _SIXS_sx_layer_var._parameters.surf_FT2 = NULL; // default pointer allocation
  _SIXS_sx_layer_var._parameters.surf_dir[0] = 0;
  _SIXS_sx_layer_var._parameters.surf_dir[1] = 0;
  _SIXS_sx_layer_var._parameters.surf_dir[2] = 0;


  /* component SIXS_sx_layer=Single_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.SIXS_sample_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIXS_sample_stage_var._rotation_absolute, _SIXS_sx_layer_var._rotation_absolute);
    rot_transpose(_SIXS_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_SIXS_sx_layer_var._rotation_absolute, tr1, _SIXS_sx_layer_var._rotation_relative);
    _SIXS_sx_layer_var._rotation_is_identity =  rot_test_identity(_SIXS_sx_layer_var._rotation_relative);
    tc1 = coords_set(
      0, - _instrument_var._parameters.SIXS_sample_thickness / 2, 0);
    rot_transpose(_SIXS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_sx_layer_var._position_absolute = coords_add(_SIXS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_sample_stage_var._position_absolute, _SIXS_sx_layer_var._position_absolute);
    _SIXS_sx_layer_var._position_relative = rot_apply(_SIXS_sx_layer_var._rotation_absolute, tc1);
  } /* SIXS_sx_layer=Single_crystal() AT ROTATED */
  DEBUG_COMPONENT("SIXS_sx_layer", _SIXS_sx_layer_var._position_absolute, _SIXS_sx_layer_var._rotation_absolute);
  instrument->_position_absolute[498] = _SIXS_sx_layer_var._position_absolute;
  instrument->_position_relative[498] = _SIXS_sx_layer_var._position_relative;
    _SIXS_sx_layer_var._position_relative_is_zero =  coords_test_zero(_SIXS_sx_layer_var._position_relative);
  instrument->counter_N[498]  = instrument->counter_P[498] = instrument->counter_P2[498] = 0;
  instrument->counter_AbsorbProp[498]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0497_SIXS_sx_layer", _SIXS_sx_layer_var._position_absolute, _SIXS_sx_layer_var._rotation_absolute, "Single_crystal");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "reflections", 0, _instrument_var._parameters.SIXS_sample_coating, "char*");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "mosaic_AB", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "yheight", "0", "_instrument_var._parameters.SIXS_sample_thickness","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "zdepth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "delta_d_d", "1e-3", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "mosaic", "-1", "1e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "mosaic_a", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "mosaic_b", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "mosaic_c", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "recip_cell", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "barns", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "ax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "ay", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "az", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "bx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "by", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "bz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "cx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "cy", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "cz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "p_transmit", "0.001", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "sigma_inc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "aa", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "bb", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "cc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "order", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "extra_order", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "RX", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "RY", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "powder", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "deltak", "1e-6", "1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "material_datafile", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "surf_size", "0", "-1","int");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "surf_k", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "surf_FT2", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0497_SIXS_sx_layer", "surf_dir", "{ 0 , 0 , 0 }", "{ 0 , 0 , 0 }","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_sx_layer_setpos */

/* component SIXS_sx_bulk=Single_crystal() SETTING, POSITION/ROTATION */
int _SIXS_sx_bulk_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_sx_bulk_setpos] component SIXS_sx_bulk=Single_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1265]");
  stracpy(_SIXS_sx_bulk_var._name, "SIXS_sx_bulk", 16384);
  stracpy(_SIXS_sx_bulk_var._type, "Single_crystal", 16384);
  _SIXS_sx_bulk_var._index=499;
  int current_setpos_index = 499;
  if(_instrument_var._parameters.SIXS_sample_bulk && strlen(_instrument_var._parameters.SIXS_sample_bulk))
    stracpy(_SIXS_sx_bulk_var._parameters.reflections, _instrument_var._parameters.SIXS_sample_bulk ? _instrument_var._parameters.SIXS_sample_bulk : "", 16384);
  else 
  _SIXS_sx_bulk_var._parameters.reflections[0]='\0';
  _SIXS_sx_bulk_var._parameters.geometry[0]='\0';
  _SIXS_sx_bulk_var._parameters.mosaic_AB[0] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[1] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[2] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[3] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[4] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[5] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[6] = 0;
  _SIXS_sx_bulk_var._parameters.mosaic_AB[7] = 0;
  _SIXS_sx_bulk_var._parameters.xwidth = 2e-3;
  _SIXS_sx_bulk_var._parameters.yheight = 1e-3;
  _SIXS_sx_bulk_var._parameters.zdepth = 0.01;
  _SIXS_sx_bulk_var._parameters.radius = 0;
  _SIXS_sx_bulk_var._parameters.delta_d_d = 1e-3;
  _SIXS_sx_bulk_var._parameters.mosaic = 1e-4;
  _SIXS_sx_bulk_var._parameters.mosaic_a = -1;
  _SIXS_sx_bulk_var._parameters.mosaic_b = -1;
  _SIXS_sx_bulk_var._parameters.mosaic_c = -1;
  _SIXS_sx_bulk_var._parameters.recip_cell = 0;
  _SIXS_sx_bulk_var._parameters.barns = 0;
  _SIXS_sx_bulk_var._parameters.ax = 0;
  _SIXS_sx_bulk_var._parameters.ay = 0;
  _SIXS_sx_bulk_var._parameters.az = 0;
  _SIXS_sx_bulk_var._parameters.bx = 0;
  _SIXS_sx_bulk_var._parameters.by = 0;
  _SIXS_sx_bulk_var._parameters.bz = 0;
  _SIXS_sx_bulk_var._parameters.cx = 0;
  _SIXS_sx_bulk_var._parameters.cy = 0;
  _SIXS_sx_bulk_var._parameters.cz = 0;
  _SIXS_sx_bulk_var._parameters.p_transmit = 0.001;
  _SIXS_sx_bulk_var._parameters.sigma_inc = 0;
  _SIXS_sx_bulk_var._parameters.aa = 0;
  _SIXS_sx_bulk_var._parameters.bb = 0;
  _SIXS_sx_bulk_var._parameters.cc = 0;
  _SIXS_sx_bulk_var._parameters.order = 1;
  _SIXS_sx_bulk_var._parameters.extra_order = 0;
  _SIXS_sx_bulk_var._parameters.RX = 0;
  _SIXS_sx_bulk_var._parameters.RY = 0;
  _SIXS_sx_bulk_var._parameters.powder = 0;
  _SIXS_sx_bulk_var._parameters.deltak = 1e-6;
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SIXS_sx_bulk_var._parameters.material_datafile, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SIXS_sx_bulk_var._parameters.material_datafile[0]='\0';
  _SIXS_sx_bulk_var._parameters.surf_size = -1;
  _SIXS_sx_bulk_var._parameters.surf_k = NULL; // default pointer allocation
  _SIXS_sx_bulk_var._parameters.surf_FT2 = NULL; // default pointer allocation
  _SIXS_sx_bulk_var._parameters.surf_dir[0] = 0;
  _SIXS_sx_bulk_var._parameters.surf_dir[1] = 0;
  _SIXS_sx_bulk_var._parameters.surf_dir[2] = 0;


  /* component SIXS_sx_bulk=Single_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_sx_layer_var._rotation_absolute, _SIXS_sx_bulk_var._rotation_absolute);
    rot_transpose(_SIXS_sx_layer_var._rotation_absolute, tr1);
    rot_mul(_SIXS_sx_bulk_var._rotation_absolute, tr1, _SIXS_sx_bulk_var._rotation_relative);
    _SIXS_sx_bulk_var._rotation_is_identity =  rot_test_identity(_SIXS_sx_bulk_var._rotation_relative);
    tc1 = coords_set(
      0, -1e-3 / 2, 0);
    rot_transpose(_SIXS_sx_layer_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_sx_bulk_var._position_absolute = coords_add(_SIXS_sx_layer_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_sx_layer_var._position_absolute, _SIXS_sx_bulk_var._position_absolute);
    _SIXS_sx_bulk_var._position_relative = rot_apply(_SIXS_sx_bulk_var._rotation_absolute, tc1);
  } /* SIXS_sx_bulk=Single_crystal() AT ROTATED */
  DEBUG_COMPONENT("SIXS_sx_bulk", _SIXS_sx_bulk_var._position_absolute, _SIXS_sx_bulk_var._rotation_absolute);
  instrument->_position_absolute[499] = _SIXS_sx_bulk_var._position_absolute;
  instrument->_position_relative[499] = _SIXS_sx_bulk_var._position_relative;
    _SIXS_sx_bulk_var._position_relative_is_zero =  coords_test_zero(_SIXS_sx_bulk_var._position_relative);
  instrument->counter_N[499]  = instrument->counter_P[499] = instrument->counter_P2[499] = 0;
  instrument->counter_AbsorbProp[499]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0498_SIXS_sx_bulk", _SIXS_sx_bulk_var._position_absolute, _SIXS_sx_bulk_var._rotation_absolute, "Single_crystal");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "reflections", 0, _instrument_var._parameters.SIXS_sample_bulk, "char*");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "mosaic_AB", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "yheight", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "zdepth", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "delta_d_d", "1e-3", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "mosaic", "-1", "1e-4","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "mosaic_a", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "mosaic_b", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "mosaic_c", "-1", "-1","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "recip_cell", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "barns", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "ax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "ay", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "az", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "bx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "by", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "bz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "cx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "cy", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "cz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "p_transmit", "0.001", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "sigma_inc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "aa", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "bb", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "cc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "order", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "extra_order", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "RX", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "RY", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "powder", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "deltak", "1e-6", "1e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "material_datafile", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "surf_size", "0", "-1","int");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "surf_k", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "surf_FT2", "NULL", "NULL","MCNUM");
        mccomp_param_nexus(nxhandle,"0498_SIXS_sx_bulk", "surf_dir", "{ 0 , 0 , 0 }", "{ 0 , 0 , 0 }","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_sx_bulk_setpos */

/* component SIXS_sample_out=Arm() SETTING, POSITION/ROTATION */
int _SIXS_sample_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_sample_out_setpos] component SIXS_sample_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIXS_sample_out_var._name, "SIXS_sample_out", 16384);
  stracpy(_SIXS_sample_out_var._type, "Arm", 16384);
  _SIXS_sample_out_var._index=500;
  int current_setpos_index = 500;
  /* component SIXS_sample_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_sample_stage_var._rotation_absolute, _SIXS_sample_out_var._rotation_absolute);
    rot_transpose(_SIXS_sx_bulk_var._rotation_absolute, tr1);
    rot_mul(_SIXS_sample_out_var._rotation_absolute, tr1, _SIXS_sample_out_var._rotation_relative);
    _SIXS_sample_out_var._rotation_is_identity =  rot_test_identity(_SIXS_sample_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_sample_out_var._position_absolute = coords_add(_SIXS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_sx_bulk_var._position_absolute, _SIXS_sample_out_var._position_absolute);
    _SIXS_sample_out_var._position_relative = rot_apply(_SIXS_sample_out_var._rotation_absolute, tc1);
  } /* SIXS_sample_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIXS_sample_out", _SIXS_sample_out_var._position_absolute, _SIXS_sample_out_var._rotation_absolute);
  instrument->_position_absolute[500] = _SIXS_sample_out_var._position_absolute;
  instrument->_position_relative[500] = _SIXS_sample_out_var._position_relative;
    _SIXS_sample_out_var._position_relative_is_zero =  coords_test_zero(_SIXS_sample_out_var._position_relative);
  instrument->counter_N[500]  = instrument->counter_P[500] = instrument->counter_P2[500] = 0;
  instrument->counter_AbsorbProp[500]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0499_SIXS_sample_out", _SIXS_sample_out_var._position_absolute, _SIXS_sample_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_sample_out_setpos */

/* component SIXS_det4pi=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_det4pi_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_det4pi_setpos] component SIXS_det4pi=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_det4pi_var._name, "SIXS_det4pi", 16384);
  stracpy(_SIXS_det4pi_var._type, "Monitor_nD", 16384);
  _SIXS_det4pi_var._index=501;
  int current_setpos_index = 501;
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_det4pi_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.user9[0]='\0';
  _SIXS_det4pi_var._parameters.xwidth = 0;
  _SIXS_det4pi_var._parameters.yheight = 0;
  _SIXS_det4pi_var._parameters.zdepth = 0;
  _SIXS_det4pi_var._parameters.bins = 2048;
  _SIXS_det4pi_var._parameters.min = -1e40;
  _SIXS_det4pi_var._parameters.max = 1e40;
  _SIXS_det4pi_var._parameters.restore_xray = 0;
  _SIXS_det4pi_var._parameters.radius = 1;
  if("theta phi" && strlen("theta phi"))
    stracpy(_SIXS_det4pi_var._parameters.options, "theta phi" ? "theta phi" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.geometry[0]='\0';
  _SIXS_det4pi_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_det4pi_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_det4pi_var._parameters.username9[0]='\0';


  /* component SIXS_det4pi=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_sample_stage_var._rotation_absolute, _SIXS_det4pi_var._rotation_absolute);
    rot_transpose(_SIXS_sample_out_var._rotation_absolute, tr1);
    rot_mul(_SIXS_det4pi_var._rotation_absolute, tr1, _SIXS_det4pi_var._rotation_relative);
    _SIXS_det4pi_var._rotation_is_identity =  rot_test_identity(_SIXS_det4pi_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_det4pi_var._position_absolute = coords_add(_SIXS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_sample_out_var._position_absolute, _SIXS_det4pi_var._position_absolute);
    _SIXS_det4pi_var._position_relative = rot_apply(_SIXS_det4pi_var._rotation_absolute, tc1);
  } /* SIXS_det4pi=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_det4pi", _SIXS_det4pi_var._position_absolute, _SIXS_det4pi_var._rotation_absolute);
  instrument->_position_absolute[501] = _SIXS_det4pi_var._position_absolute;
  instrument->_position_relative[501] = _SIXS_det4pi_var._position_relative;
    _SIXS_det4pi_var._position_relative_is_zero =  coords_test_zero(_SIXS_det4pi_var._position_relative);
  instrument->counter_N[501]  = instrument->counter_P[501] = instrument->counter_P2[501] = 0;
  instrument->counter_AbsorbProp[501]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0500_SIXS_det4pi", _SIXS_det4pi_var._position_absolute, _SIXS_det4pi_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "bins", "0", "2048","int");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "radius", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "options", "NULL", "theta phi", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0500_SIXS_det4pi", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_det4pi_setpos */

/* component SIXS_detector_layer=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_detector_layer_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_detector_layer_setpos] component SIXS_detector_layer=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_detector_layer_var._name, "SIXS_detector_layer", 16384);
  stracpy(_SIXS_detector_layer_var._type, "Monitor_nD", 16384);
  _SIXS_detector_layer_var._index=502;
  int current_setpos_index = 502;
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_layer_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.user9[0]='\0';
  _SIXS_detector_layer_var._parameters.xwidth = 0;
  _SIXS_detector_layer_var._parameters.yheight = 0;
  _SIXS_detector_layer_var._parameters.zdepth = 0;
  _SIXS_detector_layer_var._parameters.bins = 2048;
  _SIXS_detector_layer_var._parameters.min = -1e40;
  _SIXS_detector_layer_var._parameters.max = 1e40;
  _SIXS_detector_layer_var._parameters.restore_xray = 0;
  _SIXS_detector_layer_var._parameters.radius = 1;
  if("theta phi" && strlen("theta phi"))
    stracpy(_SIXS_detector_layer_var._parameters.options, "theta phi" ? "theta phi" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.geometry[0]='\0';
  _SIXS_detector_layer_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_layer_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_layer_var._parameters.username9[0]='\0';


  /* component SIXS_detector_layer=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_sample_stage_var._rotation_absolute, _SIXS_detector_layer_var._rotation_absolute);
    rot_transpose(_SIXS_det4pi_var._rotation_absolute, tr1);
    rot_mul(_SIXS_detector_layer_var._rotation_absolute, tr1, _SIXS_detector_layer_var._rotation_relative);
    _SIXS_detector_layer_var._rotation_is_identity =  rot_test_identity(_SIXS_detector_layer_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_detector_layer_var._position_absolute = coords_add(_SIXS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_det4pi_var._position_absolute, _SIXS_detector_layer_var._position_absolute);
    _SIXS_detector_layer_var._position_relative = rot_apply(_SIXS_detector_layer_var._rotation_absolute, tc1);
  } /* SIXS_detector_layer=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_detector_layer", _SIXS_detector_layer_var._position_absolute, _SIXS_detector_layer_var._rotation_absolute);
  instrument->_position_absolute[502] = _SIXS_detector_layer_var._position_absolute;
  instrument->_position_relative[502] = _SIXS_detector_layer_var._position_relative;
    _SIXS_detector_layer_var._position_relative_is_zero =  coords_test_zero(_SIXS_detector_layer_var._position_relative);
  instrument->counter_N[502]  = instrument->counter_P[502] = instrument->counter_P2[502] = 0;
  instrument->counter_AbsorbProp[502]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0501_SIXS_detector_layer", _SIXS_detector_layer_var._position_absolute, _SIXS_detector_layer_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "bins", "0", "2048","int");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "radius", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "options", "NULL", "theta phi", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0501_SIXS_detector_layer", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_detector_layer_setpos */

/* component SIXS_detector_bulk=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIXS_detector_bulk_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIXS_detector_bulk_setpos] component SIXS_detector_bulk=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIXS_detector_bulk_var._name, "SIXS_detector_bulk", 16384);
  stracpy(_SIXS_detector_bulk_var._type, "Monitor_nD", 16384);
  _SIXS_detector_bulk_var._index=503;
  int current_setpos_index = 503;
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIXS_detector_bulk_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.user9[0]='\0';
  _SIXS_detector_bulk_var._parameters.xwidth = 0;
  _SIXS_detector_bulk_var._parameters.yheight = 0;
  _SIXS_detector_bulk_var._parameters.zdepth = 0;
  _SIXS_detector_bulk_var._parameters.bins = 2048;
  _SIXS_detector_bulk_var._parameters.min = -1e40;
  _SIXS_detector_bulk_var._parameters.max = 1e40;
  _SIXS_detector_bulk_var._parameters.restore_xray = 0;
  _SIXS_detector_bulk_var._parameters.radius = 1;
  if("theta phi" && strlen("theta phi"))
    stracpy(_SIXS_detector_bulk_var._parameters.options, "theta phi" ? "theta phi" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.geometry[0]='\0';
  _SIXS_detector_bulk_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIXS_detector_bulk_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIXS_detector_bulk_var._parameters.username9[0]='\0';


  /* component SIXS_detector_bulk=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_sample_stage_var._rotation_absolute, _SIXS_detector_bulk_var._rotation_absolute);
    rot_transpose(_SIXS_detector_layer_var._rotation_absolute, tr1);
    rot_mul(_SIXS_detector_bulk_var._rotation_absolute, tr1, _SIXS_detector_bulk_var._rotation_relative);
    _SIXS_detector_bulk_var._rotation_is_identity =  rot_test_identity(_SIXS_detector_bulk_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIXS_detector_bulk_var._position_absolute = coords_add(_SIXS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_detector_layer_var._position_absolute, _SIXS_detector_bulk_var._position_absolute);
    _SIXS_detector_bulk_var._position_relative = rot_apply(_SIXS_detector_bulk_var._rotation_absolute, tc1);
  } /* SIXS_detector_bulk=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIXS_detector_bulk", _SIXS_detector_bulk_var._position_absolute, _SIXS_detector_bulk_var._rotation_absolute);
  instrument->_position_absolute[503] = _SIXS_detector_bulk_var._position_absolute;
  instrument->_position_relative[503] = _SIXS_detector_bulk_var._position_relative;
    _SIXS_detector_bulk_var._position_relative_is_zero =  coords_test_zero(_SIXS_detector_bulk_var._position_relative);
  instrument->counter_N[503]  = instrument->counter_P[503] = instrument->counter_P2[503] = 0;
  instrument->counter_AbsorbProp[503]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0502_SIXS_detector_bulk", _SIXS_detector_bulk_var._position_absolute, _SIXS_detector_bulk_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "bins", "0", "2048","int");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "radius", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "options", "NULL", "theta phi", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0502_SIXS_detector_bulk", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIXS_detector_bulk_setpos */

/* component beamdump_519=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_519_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_519_setpos] component beamdump_519=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_519_var._name, "beamdump_519", 16384);
  stracpy(_beamdump_519_var._type, "Beamstop", 16384);
  _beamdump_519_var._index=504;
  int current_setpos_index = 504;
  _beamdump_519_var._parameters.xmin = -0.05;
  _beamdump_519_var._parameters.xmax = 0.05;
  _beamdump_519_var._parameters.ymin = -0.05;
  _beamdump_519_var._parameters.ymax = 0.05;
  _beamdump_519_var._parameters.xwidth = 0;
  _beamdump_519_var._parameters.yheight = 0;
  _beamdump_519_var._parameters.radius = 0;

  /* component beamdump_519=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIXS_detector_bulk_var._rotation_absolute, _beamdump_519_var._rotation_absolute);
    rot_transpose(_SIXS_detector_bulk_var._rotation_absolute, tr1);
    rot_mul(_beamdump_519_var._rotation_absolute, tr1, _beamdump_519_var._rotation_relative);
    _beamdump_519_var._rotation_is_identity =  rot_test_identity(_beamdump_519_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIXS_detector_bulk_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_519_var._position_absolute = coords_add(_SIXS_detector_bulk_var._position_absolute, tc2);
    tc1 = coords_sub(_SIXS_detector_bulk_var._position_absolute, _beamdump_519_var._position_absolute);
    _beamdump_519_var._position_relative = rot_apply(_beamdump_519_var._rotation_absolute, tc1);
  } /* beamdump_519=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_519", _beamdump_519_var._position_absolute, _beamdump_519_var._rotation_absolute);
  instrument->_position_absolute[504] = _beamdump_519_var._position_absolute;
  instrument->_position_relative[504] = _beamdump_519_var._position_relative;
    _beamdump_519_var._position_relative_is_zero =  coords_test_zero(_beamdump_519_var._position_relative);
  instrument->counter_N[504]  = instrument->counter_P[504] = instrument->counter_P2[504] = 0;
  instrument->counter_AbsorbProp[504]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0503_beamdump_519", _beamdump_519_var._position_absolute, _beamdump_519_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0503_beamdump_519", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_519_setpos */

/* component CASSIOPEE_pos=Text() SETTING, POSITION/ROTATION */
int _CASSIOPEE_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_pos_setpos] component CASSIOPEE_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_CASSIOPEE_pos_var._name, "CASSIOPEE_pos", 16384);
  stracpy(_CASSIOPEE_pos_var._type, "Text", 16384);
  _CASSIOPEE_pos_var._index=505;
  int current_setpos_index = 505;
  if("CASSIOPEE" && strlen("CASSIOPEE"))
    stracpy(_CASSIOPEE_pos_var._parameters.text, "CASSIOPEE" ? "CASSIOPEE" : "", 16384);
  else 
  _CASSIOPEE_pos_var._parameters.text[0]='\0';
  _CASSIOPEE_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_CASSIOPEE_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _CASSIOPEE_pos_var._parameters.plane[0]='\0';
  _CASSIOPEE_pos_var._parameters.pen_thickness = 0.1;


  /* component CASSIOPEE_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-313.220)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _CASSIOPEE_pos_var._rotation_absolute);
    rot_transpose(_beamdump_519_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_pos_var._rotation_absolute, tr1, _CASSIOPEE_pos_var._rotation_relative);
    _CASSIOPEE_pos_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_pos_var._rotation_relative);
    tc1 = coords_set(
      38.582, 0, -41.056);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_519_var._position_absolute, _CASSIOPEE_pos_var._position_absolute);
    _CASSIOPEE_pos_var._position_relative = rot_apply(_CASSIOPEE_pos_var._rotation_absolute, tc1);
  } /* CASSIOPEE_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_pos", _CASSIOPEE_pos_var._position_absolute, _CASSIOPEE_pos_var._rotation_absolute);
  instrument->_position_absolute[505] = _CASSIOPEE_pos_var._position_absolute;
  instrument->_position_relative[505] = _CASSIOPEE_pos_var._position_relative;
    _CASSIOPEE_pos_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_pos_var._position_relative);
  instrument->counter_N[505]  = instrument->counter_P[505] = instrument->counter_P2[505] = 0;
  instrument->counter_AbsorbProp[505]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0504_CASSIOPEE_pos", _CASSIOPEE_pos_var._position_absolute, _CASSIOPEE_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0504_CASSIOPEE_pos", "text", "NONE", "CASSIOPEE", "char*");
        mccomp_param_nexus(nxhandle,"0504_CASSIOPEE_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0504_CASSIOPEE_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0504_CASSIOPEE_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_pos_setpos */

/* component CASSIOPEE=Arm() SETTING, POSITION/ROTATION */
int _CASSIOPEE_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_setpos] component CASSIOPEE=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CASSIOPEE_var._name, "CASSIOPEE", 16384);
  stracpy(_CASSIOPEE_var._type, "Arm", 16384);
  _CASSIOPEE_var._index=506;
  int current_setpos_index = 506;
  /* component CASSIOPEE=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_pos_var._rotation_absolute, _CASSIOPEE_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_pos_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_var._rotation_absolute, tr1, _CASSIOPEE_var._rotation_relative);
    _CASSIOPEE_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_var._position_absolute = coords_add(_CASSIOPEE_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_pos_var._position_absolute, _CASSIOPEE_var._position_absolute);
    _CASSIOPEE_var._position_relative = rot_apply(_CASSIOPEE_var._rotation_absolute, tc1);
  } /* CASSIOPEE=Arm() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE", _CASSIOPEE_var._position_absolute, _CASSIOPEE_var._rotation_absolute);
  instrument->_position_absolute[506] = _CASSIOPEE_var._position_absolute;
  instrument->_position_relative[506] = _CASSIOPEE_var._position_relative;
    _CASSIOPEE_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_var._position_relative);
  instrument->counter_N[506]  = instrument->counter_P[506] = instrument->counter_P2[506] = 0;
  instrument->counter_AbsorbProp[506]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0505_CASSIOPEE", _CASSIOPEE_var._position_absolute, _CASSIOPEE_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_setpos */

/* component CASSIOPEE_Source_HU60=Undulator() SETTING, POSITION/ROTATION */
int _CASSIOPEE_Source_HU60_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_Source_HU60_setpos] component CASSIOPEE_Source_HU60=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_CASSIOPEE_Source_HU60_var._name, "CASSIOPEE_Source_HU60", 16384);
  stracpy(_CASSIOPEE_Source_HU60_var._type, "Undulator", 16384);
  _CASSIOPEE_Source_HU60_var._index=507;
  int current_setpos_index = 507;
  _CASSIOPEE_Source_HU60_var._parameters.E0 = _instrument_var._parameters.CASSIOPEE_E0;
  _CASSIOPEE_Source_HU60_var._parameters.dE = 1e-3;
  _CASSIOPEE_Source_HU60_var._parameters.phase = 0;
  _CASSIOPEE_Source_HU60_var._parameters.randomphase = 1;
  _CASSIOPEE_Source_HU60_var._parameters.Ee = 2.75;
  _CASSIOPEE_Source_HU60_var._parameters.dEe = 0;
  _CASSIOPEE_Source_HU60_var._parameters.Ie = 0.5;
  _CASSIOPEE_Source_HU60_var._parameters.B = 0;
  _CASSIOPEE_Source_HU60_var._parameters.K = 5;
  _CASSIOPEE_Source_HU60_var._parameters.Nper = 1;
  _CASSIOPEE_Source_HU60_var._parameters.lu = 16e-3;
  _CASSIOPEE_Source_HU60_var._parameters.sigey = 10.6e-6;
  _CASSIOPEE_Source_HU60_var._parameters.sigex = 217.4e-6;
  _CASSIOPEE_Source_HU60_var._parameters.sigepx = 31.4e-6;
  _CASSIOPEE_Source_HU60_var._parameters.sigepy = 4.2e-6;
  _CASSIOPEE_Source_HU60_var._parameters.focus_xw = 0;
  _CASSIOPEE_Source_HU60_var._parameters.focus_yh = 0;
  _CASSIOPEE_Source_HU60_var._parameters.dist = 1;
  _CASSIOPEE_Source_HU60_var._parameters.quick_integ = 0;
  _CASSIOPEE_Source_HU60_var._parameters.E1st = 0;
  _CASSIOPEE_Source_HU60_var._parameters.verbose = 0;
  _CASSIOPEE_Source_HU60_var._parameters.Br = 1.35;


  /* component CASSIOPEE_Source_HU60=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_var._rotation_absolute, _CASSIOPEE_Source_HU60_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_Source_HU60_var._rotation_absolute, tr1, _CASSIOPEE_Source_HU60_var._rotation_relative);
    _CASSIOPEE_Source_HU60_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_Source_HU60_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_Source_HU60_var._position_absolute = coords_add(_CASSIOPEE_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_var._position_absolute, _CASSIOPEE_Source_HU60_var._position_absolute);
    _CASSIOPEE_Source_HU60_var._position_relative = rot_apply(_CASSIOPEE_Source_HU60_var._rotation_absolute, tc1);
  } /* CASSIOPEE_Source_HU60=Undulator() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_Source_HU60", _CASSIOPEE_Source_HU60_var._position_absolute, _CASSIOPEE_Source_HU60_var._rotation_absolute);
  instrument->_position_absolute[507] = _CASSIOPEE_Source_HU60_var._position_absolute;
  instrument->_position_relative[507] = _CASSIOPEE_Source_HU60_var._position_relative;
    _CASSIOPEE_Source_HU60_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_Source_HU60_var._position_relative);
  instrument->counter_N[507]  = instrument->counter_P[507] = instrument->counter_P2[507] = 0;
  instrument->counter_AbsorbProp[507]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", _CASSIOPEE_Source_HU60_var._position_absolute, _CASSIOPEE_Source_HU60_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "E0", "0", "_instrument_var._parameters.CASSIOPEE_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "dE", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "dEe", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "K", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "Nper", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "lu", "16e-3", "16e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "sigey", "0", "10.6e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "sigex", "0", "217.4e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "sigepx", "0", "31.4e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "sigepy", "0", "4.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0506_CASSIOPEE_Source_HU60", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_Source_HU60_setpos */

/* component CASSIOPEE_Source_HU256=Undulator() SETTING, POSITION/ROTATION */
int _CASSIOPEE_Source_HU256_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_Source_HU256_setpos] component CASSIOPEE_Source_HU256=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_CASSIOPEE_Source_HU256_var._name, "CASSIOPEE_Source_HU256", 16384);
  stracpy(_CASSIOPEE_Source_HU256_var._type, "Undulator", 16384);
  _CASSIOPEE_Source_HU256_var._index=508;
  int current_setpos_index = 508;
  _CASSIOPEE_Source_HU256_var._parameters.E0 = _instrument_var._parameters.CASSIOPEE_E0;
  _CASSIOPEE_Source_HU256_var._parameters.dE = 1e-3;
  _CASSIOPEE_Source_HU256_var._parameters.phase = 0;
  _CASSIOPEE_Source_HU256_var._parameters.randomphase = 1;
  _CASSIOPEE_Source_HU256_var._parameters.Ee = 2.75;
  _CASSIOPEE_Source_HU256_var._parameters.dEe = 0;
  _CASSIOPEE_Source_HU256_var._parameters.Ie = 0.5;
  _CASSIOPEE_Source_HU256_var._parameters.B = 0;
  _CASSIOPEE_Source_HU256_var._parameters.K = 5;
  _CASSIOPEE_Source_HU256_var._parameters.Nper = 1;
  _CASSIOPEE_Source_HU256_var._parameters.lu = 16e-3;
  _CASSIOPEE_Source_HU256_var._parameters.sigey = 8.2e-6;
  _CASSIOPEE_Source_HU256_var._parameters.sigex = 214.7e-6;
  _CASSIOPEE_Source_HU256_var._parameters.sigepx = 31.4e-6;
  _CASSIOPEE_Source_HU256_var._parameters.sigepy = 4.2e-6;
  _CASSIOPEE_Source_HU256_var._parameters.focus_xw = 0;
  _CASSIOPEE_Source_HU256_var._parameters.focus_yh = 0;
  _CASSIOPEE_Source_HU256_var._parameters.dist = 1;
  _CASSIOPEE_Source_HU256_var._parameters.quick_integ = 0;
  _CASSIOPEE_Source_HU256_var._parameters.E1st = 0;
  _CASSIOPEE_Source_HU256_var._parameters.verbose = 0;
  _CASSIOPEE_Source_HU256_var._parameters.Br = 1.35;


  /* component CASSIOPEE_Source_HU256=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_Source_HU60_var._rotation_absolute, _CASSIOPEE_Source_HU256_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_Source_HU60_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_Source_HU256_var._rotation_absolute, tr1, _CASSIOPEE_Source_HU256_var._rotation_relative);
    _CASSIOPEE_Source_HU256_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_Source_HU256_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2.727);
    rot_transpose(_CASSIOPEE_Source_HU60_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_Source_HU256_var._position_absolute = coords_add(_CASSIOPEE_Source_HU60_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_Source_HU60_var._position_absolute, _CASSIOPEE_Source_HU256_var._position_absolute);
    _CASSIOPEE_Source_HU256_var._position_relative = rot_apply(_CASSIOPEE_Source_HU256_var._rotation_absolute, tc1);
  } /* CASSIOPEE_Source_HU256=Undulator() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_Source_HU256", _CASSIOPEE_Source_HU256_var._position_absolute, _CASSIOPEE_Source_HU256_var._rotation_absolute);
  instrument->_position_absolute[508] = _CASSIOPEE_Source_HU256_var._position_absolute;
  instrument->_position_relative[508] = _CASSIOPEE_Source_HU256_var._position_relative;
    _CASSIOPEE_Source_HU256_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_Source_HU256_var._position_relative);
  instrument->counter_N[508]  = instrument->counter_P[508] = instrument->counter_P2[508] = 0;
  instrument->counter_AbsorbProp[508]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", _CASSIOPEE_Source_HU256_var._position_absolute, _CASSIOPEE_Source_HU256_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "E0", "0", "_instrument_var._parameters.CASSIOPEE_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "dE", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "dEe", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "B", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "K", "0", "5","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "Nper", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "lu", "16e-3", "16e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "sigey", "0", "8.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "sigex", "0", "214.7e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "sigepx", "0", "31.4e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "sigepy", "0", "4.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0507_CASSIOPEE_Source_HU256", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_Source_HU256_setpos */

/* component CASSIOPEE_M1a_location=Arm() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M1a_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M1a_location_setpos] component CASSIOPEE_M1a_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CASSIOPEE_M1a_location_var._name, "CASSIOPEE_M1a_location", 16384);
  stracpy(_CASSIOPEE_M1a_location_var._type, "Arm", 16384);
  _CASSIOPEE_M1a_location_var._index=509;
  int current_setpos_index = 509;
  /* component CASSIOPEE_M1a_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_Source_HU60_var._rotation_absolute, _CASSIOPEE_M1a_location_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_Source_HU256_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M1a_location_var._rotation_absolute, tr1, _CASSIOPEE_M1a_location_var._rotation_relative);
    _CASSIOPEE_M1a_location_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M1a_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 21.83);
    rot_transpose(_CASSIOPEE_Source_HU60_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M1a_location_var._position_absolute = coords_add(_CASSIOPEE_Source_HU60_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_Source_HU256_var._position_absolute, _CASSIOPEE_M1a_location_var._position_absolute);
    _CASSIOPEE_M1a_location_var._position_relative = rot_apply(_CASSIOPEE_M1a_location_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M1a_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M1a_location", _CASSIOPEE_M1a_location_var._position_absolute, _CASSIOPEE_M1a_location_var._rotation_absolute);
  instrument->_position_absolute[509] = _CASSIOPEE_M1a_location_var._position_absolute;
  instrument->_position_relative[509] = _CASSIOPEE_M1a_location_var._position_relative;
    _CASSIOPEE_M1a_location_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M1a_location_var._position_relative);
  instrument->counter_N[509]  = instrument->counter_P[509] = instrument->counter_P2[509] = 0;
  instrument->counter_AbsorbProp[509]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0508_CASSIOPEE_M1a_location", _CASSIOPEE_M1a_location_var._position_absolute, _CASSIOPEE_M1a_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M1a_location_setpos */

/* component CASSIOPEE_M1a=Mirror_curved() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M1a_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M1a_setpos] component CASSIOPEE_M1a=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_CASSIOPEE_M1a_var._name, "CASSIOPEE_M1a", 16384);
  stracpy(_CASSIOPEE_M1a_var._type, "Mirror_curved", 16384);
  _CASSIOPEE_M1a_var._index=510;
  int current_setpos_index = 510;
  _CASSIOPEE_M1a_var._parameters.radius = 0;
  _CASSIOPEE_M1a_var._parameters.R0 = 1;
  if(_instrument_var._parameters.CASSIOPEE_mirror_material && strlen(_instrument_var._parameters.CASSIOPEE_mirror_material))
    stracpy(_CASSIOPEE_M1a_var._parameters.coating, _instrument_var._parameters.CASSIOPEE_mirror_material ? _instrument_var._parameters.CASSIOPEE_mirror_material : "", 16384);
  else 
  _CASSIOPEE_M1a_var._parameters.coating[0]='\0';
  _CASSIOPEE_M1a_var._parameters.zdepth = 0.130;
  _CASSIOPEE_M1a_var._parameters.yheight = 0.025;
  _CASSIOPEE_M1a_var._parameters.length = 0;
  _CASSIOPEE_M1a_var._parameters.width = 0;


  /* component CASSIOPEE_M1a=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (_instrument_var._parameters.CASSIOPEE_M1_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1a_location_var._rotation_absolute, _CASSIOPEE_M1a_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_Source_HU256_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M1a_var._rotation_absolute, tr1, _CASSIOPEE_M1a_var._rotation_relative);
    _CASSIOPEE_M1a_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M1a_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_M1a_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M1a_var._position_absolute = coords_add(_CASSIOPEE_M1a_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_Source_HU256_var._position_absolute, _CASSIOPEE_M1a_var._position_absolute);
    _CASSIOPEE_M1a_var._position_relative = rot_apply(_CASSIOPEE_M1a_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M1a=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M1a", _CASSIOPEE_M1a_var._position_absolute, _CASSIOPEE_M1a_var._rotation_absolute);
  instrument->_position_absolute[510] = _CASSIOPEE_M1a_var._position_absolute;
  instrument->_position_relative[510] = _CASSIOPEE_M1a_var._position_relative;
    _CASSIOPEE_M1a_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M1a_var._position_relative);
  instrument->counter_N[510]  = instrument->counter_P[510] = instrument->counter_P2[510] = 0;
  instrument->counter_AbsorbProp[510]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0509_CASSIOPEE_M1a", _CASSIOPEE_M1a_var._position_absolute, _CASSIOPEE_M1a_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "radius", "1", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "coating", "Be.txt", _instrument_var._parameters.CASSIOPEE_mirror_material, "char*");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "zdepth", "0.2", "0.130","MCNUM");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "yheight", "0.2", "0.025","MCNUM");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "length", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0509_CASSIOPEE_M1a", "width", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M1a_setpos */

/* component CASSIOPEE_M1a_out=Arm() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M1a_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M1a_out_setpos] component CASSIOPEE_M1a_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CASSIOPEE_M1a_out_var._name, "CASSIOPEE_M1a_out", 16384);
  stracpy(_CASSIOPEE_M1a_out_var._type, "Arm", 16384);
  _CASSIOPEE_M1a_out_var._index=511;
  int current_setpos_index = 511;
  /* component CASSIOPEE_M1a_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (2 * _instrument_var._parameters.CASSIOPEE_M1_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1a_location_var._rotation_absolute, _CASSIOPEE_M1a_out_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M1a_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M1a_out_var._rotation_absolute, tr1, _CASSIOPEE_M1a_out_var._rotation_relative);
    _CASSIOPEE_M1a_out_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M1a_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_M1a_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M1a_out_var._position_absolute = coords_add(_CASSIOPEE_M1a_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M1a_var._position_absolute, _CASSIOPEE_M1a_out_var._position_absolute);
    _CASSIOPEE_M1a_out_var._position_relative = rot_apply(_CASSIOPEE_M1a_out_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M1a_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M1a_out", _CASSIOPEE_M1a_out_var._position_absolute, _CASSIOPEE_M1a_out_var._rotation_absolute);
  instrument->_position_absolute[511] = _CASSIOPEE_M1a_out_var._position_absolute;
  instrument->_position_relative[511] = _CASSIOPEE_M1a_out_var._position_relative;
    _CASSIOPEE_M1a_out_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M1a_out_var._position_relative);
  instrument->counter_N[511]  = instrument->counter_P[511] = instrument->counter_P2[511] = 0;
  instrument->counter_AbsorbProp[511]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0510_CASSIOPEE_M1a_out", _CASSIOPEE_M1a_out_var._position_absolute, _CASSIOPEE_M1a_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M1a_out_setpos */

/* component CASSIOPEE_M1b=Mirror_curved() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M1b_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M1b_setpos] component CASSIOPEE_M1b=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_CASSIOPEE_M1b_var._name, "CASSIOPEE_M1b", 16384);
  stracpy(_CASSIOPEE_M1b_var._type, "Mirror_curved", 16384);
  _CASSIOPEE_M1b_var._index=512;
  int current_setpos_index = 512;
  _CASSIOPEE_M1b_var._parameters.radius = -108.4;
  _CASSIOPEE_M1b_var._parameters.R0 = 1;
  if(_instrument_var._parameters.CASSIOPEE_mirror_material && strlen(_instrument_var._parameters.CASSIOPEE_mirror_material))
    stracpy(_CASSIOPEE_M1b_var._parameters.coating, _instrument_var._parameters.CASSIOPEE_mirror_material ? _instrument_var._parameters.CASSIOPEE_mirror_material : "", 16384);
  else 
  _CASSIOPEE_M1b_var._parameters.coating[0]='\0';
  _CASSIOPEE_M1b_var._parameters.zdepth = 0.2;
  _CASSIOPEE_M1b_var._parameters.yheight = 0.2;
  _CASSIOPEE_M1b_var._parameters.length = 0.150;
  _CASSIOPEE_M1b_var._parameters.width = 0.025;


  /* component CASSIOPEE_M1b=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.CASSIOPEE_M1_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1a_out_var._rotation_absolute, _CASSIOPEE_M1b_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M1a_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M1b_var._rotation_absolute, tr1, _CASSIOPEE_M1b_var._rotation_relative);
    _CASSIOPEE_M1b_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M1b_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.352);
    rot_transpose(_CASSIOPEE_M1a_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M1b_var._position_absolute = coords_add(_CASSIOPEE_M1a_out_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M1a_var._position_absolute, _CASSIOPEE_M1b_var._position_absolute);
    _CASSIOPEE_M1b_var._position_relative = rot_apply(_CASSIOPEE_M1b_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M1b=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M1b", _CASSIOPEE_M1b_var._position_absolute, _CASSIOPEE_M1b_var._rotation_absolute);
  instrument->_position_absolute[512] = _CASSIOPEE_M1b_var._position_absolute;
  instrument->_position_relative[512] = _CASSIOPEE_M1b_var._position_relative;
    _CASSIOPEE_M1b_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M1b_var._position_relative);
  instrument->counter_N[512]  = instrument->counter_P[512] = instrument->counter_P2[512] = 0;
  instrument->counter_AbsorbProp[512]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0511_CASSIOPEE_M1b", _CASSIOPEE_M1b_var._position_absolute, _CASSIOPEE_M1b_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "radius", "1", "-108.4","MCNUM");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "coating", "Be.txt", _instrument_var._parameters.CASSIOPEE_mirror_material, "char*");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "length", "0", "0.150","MCNUM");
        mccomp_param_nexus(nxhandle,"0511_CASSIOPEE_M1b", "width", "0", "0.025","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M1b_setpos */

/* component CASSIOPEE_M1c=Mirror_curved() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M1c_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M1c_setpos] component CASSIOPEE_M1c=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_CASSIOPEE_M1c_var._name, "CASSIOPEE_M1c", 16384);
  stracpy(_CASSIOPEE_M1c_var._type, "Mirror_curved", 16384);
  _CASSIOPEE_M1c_var._index=513;
  int current_setpos_index = 513;
  _CASSIOPEE_M1c_var._parameters.radius = -120;
  _CASSIOPEE_M1c_var._parameters.R0 = 1;
  if(_instrument_var._parameters.CASSIOPEE_mirror_material && strlen(_instrument_var._parameters.CASSIOPEE_mirror_material))
    stracpy(_CASSIOPEE_M1c_var._parameters.coating, _instrument_var._parameters.CASSIOPEE_mirror_material ? _instrument_var._parameters.CASSIOPEE_mirror_material : "", 16384);
  else 
  _CASSIOPEE_M1c_var._parameters.coating[0]='\0';
  _CASSIOPEE_M1c_var._parameters.zdepth = 0.2;
  _CASSIOPEE_M1c_var._parameters.yheight = 0.2;
  _CASSIOPEE_M1c_var._parameters.length = 0.160;
  _CASSIOPEE_M1c_var._parameters.width = 0.025;


  /* component CASSIOPEE_M1c=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.CASSIOPEE_M1_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1a_out_var._rotation_absolute, _CASSIOPEE_M1c_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M1b_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M1c_var._rotation_absolute, tr1, _CASSIOPEE_M1c_var._rotation_relative);
    _CASSIOPEE_M1c_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M1c_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.352 + 0.357);
    rot_transpose(_CASSIOPEE_M1a_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M1c_var._position_absolute = coords_add(_CASSIOPEE_M1a_out_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M1b_var._position_absolute, _CASSIOPEE_M1c_var._position_absolute);
    _CASSIOPEE_M1c_var._position_relative = rot_apply(_CASSIOPEE_M1c_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M1c=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M1c", _CASSIOPEE_M1c_var._position_absolute, _CASSIOPEE_M1c_var._rotation_absolute);
  instrument->_position_absolute[513] = _CASSIOPEE_M1c_var._position_absolute;
  instrument->_position_relative[513] = _CASSIOPEE_M1c_var._position_relative;
    _CASSIOPEE_M1c_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M1c_var._position_relative);
  instrument->counter_N[513]  = instrument->counter_P[513] = instrument->counter_P2[513] = 0;
  instrument->counter_AbsorbProp[513]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0512_CASSIOPEE_M1c", _CASSIOPEE_M1c_var._position_absolute, _CASSIOPEE_M1c_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "radius", "1", "-120","MCNUM");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "coating", "Be.txt", _instrument_var._parameters.CASSIOPEE_mirror_material, "char*");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "length", "0", "0.160","MCNUM");
        mccomp_param_nexus(nxhandle,"0512_CASSIOPEE_M1c", "width", "0", "0.025","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M1c_setpos */

/* component CASSIOPEE_M1bc_out=Arm() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M1bc_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M1bc_out_setpos] component CASSIOPEE_M1bc_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CASSIOPEE_M1bc_out_var._name, "CASSIOPEE_M1bc_out", 16384);
  stracpy(_CASSIOPEE_M1bc_out_var._type, "Arm", 16384);
  _CASSIOPEE_M1bc_out_var._index=514;
  int current_setpos_index = 514;
  /* component CASSIOPEE_M1bc_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (- _instrument_var._parameters.CASSIOPEE_M1_angle)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1c_var._rotation_absolute, _CASSIOPEE_M1bc_out_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M1c_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M1bc_out_var._rotation_absolute, tr1, _CASSIOPEE_M1bc_out_var._rotation_relative);
    _CASSIOPEE_M1bc_out_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M1bc_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_M1c_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M1bc_out_var._position_absolute = coords_add(_CASSIOPEE_M1c_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M1c_var._position_absolute, _CASSIOPEE_M1bc_out_var._position_absolute);
    _CASSIOPEE_M1bc_out_var._position_relative = rot_apply(_CASSIOPEE_M1bc_out_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M1bc_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M1bc_out", _CASSIOPEE_M1bc_out_var._position_absolute, _CASSIOPEE_M1bc_out_var._rotation_absolute);
  instrument->_position_absolute[514] = _CASSIOPEE_M1bc_out_var._position_absolute;
  instrument->_position_relative[514] = _CASSIOPEE_M1bc_out_var._position_relative;
    _CASSIOPEE_M1bc_out_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M1bc_out_var._position_relative);
  instrument->counter_N[514]  = instrument->counter_P[514] = instrument->counter_P2[514] = 0;
  instrument->counter_AbsorbProp[514]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0513_CASSIOPEE_M1bc_out", _CASSIOPEE_M1bc_out_var._position_absolute, _CASSIOPEE_M1bc_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M1bc_out_setpos */

/* component CASSIOPEE_PSD_M1out=Monitor_nD() SETTING, POSITION/ROTATION */
int _CASSIOPEE_PSD_M1out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_PSD_M1out_setpos] component CASSIOPEE_PSD_M1out=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_CASSIOPEE_PSD_M1out_var._name, "CASSIOPEE_PSD_M1out", 16384);
  stracpy(_CASSIOPEE_PSD_M1out_var._type, "Monitor_nD", 16384);
  _CASSIOPEE_PSD_M1out_var._index=515;
  int current_setpos_index = 515;
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.user9[0]='\0';
  _CASSIOPEE_PSD_M1out_var._parameters.xwidth = 1e-3;
  _CASSIOPEE_PSD_M1out_var._parameters.yheight = 1e-3;
  _CASSIOPEE_PSD_M1out_var._parameters.zdepth = 0;
  _CASSIOPEE_PSD_M1out_var._parameters.bins = 512;
  _CASSIOPEE_PSD_M1out_var._parameters.min = -1e40;
  _CASSIOPEE_PSD_M1out_var._parameters.max = 1e40;
  _CASSIOPEE_PSD_M1out_var._parameters.restore_xray = 0;
  _CASSIOPEE_PSD_M1out_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.geometry[0]='\0';
  _CASSIOPEE_PSD_M1out_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_M1out_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_M1out_var._parameters.username9[0]='\0';


  /* component CASSIOPEE_PSD_M1out=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1bc_out_var._rotation_absolute, _CASSIOPEE_PSD_M1out_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M1c_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_PSD_M1out_var._rotation_absolute, tr1, _CASSIOPEE_PSD_M1out_var._rotation_relative);
    _CASSIOPEE_PSD_M1out_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_PSD_M1out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 3);
    rot_transpose(_CASSIOPEE_M1bc_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_PSD_M1out_var._position_absolute = coords_add(_CASSIOPEE_M1bc_out_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M1c_var._position_absolute, _CASSIOPEE_PSD_M1out_var._position_absolute);
    _CASSIOPEE_PSD_M1out_var._position_relative = rot_apply(_CASSIOPEE_PSD_M1out_var._rotation_absolute, tc1);
  } /* CASSIOPEE_PSD_M1out=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_PSD_M1out", _CASSIOPEE_PSD_M1out_var._position_absolute, _CASSIOPEE_PSD_M1out_var._rotation_absolute);
  instrument->_position_absolute[515] = _CASSIOPEE_PSD_M1out_var._position_absolute;
  instrument->_position_relative[515] = _CASSIOPEE_PSD_M1out_var._position_relative;
    _CASSIOPEE_PSD_M1out_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_PSD_M1out_var._position_relative);
  instrument->counter_N[515]  = instrument->counter_P[515] = instrument->counter_P2[515] = 0;
  instrument->counter_AbsorbProp[515]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", _CASSIOPEE_PSD_M1out_var._position_absolute, _CASSIOPEE_PSD_M1out_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "xwidth", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "yheight", "0", "1e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0514_CASSIOPEE_PSD_M1out", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_PSD_M1out_setpos */

/* component CASSIOPEE_PG_location=Arm() SETTING, POSITION/ROTATION */
int _CASSIOPEE_PG_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_PG_location_setpos] component CASSIOPEE_PG_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CASSIOPEE_PG_location_var._name, "CASSIOPEE_PG_location", 16384);
  stracpy(_CASSIOPEE_PG_location_var._type, "Arm", 16384);
  _CASSIOPEE_PG_location_var._index=516;
  int current_setpos_index = 516;
  /* component CASSIOPEE_PG_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M1bc_out_var._rotation_absolute, _CASSIOPEE_PG_location_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_PSD_M1out_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_PG_location_var._rotation_absolute, tr1, _CASSIOPEE_PG_location_var._rotation_relative);
    _CASSIOPEE_PG_location_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_PG_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 6 - 0.352 - 0.357);
    rot_transpose(_CASSIOPEE_M1bc_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_PG_location_var._position_absolute = coords_add(_CASSIOPEE_M1bc_out_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_PSD_M1out_var._position_absolute, _CASSIOPEE_PG_location_var._position_absolute);
    _CASSIOPEE_PG_location_var._position_relative = rot_apply(_CASSIOPEE_PG_location_var._rotation_absolute, tc1);
  } /* CASSIOPEE_PG_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_PG_location", _CASSIOPEE_PG_location_var._position_absolute, _CASSIOPEE_PG_location_var._rotation_absolute);
  instrument->_position_absolute[516] = _CASSIOPEE_PG_location_var._position_absolute;
  instrument->_position_relative[516] = _CASSIOPEE_PG_location_var._position_relative;
    _CASSIOPEE_PG_location_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_PG_location_var._position_relative);
  instrument->counter_N[516]  = instrument->counter_P[516] = instrument->counter_P2[516] = 0;
  instrument->counter_AbsorbProp[516]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0515_CASSIOPEE_PG_location", _CASSIOPEE_PG_location_var._position_absolute, _CASSIOPEE_PG_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_PG_location_setpos */

/* component CASSIOPEE_PG=Grating_reflect() SETTING, POSITION/ROTATION */
int _CASSIOPEE_PG_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_PG_setpos] component CASSIOPEE_PG=Grating_reflect() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Grating_reflect.comp:79]");
  stracpy(_CASSIOPEE_PG_var._name, "CASSIOPEE_PG", 16384);
  stracpy(_CASSIOPEE_PG_var._type, "Grating_reflect", 16384);
  _CASSIOPEE_PG_var._index=517;
  int current_setpos_index = 517;
  _CASSIOPEE_PG_var._parameters.d_phi = 2;
  _CASSIOPEE_PG_var._parameters.R0 = 1;
  _CASSIOPEE_PG_var._parameters.rho_l = _instrument_var._parameters.CASSIOPEE_r_rho;
  _CASSIOPEE_PG_var._parameters.order = 1;
  _CASSIOPEE_PG_var._parameters.phi0 = 0;
  _CASSIOPEE_PG_var._parameters.zdepth = 0.095;
  _CASSIOPEE_PG_var._parameters.xwidth = 0.040;
  _CASSIOPEE_PG_var._parameters.verbose = 0;


  /* component CASSIOPEE_PG=Grating_reflect() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.CASSIOPEE_PG_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_PG_location_var._rotation_absolute, _CASSIOPEE_PG_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_PSD_M1out_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_PG_var._rotation_absolute, tr1, _CASSIOPEE_PG_var._rotation_relative);
    _CASSIOPEE_PG_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_PG_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_PG_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_PG_var._position_absolute = coords_add(_CASSIOPEE_PG_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_PSD_M1out_var._position_absolute, _CASSIOPEE_PG_var._position_absolute);
    _CASSIOPEE_PG_var._position_relative = rot_apply(_CASSIOPEE_PG_var._rotation_absolute, tc1);
  } /* CASSIOPEE_PG=Grating_reflect() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_PG", _CASSIOPEE_PG_var._position_absolute, _CASSIOPEE_PG_var._rotation_absolute);
  instrument->_position_absolute[517] = _CASSIOPEE_PG_var._position_absolute;
  instrument->_position_relative[517] = _CASSIOPEE_PG_var._position_relative;
    _CASSIOPEE_PG_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_PG_var._position_relative);
  instrument->counter_N[517]  = instrument->counter_P[517] = instrument->counter_P2[517] = 0;
  instrument->counter_AbsorbProp[517]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0516_CASSIOPEE_PG", _CASSIOPEE_PG_var._position_absolute, _CASSIOPEE_PG_var._rotation_absolute, "Grating_reflect");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "d_phi", "1", "2","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "rho_l", "800", "_instrument_var._parameters.CASSIOPEE_r_rho","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "order", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "phi0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "zdepth", "0.015", "0.095","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "xwidth", "0.136", "0.040","MCNUM");
        mccomp_param_nexus(nxhandle,"0516_CASSIOPEE_PG", "verbose", "0", "0","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_PG_setpos */

/* component CASSIOPEE_M2_rotation_axis=Monitor_nD() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M2_rotation_axis_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M2_rotation_axis_setpos] component CASSIOPEE_M2_rotation_axis=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_CASSIOPEE_M2_rotation_axis_var._name, "CASSIOPEE_M2_rotation_axis", 16384);
  stracpy(_CASSIOPEE_M2_rotation_axis_var._type, "Monitor_nD", 16384);
  _CASSIOPEE_M2_rotation_axis_var._index=518;
  int current_setpos_index = 518;
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.user9[0]='\0';
  _CASSIOPEE_M2_rotation_axis_var._parameters.xwidth = 1e-2;
  _CASSIOPEE_M2_rotation_axis_var._parameters.yheight = 1e-2;
  _CASSIOPEE_M2_rotation_axis_var._parameters.zdepth = 0;
  _CASSIOPEE_M2_rotation_axis_var._parameters.bins = 512;
  _CASSIOPEE_M2_rotation_axis_var._parameters.min = -1e40;
  _CASSIOPEE_M2_rotation_axis_var._parameters.max = 1e40;
  _CASSIOPEE_M2_rotation_axis_var._parameters.restore_xray = 0;
  _CASSIOPEE_M2_rotation_axis_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.geometry[0]='\0';
  _CASSIOPEE_M2_rotation_axis_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_M2_rotation_axis_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_M2_rotation_axis_var._parameters.username9[0]='\0';


  /* component CASSIOPEE_M2_rotation_axis=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_PG_location_var._rotation_absolute, _CASSIOPEE_M2_rotation_axis_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_PG_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M2_rotation_axis_var._rotation_absolute, tr1, _CASSIOPEE_M2_rotation_axis_var._rotation_relative);
    _CASSIOPEE_M2_rotation_axis_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M2_rotation_axis_var._rotation_relative);
    tc1 = coords_set(
      0, -0.01, 0);
    rot_transpose(_CASSIOPEE_PG_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M2_rotation_axis_var._position_absolute = coords_add(_CASSIOPEE_PG_location_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_PG_var._position_absolute, _CASSIOPEE_M2_rotation_axis_var._position_absolute);
    _CASSIOPEE_M2_rotation_axis_var._position_relative = rot_apply(_CASSIOPEE_M2_rotation_axis_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M2_rotation_axis=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M2_rotation_axis", _CASSIOPEE_M2_rotation_axis_var._position_absolute, _CASSIOPEE_M2_rotation_axis_var._rotation_absolute);
  instrument->_position_absolute[518] = _CASSIOPEE_M2_rotation_axis_var._position_absolute;
  instrument->_position_relative[518] = _CASSIOPEE_M2_rotation_axis_var._position_relative;
    _CASSIOPEE_M2_rotation_axis_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M2_rotation_axis_var._position_relative);
  instrument->counter_N[518]  = instrument->counter_P[518] = instrument->counter_P2[518] = 0;
  instrument->counter_AbsorbProp[518]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", _CASSIOPEE_M2_rotation_axis_var._position_absolute, _CASSIOPEE_M2_rotation_axis_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0517_CASSIOPEE_M2_rotation_axis", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M2_rotation_axis_setpos */

/* component CASSIOPEE_M2=Mirror() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M2_setpos] component CASSIOPEE_M2=Mirror() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:69]");
  stracpy(_CASSIOPEE_M2_var._name, "CASSIOPEE_M2", 16384);
  stracpy(_CASSIOPEE_M2_var._type, "Mirror", 16384);
  _CASSIOPEE_M2_var._index=519;
  int current_setpos_index = 519;
  _CASSIOPEE_M2_var._parameters.zdepth = 0.320;
  _CASSIOPEE_M2_var._parameters.xwidth = 0.030;
  _CASSIOPEE_M2_var._parameters.yheight = 0;
  if(_instrument_var._parameters.CASSIOPEE_mirror_material && strlen(_instrument_var._parameters.CASSIOPEE_mirror_material))
    stracpy(_CASSIOPEE_M2_var._parameters.coating, _instrument_var._parameters.CASSIOPEE_mirror_material ? _instrument_var._parameters.CASSIOPEE_mirror_material : "", 16384);
  else 
  _CASSIOPEE_M2_var._parameters.coating[0]='\0';
  _CASSIOPEE_M2_var._parameters.R0 = 0;
  if("" && strlen(""))
    stracpy(_CASSIOPEE_M2_var._parameters.geometry, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_M2_var._parameters.geometry[0]='\0';


  /* component CASSIOPEE_M2=Mirror() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.CASSIOPEE_PM_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M2_rotation_axis_var._rotation_absolute, _CASSIOPEE_M2_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M2_rotation_axis_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M2_var._rotation_absolute, tr1, _CASSIOPEE_M2_var._rotation_relative);
    _CASSIOPEE_M2_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M2_var._rotation_relative);
    tc1 = coords_set(
      0, 0.02, .190);
    rot_transpose(_CASSIOPEE_M2_rotation_axis_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M2_var._position_absolute = coords_add(_CASSIOPEE_M2_rotation_axis_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M2_rotation_axis_var._position_absolute, _CASSIOPEE_M2_var._position_absolute);
    _CASSIOPEE_M2_var._position_relative = rot_apply(_CASSIOPEE_M2_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M2=Mirror() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M2", _CASSIOPEE_M2_var._position_absolute, _CASSIOPEE_M2_var._rotation_absolute);
  instrument->_position_absolute[519] = _CASSIOPEE_M2_var._position_absolute;
  instrument->_position_relative[519] = _CASSIOPEE_M2_var._position_relative;
    _CASSIOPEE_M2_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M2_var._position_relative);
  instrument->counter_N[519]  = instrument->counter_P[519] = instrument->counter_P2[519] = 0;
  instrument->counter_AbsorbProp[519]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0518_CASSIOPEE_M2", _CASSIOPEE_M2_var._position_absolute, _CASSIOPEE_M2_var._rotation_absolute, "Mirror");
        mccomp_param_nexus(nxhandle,"0518_CASSIOPEE_M2", "zdepth", "0.1", "0.320","MCNUM");
        mccomp_param_nexus(nxhandle,"0518_CASSIOPEE_M2", "xwidth", "0.01", "0.030","MCNUM");
        mccomp_param_nexus(nxhandle,"0518_CASSIOPEE_M2", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0518_CASSIOPEE_M2", "coating", "", _instrument_var._parameters.CASSIOPEE_mirror_material, "char*");
        mccomp_param_nexus(nxhandle,"0518_CASSIOPEE_M2", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0518_CASSIOPEE_M2", "geometry", "", "", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M2_setpos */

/* component CASSIOPEE_PM_takeoff=Arm() SETTING, POSITION/ROTATION */
int _CASSIOPEE_PM_takeoff_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_PM_takeoff_setpos] component CASSIOPEE_PM_takeoff=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_CASSIOPEE_PM_takeoff_var._name, "CASSIOPEE_PM_takeoff", 16384);
  stracpy(_CASSIOPEE_PM_takeoff_var._type, "Arm", 16384);
  _CASSIOPEE_PM_takeoff_var._index=520;
  int current_setpos_index = 520;
  /* component CASSIOPEE_PM_takeoff=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_Source_HU256_var._rotation_absolute, _CASSIOPEE_PM_takeoff_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M2_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_PM_takeoff_var._rotation_absolute, tr1, _CASSIOPEE_PM_takeoff_var._rotation_relative);
    _CASSIOPEE_PM_takeoff_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_PM_takeoff_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_M2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_PM_takeoff_var._position_absolute = coords_add(_CASSIOPEE_M2_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M2_var._position_absolute, _CASSIOPEE_PM_takeoff_var._position_absolute);
    _CASSIOPEE_PM_takeoff_var._position_relative = rot_apply(_CASSIOPEE_PM_takeoff_var._rotation_absolute, tc1);
  } /* CASSIOPEE_PM_takeoff=Arm() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_PM_takeoff", _CASSIOPEE_PM_takeoff_var._position_absolute, _CASSIOPEE_PM_takeoff_var._rotation_absolute);
  instrument->_position_absolute[520] = _CASSIOPEE_PM_takeoff_var._position_absolute;
  instrument->_position_relative[520] = _CASSIOPEE_PM_takeoff_var._position_relative;
    _CASSIOPEE_PM_takeoff_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_PM_takeoff_var._position_relative);
  instrument->counter_N[520]  = instrument->counter_P[520] = instrument->counter_P2[520] = 0;
  instrument->counter_AbsorbProp[520]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0519_CASSIOPEE_PM_takeoff", _CASSIOPEE_PM_takeoff_var._position_absolute, _CASSIOPEE_PM_takeoff_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_PM_takeoff_setpos */

/* component CASSIOPEE_slit=Slit() SETTING, POSITION/ROTATION */
int _CASSIOPEE_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_slit_setpos] component CASSIOPEE_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_CASSIOPEE_slit_var._name, "CASSIOPEE_slit", 16384);
  stracpy(_CASSIOPEE_slit_var._type, "Slit", 16384);
  _CASSIOPEE_slit_var._index=521;
  int current_setpos_index = 521;
  _CASSIOPEE_slit_var._parameters.xmin = 0;
  _CASSIOPEE_slit_var._parameters.xmax = 0;
  _CASSIOPEE_slit_var._parameters.ymin = 0;
  _CASSIOPEE_slit_var._parameters.ymax = 0;
  _CASSIOPEE_slit_var._parameters.radius = 0;
  _CASSIOPEE_slit_var._parameters.xwidth = 0.001;
  _CASSIOPEE_slit_var._parameters.yheight = 0.001;
  _CASSIOPEE_slit_var._parameters.dist = 0;
  _CASSIOPEE_slit_var._parameters.focus_xw = 0;
  _CASSIOPEE_slit_var._parameters.focus_yh = 0;
  _CASSIOPEE_slit_var._parameters.focus_x0 = 0;
  _CASSIOPEE_slit_var._parameters.focus_y0 = 0;

  /* component CASSIOPEE_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_Source_HU256_var._rotation_absolute, _CASSIOPEE_slit_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M2_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_slit_var._rotation_absolute, tr1, _CASSIOPEE_slit_var._rotation_relative);
    _CASSIOPEE_slit_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_slit_var._rotation_relative);
    tc1 = coords_set(
      -0.062, 0, 30.83);
    rot_transpose(_CASSIOPEE_Source_HU256_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_slit_var._position_absolute = coords_add(_CASSIOPEE_Source_HU256_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M2_var._position_absolute, _CASSIOPEE_slit_var._position_absolute);
    _CASSIOPEE_slit_var._position_relative = rot_apply(_CASSIOPEE_slit_var._rotation_absolute, tc1);
  } /* CASSIOPEE_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_slit", _CASSIOPEE_slit_var._position_absolute, _CASSIOPEE_slit_var._rotation_absolute);
  instrument->_position_absolute[521] = _CASSIOPEE_slit_var._position_absolute;
  instrument->_position_relative[521] = _CASSIOPEE_slit_var._position_relative;
    _CASSIOPEE_slit_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_slit_var._position_relative);
  instrument->counter_N[521]  = instrument->counter_P[521] = instrument->counter_P2[521] = 0;
  instrument->counter_AbsorbProp[521]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0520_CASSIOPEE_slit", _CASSIOPEE_slit_var._position_absolute, _CASSIOPEE_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "xwidth", "0.001", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "yheight", "0.001", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0520_CASSIOPEE_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_slit_setpos */

/* component CASSIOPEE_M4=Mirror_curved() SETTING, POSITION/ROTATION */
int _CASSIOPEE_M4_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_M4_setpos] component CASSIOPEE_M4=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_CASSIOPEE_M4_var._name, "CASSIOPEE_M4", 16384);
  stracpy(_CASSIOPEE_M4_var._type, "Mirror_curved", 16384);
  _CASSIOPEE_M4_var._index=522;
  int current_setpos_index = 522;
  _CASSIOPEE_M4_var._parameters.radius = 1;
  _CASSIOPEE_M4_var._parameters.R0 = 1;
  if(_instrument_var._parameters.CASSIOPEE_mirror_material && strlen(_instrument_var._parameters.CASSIOPEE_mirror_material))
    stracpy(_CASSIOPEE_M4_var._parameters.coating, _instrument_var._parameters.CASSIOPEE_mirror_material ? _instrument_var._parameters.CASSIOPEE_mirror_material : "", 16384);
  else 
  _CASSIOPEE_M4_var._parameters.coating[0]='\0';
  _CASSIOPEE_M4_var._parameters.zdepth = 0.2;
  _CASSIOPEE_M4_var._parameters.yheight = 0.2;
  _CASSIOPEE_M4_var._parameters.length = 0;
  _CASSIOPEE_M4_var._parameters.width = 0;


  /* component CASSIOPEE_M4=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_Source_HU256_var._rotation_absolute, _CASSIOPEE_M4_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_slit_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_M4_var._rotation_absolute, tr1, _CASSIOPEE_M4_var._rotation_relative);
    _CASSIOPEE_M4_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_M4_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_M4_var._position_absolute = coords_add(_CASSIOPEE_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_slit_var._position_absolute, _CASSIOPEE_M4_var._position_absolute);
    _CASSIOPEE_M4_var._position_relative = rot_apply(_CASSIOPEE_M4_var._rotation_absolute, tc1);
  } /* CASSIOPEE_M4=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_M4", _CASSIOPEE_M4_var._position_absolute, _CASSIOPEE_M4_var._rotation_absolute);
  instrument->_position_absolute[522] = _CASSIOPEE_M4_var._position_absolute;
  instrument->_position_relative[522] = _CASSIOPEE_M4_var._position_relative;
    _CASSIOPEE_M4_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_M4_var._position_relative);
  instrument->counter_N[522]  = instrument->counter_P[522] = instrument->counter_P2[522] = 0;
  instrument->counter_AbsorbProp[522]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0521_CASSIOPEE_M4", _CASSIOPEE_M4_var._position_absolute, _CASSIOPEE_M4_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "radius", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "coating", "Be.txt", _instrument_var._parameters.CASSIOPEE_mirror_material, "char*");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "length", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0521_CASSIOPEE_M4", "width", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_M4_setpos */

/* component CASSIOPEE_PSD=Monitor_nD() SETTING, POSITION/ROTATION */
int _CASSIOPEE_PSD_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_CASSIOPEE_PSD_setpos] component CASSIOPEE_PSD=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_CASSIOPEE_PSD_var._name, "CASSIOPEE_PSD", 16384);
  stracpy(_CASSIOPEE_PSD_var._type, "Monitor_nD", 16384);
  _CASSIOPEE_PSD_var._index=523;
  int current_setpos_index = 523;
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_CASSIOPEE_PSD_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.user9[0]='\0';
  _CASSIOPEE_PSD_var._parameters.xwidth = 1e-2;
  _CASSIOPEE_PSD_var._parameters.yheight = 1e-2;
  _CASSIOPEE_PSD_var._parameters.zdepth = 0;
  _CASSIOPEE_PSD_var._parameters.bins = 0;
  _CASSIOPEE_PSD_var._parameters.min = -1e40;
  _CASSIOPEE_PSD_var._parameters.max = 1e40;
  _CASSIOPEE_PSD_var._parameters.restore_xray = 0;
  _CASSIOPEE_PSD_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_CASSIOPEE_PSD_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.geometry[0]='\0';
  _CASSIOPEE_PSD_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_CASSIOPEE_PSD_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _CASSIOPEE_PSD_var._parameters.username9[0]='\0';


  /* component CASSIOPEE_PSD=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_M4_var._rotation_absolute, _CASSIOPEE_PSD_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_M4_var._rotation_absolute, tr1);
    rot_mul(_CASSIOPEE_PSD_var._rotation_absolute, tr1, _CASSIOPEE_PSD_var._rotation_relative);
    _CASSIOPEE_PSD_var._rotation_is_identity =  rot_test_identity(_CASSIOPEE_PSD_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_CASSIOPEE_M4_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _CASSIOPEE_PSD_var._position_absolute = coords_add(_CASSIOPEE_M4_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_M4_var._position_absolute, _CASSIOPEE_PSD_var._position_absolute);
    _CASSIOPEE_PSD_var._position_relative = rot_apply(_CASSIOPEE_PSD_var._rotation_absolute, tc1);
  } /* CASSIOPEE_PSD=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("CASSIOPEE_PSD", _CASSIOPEE_PSD_var._position_absolute, _CASSIOPEE_PSD_var._rotation_absolute);
  instrument->_position_absolute[523] = _CASSIOPEE_PSD_var._position_absolute;
  instrument->_position_relative[523] = _CASSIOPEE_PSD_var._position_relative;
    _CASSIOPEE_PSD_var._position_relative_is_zero =  coords_test_zero(_CASSIOPEE_PSD_var._position_relative);
  instrument->counter_N[523]  = instrument->counter_P[523] = instrument->counter_P2[523] = 0;
  instrument->counter_AbsorbProp[523]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0522_CASSIOPEE_PSD", _CASSIOPEE_PSD_var._position_absolute, _CASSIOPEE_PSD_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "xwidth", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "yheight", "0", "1e-2","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0522_CASSIOPEE_PSD", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _CASSIOPEE_PSD_setpos */

/* component beamdump_540=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_540_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_540_setpos] component beamdump_540=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_540_var._name, "beamdump_540", 16384);
  stracpy(_beamdump_540_var._type, "Beamstop", 16384);
  _beamdump_540_var._index=524;
  int current_setpos_index = 524;
  _beamdump_540_var._parameters.xmin = -0.05;
  _beamdump_540_var._parameters.xmax = 0.05;
  _beamdump_540_var._parameters.ymin = -0.05;
  _beamdump_540_var._parameters.ymax = 0.05;
  _beamdump_540_var._parameters.xwidth = 0;
  _beamdump_540_var._parameters.yheight = 0;
  _beamdump_540_var._parameters.radius = 0;

  /* component beamdump_540=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _CASSIOPEE_PSD_var._rotation_absolute, _beamdump_540_var._rotation_absolute);
    rot_transpose(_CASSIOPEE_PSD_var._rotation_absolute, tr1);
    rot_mul(_beamdump_540_var._rotation_absolute, tr1, _beamdump_540_var._rotation_relative);
    _beamdump_540_var._rotation_is_identity =  rot_test_identity(_beamdump_540_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_CASSIOPEE_PSD_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_540_var._position_absolute = coords_add(_CASSIOPEE_PSD_var._position_absolute, tc2);
    tc1 = coords_sub(_CASSIOPEE_PSD_var._position_absolute, _beamdump_540_var._position_absolute);
    _beamdump_540_var._position_relative = rot_apply(_beamdump_540_var._rotation_absolute, tc1);
  } /* beamdump_540=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_540", _beamdump_540_var._position_absolute, _beamdump_540_var._rotation_absolute);
  instrument->_position_absolute[524] = _beamdump_540_var._position_absolute;
  instrument->_position_relative[524] = _beamdump_540_var._position_relative;
    _beamdump_540_var._position_relative_is_zero =  coords_test_zero(_beamdump_540_var._position_relative);
  instrument->counter_N[524]  = instrument->counter_P[524] = instrument->counter_P2[524] = 0;
  instrument->counter_AbsorbProp[524]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0523_beamdump_540", _beamdump_540_var._position_absolute, _beamdump_540_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0523_beamdump_540", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_540_setpos */

/* component SIRIUS_pos=Text() SETTING, POSITION/ROTATION */
int _SIRIUS_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_pos_setpos] component SIRIUS_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_SIRIUS_pos_var._name, "SIRIUS_pos", 16384);
  stracpy(_SIRIUS_pos_var._type, "Text", 16384);
  _SIRIUS_pos_var._index=525;
  int current_setpos_index = 525;
  if("SIRIUS" && strlen("SIRIUS"))
    stracpy(_SIRIUS_pos_var._parameters.text, "SIRIUS" ? "SIRIUS" : "", 16384);
  else 
  _SIRIUS_pos_var._parameters.text[0]='\0';
  _SIRIUS_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_SIRIUS_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _SIRIUS_pos_var._parameters.plane[0]='\0';
  _SIRIUS_pos_var._parameters.pen_thickness = 0.1;


  /* component SIRIUS_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-326.390)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _SIRIUS_pos_var._rotation_absolute);
    rot_transpose(_beamdump_540_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_pos_var._rotation_absolute, tr1, _SIRIUS_pos_var._rotation_relative);
    _SIRIUS_pos_var._rotation_is_identity =  rot_test_identity(_SIRIUS_pos_var._rotation_relative);
    tc1 = coords_set(
      46.921, 0, -31.186);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_540_var._position_absolute, _SIRIUS_pos_var._position_absolute);
    _SIRIUS_pos_var._position_relative = rot_apply(_SIRIUS_pos_var._rotation_absolute, tc1);
  } /* SIRIUS_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_pos", _SIRIUS_pos_var._position_absolute, _SIRIUS_pos_var._rotation_absolute);
  instrument->_position_absolute[525] = _SIRIUS_pos_var._position_absolute;
  instrument->_position_relative[525] = _SIRIUS_pos_var._position_relative;
    _SIRIUS_pos_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_pos_var._position_relative);
  instrument->counter_N[525]  = instrument->counter_P[525] = instrument->counter_P2[525] = 0;
  instrument->counter_AbsorbProp[525]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0524_SIRIUS_pos", _SIRIUS_pos_var._position_absolute, _SIRIUS_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0524_SIRIUS_pos", "text", "NONE", "SIRIUS", "char*");
        mccomp_param_nexus(nxhandle,"0524_SIRIUS_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0524_SIRIUS_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0524_SIRIUS_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_pos_setpos */

/* component SIRIUS=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_setpos] component SIRIUS=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_var._name, "SIRIUS", 16384);
  stracpy(_SIRIUS_var._type, "Arm", 16384);
  _SIRIUS_var._index=526;
  int current_setpos_index = 526;
  /* component SIRIUS=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_pos_var._rotation_absolute, _SIRIUS_var._rotation_absolute);
    rot_transpose(_SIRIUS_pos_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_var._rotation_absolute, tr1, _SIRIUS_var._rotation_relative);
    _SIRIUS_var._rotation_is_identity =  rot_test_identity(_SIRIUS_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_var._position_absolute = coords_add(_SIRIUS_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_pos_var._position_absolute, _SIRIUS_var._position_absolute);
    _SIRIUS_var._position_relative = rot_apply(_SIRIUS_var._rotation_absolute, tc1);
  } /* SIRIUS=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS", _SIRIUS_var._position_absolute, _SIRIUS_var._rotation_absolute);
  instrument->_position_absolute[526] = _SIRIUS_var._position_absolute;
  instrument->_position_relative[526] = _SIRIUS_var._position_relative;
    _SIRIUS_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_var._position_relative);
  instrument->counter_N[526]  = instrument->counter_P[526] = instrument->counter_P2[526] = 0;
  instrument->counter_AbsorbProp[526]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0525_SIRIUS", _SIRIUS_var._position_absolute, _SIRIUS_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_setpos */

/* component SIRIUS_source=Bending_magnet() SETTING, POSITION/ROTATION */
int _SIRIUS_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_source_setpos] component SIRIUS_source=Bending_magnet() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");
  stracpy(_SIRIUS_source_var._name, "SIRIUS_source", 16384);
  stracpy(_SIRIUS_source_var._type, "Bending_magnet", 16384);
  _SIRIUS_source_var._index=527;
  int current_setpos_index = 527;
  _SIRIUS_source_var._parameters.E0 = _instrument_var._parameters.SIRIUS_E0;
  _SIRIUS_source_var._parameters.dE = _instrument_var._parameters.SIRIUS_dE;
  _SIRIUS_source_var._parameters.lambda0 = 0;
  _SIRIUS_source_var._parameters.dlambda = 0;
  _SIRIUS_source_var._parameters.phase = 0;
  _SIRIUS_source_var._parameters.randomphase = 1;
  _SIRIUS_source_var._parameters.Ee = 2.75;
  _SIRIUS_source_var._parameters.Ie = 0.5;
  _SIRIUS_source_var._parameters.B = 1.72;
  _SIRIUS_source_var._parameters.sigey = 25e-6;
  _SIRIUS_source_var._parameters.sigex = 60e-6;
  _SIRIUS_source_var._parameters.focus_xw = 0;
  _SIRIUS_source_var._parameters.focus_yh = 0;
  _SIRIUS_source_var._parameters.dist = 1;
  _SIRIUS_source_var._parameters.gauss_t = 0;


  /* component SIRIUS_source=Bending_magnet() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_var._rotation_absolute, _SIRIUS_source_var._rotation_absolute);
    rot_transpose(_SIRIUS_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_source_var._rotation_absolute, tr1, _SIRIUS_source_var._rotation_relative);
    _SIRIUS_source_var._rotation_is_identity =  rot_test_identity(_SIRIUS_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_source_var._position_absolute = coords_add(_SIRIUS_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_var._position_absolute, _SIRIUS_source_var._position_absolute);
    _SIRIUS_source_var._position_relative = rot_apply(_SIRIUS_source_var._rotation_absolute, tc1);
  } /* SIRIUS_source=Bending_magnet() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_source", _SIRIUS_source_var._position_absolute, _SIRIUS_source_var._rotation_absolute);
  instrument->_position_absolute[527] = _SIRIUS_source_var._position_absolute;
  instrument->_position_relative[527] = _SIRIUS_source_var._position_relative;
    _SIRIUS_source_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_source_var._position_relative);
  instrument->counter_N[527]  = instrument->counter_P[527] = instrument->counter_P2[527] = 0;
  instrument->counter_AbsorbProp[527]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0526_SIRIUS_source", _SIRIUS_source_var._position_absolute, _SIRIUS_source_var._rotation_absolute, "Bending_magnet");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "E0", "0", "_instrument_var._parameters.SIRIUS_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "dE", "0", "_instrument_var._parameters.SIRIUS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "lambda0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "dlambda", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "B", "1.6", "1.72","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "sigey", "0", "25e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "sigex", "0", "60e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0526_SIRIUS_source", "gauss_t", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_source_setpos */

/* component SIRIUS_M1_loc=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_M1_loc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_M1_loc_setpos] component SIRIUS_M1_loc=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_M1_loc_var._name, "SIRIUS_M1_loc", 16384);
  stracpy(_SIRIUS_M1_loc_var._type, "Monitor_nD", 16384);
  _SIRIUS_M1_loc_var._index=528;
  int current_setpos_index = 528;
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_M1_loc_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.user9[0]='\0';
  _SIRIUS_M1_loc_var._parameters.xwidth = 0.02;
  _SIRIUS_M1_loc_var._parameters.yheight = 0.02;
  _SIRIUS_M1_loc_var._parameters.zdepth = 0;
  _SIRIUS_M1_loc_var._parameters.bins = 0;
  _SIRIUS_M1_loc_var._parameters.min = -1e40;
  _SIRIUS_M1_loc_var._parameters.max = 1e40;
  _SIRIUS_M1_loc_var._parameters.restore_xray = 1;
  _SIRIUS_M1_loc_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIRIUS_M1_loc_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.geometry[0]='\0';
  _SIRIUS_M1_loc_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_M1_loc_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_M1_loc_var._parameters.username9[0]='\0';


  /* component SIRIUS_M1_loc=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_source_var._rotation_absolute, _SIRIUS_M1_loc_var._rotation_absolute);
    rot_transpose(_SIRIUS_source_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_M1_loc_var._rotation_absolute, tr1, _SIRIUS_M1_loc_var._rotation_relative);
    _SIRIUS_M1_loc_var._rotation_is_identity =  rot_test_identity(_SIRIUS_M1_loc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 14);
    rot_transpose(_SIRIUS_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_M1_loc_var._position_absolute = coords_add(_SIRIUS_source_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_source_var._position_absolute, _SIRIUS_M1_loc_var._position_absolute);
    _SIRIUS_M1_loc_var._position_relative = rot_apply(_SIRIUS_M1_loc_var._rotation_absolute, tc1);
  } /* SIRIUS_M1_loc=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_M1_loc", _SIRIUS_M1_loc_var._position_absolute, _SIRIUS_M1_loc_var._rotation_absolute);
  instrument->_position_absolute[528] = _SIRIUS_M1_loc_var._position_absolute;
  instrument->_position_relative[528] = _SIRIUS_M1_loc_var._position_relative;
    _SIRIUS_M1_loc_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_M1_loc_var._position_relative);
  instrument->counter_N[528]  = instrument->counter_P[528] = instrument->counter_P2[528] = 0;
  instrument->counter_AbsorbProp[528]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0527_SIRIUS_M1_loc", _SIRIUS_M1_loc_var._position_absolute, _SIRIUS_M1_loc_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0527_SIRIUS_M1_loc", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_M1_loc_setpos */

/* component SIRIUS_M1_rot=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_M1_rot_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_M1_rot_setpos] component SIRIUS_M1_rot=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_M1_rot_var._name, "SIRIUS_M1_rot", 16384);
  stracpy(_SIRIUS_M1_rot_var._type, "Arm", 16384);
  _SIRIUS_M1_rot_var._index=529;
  int current_setpos_index = 529;
  /* component SIRIUS_M1_rot=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIRIUS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_M1_loc_var._rotation_absolute, _SIRIUS_M1_rot_var._rotation_absolute);
    rot_transpose(_SIRIUS_M1_loc_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_M1_rot_var._rotation_absolute, tr1, _SIRIUS_M1_rot_var._rotation_relative);
    _SIRIUS_M1_rot_var._rotation_is_identity =  rot_test_identity(_SIRIUS_M1_rot_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_M1_loc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_M1_rot_var._position_absolute = coords_add(_SIRIUS_M1_loc_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_M1_loc_var._position_absolute, _SIRIUS_M1_rot_var._position_absolute);
    _SIRIUS_M1_rot_var._position_relative = rot_apply(_SIRIUS_M1_rot_var._rotation_absolute, tc1);
  } /* SIRIUS_M1_rot=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_M1_rot", _SIRIUS_M1_rot_var._position_absolute, _SIRIUS_M1_rot_var._rotation_absolute);
  instrument->_position_absolute[529] = _SIRIUS_M1_rot_var._position_absolute;
  instrument->_position_relative[529] = _SIRIUS_M1_rot_var._position_relative;
    _SIRIUS_M1_rot_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_M1_rot_var._position_relative);
  instrument->counter_N[529]  = instrument->counter_P[529] = instrument->counter_P2[529] = 0;
  instrument->counter_AbsorbProp[529]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0528_SIRIUS_M1_rot", _SIRIUS_M1_rot_var._position_absolute, _SIRIUS_M1_rot_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_M1_rot_setpos */

/* component SIRIUS_M1=Mirror_curved() SETTING, POSITION/ROTATION */
int _SIRIUS_M1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_M1_setpos] component SIRIUS_M1=Mirror_curved() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");
  stracpy(_SIRIUS_M1_var._name, "SIRIUS_M1", 16384);
  stracpy(_SIRIUS_M1_var._type, "Mirror_curved", 16384);
  _SIRIUS_M1_var._index=530;
  int current_setpos_index = 530;
  _SIRIUS_M1_var._parameters.radius = SIRIUS_M1_radius;
  _SIRIUS_M1_var._parameters.R0 = 1;
  if("Pd.txt" && strlen("Pd.txt"))
    stracpy(_SIRIUS_M1_var._parameters.coating, "Pd.txt" ? "Pd.txt" : "", 16384);
  else 
  _SIRIUS_M1_var._parameters.coating[0]='\0';
  _SIRIUS_M1_var._parameters.zdepth = 0.2;
  _SIRIUS_M1_var._parameters.yheight = 0.2;
  _SIRIUS_M1_var._parameters.length = 1.3;
  _SIRIUS_M1_var._parameters.width = 0.1;


  /* component SIRIUS_M1=Mirror_curved() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (90)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_M1_rot_var._rotation_absolute, _SIRIUS_M1_var._rotation_absolute);
    rot_transpose(_SIRIUS_M1_loc_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_M1_var._rotation_absolute, tr1, _SIRIUS_M1_var._rotation_relative);
    _SIRIUS_M1_var._rotation_is_identity =  rot_test_identity(_SIRIUS_M1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_M1_rot_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_M1_var._position_absolute = coords_add(_SIRIUS_M1_rot_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_M1_loc_var._position_absolute, _SIRIUS_M1_var._position_absolute);
    _SIRIUS_M1_var._position_relative = rot_apply(_SIRIUS_M1_var._rotation_absolute, tc1);
  } /* SIRIUS_M1=Mirror_curved() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_M1", _SIRIUS_M1_var._position_absolute, _SIRIUS_M1_var._rotation_absolute);
  instrument->_position_absolute[530] = _SIRIUS_M1_var._position_absolute;
  instrument->_position_relative[530] = _SIRIUS_M1_var._position_relative;
    _SIRIUS_M1_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_M1_var._position_relative);
  instrument->counter_N[530]  = instrument->counter_P[530] = instrument->counter_P2[530] = 0;
  instrument->counter_AbsorbProp[530]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0529_SIRIUS_M1", _SIRIUS_M1_var._position_absolute, _SIRIUS_M1_var._rotation_absolute, "Mirror_curved");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "radius", "1", "SIRIUS_M1_radius","MCNUM");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "R0", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "coating", "Be.txt", "Pd.txt", "char*");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "zdepth", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "yheight", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "length", "0", "1.3","MCNUM");
        mccomp_param_nexus(nxhandle,"0529_SIRIUS_M1", "width", "0", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_M1_setpos */

/* component SIRIUS_M1_out=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_M1_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_M1_out_setpos] component SIRIUS_M1_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_M1_out_var._name, "SIRIUS_M1_out", 16384);
  stracpy(_SIRIUS_M1_out_var._type, "Arm", 16384);
  _SIRIUS_M1_out_var._index=531;
  int current_setpos_index = 531;
  /* component SIRIUS_M1_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIRIUS_M1_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_M1_loc_var._rotation_absolute, _SIRIUS_M1_out_var._rotation_absolute);
    rot_transpose(_SIRIUS_M1_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_M1_out_var._rotation_absolute, tr1, _SIRIUS_M1_out_var._rotation_relative);
    _SIRIUS_M1_out_var._rotation_is_identity =  rot_test_identity(_SIRIUS_M1_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_M1_rot_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_M1_out_var._position_absolute = coords_add(_SIRIUS_M1_rot_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_M1_var._position_absolute, _SIRIUS_M1_out_var._position_absolute);
    _SIRIUS_M1_out_var._position_relative = rot_apply(_SIRIUS_M1_out_var._rotation_absolute, tc1);
  } /* SIRIUS_M1_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_M1_out", _SIRIUS_M1_out_var._position_absolute, _SIRIUS_M1_out_var._rotation_absolute);
  instrument->_position_absolute[531] = _SIRIUS_M1_out_var._position_absolute;
  instrument->_position_relative[531] = _SIRIUS_M1_out_var._position_relative;
    _SIRIUS_M1_out_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_M1_out_var._position_relative);
  instrument->counter_N[531]  = instrument->counter_P[531] = instrument->counter_P2[531] = 0;
  instrument->counter_AbsorbProp[531]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0530_SIRIUS_M1_out", _SIRIUS_M1_out_var._position_absolute, _SIRIUS_M1_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_M1_out_setpos */

/* component SIRIUS_DCM_location=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_DCM_location_setpos] component SIRIUS_DCM_location=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_DCM_location_var._name, "SIRIUS_DCM_location", 16384);
  stracpy(_SIRIUS_DCM_location_var._type, "Monitor_nD", 16384);
  _SIRIUS_DCM_location_var._index=532;
  int current_setpos_index = 532;
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_location_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.user9[0]='\0';
  _SIRIUS_DCM_location_var._parameters.xwidth = 0.02;
  _SIRIUS_DCM_location_var._parameters.yheight = 0.02;
  _SIRIUS_DCM_location_var._parameters.zdepth = 0;
  _SIRIUS_DCM_location_var._parameters.bins = 0;
  _SIRIUS_DCM_location_var._parameters.min = -1e40;
  _SIRIUS_DCM_location_var._parameters.max = 1e40;
  _SIRIUS_DCM_location_var._parameters.restore_xray = 1;
  _SIRIUS_DCM_location_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIRIUS_DCM_location_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.geometry[0]='\0';
  _SIRIUS_DCM_location_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_location_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_location_var._parameters.username9[0]='\0';


  /* component SIRIUS_DCM_location=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_M1_out_var._rotation_absolute, _SIRIUS_DCM_location_var._rotation_absolute);
    rot_transpose(_SIRIUS_M1_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_DCM_location_var._rotation_absolute, tr1, _SIRIUS_DCM_location_var._rotation_relative);
    _SIRIUS_DCM_location_var._rotation_is_identity =  rot_test_identity(_SIRIUS_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2);
    rot_transpose(_SIRIUS_M1_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_DCM_location_var._position_absolute = coords_add(_SIRIUS_M1_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_M1_var._position_absolute, _SIRIUS_DCM_location_var._position_absolute);
    _SIRIUS_DCM_location_var._position_relative = rot_apply(_SIRIUS_DCM_location_var._rotation_absolute, tc1);
  } /* SIRIUS_DCM_location=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_DCM_location", _SIRIUS_DCM_location_var._position_absolute, _SIRIUS_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[532] = _SIRIUS_DCM_location_var._position_absolute;
  instrument->_position_relative[532] = _SIRIUS_DCM_location_var._position_relative;
    _SIRIUS_DCM_location_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_DCM_location_var._position_relative);
  instrument->counter_N[532]  = instrument->counter_P[532] = instrument->counter_P2[532] = 0;
  instrument->counter_AbsorbProp[532]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0531_SIRIUS_DCM_location", _SIRIUS_DCM_location_var._position_absolute, _SIRIUS_DCM_location_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0531_SIRIUS_DCM_location", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_DCM_location_setpos */

/* component SIRIUS_bragg_crystal=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SIRIUS_bragg_crystal_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_bragg_crystal_setpos] component SIRIUS_bragg_crystal=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SIRIUS_bragg_crystal_var._name, "SIRIUS_bragg_crystal", 16384);
  stracpy(_SIRIUS_bragg_crystal_var._type, "Bragg_crystal", 16384);
  _SIRIUS_bragg_crystal_var._index=533;
  int current_setpos_index = 533;
  _SIRIUS_bragg_crystal_var._parameters.length = 0.2;
  _SIRIUS_bragg_crystal_var._parameters.width = 0.1;
  _SIRIUS_bragg_crystal_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SIRIUS_bragg_crystal_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SIRIUS_bragg_crystal_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SIRIUS_bragg_crystal_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SIRIUS_bragg_crystal_var._parameters.material[0]='\0';
  _SIRIUS_bragg_crystal_var._parameters.alpha = 0.0;
  _SIRIUS_bragg_crystal_var._parameters.R0 = 0;
  _SIRIUS_bragg_crystal_var._parameters.debye_waller_B = 0.4632;
  _SIRIUS_bragg_crystal_var._parameters.crystal_type = 2;
  _SIRIUS_bragg_crystal_var._parameters.h = 1;
  _SIRIUS_bragg_crystal_var._parameters.k = 1;
  _SIRIUS_bragg_crystal_var._parameters.l = 1;
  _SIRIUS_bragg_crystal_var._parameters.structure_factor_scale_r = 0.0;
  _SIRIUS_bragg_crystal_var._parameters.structure_factor_scale_i = 0.0;


  /* component SIRIUS_bragg_crystal=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- SIRIUS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_DCM_location_var._rotation_absolute, _SIRIUS_bragg_crystal_var._rotation_absolute);
    rot_transpose(_SIRIUS_DCM_location_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_bragg_crystal_var._rotation_absolute, tr1, _SIRIUS_bragg_crystal_var._rotation_relative);
    _SIRIUS_bragg_crystal_var._rotation_is_identity =  rot_test_identity(_SIRIUS_bragg_crystal_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_bragg_crystal_var._position_absolute = coords_add(_SIRIUS_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_DCM_location_var._position_absolute, _SIRIUS_bragg_crystal_var._position_absolute);
    _SIRIUS_bragg_crystal_var._position_relative = rot_apply(_SIRIUS_bragg_crystal_var._rotation_absolute, tc1);
  } /* SIRIUS_bragg_crystal=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_bragg_crystal", _SIRIUS_bragg_crystal_var._position_absolute, _SIRIUS_bragg_crystal_var._rotation_absolute);
  instrument->_position_absolute[533] = _SIRIUS_bragg_crystal_var._position_absolute;
  instrument->_position_relative[533] = _SIRIUS_bragg_crystal_var._position_relative;
    _SIRIUS_bragg_crystal_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_bragg_crystal_var._position_relative);
  instrument->counter_N[533]  = instrument->counter_P[533] = instrument->counter_P2[533] = 0;
  instrument->counter_AbsorbProp[533]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", _SIRIUS_bragg_crystal_var._position_absolute, _SIRIUS_bragg_crystal_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "length", "0.05", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "width", "0.02", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0532_SIRIUS_bragg_crystal", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_bragg_crystal_setpos */

/* component SIRIUS_arm_crystal1=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_arm_crystal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_arm_crystal1_setpos] component SIRIUS_arm_crystal1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_arm_crystal1_var._name, "SIRIUS_arm_crystal1", 16384);
  stracpy(_SIRIUS_arm_crystal1_var._type, "Arm", 16384);
  _SIRIUS_arm_crystal1_var._index=534;
  int current_setpos_index = 534;
  /* component SIRIUS_arm_crystal1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- SIRIUS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_bragg_crystal_var._rotation_absolute, _SIRIUS_arm_crystal1_var._rotation_absolute);
    rot_transpose(_SIRIUS_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_arm_crystal1_var._rotation_absolute, tr1, _SIRIUS_arm_crystal1_var._rotation_relative);
    _SIRIUS_arm_crystal1_var._rotation_is_identity =  rot_test_identity(_SIRIUS_arm_crystal1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_arm_crystal1_var._position_absolute = coords_add(_SIRIUS_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_bragg_crystal_var._position_absolute, _SIRIUS_arm_crystal1_var._position_absolute);
    _SIRIUS_arm_crystal1_var._position_relative = rot_apply(_SIRIUS_arm_crystal1_var._rotation_absolute, tc1);
  } /* SIRIUS_arm_crystal1=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_arm_crystal1", _SIRIUS_arm_crystal1_var._position_absolute, _SIRIUS_arm_crystal1_var._rotation_absolute);
  instrument->_position_absolute[534] = _SIRIUS_arm_crystal1_var._position_absolute;
  instrument->_position_relative[534] = _SIRIUS_arm_crystal1_var._position_relative;
    _SIRIUS_arm_crystal1_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_arm_crystal1_var._position_relative);
  instrument->counter_N[534]  = instrument->counter_P[534] = instrument->counter_P2[534] = 0;
  instrument->counter_AbsorbProp[534]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0533_SIRIUS_arm_crystal1", _SIRIUS_arm_crystal1_var._position_absolute, _SIRIUS_arm_crystal1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_arm_crystal1_setpos */

/* component SIRIUS_bragg_crystal_two=Bragg_crystal() SETTING, POSITION/ROTATION */
int _SIRIUS_bragg_crystal_two_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_bragg_crystal_two_setpos] component SIRIUS_bragg_crystal_two=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_SIRIUS_bragg_crystal_two_var._name, "SIRIUS_bragg_crystal_two", 16384);
  stracpy(_SIRIUS_bragg_crystal_two_var._type, "Bragg_crystal", 16384);
  _SIRIUS_bragg_crystal_two_var._index=535;
  int current_setpos_index = 535;
  _SIRIUS_bragg_crystal_two_var._parameters.length = 0.2;
  _SIRIUS_bragg_crystal_two_var._parameters.width = 0.1;
  _SIRIUS_bragg_crystal_two_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_SIRIUS_bragg_crystal_two_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _SIRIUS_bragg_crystal_two_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_SIRIUS_bragg_crystal_two_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _SIRIUS_bragg_crystal_two_var._parameters.material[0]='\0';
  _SIRIUS_bragg_crystal_two_var._parameters.alpha = 0.0;
  _SIRIUS_bragg_crystal_two_var._parameters.R0 = 0;
  _SIRIUS_bragg_crystal_two_var._parameters.debye_waller_B = 0.4632;
  _SIRIUS_bragg_crystal_two_var._parameters.crystal_type = 2;
  _SIRIUS_bragg_crystal_two_var._parameters.h = 1;
  _SIRIUS_bragg_crystal_two_var._parameters.k = 1;
  _SIRIUS_bragg_crystal_two_var._parameters.l = 1;
  _SIRIUS_bragg_crystal_two_var._parameters.structure_factor_scale_r = 0.0;
  _SIRIUS_bragg_crystal_two_var._parameters.structure_factor_scale_i = 0.0;


  /* component SIRIUS_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (SIRIUS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_arm_crystal1_var._rotation_absolute, _SIRIUS_bragg_crystal_two_var._rotation_absolute);
    rot_transpose(_SIRIUS_bragg_crystal_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_bragg_crystal_two_var._rotation_absolute, tr1, _SIRIUS_bragg_crystal_two_var._rotation_relative);
    _SIRIUS_bragg_crystal_two_var._rotation_is_identity =  rot_test_identity(_SIRIUS_bragg_crystal_two_var._rotation_relative);
    tc1 = coords_set(
      0, SIRIUS_dcm_gap, SIRIUS_DCM_theta ? SIRIUS_dcm_gap / tan ( SIRIUS_DCM_theta * DEG2RAD ) : 0);
    rot_transpose(_SIRIUS_bragg_crystal_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_bragg_crystal_two_var._position_absolute = coords_add(_SIRIUS_bragg_crystal_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_bragg_crystal_var._position_absolute, _SIRIUS_bragg_crystal_two_var._position_absolute);
    _SIRIUS_bragg_crystal_two_var._position_relative = rot_apply(_SIRIUS_bragg_crystal_two_var._rotation_absolute, tc1);
  } /* SIRIUS_bragg_crystal_two=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_bragg_crystal_two", _SIRIUS_bragg_crystal_two_var._position_absolute, _SIRIUS_bragg_crystal_two_var._rotation_absolute);
  instrument->_position_absolute[535] = _SIRIUS_bragg_crystal_two_var._position_absolute;
  instrument->_position_relative[535] = _SIRIUS_bragg_crystal_two_var._position_relative;
    _SIRIUS_bragg_crystal_two_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_bragg_crystal_two_var._position_relative);
  instrument->counter_N[535]  = instrument->counter_P[535] = instrument->counter_P2[535] = 0;
  instrument->counter_AbsorbProp[535]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", _SIRIUS_bragg_crystal_two_var._position_absolute, _SIRIUS_bragg_crystal_two_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "length", "0.05", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "width", "0.02", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "crystal_type", "1", "2","int");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0534_SIRIUS_bragg_crystal_two", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_bragg_crystal_two_setpos */

/* component SIRIUS_arm_crystal2=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_arm_crystal2_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_arm_crystal2_setpos] component SIRIUS_arm_crystal2=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_arm_crystal2_var._name, "SIRIUS_arm_crystal2", 16384);
  stracpy(_SIRIUS_arm_crystal2_var._type, "Arm", 16384);
  _SIRIUS_arm_crystal2_var._index=536;
  int current_setpos_index = 536;
  /* component SIRIUS_arm_crystal2=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (SIRIUS_DCM_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_bragg_crystal_two_var._rotation_absolute, _SIRIUS_arm_crystal2_var._rotation_absolute);
    rot_transpose(_SIRIUS_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_arm_crystal2_var._rotation_absolute, tr1, _SIRIUS_arm_crystal2_var._rotation_relative);
    _SIRIUS_arm_crystal2_var._rotation_is_identity =  rot_test_identity(_SIRIUS_arm_crystal2_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_bragg_crystal_two_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_arm_crystal2_var._position_absolute = coords_add(_SIRIUS_bragg_crystal_two_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_bragg_crystal_two_var._position_absolute, _SIRIUS_arm_crystal2_var._position_absolute);
    _SIRIUS_arm_crystal2_var._position_relative = rot_apply(_SIRIUS_arm_crystal2_var._rotation_absolute, tc1);
  } /* SIRIUS_arm_crystal2=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_arm_crystal2", _SIRIUS_arm_crystal2_var._position_absolute, _SIRIUS_arm_crystal2_var._rotation_absolute);
  instrument->_position_absolute[536] = _SIRIUS_arm_crystal2_var._position_absolute;
  instrument->_position_relative[536] = _SIRIUS_arm_crystal2_var._position_relative;
    _SIRIUS_arm_crystal2_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_arm_crystal2_var._position_relative);
  instrument->counter_N[536]  = instrument->counter_P[536] = instrument->counter_P2[536] = 0;
  instrument->counter_AbsorbProp[536]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0535_SIRIUS_arm_crystal2", _SIRIUS_arm_crystal2_var._position_absolute, _SIRIUS_arm_crystal2_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_arm_crystal2_setpos */

/* component SIRIUS_DCM_out=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_DCM_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_DCM_out_setpos] component SIRIUS_DCM_out=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_DCM_out_var._name, "SIRIUS_DCM_out", 16384);
  stracpy(_SIRIUS_DCM_out_var._type, "Monitor_nD", 16384);
  _SIRIUS_DCM_out_var._index=537;
  int current_setpos_index = 537;
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.user9[0]='\0';
  _SIRIUS_DCM_out_var._parameters.xwidth = 0.02;
  _SIRIUS_DCM_out_var._parameters.yheight = 0.02;
  _SIRIUS_DCM_out_var._parameters.zdepth = 0;
  _SIRIUS_DCM_out_var._parameters.bins = 0;
  _SIRIUS_DCM_out_var._parameters.min = -1e40;
  _SIRIUS_DCM_out_var._parameters.max = 1e40;
  _SIRIUS_DCM_out_var._parameters.restore_xray = 1;
  _SIRIUS_DCM_out_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIRIUS_DCM_out_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.geometry[0]='\0';
  _SIRIUS_DCM_out_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_var._parameters.username9[0]='\0';


  /* component SIRIUS_DCM_out=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_arm_crystal2_var._rotation_absolute, _SIRIUS_DCM_out_var._rotation_absolute);
    rot_transpose(_SIRIUS_bragg_crystal_two_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_DCM_out_var._rotation_absolute, tr1, _SIRIUS_DCM_out_var._rotation_relative);
    _SIRIUS_DCM_out_var._rotation_is_identity =  rot_test_identity(_SIRIUS_DCM_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.2);
    rot_transpose(_SIRIUS_arm_crystal2_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_DCM_out_var._position_absolute = coords_add(_SIRIUS_arm_crystal2_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_bragg_crystal_two_var._position_absolute, _SIRIUS_DCM_out_var._position_absolute);
    _SIRIUS_DCM_out_var._position_relative = rot_apply(_SIRIUS_DCM_out_var._rotation_absolute, tc1);
  } /* SIRIUS_DCM_out=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_DCM_out", _SIRIUS_DCM_out_var._position_absolute, _SIRIUS_DCM_out_var._rotation_absolute);
  instrument->_position_absolute[537] = _SIRIUS_DCM_out_var._position_absolute;
  instrument->_position_relative[537] = _SIRIUS_DCM_out_var._position_relative;
    _SIRIUS_DCM_out_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_DCM_out_var._position_relative);
  instrument->counter_N[537]  = instrument->counter_P[537] = instrument->counter_P2[537] = 0;
  instrument->counter_AbsorbProp[537]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0536_SIRIUS_DCM_out", _SIRIUS_DCM_out_var._position_absolute, _SIRIUS_DCM_out_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0536_SIRIUS_DCM_out", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_DCM_out_setpos */

/* component SIRIUS_DCM_out_div=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_DCM_out_div_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_DCM_out_div_setpos] component SIRIUS_DCM_out_div=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_DCM_out_div_var._name, "SIRIUS_DCM_out_div", 16384);
  stracpy(_SIRIUS_DCM_out_div_var._type, "Monitor_nD", 16384);
  _SIRIUS_DCM_out_div_var._index=538;
  int current_setpos_index = 538;
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.user9[0]='\0';
  _SIRIUS_DCM_out_div_var._parameters.xwidth = 0.02;
  _SIRIUS_DCM_out_div_var._parameters.yheight = 0.2;
  _SIRIUS_DCM_out_div_var._parameters.zdepth = 0;
  _SIRIUS_DCM_out_div_var._parameters.bins = 0;
  _SIRIUS_DCM_out_div_var._parameters.min = -1e40;
  _SIRIUS_DCM_out_div_var._parameters.max = 1e40;
  _SIRIUS_DCM_out_div_var._parameters.restore_xray = 1;
  _SIRIUS_DCM_out_div_var._parameters.radius = 0;
  if("dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" && strlen("dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.options, "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" ? "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.geometry[0]='\0';
  _SIRIUS_DCM_out_div_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_div_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_div_var._parameters.username9[0]='\0';


  /* component SIRIUS_DCM_out_div=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_DCM_out_var._rotation_absolute, _SIRIUS_DCM_out_div_var._rotation_absolute);
    rot_transpose(_SIRIUS_DCM_out_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_DCM_out_div_var._rotation_absolute, tr1, _SIRIUS_DCM_out_div_var._rotation_relative);
    _SIRIUS_DCM_out_div_var._rotation_is_identity =  rot_test_identity(_SIRIUS_DCM_out_div_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_DCM_out_div_var._position_absolute = coords_add(_SIRIUS_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_DCM_out_var._position_absolute, _SIRIUS_DCM_out_div_var._position_absolute);
    _SIRIUS_DCM_out_div_var._position_relative = rot_apply(_SIRIUS_DCM_out_div_var._rotation_absolute, tc1);
  } /* SIRIUS_DCM_out_div=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_DCM_out_div", _SIRIUS_DCM_out_div_var._position_absolute, _SIRIUS_DCM_out_div_var._rotation_absolute);
  instrument->_position_absolute[538] = _SIRIUS_DCM_out_div_var._position_absolute;
  instrument->_position_relative[538] = _SIRIUS_DCM_out_div_var._position_relative;
    _SIRIUS_DCM_out_div_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_DCM_out_div_var._position_relative);
  instrument->counter_N[538]  = instrument->counter_P[538] = instrument->counter_P2[538] = 0;
  instrument->counter_AbsorbProp[538]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", _SIRIUS_DCM_out_div_var._position_absolute, _SIRIUS_DCM_out_div_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "yheight", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "options", "NULL", "dx limits=[-0.5 0.5], dy limits=[-0.5 0.5]", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0537_SIRIUS_DCM_out_div", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_DCM_out_div_setpos */

/* component SIRIUS_DCM_out_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_DCM_out_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_DCM_out_e_setpos] component SIRIUS_DCM_out_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_DCM_out_e_var._name, "SIRIUS_DCM_out_e", 16384);
  stracpy(_SIRIUS_DCM_out_e_var._type, "Monitor_nD", 16384);
  _SIRIUS_DCM_out_e_var._index=539;
  int current_setpos_index = 539;
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.user9[0]='\0';
  _SIRIUS_DCM_out_e_var._parameters.xwidth = 0.1;
  _SIRIUS_DCM_out_e_var._parameters.yheight = 0.2;
  _SIRIUS_DCM_out_e_var._parameters.zdepth = 0;
  _SIRIUS_DCM_out_e_var._parameters.bins = 512;
  _SIRIUS_DCM_out_e_var._parameters.min = _instrument_var._parameters.SIRIUS_E0 - _instrument_var._parameters.SIRIUS_dE;
  _SIRIUS_DCM_out_e_var._parameters.max = _instrument_var._parameters.SIRIUS_E0 + _instrument_var._parameters.SIRIUS_dE;
  _SIRIUS_DCM_out_e_var._parameters.restore_xray = 0;
  _SIRIUS_DCM_out_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.geometry[0]='\0';
  _SIRIUS_DCM_out_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_DCM_out_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_DCM_out_e_var._parameters.username9[0]='\0';


  /* component SIRIUS_DCM_out_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_DCM_out_var._rotation_absolute, _SIRIUS_DCM_out_e_var._rotation_absolute);
    rot_transpose(_SIRIUS_DCM_out_div_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_DCM_out_e_var._rotation_absolute, tr1, _SIRIUS_DCM_out_e_var._rotation_relative);
    _SIRIUS_DCM_out_e_var._rotation_is_identity =  rot_test_identity(_SIRIUS_DCM_out_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_DCM_out_e_var._position_absolute = coords_add(_SIRIUS_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_DCM_out_div_var._position_absolute, _SIRIUS_DCM_out_e_var._position_absolute);
    _SIRIUS_DCM_out_e_var._position_relative = rot_apply(_SIRIUS_DCM_out_e_var._rotation_absolute, tc1);
  } /* SIRIUS_DCM_out_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_DCM_out_e", _SIRIUS_DCM_out_e_var._position_absolute, _SIRIUS_DCM_out_e_var._rotation_absolute);
  instrument->_position_absolute[539] = _SIRIUS_DCM_out_e_var._position_absolute;
  instrument->_position_relative[539] = _SIRIUS_DCM_out_e_var._position_relative;
    _SIRIUS_DCM_out_e_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_DCM_out_e_var._position_relative);
  instrument->counter_N[539]  = instrument->counter_P[539] = instrument->counter_P2[539] = 0;
  instrument->counter_AbsorbProp[539]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", _SIRIUS_DCM_out_e_var._position_absolute, _SIRIUS_DCM_out_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "yheight", "0", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "bins", "0", "512","int");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "min", "-1e40", "_instrument_var._parameters.SIRIUS_E0 - _instrument_var._parameters.SIRIUS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "max", "1e40", "_instrument_var._parameters.SIRIUS_E0 + _instrument_var._parameters.SIRIUS_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0538_SIRIUS_DCM_out_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_DCM_out_e_setpos */

/* component SIRIUS_def_loc=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_def_loc_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_def_loc_setpos] component SIRIUS_def_loc=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_def_loc_var._name, "SIRIUS_def_loc", 16384);
  stracpy(_SIRIUS_def_loc_var._type, "Monitor_nD", 16384);
  _SIRIUS_def_loc_var._index=540;
  int current_setpos_index = 540;
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_def_loc_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.user9[0]='\0';
  _SIRIUS_def_loc_var._parameters.xwidth = 0.02;
  _SIRIUS_def_loc_var._parameters.yheight = 0.02;
  _SIRIUS_def_loc_var._parameters.zdepth = 0;
  _SIRIUS_def_loc_var._parameters.bins = 0;
  _SIRIUS_def_loc_var._parameters.min = -1e40;
  _SIRIUS_def_loc_var._parameters.max = 1e40;
  _SIRIUS_def_loc_var._parameters.restore_xray = 1;
  _SIRIUS_def_loc_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIRIUS_def_loc_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.geometry[0]='\0';
  _SIRIUS_def_loc_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_def_loc_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_def_loc_var._parameters.username9[0]='\0';


  /* component SIRIUS_def_loc=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_DCM_out_var._rotation_absolute, _SIRIUS_def_loc_var._rotation_absolute);
    rot_transpose(_SIRIUS_DCM_out_e_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_def_loc_var._rotation_absolute, tr1, _SIRIUS_def_loc_var._rotation_relative);
    _SIRIUS_def_loc_var._rotation_is_identity =  rot_test_identity(_SIRIUS_def_loc_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 2);
    rot_transpose(_SIRIUS_DCM_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_def_loc_var._position_absolute = coords_add(_SIRIUS_DCM_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_DCM_out_e_var._position_absolute, _SIRIUS_def_loc_var._position_absolute);
    _SIRIUS_def_loc_var._position_relative = rot_apply(_SIRIUS_def_loc_var._rotation_absolute, tc1);
  } /* SIRIUS_def_loc=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_def_loc", _SIRIUS_def_loc_var._position_absolute, _SIRIUS_def_loc_var._rotation_absolute);
  instrument->_position_absolute[540] = _SIRIUS_def_loc_var._position_absolute;
  instrument->_position_relative[540] = _SIRIUS_def_loc_var._position_relative;
    _SIRIUS_def_loc_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_def_loc_var._position_relative);
  instrument->counter_N[540]  = instrument->counter_P[540] = instrument->counter_P2[540] = 0;
  instrument->counter_AbsorbProp[540]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0539_SIRIUS_def_loc", _SIRIUS_def_loc_var._position_absolute, _SIRIUS_def_loc_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0539_SIRIUS_def_loc", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_def_loc_setpos */

/* component SIRIUS_def_rot=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_def_rot_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_def_rot_setpos] component SIRIUS_def_rot=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_def_rot_var._name, "SIRIUS_def_rot", 16384);
  stracpy(_SIRIUS_def_rot_var._type, "Arm", 16384);
  _SIRIUS_def_rot_var._index=541;
  int current_setpos_index = 541;
  /* component SIRIUS_def_rot=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIRIUS_def_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_def_loc_var._rotation_absolute, _SIRIUS_def_rot_var._rotation_absolute);
    rot_transpose(_SIRIUS_def_loc_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_def_rot_var._rotation_absolute, tr1, _SIRIUS_def_rot_var._rotation_relative);
    _SIRIUS_def_rot_var._rotation_is_identity =  rot_test_identity(_SIRIUS_def_rot_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_def_loc_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_def_rot_var._position_absolute = coords_add(_SIRIUS_def_loc_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_def_loc_var._position_absolute, _SIRIUS_def_rot_var._position_absolute);
    _SIRIUS_def_rot_var._position_relative = rot_apply(_SIRIUS_def_rot_var._rotation_absolute, tc1);
  } /* SIRIUS_def_rot=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_def_rot", _SIRIUS_def_rot_var._position_absolute, _SIRIUS_def_rot_var._rotation_absolute);
  instrument->_position_absolute[541] = _SIRIUS_def_rot_var._position_absolute;
  instrument->_position_relative[541] = _SIRIUS_def_rot_var._position_relative;
    _SIRIUS_def_rot_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_def_rot_var._position_relative);
  instrument->counter_N[541]  = instrument->counter_P[541] = instrument->counter_P2[541] = 0;
  instrument->counter_AbsorbProp[541]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0540_SIRIUS_def_rot", _SIRIUS_def_rot_var._position_absolute, _SIRIUS_def_rot_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_def_rot_setpos */

/* component SIRIUS_def_mirror=Mirror() SETTING, POSITION/ROTATION */
int _SIRIUS_def_mirror_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_def_mirror_setpos] component SIRIUS_def_mirror=Mirror() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:69]");
  stracpy(_SIRIUS_def_mirror_var._name, "SIRIUS_def_mirror", 16384);
  stracpy(_SIRIUS_def_mirror_var._type, "Mirror", 16384);
  _SIRIUS_def_mirror_var._index=542;
  int current_setpos_index = 542;
  _SIRIUS_def_mirror_var._parameters.zdepth = 0.1;
  _SIRIUS_def_mirror_var._parameters.xwidth = 0.1;
  _SIRIUS_def_mirror_var._parameters.yheight = 0.05;
  if("" && strlen(""))
    stracpy(_SIRIUS_def_mirror_var._parameters.coating, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_mirror_var._parameters.coating[0]='\0';
  _SIRIUS_def_mirror_var._parameters.R0 = 0;
  if("" && strlen(""))
    stracpy(_SIRIUS_def_mirror_var._parameters.geometry, "" ? "" : "", 16384);
  else 
  _SIRIUS_def_mirror_var._parameters.geometry[0]='\0';


  /* component SIRIUS_def_mirror=Mirror() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_def_rot_var._rotation_absolute, _SIRIUS_def_mirror_var._rotation_absolute);
    rot_transpose(_SIRIUS_def_loc_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_def_mirror_var._rotation_absolute, tr1, _SIRIUS_def_mirror_var._rotation_relative);
    _SIRIUS_def_mirror_var._rotation_is_identity =  rot_test_identity(_SIRIUS_def_mirror_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_def_rot_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_def_mirror_var._position_absolute = coords_add(_SIRIUS_def_rot_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_def_loc_var._position_absolute, _SIRIUS_def_mirror_var._position_absolute);
    _SIRIUS_def_mirror_var._position_relative = rot_apply(_SIRIUS_def_mirror_var._rotation_absolute, tc1);
  } /* SIRIUS_def_mirror=Mirror() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_def_mirror", _SIRIUS_def_mirror_var._position_absolute, _SIRIUS_def_mirror_var._rotation_absolute);
  instrument->_position_absolute[542] = _SIRIUS_def_mirror_var._position_absolute;
  instrument->_position_relative[542] = _SIRIUS_def_mirror_var._position_relative;
    _SIRIUS_def_mirror_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_def_mirror_var._position_relative);
  instrument->counter_N[542]  = instrument->counter_P[542] = instrument->counter_P2[542] = 0;
  instrument->counter_AbsorbProp[542]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0541_SIRIUS_def_mirror", _SIRIUS_def_mirror_var._position_absolute, _SIRIUS_def_mirror_var._rotation_absolute, "Mirror");
        mccomp_param_nexus(nxhandle,"0541_SIRIUS_def_mirror", "zdepth", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0541_SIRIUS_def_mirror", "xwidth", "0.01", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0541_SIRIUS_def_mirror", "yheight", "0", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0541_SIRIUS_def_mirror", "coating", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0541_SIRIUS_def_mirror", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0541_SIRIUS_def_mirror", "geometry", "", "", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_def_mirror_setpos */

/* component SIRIUS_def_out=Arm() SETTING, POSITION/ROTATION */
int _SIRIUS_def_out_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_def_out_setpos] component SIRIUS_def_out=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_SIRIUS_def_out_var._name, "SIRIUS_def_out", 16384);
  stracpy(_SIRIUS_def_out_var._type, "Arm", 16384);
  _SIRIUS_def_out_var._index=543;
  int current_setpos_index = 543;
  /* component SIRIUS_def_out=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.SIRIUS_def_angle)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_def_loc_var._rotation_absolute, _SIRIUS_def_out_var._rotation_absolute);
    rot_transpose(_SIRIUS_def_mirror_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_def_out_var._rotation_absolute, tr1, _SIRIUS_def_out_var._rotation_relative);
    _SIRIUS_def_out_var._rotation_is_identity =  rot_test_identity(_SIRIUS_def_out_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_def_rot_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_def_out_var._position_absolute = coords_add(_SIRIUS_def_rot_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_def_mirror_var._position_absolute, _SIRIUS_def_out_var._position_absolute);
    _SIRIUS_def_out_var._position_relative = rot_apply(_SIRIUS_def_out_var._rotation_absolute, tc1);
  } /* SIRIUS_def_out=Arm() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_def_out", _SIRIUS_def_out_var._position_absolute, _SIRIUS_def_out_var._rotation_absolute);
  instrument->_position_absolute[543] = _SIRIUS_def_out_var._position_absolute;
  instrument->_position_relative[543] = _SIRIUS_def_out_var._position_relative;
    _SIRIUS_def_out_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_def_out_var._position_relative);
  instrument->counter_N[543]  = instrument->counter_P[543] = instrument->counter_P2[543] = 0;
  instrument->counter_AbsorbProp[543]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0542_SIRIUS_def_out", _SIRIUS_def_out_var._position_absolute, _SIRIUS_def_out_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_def_out_setpos */

/* component SIRIUS_sample_stage=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_sample_stage_setpos] component SIRIUS_sample_stage=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_sample_stage_var._name, "SIRIUS_sample_stage", 16384);
  stracpy(_SIRIUS_sample_stage_var._type, "Monitor_nD", 16384);
  _SIRIUS_sample_stage_var._index=544;
  int current_setpos_index = 544;
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_sample_stage_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.user9[0]='\0';
  _SIRIUS_sample_stage_var._parameters.xwidth = 0.02;
  _SIRIUS_sample_stage_var._parameters.yheight = 0.02;
  _SIRIUS_sample_stage_var._parameters.zdepth = 0;
  _SIRIUS_sample_stage_var._parameters.bins = 0;
  _SIRIUS_sample_stage_var._parameters.min = -1e40;
  _SIRIUS_sample_stage_var._parameters.max = 1e40;
  _SIRIUS_sample_stage_var._parameters.restore_xray = 1;
  _SIRIUS_sample_stage_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_SIRIUS_sample_stage_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.geometry[0]='\0';
  _SIRIUS_sample_stage_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_sample_stage_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_sample_stage_var._parameters.username9[0]='\0';


  /* component SIRIUS_sample_stage=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_def_out_var._rotation_absolute, _SIRIUS_sample_stage_var._rotation_absolute);
    rot_transpose(_SIRIUS_def_mirror_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_sample_stage_var._rotation_absolute, tr1, _SIRIUS_sample_stage_var._rotation_relative);
    _SIRIUS_sample_stage_var._rotation_is_identity =  rot_test_identity(_SIRIUS_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, _instrument_var._parameters.SIRIUS_sample_pos - 18);
    rot_transpose(_SIRIUS_def_out_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_sample_stage_var._position_absolute = coords_add(_SIRIUS_def_out_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_def_mirror_var._position_absolute, _SIRIUS_sample_stage_var._position_absolute);
    _SIRIUS_sample_stage_var._position_relative = rot_apply(_SIRIUS_sample_stage_var._rotation_absolute, tc1);
  } /* SIRIUS_sample_stage=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_sample_stage", _SIRIUS_sample_stage_var._position_absolute, _SIRIUS_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[544] = _SIRIUS_sample_stage_var._position_absolute;
  instrument->_position_relative[544] = _SIRIUS_sample_stage_var._position_relative;
    _SIRIUS_sample_stage_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_sample_stage_var._position_relative);
  instrument->counter_N[544]  = instrument->counter_P[544] = instrument->counter_P2[544] = 0;
  instrument->counter_AbsorbProp[544]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0543_SIRIUS_sample_stage", _SIRIUS_sample_stage_var._position_absolute, _SIRIUS_sample_stage_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "xwidth", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "yheight", "0", "0.02","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0543_SIRIUS_sample_stage", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_sample_stage_setpos */

/* component SIRIUS_fluo=FluoPowder() SETTING, POSITION/ROTATION */
int _SIRIUS_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_fluo_setpos] component SIRIUS_fluo=FluoPowder() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");
  stracpy(_SIRIUS_fluo_var._name, "SIRIUS_fluo", 16384);
  stracpy(_SIRIUS_fluo_var._type, "FluoPowder", 16384);
  _SIRIUS_fluo_var._index=545;
  int current_setpos_index = 545;
  _SIRIUS_fluo_var._parameters.geometry[0]='\0';
  _SIRIUS_fluo_var._parameters.radius = 0;
  _SIRIUS_fluo_var._parameters.thickness = 0;
  _SIRIUS_fluo_var._parameters.xwidth = 0.002;
  _SIRIUS_fluo_var._parameters.yheight = 0.002;
  _SIRIUS_fluo_var._parameters.zdepth = 1e-5;
  _SIRIUS_fluo_var._parameters.concentric = 0;
  if(_instrument_var._parameters.SIRIUS_sample && strlen(_instrument_var._parameters.SIRIUS_sample))
    stracpy(_SIRIUS_fluo_var._parameters.material, _instrument_var._parameters.SIRIUS_sample ? _instrument_var._parameters.SIRIUS_sample : "", 16384);
  else 
  _SIRIUS_fluo_var._parameters.material[0]='\0';
  _SIRIUS_fluo_var._parameters.packing_factor = 0;
  _SIRIUS_fluo_var._parameters.density = 0;
  _SIRIUS_fluo_var._parameters.weight = 0;
  _SIRIUS_fluo_var._parameters.p_interact = 1;
  _SIRIUS_fluo_var._parameters.target_x = 0;
  _SIRIUS_fluo_var._parameters.target_y = 0;
  _SIRIUS_fluo_var._parameters.target_z = 1;
  _SIRIUS_fluo_var._parameters.focus_r = 0;
  _SIRIUS_fluo_var._parameters.focus_xw = 0;
  _SIRIUS_fluo_var._parameters.focus_yh = 0;
  _SIRIUS_fluo_var._parameters.focus_aw = 0;
  _SIRIUS_fluo_var._parameters.focus_ah = 0;
  _SIRIUS_fluo_var._parameters.target_index = 0;
  _SIRIUS_fluo_var._parameters.flag_compton = 1;
  _SIRIUS_fluo_var._parameters.flag_rayleigh = 1;
  _SIRIUS_fluo_var._parameters.flag_lorentzian = 0;
  _SIRIUS_fluo_var._parameters.flag_powder = 1;
  _SIRIUS_fluo_var._parameters.flag_kissel = 0;
  if("" && strlen(""))
    stracpy(_SIRIUS_fluo_var._parameters.powder_refl, "" ? "" : "", 16384);
  else 
  _SIRIUS_fluo_var._parameters.powder_refl[0]='\0';
  _SIRIUS_fluo_var._parameters.powder_format[0] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[1] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[2] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[3] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[4] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[5] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[6] = 0;
  _SIRIUS_fluo_var._parameters.powder_format[7] = 0;
  _SIRIUS_fluo_var._parameters.Vc = 0;
  _SIRIUS_fluo_var._parameters.delta_d_d = 0;
  _SIRIUS_fluo_var._parameters.DW = 0;
  _SIRIUS_fluo_var._parameters.d_phi = 0;
  _SIRIUS_fluo_var._parameters.nb_atoms = 1;
  _SIRIUS_fluo_var._parameters.barns = 1;
  _SIRIUS_fluo_var._parameters.tth_sign = 0;
  _SIRIUS_fluo_var._parameters.order = 1;


  /* component SIRIUS_fluo=FluoPowder() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_sample_stage_var._rotation_absolute, _SIRIUS_fluo_var._rotation_absolute);
    rot_transpose(_SIRIUS_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_fluo_var._rotation_absolute, tr1, _SIRIUS_fluo_var._rotation_relative);
    _SIRIUS_fluo_var._rotation_is_identity =  rot_test_identity(_SIRIUS_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_fluo_var._position_absolute = coords_add(_SIRIUS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_sample_stage_var._position_absolute, _SIRIUS_fluo_var._position_absolute);
    _SIRIUS_fluo_var._position_relative = rot_apply(_SIRIUS_fluo_var._rotation_absolute, tc1);
  } /* SIRIUS_fluo=FluoPowder() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_fluo", _SIRIUS_fluo_var._position_absolute, _SIRIUS_fluo_var._rotation_absolute);
  instrument->_position_absolute[545] = _SIRIUS_fluo_var._position_absolute;
  instrument->_position_relative[545] = _SIRIUS_fluo_var._position_relative;
    _SIRIUS_fluo_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_fluo_var._position_relative);
  instrument->counter_N[545]  = instrument->counter_P[545] = instrument->counter_P2[545] = 0;
  instrument->counter_AbsorbProp[545]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0544_SIRIUS_fluo", _SIRIUS_fluo_var._position_absolute, _SIRIUS_fluo_var._rotation_absolute, "FluoPowder");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "xwidth", "0", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "yheight", "0", "0.002","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "zdepth", "0", "1e-5","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "material", "LaB6.cif", _instrument_var._parameters.SIRIUS_sample, "char*");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "p_interact", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "target_z", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "focus_aw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "focus_ah", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "flag_powder", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "powder_refl", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "powder_format", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }", "{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "Vc", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "delta_d_d", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "DW", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "d_phi", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "nb_atoms", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "barns", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "tth_sign", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0544_SIRIUS_fluo", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_fluo_setpos */

/* component SIRIUS_det_2d=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_det_2d_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_det_2d_setpos] component SIRIUS_det_2d=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_det_2d_var._name, "SIRIUS_det_2d", 16384);
  stracpy(_SIRIUS_det_2d_var._type, "Monitor_nD", 16384);
  _SIRIUS_det_2d_var._index=546;
  int current_setpos_index = 546;
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_2d_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.user9[0]='\0';
  _SIRIUS_det_2d_var._parameters.xwidth = 0.1;
  _SIRIUS_det_2d_var._parameters.yheight = 0.1;
  _SIRIUS_det_2d_var._parameters.zdepth = 0;
  _SIRIUS_det_2d_var._parameters.bins = 0;
  _SIRIUS_det_2d_var._parameters.min = -1e40;
  _SIRIUS_det_2d_var._parameters.max = 1e40;
  _SIRIUS_det_2d_var._parameters.restore_xray = 0;
  _SIRIUS_det_2d_var._parameters.radius = 0.5;
  if("theta bins=256, phi bins=256" && strlen("theta bins=256, phi bins=256"))
    stracpy(_SIRIUS_det_2d_var._parameters.options, "theta bins=256, phi bins=256" ? "theta bins=256, phi bins=256" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.geometry[0]='\0';
  _SIRIUS_det_2d_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_2d_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_2d_var._parameters.username9[0]='\0';


  /* component SIRIUS_det_2d=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_sample_stage_var._rotation_absolute, _SIRIUS_det_2d_var._rotation_absolute);
    rot_transpose(_SIRIUS_fluo_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_det_2d_var._rotation_absolute, tr1, _SIRIUS_det_2d_var._rotation_relative);
    _SIRIUS_det_2d_var._rotation_is_identity =  rot_test_identity(_SIRIUS_det_2d_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.0);
    rot_transpose(_SIRIUS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_det_2d_var._position_absolute = coords_add(_SIRIUS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_fluo_var._position_absolute, _SIRIUS_det_2d_var._position_absolute);
    _SIRIUS_det_2d_var._position_relative = rot_apply(_SIRIUS_det_2d_var._rotation_absolute, tc1);
  } /* SIRIUS_det_2d=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_det_2d", _SIRIUS_det_2d_var._position_absolute, _SIRIUS_det_2d_var._rotation_absolute);
  instrument->_position_absolute[546] = _SIRIUS_det_2d_var._position_absolute;
  instrument->_position_relative[546] = _SIRIUS_det_2d_var._position_relative;
    _SIRIUS_det_2d_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_det_2d_var._position_relative);
  instrument->counter_N[546]  = instrument->counter_P[546] = instrument->counter_P2[546] = 0;
  instrument->counter_AbsorbProp[546]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0545_SIRIUS_det_2d", _SIRIUS_det_2d_var._position_absolute, _SIRIUS_det_2d_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "bins", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "radius", "0", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "options", "NULL", "theta bins=256, phi bins=256", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0545_SIRIUS_det_2d", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_det_2d_setpos */

/* component SIRIUS_det_fluo=Monitor_nD() SETTING, POSITION/ROTATION */
int _SIRIUS_det_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_SIRIUS_det_fluo_setpos] component SIRIUS_det_fluo=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_SIRIUS_det_fluo_var._name, "SIRIUS_det_fluo", 16384);
  stracpy(_SIRIUS_det_fluo_var._type, "Monitor_nD", 16384);
  _SIRIUS_det_fluo_var._index=547;
  int current_setpos_index = 547;
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_SIRIUS_det_fluo_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.user9[0]='\0';
  _SIRIUS_det_fluo_var._parameters.xwidth = 0;
  _SIRIUS_det_fluo_var._parameters.yheight = 0;
  _SIRIUS_det_fluo_var._parameters.zdepth = 0;
  _SIRIUS_det_fluo_var._parameters.bins = 128;
  _SIRIUS_det_fluo_var._parameters.min = -1e40;
  _SIRIUS_det_fluo_var._parameters.max = 1e40;
  _SIRIUS_det_fluo_var._parameters.restore_xray = 0;
  _SIRIUS_det_fluo_var._parameters.radius = 0.1;
  if("energy" && strlen("energy"))
    stracpy(_SIRIUS_det_fluo_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.geometry[0]='\0';
  _SIRIUS_det_fluo_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_SIRIUS_det_fluo_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _SIRIUS_det_fluo_var._parameters.username9[0]='\0';


  /* component SIRIUS_det_fluo=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_sample_stage_var._rotation_absolute, _SIRIUS_det_fluo_var._rotation_absolute);
    rot_transpose(_SIRIUS_det_2d_var._rotation_absolute, tr1);
    rot_mul(_SIRIUS_det_fluo_var._rotation_absolute, tr1, _SIRIUS_det_fluo_var._rotation_relative);
    _SIRIUS_det_fluo_var._rotation_is_identity =  rot_test_identity(_SIRIUS_det_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 1.0);
    rot_transpose(_SIRIUS_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _SIRIUS_det_fluo_var._position_absolute = coords_add(_SIRIUS_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_det_2d_var._position_absolute, _SIRIUS_det_fluo_var._position_absolute);
    _SIRIUS_det_fluo_var._position_relative = rot_apply(_SIRIUS_det_fluo_var._rotation_absolute, tc1);
  } /* SIRIUS_det_fluo=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("SIRIUS_det_fluo", _SIRIUS_det_fluo_var._position_absolute, _SIRIUS_det_fluo_var._rotation_absolute);
  instrument->_position_absolute[547] = _SIRIUS_det_fluo_var._position_absolute;
  instrument->_position_relative[547] = _SIRIUS_det_fluo_var._position_relative;
    _SIRIUS_det_fluo_var._position_relative_is_zero =  coords_test_zero(_SIRIUS_det_fluo_var._position_relative);
  instrument->counter_N[547]  = instrument->counter_P[547] = instrument->counter_P2[547] = 0;
  instrument->counter_AbsorbProp[547]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0546_SIRIUS_det_fluo", _SIRIUS_det_fluo_var._position_absolute, _SIRIUS_det_fluo_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "radius", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0546_SIRIUS_det_fluo", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _SIRIUS_det_fluo_setpos */

/* component beamdump_565=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_565_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_565_setpos] component beamdump_565=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_565_var._name, "beamdump_565", 16384);
  stracpy(_beamdump_565_var._type, "Beamstop", 16384);
  _beamdump_565_var._index=548;
  int current_setpos_index = 548;
  _beamdump_565_var._parameters.xmin = -0.05;
  _beamdump_565_var._parameters.xmax = 0.05;
  _beamdump_565_var._parameters.ymin = -0.05;
  _beamdump_565_var._parameters.ymax = 0.05;
  _beamdump_565_var._parameters.xwidth = 0;
  _beamdump_565_var._parameters.yheight = 0;
  _beamdump_565_var._parameters.radius = 0;

  /* component beamdump_565=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _SIRIUS_det_fluo_var._rotation_absolute, _beamdump_565_var._rotation_absolute);
    rot_transpose(_SIRIUS_det_fluo_var._rotation_absolute, tr1);
    rot_mul(_beamdump_565_var._rotation_absolute, tr1, _beamdump_565_var._rotation_relative);
    _beamdump_565_var._rotation_is_identity =  rot_test_identity(_beamdump_565_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_SIRIUS_det_fluo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_565_var._position_absolute = coords_add(_SIRIUS_det_fluo_var._position_absolute, tc2);
    tc1 = coords_sub(_SIRIUS_det_fluo_var._position_absolute, _beamdump_565_var._position_absolute);
    _beamdump_565_var._position_relative = rot_apply(_beamdump_565_var._rotation_absolute, tc1);
  } /* beamdump_565=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_565", _beamdump_565_var._position_absolute, _beamdump_565_var._rotation_absolute);
  instrument->_position_absolute[548] = _beamdump_565_var._position_absolute;
  instrument->_position_relative[548] = _beamdump_565_var._position_relative;
    _beamdump_565_var._position_relative_is_zero =  coords_test_zero(_beamdump_565_var._position_relative);
  instrument->counter_N[548]  = instrument->counter_P[548] = instrument->counter_P2[548] = 0;
  instrument->counter_AbsorbProp[548]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0547_beamdump_565", _beamdump_565_var._position_absolute, _beamdump_565_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0547_beamdump_565", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_565_setpos */

/* component LUCIA_pos=Text() SETTING, POSITION/ROTATION */
int _LUCIA_pos_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_pos_setpos] component LUCIA_pos=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_LUCIA_pos_var._name, "LUCIA_pos", 16384);
  stracpy(_LUCIA_pos_var._type, "Text", 16384);
  _LUCIA_pos_var._index=549;
  int current_setpos_index = 549;
  if("LUCIA" && strlen("LUCIA"))
    stracpy(_LUCIA_pos_var._parameters.text, "LUCIA" ? "LUCIA" : "", 16384);
  else 
  _LUCIA_pos_var._parameters.text[0]='\0';
  _LUCIA_pos_var._parameters.size = 0.5;
  if("XY" && strlen("XY"))
    stracpy(_LUCIA_pos_var._parameters.plane, "XY" ? "XY" : "", 16384);
  else 
  _LUCIA_pos_var._parameters.plane[0]='\0';
  _LUCIA_pos_var._parameters.pen_thickness = 0.1;


  /* component LUCIA_pos=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-337.698)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _LUCIA_pos_var._rotation_absolute);
    rot_transpose(_beamdump_565_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_pos_var._rotation_absolute, tr1, _LUCIA_pos_var._rotation_relative);
    _LUCIA_pos_var._rotation_is_identity =  rot_test_identity(_LUCIA_pos_var._rotation_relative);
    tc1 = coords_set(
      52.126, 0, -21.380);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_pos_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_565_var._position_absolute, _LUCIA_pos_var._position_absolute);
    _LUCIA_pos_var._position_relative = rot_apply(_LUCIA_pos_var._rotation_absolute, tc1);
  } /* LUCIA_pos=Text() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_pos", _LUCIA_pos_var._position_absolute, _LUCIA_pos_var._rotation_absolute);
  instrument->_position_absolute[549] = _LUCIA_pos_var._position_absolute;
  instrument->_position_relative[549] = _LUCIA_pos_var._position_relative;
    _LUCIA_pos_var._position_relative_is_zero =  coords_test_zero(_LUCIA_pos_var._position_relative);
  instrument->counter_N[549]  = instrument->counter_P[549] = instrument->counter_P2[549] = 0;
  instrument->counter_AbsorbProp[549]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0548_LUCIA_pos", _LUCIA_pos_var._position_absolute, _LUCIA_pos_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0548_LUCIA_pos", "text", "NONE", "LUCIA", "char*");
        mccomp_param_nexus(nxhandle,"0548_LUCIA_pos", "size", "0.5", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0548_LUCIA_pos", "plane", "XY", "XY", "char*");
        mccomp_param_nexus(nxhandle,"0548_LUCIA_pos", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_pos_setpos */

/* component LUCIA=Arm() SETTING, POSITION/ROTATION */
int _LUCIA_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_setpos] component LUCIA=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_LUCIA_var._name, "LUCIA", 16384);
  stracpy(_LUCIA_var._type, "Arm", 16384);
  _LUCIA_var._index=550;
  int current_setpos_index = 550;
  /* component LUCIA=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_pos_var._rotation_absolute, _LUCIA_var._rotation_absolute);
    rot_transpose(_LUCIA_pos_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_var._rotation_absolute, tr1, _LUCIA_var._rotation_relative);
    _LUCIA_var._rotation_is_identity =  rot_test_identity(_LUCIA_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_pos_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_var._position_absolute = coords_add(_LUCIA_pos_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_pos_var._position_absolute, _LUCIA_var._position_absolute);
    _LUCIA_var._position_relative = rot_apply(_LUCIA_var._rotation_absolute, tc1);
  } /* LUCIA=Arm() AT ROTATED */
  DEBUG_COMPONENT("LUCIA", _LUCIA_var._position_absolute, _LUCIA_var._rotation_absolute);
  instrument->_position_absolute[550] = _LUCIA_var._position_absolute;
  instrument->_position_relative[550] = _LUCIA_var._position_relative;
    _LUCIA_var._position_relative_is_zero =  coords_test_zero(_LUCIA_var._position_relative);
  instrument->counter_N[550]  = instrument->counter_P[550] = instrument->counter_P2[550] = 0;
  instrument->counter_AbsorbProp[550]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0549_LUCIA", _LUCIA_var._position_absolute, _LUCIA_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_setpos */

/* component LUCIA_source=Undulator() SETTING, POSITION/ROTATION */
int _LUCIA_source_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_source_setpos] component LUCIA_source=Undulator() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");
  stracpy(_LUCIA_source_var._name, "LUCIA_source", 16384);
  stracpy(_LUCIA_source_var._type, "Undulator", 16384);
  _LUCIA_source_var._index=551;
  int current_setpos_index = 551;
  _LUCIA_source_var._parameters.E0 = _instrument_var._parameters.LUCIA_E0;
  _LUCIA_source_var._parameters.dE = _instrument_var._parameters.LUCIA_dE;
  _LUCIA_source_var._parameters.phase = 0;
  _LUCIA_source_var._parameters.randomphase = 1;
  _LUCIA_source_var._parameters.Ee = 2.75;
  _LUCIA_source_var._parameters.dEe = 0.001;
  _LUCIA_source_var._parameters.Ie = 0.5;
  _LUCIA_source_var._parameters.B = 0.42;
  _LUCIA_source_var._parameters.K = 0;
  _LUCIA_source_var._parameters.Nper = 32;
  _LUCIA_source_var._parameters.lu = 52.4e-3;
  _LUCIA_source_var._parameters.sigey = 8.2e-6;
  _LUCIA_source_var._parameters.sigex = 218.2e-6;
  _LUCIA_source_var._parameters.sigepx = 30e-6;
  _LUCIA_source_var._parameters.sigepy = 3.7e-6;
  _LUCIA_source_var._parameters.focus_xw = 0;
  _LUCIA_source_var._parameters.focus_yh = 0;
  _LUCIA_source_var._parameters.dist = 1;
  _LUCIA_source_var._parameters.quick_integ = 0;
  _LUCIA_source_var._parameters.E1st = 0;
  _LUCIA_source_var._parameters.verbose = 0;
  _LUCIA_source_var._parameters.Br = 1.35;


  /* component LUCIA_source=Undulator() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_var._rotation_absolute, _LUCIA_source_var._rotation_absolute);
    rot_transpose(_LUCIA_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_source_var._rotation_absolute, tr1, _LUCIA_source_var._rotation_relative);
    _LUCIA_source_var._rotation_is_identity =  rot_test_identity(_LUCIA_source_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_source_var._position_absolute = coords_add(_LUCIA_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_var._position_absolute, _LUCIA_source_var._position_absolute);
    _LUCIA_source_var._position_relative = rot_apply(_LUCIA_source_var._rotation_absolute, tc1);
  } /* LUCIA_source=Undulator() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_source", _LUCIA_source_var._position_absolute, _LUCIA_source_var._rotation_absolute);
  instrument->_position_absolute[551] = _LUCIA_source_var._position_absolute;
  instrument->_position_relative[551] = _LUCIA_source_var._position_relative;
    _LUCIA_source_var._position_relative_is_zero =  coords_test_zero(_LUCIA_source_var._position_relative);
  instrument->counter_N[551]  = instrument->counter_P[551] = instrument->counter_P2[551] = 0;
  instrument->counter_AbsorbProp[551]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0550_LUCIA_source", _LUCIA_source_var._position_absolute, _LUCIA_source_var._rotation_absolute, "Undulator");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "E0", "0", "_instrument_var._parameters.LUCIA_E0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "dE", "0", "_instrument_var._parameters.LUCIA_dE","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "phase", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "randomphase", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "Ee", "2.4", "2.75","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "dEe", "0", "0.001","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "Ie", "0.4", "0.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "B", "0", "0.42","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "K", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "Nper", "1", "32","int");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "lu", "16e-3", "52.4e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "sigey", "0", "8.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "sigex", "0", "218.2e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "sigepx", "0", "30e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "sigepy", "0", "3.7e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "dist", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "quick_integ", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "E1st", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "verbose", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0550_LUCIA_source", "Br", "1.35", "1.35","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_source_setpos */

/* component LUCIA_mon_src_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_mon_src_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_mon_src_xy_setpos] component LUCIA_mon_src_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_mon_src_xy_var._name, "LUCIA_mon_src_xy", 16384);
  stracpy(_LUCIA_mon_src_xy_var._type, "Monitor_nD", 16384);
  _LUCIA_mon_src_xy_var._index=552;
  int current_setpos_index = 552;
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.user9[0]='\0';
  _LUCIA_mon_src_xy_var._parameters.xwidth = 2e-3;
  _LUCIA_mon_src_xy_var._parameters.yheight = 2e-3;
  _LUCIA_mon_src_xy_var._parameters.zdepth = 0;
  _LUCIA_mon_src_xy_var._parameters.bins = 128;
  _LUCIA_mon_src_xy_var._parameters.min = -1e40;
  _LUCIA_mon_src_xy_var._parameters.max = 1e40;
  _LUCIA_mon_src_xy_var._parameters.restore_xray = 0;
  _LUCIA_mon_src_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.geometry[0]='\0';
  _LUCIA_mon_src_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_xy_var._parameters.username9[0]='\0';


  /* component LUCIA_mon_src_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_source_var._rotation_absolute, _LUCIA_mon_src_xy_var._rotation_absolute);
    rot_transpose(_LUCIA_source_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_mon_src_xy_var._rotation_absolute, tr1, _LUCIA_mon_src_xy_var._rotation_relative);
    _LUCIA_mon_src_xy_var._rotation_is_identity =  rot_test_identity(_LUCIA_mon_src_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 13.3);
    rot_transpose(_LUCIA_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_mon_src_xy_var._position_absolute = coords_add(_LUCIA_source_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_source_var._position_absolute, _LUCIA_mon_src_xy_var._position_absolute);
    _LUCIA_mon_src_xy_var._position_relative = rot_apply(_LUCIA_mon_src_xy_var._rotation_absolute, tc1);
  } /* LUCIA_mon_src_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_mon_src_xy", _LUCIA_mon_src_xy_var._position_absolute, _LUCIA_mon_src_xy_var._rotation_absolute);
  instrument->_position_absolute[552] = _LUCIA_mon_src_xy_var._position_absolute;
  instrument->_position_relative[552] = _LUCIA_mon_src_xy_var._position_relative;
    _LUCIA_mon_src_xy_var._position_relative_is_zero =  coords_test_zero(_LUCIA_mon_src_xy_var._position_relative);
  instrument->counter_N[552]  = instrument->counter_P[552] = instrument->counter_P2[552] = 0;
  instrument->counter_AbsorbProp[552]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0551_LUCIA_mon_src_xy", _LUCIA_mon_src_xy_var._position_absolute, _LUCIA_mon_src_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0551_LUCIA_mon_src_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_mon_src_xy_setpos */

/* component LUCIA_mon_src_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_mon_src_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_mon_src_e_setpos] component LUCIA_mon_src_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_mon_src_e_var._name, "LUCIA_mon_src_e", 16384);
  stracpy(_LUCIA_mon_src_e_var._type, "Monitor_nD", 16384);
  _LUCIA_mon_src_e_var._index=553;
  int current_setpos_index = 553;
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_src_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.user9[0]='\0';
  _LUCIA_mon_src_e_var._parameters.xwidth = 2e-3;
  _LUCIA_mon_src_e_var._parameters.yheight = 2e-3;
  _LUCIA_mon_src_e_var._parameters.zdepth = 0;
  _LUCIA_mon_src_e_var._parameters.bins = 128;
  _LUCIA_mon_src_e_var._parameters.min = _instrument_var._parameters.LUCIA_E0 - _instrument_var._parameters.LUCIA_dE * 1.1;
  _LUCIA_mon_src_e_var._parameters.max = _instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.1;
  _LUCIA_mon_src_e_var._parameters.restore_xray = 0;
  _LUCIA_mon_src_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_LUCIA_mon_src_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.geometry[0]='\0';
  _LUCIA_mon_src_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_src_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_src_e_var._parameters.username9[0]='\0';


  /* component LUCIA_mon_src_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_mon_src_xy_var._rotation_absolute, _LUCIA_mon_src_e_var._rotation_absolute);
    rot_transpose(_LUCIA_mon_src_xy_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_mon_src_e_var._rotation_absolute, tr1, _LUCIA_mon_src_e_var._rotation_relative);
    _LUCIA_mon_src_e_var._rotation_is_identity =  rot_test_identity(_LUCIA_mon_src_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_mon_src_xy_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_mon_src_e_var._position_absolute = coords_add(_LUCIA_mon_src_xy_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_mon_src_xy_var._position_absolute, _LUCIA_mon_src_e_var._position_absolute);
    _LUCIA_mon_src_e_var._position_relative = rot_apply(_LUCIA_mon_src_e_var._rotation_absolute, tc1);
  } /* LUCIA_mon_src_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_mon_src_e", _LUCIA_mon_src_e_var._position_absolute, _LUCIA_mon_src_e_var._rotation_absolute);
  instrument->_position_absolute[553] = _LUCIA_mon_src_e_var._position_absolute;
  instrument->_position_relative[553] = _LUCIA_mon_src_e_var._position_relative;
    _LUCIA_mon_src_e_var._position_relative_is_zero =  coords_test_zero(_LUCIA_mon_src_e_var._position_relative);
  instrument->counter_N[553]  = instrument->counter_P[553] = instrument->counter_P2[553] = 0;
  instrument->counter_AbsorbProp[553]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0552_LUCIA_mon_src_e", _LUCIA_mon_src_e_var._position_absolute, _LUCIA_mon_src_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "min", "-1e40", "_instrument_var._parameters.LUCIA_E0 - _instrument_var._parameters.LUCIA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "max", "1e40", "_instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0552_LUCIA_mon_src_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_mon_src_e_setpos */

/* component LUCIA_slit=Slit() SETTING, POSITION/ROTATION */
int _LUCIA_slit_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_slit_setpos] component LUCIA_slit=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_LUCIA_slit_var._name, "LUCIA_slit", 16384);
  stracpy(_LUCIA_slit_var._type, "Slit", 16384);
  _LUCIA_slit_var._index=554;
  int current_setpos_index = 554;
  _LUCIA_slit_var._parameters.xmin = 0;
  _LUCIA_slit_var._parameters.xmax = 0;
  _LUCIA_slit_var._parameters.ymin = 0;
  _LUCIA_slit_var._parameters.ymax = 0;
  _LUCIA_slit_var._parameters.radius = 0;
  _LUCIA_slit_var._parameters.xwidth = 0.5e-3;
  _LUCIA_slit_var._parameters.yheight = 0.5e-3;
  _LUCIA_slit_var._parameters.dist = 0;
  _LUCIA_slit_var._parameters.focus_xw = 0;
  _LUCIA_slit_var._parameters.focus_yh = 0;
  _LUCIA_slit_var._parameters.focus_x0 = 0;
  _LUCIA_slit_var._parameters.focus_y0 = 0;

  /* component LUCIA_slit=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_mon_src_e_var._rotation_absolute, _LUCIA_slit_var._rotation_absolute);
    rot_transpose(_LUCIA_mon_src_e_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_slit_var._rotation_absolute, tr1, _LUCIA_slit_var._rotation_relative);
    _LUCIA_slit_var._rotation_is_identity =  rot_test_identity(_LUCIA_slit_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_LUCIA_mon_src_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_slit_var._position_absolute = coords_add(_LUCIA_mon_src_e_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_mon_src_e_var._position_absolute, _LUCIA_slit_var._position_absolute);
    _LUCIA_slit_var._position_relative = rot_apply(_LUCIA_slit_var._rotation_absolute, tc1);
  } /* LUCIA_slit=Slit() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_slit", _LUCIA_slit_var._position_absolute, _LUCIA_slit_var._rotation_absolute);
  instrument->_position_absolute[554] = _LUCIA_slit_var._position_absolute;
  instrument->_position_relative[554] = _LUCIA_slit_var._position_relative;
    _LUCIA_slit_var._position_relative_is_zero =  coords_test_zero(_LUCIA_slit_var._position_relative);
  instrument->counter_N[554]  = instrument->counter_P[554] = instrument->counter_P2[554] = 0;
  instrument->counter_AbsorbProp[554]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0553_LUCIA_slit", _LUCIA_slit_var._position_absolute, _LUCIA_slit_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "xwidth", "0.001", "0.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "yheight", "0.001", "0.5e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0553_LUCIA_slit", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_slit_setpos */

/* component LUCIA_slit_mon_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_slit_mon_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_slit_mon_xy_setpos] component LUCIA_slit_mon_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_slit_mon_xy_var._name, "LUCIA_slit_mon_xy", 16384);
  stracpy(_LUCIA_slit_mon_xy_var._type, "Monitor_nD", 16384);
  _LUCIA_slit_mon_xy_var._index=555;
  int current_setpos_index = 555;
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.user9[0]='\0';
  _LUCIA_slit_mon_xy_var._parameters.xwidth = 2e-3;
  _LUCIA_slit_mon_xy_var._parameters.yheight = 2e-3;
  _LUCIA_slit_mon_xy_var._parameters.zdepth = 0;
  _LUCIA_slit_mon_xy_var._parameters.bins = 128;
  _LUCIA_slit_mon_xy_var._parameters.min = -1e40;
  _LUCIA_slit_mon_xy_var._parameters.max = 1e40;
  _LUCIA_slit_mon_xy_var._parameters.restore_xray = 0;
  _LUCIA_slit_mon_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.geometry[0]='\0';
  _LUCIA_slit_mon_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_slit_mon_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_slit_mon_xy_var._parameters.username9[0]='\0';


  /* component LUCIA_slit_mon_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_slit_var._rotation_absolute, _LUCIA_slit_mon_xy_var._rotation_absolute);
    rot_transpose(_LUCIA_slit_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_slit_mon_xy_var._rotation_absolute, tr1, _LUCIA_slit_mon_xy_var._rotation_relative);
    _LUCIA_slit_mon_xy_var._rotation_is_identity =  rot_test_identity(_LUCIA_slit_mon_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_slit_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_slit_mon_xy_var._position_absolute = coords_add(_LUCIA_slit_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_slit_var._position_absolute, _LUCIA_slit_mon_xy_var._position_absolute);
    _LUCIA_slit_mon_xy_var._position_relative = rot_apply(_LUCIA_slit_mon_xy_var._rotation_absolute, tc1);
  } /* LUCIA_slit_mon_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_slit_mon_xy", _LUCIA_slit_mon_xy_var._position_absolute, _LUCIA_slit_mon_xy_var._rotation_absolute);
  instrument->_position_absolute[555] = _LUCIA_slit_mon_xy_var._position_absolute;
  instrument->_position_relative[555] = _LUCIA_slit_mon_xy_var._position_relative;
    _LUCIA_slit_mon_xy_var._position_relative_is_zero =  coords_test_zero(_LUCIA_slit_mon_xy_var._position_relative);
  instrument->counter_N[555]  = instrument->counter_P[555] = instrument->counter_P2[555] = 0;
  instrument->counter_AbsorbProp[555]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", _LUCIA_slit_mon_xy_var._position_absolute, _LUCIA_slit_mon_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0554_LUCIA_slit_mon_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_slit_mon_xy_setpos */

/* component LUCIA_DCM_location=Arm() SETTING, POSITION/ROTATION */
int _LUCIA_DCM_location_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_DCM_location_setpos] component LUCIA_DCM_location=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_LUCIA_DCM_location_var._name, "LUCIA_DCM_location", 16384);
  stracpy(_LUCIA_DCM_location_var._type, "Arm", 16384);
  _LUCIA_DCM_location_var._index=556;
  int current_setpos_index = 556;
  /* component LUCIA_DCM_location=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_source_var._rotation_absolute, _LUCIA_DCM_location_var._rotation_absolute);
    rot_transpose(_LUCIA_slit_mon_xy_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_DCM_location_var._rotation_absolute, tr1, _LUCIA_DCM_location_var._rotation_relative);
    _LUCIA_DCM_location_var._rotation_is_identity =  rot_test_identity(_LUCIA_DCM_location_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 20.5);
    rot_transpose(_LUCIA_source_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_DCM_location_var._position_absolute = coords_add(_LUCIA_source_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_slit_mon_xy_var._position_absolute, _LUCIA_DCM_location_var._position_absolute);
    _LUCIA_DCM_location_var._position_relative = rot_apply(_LUCIA_DCM_location_var._rotation_absolute, tc1);
  } /* LUCIA_DCM_location=Arm() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_DCM_location", _LUCIA_DCM_location_var._position_absolute, _LUCIA_DCM_location_var._rotation_absolute);
  instrument->_position_absolute[556] = _LUCIA_DCM_location_var._position_absolute;
  instrument->_position_relative[556] = _LUCIA_DCM_location_var._position_relative;
    _LUCIA_DCM_location_var._position_relative_is_zero =  coords_test_zero(_LUCIA_DCM_location_var._position_relative);
  instrument->counter_N[556]  = instrument->counter_P[556] = instrument->counter_P2[556] = 0;
  instrument->counter_AbsorbProp[556]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0555_LUCIA_DCM_location", _LUCIA_DCM_location_var._position_absolute, _LUCIA_DCM_location_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_DCM_location_setpos */

/* component LUCIA_dcm_xtal0=Bragg_crystal() SETTING, POSITION/ROTATION */
int _LUCIA_dcm_xtal0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_dcm_xtal0_setpos] component LUCIA_dcm_xtal0=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_LUCIA_dcm_xtal0_var._name, "LUCIA_dcm_xtal0", 16384);
  stracpy(_LUCIA_dcm_xtal0_var._type, "Bragg_crystal", 16384);
  _LUCIA_dcm_xtal0_var._index=557;
  int current_setpos_index = 557;
  _LUCIA_dcm_xtal0_var._parameters.length = 0.04;
  _LUCIA_dcm_xtal0_var._parameters.width = 0.04;
  _LUCIA_dcm_xtal0_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_LUCIA_dcm_xtal0_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _LUCIA_dcm_xtal0_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_LUCIA_dcm_xtal0_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _LUCIA_dcm_xtal0_var._parameters.material[0]='\0';
  _LUCIA_dcm_xtal0_var._parameters.alpha = 0.0;
  _LUCIA_dcm_xtal0_var._parameters.R0 = 0;
  _LUCIA_dcm_xtal0_var._parameters.debye_waller_B = 0.4632;
  _LUCIA_dcm_xtal0_var._parameters.crystal_type = 1;
  _LUCIA_dcm_xtal0_var._parameters.h = 1;
  _LUCIA_dcm_xtal0_var._parameters.k = 1;
  _LUCIA_dcm_xtal0_var._parameters.l = 1;
  _LUCIA_dcm_xtal0_var._parameters.structure_factor_scale_r = 0.0;
  _LUCIA_dcm_xtal0_var._parameters.structure_factor_scale_i = 0.0;


  /* component LUCIA_dcm_xtal0=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.LUCIA_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_DCM_location_var._rotation_absolute, _LUCIA_dcm_xtal0_var._rotation_absolute);
    rot_transpose(_LUCIA_slit_mon_xy_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_dcm_xtal0_var._rotation_absolute, tr1, _LUCIA_dcm_xtal0_var._rotation_relative);
    _LUCIA_dcm_xtal0_var._rotation_is_identity =  rot_test_identity(_LUCIA_dcm_xtal0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_DCM_location_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_dcm_xtal0_var._position_absolute = coords_add(_LUCIA_DCM_location_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_slit_mon_xy_var._position_absolute, _LUCIA_dcm_xtal0_var._position_absolute);
    _LUCIA_dcm_xtal0_var._position_relative = rot_apply(_LUCIA_dcm_xtal0_var._rotation_absolute, tc1);
  } /* LUCIA_dcm_xtal0=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_dcm_xtal0", _LUCIA_dcm_xtal0_var._position_absolute, _LUCIA_dcm_xtal0_var._rotation_absolute);
  instrument->_position_absolute[557] = _LUCIA_dcm_xtal0_var._position_absolute;
  instrument->_position_relative[557] = _LUCIA_dcm_xtal0_var._position_relative;
    _LUCIA_dcm_xtal0_var._position_relative_is_zero =  coords_test_zero(_LUCIA_dcm_xtal0_var._position_relative);
  instrument->counter_N[557]  = instrument->counter_P[557] = instrument->counter_P2[557] = 0;
  instrument->counter_AbsorbProp[557]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", _LUCIA_dcm_xtal0_var._position_absolute, _LUCIA_dcm_xtal0_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0556_LUCIA_dcm_xtal0", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_dcm_xtal0_setpos */

/* component LUCIA_dcm0=Arm() SETTING, POSITION/ROTATION */
int _LUCIA_dcm0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_dcm0_setpos] component LUCIA_dcm0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_LUCIA_dcm0_var._name, "LUCIA_dcm0", 16384);
  stracpy(_LUCIA_dcm0_var._type, "Arm", 16384);
  _LUCIA_dcm0_var._index=558;
  int current_setpos_index = 558;
  /* component LUCIA_dcm0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (- _instrument_var._parameters.LUCIA_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_dcm_xtal0_var._rotation_absolute, _LUCIA_dcm0_var._rotation_absolute);
    rot_transpose(_LUCIA_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_dcm0_var._rotation_absolute, tr1, _LUCIA_dcm0_var._rotation_relative);
    _LUCIA_dcm0_var._rotation_is_identity =  rot_test_identity(_LUCIA_dcm0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_dcm0_var._position_absolute = coords_add(_LUCIA_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_dcm_xtal0_var._position_absolute, _LUCIA_dcm0_var._position_absolute);
    _LUCIA_dcm0_var._position_relative = rot_apply(_LUCIA_dcm0_var._rotation_absolute, tc1);
  } /* LUCIA_dcm0=Arm() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_dcm0", _LUCIA_dcm0_var._position_absolute, _LUCIA_dcm0_var._rotation_absolute);
  instrument->_position_absolute[558] = _LUCIA_dcm0_var._position_absolute;
  instrument->_position_relative[558] = _LUCIA_dcm0_var._position_relative;
    _LUCIA_dcm0_var._position_relative_is_zero =  coords_test_zero(_LUCIA_dcm0_var._position_relative);
  instrument->counter_N[558]  = instrument->counter_P[558] = instrument->counter_P2[558] = 0;
  instrument->counter_AbsorbProp[558]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0557_LUCIA_dcm0", _LUCIA_dcm0_var._position_absolute, _LUCIA_dcm0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_dcm0_setpos */

/* component LUCIA_dcm_xtal1=Bragg_crystal() SETTING, POSITION/ROTATION */
int _LUCIA_dcm_xtal1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_dcm_xtal1_setpos] component LUCIA_dcm_xtal1=Bragg_crystal() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");
  stracpy(_LUCIA_dcm_xtal1_var._name, "LUCIA_dcm_xtal1", 16384);
  stracpy(_LUCIA_dcm_xtal1_var._type, "Bragg_crystal", 16384);
  _LUCIA_dcm_xtal1_var._index=559;
  int current_setpos_index = 559;
  _LUCIA_dcm_xtal1_var._parameters.length = 0.04;
  _LUCIA_dcm_xtal1_var._parameters.width = 0.04;
  _LUCIA_dcm_xtal1_var._parameters.V = 160.1826;
  if("FormFactors.txt" && strlen("FormFactors.txt"))
    stracpy(_LUCIA_dcm_xtal1_var._parameters.form_factors, "FormFactors.txt" ? "FormFactors.txt" : "", 16384);
  else 
  _LUCIA_dcm_xtal1_var._parameters.form_factors[0]='\0';
  if("Si.txt" && strlen("Si.txt"))
    stracpy(_LUCIA_dcm_xtal1_var._parameters.material, "Si.txt" ? "Si.txt" : "", 16384);
  else 
  _LUCIA_dcm_xtal1_var._parameters.material[0]='\0';
  _LUCIA_dcm_xtal1_var._parameters.alpha = 0.0;
  _LUCIA_dcm_xtal1_var._parameters.R0 = 0;
  _LUCIA_dcm_xtal1_var._parameters.debye_waller_B = 0.4632;
  _LUCIA_dcm_xtal1_var._parameters.crystal_type = 1;
  _LUCIA_dcm_xtal1_var._parameters.h = 1;
  _LUCIA_dcm_xtal1_var._parameters.k = 1;
  _LUCIA_dcm_xtal1_var._parameters.l = 1;
  _LUCIA_dcm_xtal1_var._parameters.structure_factor_scale_r = 0.0;
  _LUCIA_dcm_xtal1_var._parameters.structure_factor_scale_i = 0.0;


  /* component LUCIA_dcm_xtal1=Bragg_crystal() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.LUCIA_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_dcm0_var._rotation_absolute, _LUCIA_dcm_xtal1_var._rotation_absolute);
    rot_transpose(_LUCIA_dcm_xtal0_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_dcm_xtal1_var._rotation_absolute, tr1, _LUCIA_dcm_xtal1_var._rotation_relative);
    _LUCIA_dcm_xtal1_var._rotation_is_identity =  rot_test_identity(_LUCIA_dcm_xtal1_var._rotation_relative);
    tc1 = coords_set(
      0, LUCIA_dcm_gap, _instrument_var._parameters.LUCIA_dcm_theta ? LUCIA_dcm_gap / tan ( _instrument_var._parameters.LUCIA_dcm_theta * DEG2RAD ) : 0);
    rot_transpose(_LUCIA_dcm_xtal0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_dcm_xtal1_var._position_absolute = coords_add(_LUCIA_dcm_xtal0_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_dcm_xtal0_var._position_absolute, _LUCIA_dcm_xtal1_var._position_absolute);
    _LUCIA_dcm_xtal1_var._position_relative = rot_apply(_LUCIA_dcm_xtal1_var._rotation_absolute, tc1);
  } /* LUCIA_dcm_xtal1=Bragg_crystal() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_dcm_xtal1", _LUCIA_dcm_xtal1_var._position_absolute, _LUCIA_dcm_xtal1_var._rotation_absolute);
  instrument->_position_absolute[559] = _LUCIA_dcm_xtal1_var._position_absolute;
  instrument->_position_relative[559] = _LUCIA_dcm_xtal1_var._position_relative;
    _LUCIA_dcm_xtal1_var._position_relative_is_zero =  coords_test_zero(_LUCIA_dcm_xtal1_var._position_relative);
  instrument->counter_N[559]  = instrument->counter_P[559] = instrument->counter_P2[559] = 0;
  instrument->counter_AbsorbProp[559]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", _LUCIA_dcm_xtal1_var._position_absolute, _LUCIA_dcm_xtal1_var._rotation_absolute, "Bragg_crystal");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "length", "0.05", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "width", "0.02", "0.04","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "V", "160.1826", "160.1826","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "form_factors", "FormFactors.txt", "FormFactors.txt", "char*");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "material", "Si.txt", "Si.txt", "char*");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "alpha", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "R0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "debye_waller_B", "0.4632", "0.4632","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "crystal_type", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "h", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "k", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "l", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "structure_factor_scale_r", "0.0", "0.0","MCNUM");
        mccomp_param_nexus(nxhandle,"0558_LUCIA_dcm_xtal1", "structure_factor_scale_i", "0.0", "0.0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_dcm_xtal1_setpos */

/* component LUCIA_dcm1=Arm() SETTING, POSITION/ROTATION */
int _LUCIA_dcm1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_dcm1_setpos] component LUCIA_dcm1=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_LUCIA_dcm1_var._name, "LUCIA_dcm1", 16384);
  stracpy(_LUCIA_dcm1_var._type, "Arm", 16384);
  _LUCIA_dcm1_var._index=560;
  int current_setpos_index = 560;
  /* component LUCIA_dcm1=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (_instrument_var._parameters.LUCIA_dcm_theta)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_dcm_xtal1_var._rotation_absolute, _LUCIA_dcm1_var._rotation_absolute);
    rot_transpose(_LUCIA_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_dcm1_var._rotation_absolute, tr1, _LUCIA_dcm1_var._rotation_relative);
    _LUCIA_dcm1_var._rotation_is_identity =  rot_test_identity(_LUCIA_dcm1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_dcm_xtal1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_dcm1_var._position_absolute = coords_add(_LUCIA_dcm_xtal1_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_dcm_xtal1_var._position_absolute, _LUCIA_dcm1_var._position_absolute);
    _LUCIA_dcm1_var._position_relative = rot_apply(_LUCIA_dcm1_var._rotation_absolute, tc1);
  } /* LUCIA_dcm1=Arm() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_dcm1", _LUCIA_dcm1_var._position_absolute, _LUCIA_dcm1_var._rotation_absolute);
  instrument->_position_absolute[560] = _LUCIA_dcm1_var._position_absolute;
  instrument->_position_relative[560] = _LUCIA_dcm1_var._position_relative;
    _LUCIA_dcm1_var._position_relative_is_zero =  coords_test_zero(_LUCIA_dcm1_var._position_relative);
  instrument->counter_N[560]  = instrument->counter_P[560] = instrument->counter_P2[560] = 0;
  instrument->counter_AbsorbProp[560]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0559_LUCIA_dcm1", _LUCIA_dcm1_var._position_absolute, _LUCIA_dcm1_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_dcm1_setpos */

/* component LUCIA_mon_dcm_e=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_mon_dcm_e_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_mon_dcm_e_setpos] component LUCIA_mon_dcm_e=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_mon_dcm_e_var._name, "LUCIA_mon_dcm_e", 16384);
  stracpy(_LUCIA_mon_dcm_e_var._type, "Monitor_nD", 16384);
  _LUCIA_mon_dcm_e_var._index=561;
  int current_setpos_index = 561;
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.user9[0]='\0';
  _LUCIA_mon_dcm_e_var._parameters.xwidth = 2e-3;
  _LUCIA_mon_dcm_e_var._parameters.yheight = 2e-3;
  _LUCIA_mon_dcm_e_var._parameters.zdepth = 0;
  _LUCIA_mon_dcm_e_var._parameters.bins = 128;
  _LUCIA_mon_dcm_e_var._parameters.min = _instrument_var._parameters.LUCIA_E0 - _instrument_var._parameters.LUCIA_dE * 1.1;
  _LUCIA_mon_dcm_e_var._parameters.max = _instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.1;
  _LUCIA_mon_dcm_e_var._parameters.restore_xray = 0;
  _LUCIA_mon_dcm_e_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.geometry[0]='\0';
  _LUCIA_mon_dcm_e_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_e_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_e_var._parameters.username9[0]='\0';


  /* component LUCIA_mon_dcm_e=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_dcm1_var._rotation_absolute, _LUCIA_mon_dcm_e_var._rotation_absolute);
    rot_transpose(_LUCIA_dcm_xtal1_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_mon_dcm_e_var._rotation_absolute, tr1, _LUCIA_mon_dcm_e_var._rotation_relative);
    _LUCIA_mon_dcm_e_var._rotation_is_identity =  rot_test_identity(_LUCIA_mon_dcm_e_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.5);
    rot_transpose(_LUCIA_dcm1_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_mon_dcm_e_var._position_absolute = coords_add(_LUCIA_dcm1_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_dcm_xtal1_var._position_absolute, _LUCIA_mon_dcm_e_var._position_absolute);
    _LUCIA_mon_dcm_e_var._position_relative = rot_apply(_LUCIA_mon_dcm_e_var._rotation_absolute, tc1);
  } /* LUCIA_mon_dcm_e=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_mon_dcm_e", _LUCIA_mon_dcm_e_var._position_absolute, _LUCIA_mon_dcm_e_var._rotation_absolute);
  instrument->_position_absolute[561] = _LUCIA_mon_dcm_e_var._position_absolute;
  instrument->_position_relative[561] = _LUCIA_mon_dcm_e_var._position_relative;
    _LUCIA_mon_dcm_e_var._position_relative_is_zero =  coords_test_zero(_LUCIA_mon_dcm_e_var._position_relative);
  instrument->counter_N[561]  = instrument->counter_P[561] = instrument->counter_P2[561] = 0;
  instrument->counter_AbsorbProp[561]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", _LUCIA_mon_dcm_e_var._position_absolute, _LUCIA_mon_dcm_e_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "min", "-1e40", "_instrument_var._parameters.LUCIA_E0 - _instrument_var._parameters.LUCIA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "max", "1e40", "_instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0560_LUCIA_mon_dcm_e", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_mon_dcm_e_setpos */

/* component LUCIA_mon_dcm_xy=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_mon_dcm_xy_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_mon_dcm_xy_setpos] component LUCIA_mon_dcm_xy=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_mon_dcm_xy_var._name, "LUCIA_mon_dcm_xy", 16384);
  stracpy(_LUCIA_mon_dcm_xy_var._type, "Monitor_nD", 16384);
  _LUCIA_mon_dcm_xy_var._index=562;
  int current_setpos_index = 562;
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.user9[0]='\0';
  _LUCIA_mon_dcm_xy_var._parameters.xwidth = 2e-3;
  _LUCIA_mon_dcm_xy_var._parameters.yheight = 2e-3;
  _LUCIA_mon_dcm_xy_var._parameters.zdepth = 0;
  _LUCIA_mon_dcm_xy_var._parameters.bins = 128;
  _LUCIA_mon_dcm_xy_var._parameters.min = -1e40;
  _LUCIA_mon_dcm_xy_var._parameters.max = 1e40;
  _LUCIA_mon_dcm_xy_var._parameters.restore_xray = 0;
  _LUCIA_mon_dcm_xy_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.geometry[0]='\0';
  _LUCIA_mon_dcm_xy_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_dcm_xy_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_dcm_xy_var._parameters.username9[0]='\0';


  /* component LUCIA_mon_dcm_xy=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_mon_dcm_e_var._rotation_absolute, _LUCIA_mon_dcm_xy_var._rotation_absolute);
    rot_transpose(_LUCIA_mon_dcm_e_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_mon_dcm_xy_var._rotation_absolute, tr1, _LUCIA_mon_dcm_xy_var._rotation_relative);
    _LUCIA_mon_dcm_xy_var._rotation_is_identity =  rot_test_identity(_LUCIA_mon_dcm_xy_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_mon_dcm_xy_var._position_absolute = coords_add(_LUCIA_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_mon_dcm_e_var._position_absolute, _LUCIA_mon_dcm_xy_var._position_absolute);
    _LUCIA_mon_dcm_xy_var._position_relative = rot_apply(_LUCIA_mon_dcm_xy_var._rotation_absolute, tc1);
  } /* LUCIA_mon_dcm_xy=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_mon_dcm_xy", _LUCIA_mon_dcm_xy_var._position_absolute, _LUCIA_mon_dcm_xy_var._rotation_absolute);
  instrument->_position_absolute[562] = _LUCIA_mon_dcm_xy_var._position_absolute;
  instrument->_position_relative[562] = _LUCIA_mon_dcm_xy_var._position_relative;
    _LUCIA_mon_dcm_xy_var._position_relative_is_zero =  coords_test_zero(_LUCIA_mon_dcm_xy_var._position_relative);
  instrument->counter_N[562]  = instrument->counter_P[562] = instrument->counter_P2[562] = 0;
  instrument->counter_AbsorbProp[562]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", _LUCIA_mon_dcm_xy_var._position_absolute, _LUCIA_mon_dcm_xy_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "xwidth", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "yheight", "0", "2e-3","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "restore_xray", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0561_LUCIA_mon_dcm_xy", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_mon_dcm_xy_setpos */

/* component LUCIA_diaphragm=Slit() SETTING, POSITION/ROTATION */
int _LUCIA_diaphragm_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_diaphragm_setpos] component LUCIA_diaphragm=Slit() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");
  stracpy(_LUCIA_diaphragm_var._name, "LUCIA_diaphragm", 16384);
  stracpy(_LUCIA_diaphragm_var._type, "Slit", 16384);
  _LUCIA_diaphragm_var._index=563;
  int current_setpos_index = 563;
  _LUCIA_diaphragm_var._parameters.xmin = 0;
  _LUCIA_diaphragm_var._parameters.xmax = 0;
  _LUCIA_diaphragm_var._parameters.ymin = 0;
  _LUCIA_diaphragm_var._parameters.ymax = 0;
  _LUCIA_diaphragm_var._parameters.radius = 0;
  _LUCIA_diaphragm_var._parameters.xwidth = 100e-6;
  _LUCIA_diaphragm_var._parameters.yheight = 100e-6;
  _LUCIA_diaphragm_var._parameters.dist = 0;
  _LUCIA_diaphragm_var._parameters.focus_xw = 0;
  _LUCIA_diaphragm_var._parameters.focus_yh = 0;
  _LUCIA_diaphragm_var._parameters.focus_x0 = 0;
  _LUCIA_diaphragm_var._parameters.focus_y0 = 0;

  /* component LUCIA_diaphragm=Slit() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_mon_dcm_e_var._rotation_absolute, _LUCIA_diaphragm_var._rotation_absolute);
    rot_transpose(_LUCIA_mon_dcm_xy_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_diaphragm_var._rotation_absolute, tr1, _LUCIA_diaphragm_var._rotation_relative);
    _LUCIA_diaphragm_var._rotation_is_identity =  rot_test_identity(_LUCIA_diaphragm_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 8);
    rot_transpose(_LUCIA_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_diaphragm_var._position_absolute = coords_add(_LUCIA_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_mon_dcm_xy_var._position_absolute, _LUCIA_diaphragm_var._position_absolute);
    _LUCIA_diaphragm_var._position_relative = rot_apply(_LUCIA_diaphragm_var._rotation_absolute, tc1);
  } /* LUCIA_diaphragm=Slit() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_diaphragm", _LUCIA_diaphragm_var._position_absolute, _LUCIA_diaphragm_var._rotation_absolute);
  instrument->_position_absolute[563] = _LUCIA_diaphragm_var._position_absolute;
  instrument->_position_relative[563] = _LUCIA_diaphragm_var._position_relative;
    _LUCIA_diaphragm_var._position_relative_is_zero =  coords_test_zero(_LUCIA_diaphragm_var._position_relative);
  instrument->counter_N[563]  = instrument->counter_P[563] = instrument->counter_P2[563] = 0;
  instrument->counter_AbsorbProp[563]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0562_LUCIA_diaphragm", _LUCIA_diaphragm_var._position_absolute, _LUCIA_diaphragm_var._rotation_absolute, "Slit");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "xmin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "xmax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "ymin", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "ymax", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "xwidth", "0.001", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "yheight", "0.001", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "dist", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "focus_x0", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0562_LUCIA_diaphragm", "focus_y0", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_diaphragm_setpos */

/* component LUCIA_sample_stage=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_sample_stage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_sample_stage_setpos] component LUCIA_sample_stage=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_sample_stage_var._name, "LUCIA_sample_stage", 16384);
  stracpy(_LUCIA_sample_stage_var._type, "Monitor_nD", 16384);
  _LUCIA_sample_stage_var._index=564;
  int current_setpos_index = 564;
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_sample_stage_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.user9[0]='\0';
  _LUCIA_sample_stage_var._parameters.xwidth = 100e-6;
  _LUCIA_sample_stage_var._parameters.yheight = 100e-6;
  _LUCIA_sample_stage_var._parameters.zdepth = 0;
  _LUCIA_sample_stage_var._parameters.bins = 128;
  _LUCIA_sample_stage_var._parameters.min = -1e40;
  _LUCIA_sample_stage_var._parameters.max = 1e40;
  _LUCIA_sample_stage_var._parameters.restore_xray = 1;
  _LUCIA_sample_stage_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_LUCIA_sample_stage_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.geometry[0]='\0';
  _LUCIA_sample_stage_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_sample_stage_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_sample_stage_var._parameters.username9[0]='\0';


  /* component LUCIA_sample_stage=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_mon_dcm_e_var._rotation_absolute, _LUCIA_sample_stage_var._rotation_absolute);
    rot_transpose(_LUCIA_diaphragm_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_sample_stage_var._rotation_absolute, tr1, _LUCIA_sample_stage_var._rotation_relative);
    _LUCIA_sample_stage_var._rotation_is_identity =  rot_test_identity(_LUCIA_sample_stage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 8.13);
    rot_transpose(_LUCIA_mon_dcm_e_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_sample_stage_var._position_absolute = coords_add(_LUCIA_mon_dcm_e_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_diaphragm_var._position_absolute, _LUCIA_sample_stage_var._position_absolute);
    _LUCIA_sample_stage_var._position_relative = rot_apply(_LUCIA_sample_stage_var._rotation_absolute, tc1);
  } /* LUCIA_sample_stage=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_sample_stage", _LUCIA_sample_stage_var._position_absolute, _LUCIA_sample_stage_var._rotation_absolute);
  instrument->_position_absolute[564] = _LUCIA_sample_stage_var._position_absolute;
  instrument->_position_relative[564] = _LUCIA_sample_stage_var._position_relative;
    _LUCIA_sample_stage_var._position_relative_is_zero =  coords_test_zero(_LUCIA_sample_stage_var._position_relative);
  instrument->counter_N[564]  = instrument->counter_P[564] = instrument->counter_P2[564] = 0;
  instrument->counter_AbsorbProp[564]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0563_LUCIA_sample_stage", _LUCIA_sample_stage_var._position_absolute, _LUCIA_sample_stage_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "xwidth", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "yheight", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0563_LUCIA_sample_stage", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_sample_stage_setpos */

/* component LUCIA_fluo_rotated=Arm() SETTING, POSITION/ROTATION */
int _LUCIA_fluo_rotated_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_fluo_rotated_setpos] component LUCIA_fluo_rotated=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_LUCIA_fluo_rotated_var._name, "LUCIA_fluo_rotated", 16384);
  stracpy(_LUCIA_fluo_rotated_var._type, "Arm", 16384);
  _LUCIA_fluo_rotated_var._index=565;
  int current_setpos_index = 565;
  /* component LUCIA_fluo_rotated=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (90)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_sample_stage_var._rotation_absolute, _LUCIA_fluo_rotated_var._rotation_absolute);
    rot_transpose(_LUCIA_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_fluo_rotated_var._rotation_absolute, tr1, _LUCIA_fluo_rotated_var._rotation_relative);
    _LUCIA_fluo_rotated_var._rotation_is_identity =  rot_test_identity(_LUCIA_fluo_rotated_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_fluo_rotated_var._position_absolute = coords_add(_LUCIA_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_sample_stage_var._position_absolute, _LUCIA_fluo_rotated_var._position_absolute);
    _LUCIA_fluo_rotated_var._position_relative = rot_apply(_LUCIA_fluo_rotated_var._rotation_absolute, tc1);
  } /* LUCIA_fluo_rotated=Arm() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_fluo_rotated", _LUCIA_fluo_rotated_var._position_absolute, _LUCIA_fluo_rotated_var._rotation_absolute);
  instrument->_position_absolute[565] = _LUCIA_fluo_rotated_var._position_absolute;
  instrument->_position_relative[565] = _LUCIA_fluo_rotated_var._position_relative;
    _LUCIA_fluo_rotated_var._position_relative_is_zero =  coords_test_zero(_LUCIA_fluo_rotated_var._position_relative);
  instrument->counter_N[565]  = instrument->counter_P[565] = instrument->counter_P2[565] = 0;
  instrument->counter_AbsorbProp[565]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0564_LUCIA_fluo_rotated", _LUCIA_fluo_rotated_var._position_absolute, _LUCIA_fluo_rotated_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_fluo_rotated_setpos */

/* component LUCIA_sample=Fluorescence() SETTING, POSITION/ROTATION */
int _LUCIA_sample_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_sample_setpos] component LUCIA_sample=Fluorescence() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:440]");
  stracpy(_LUCIA_sample_var._name, "LUCIA_sample", 16384);
  stracpy(_LUCIA_sample_var._type, "Fluorescence", 16384);
  _LUCIA_sample_var._index=566;
  int current_setpos_index = 566;
  if(_instrument_var._parameters.LUCIA_sample_geometry && strlen(_instrument_var._parameters.LUCIA_sample_geometry))
    stracpy(_LUCIA_sample_var._parameters.geometry, _instrument_var._parameters.LUCIA_sample_geometry ? _instrument_var._parameters.LUCIA_sample_geometry : "", 16384);
  else 
  _LUCIA_sample_var._parameters.geometry[0]='\0';
  _LUCIA_sample_var._parameters.radius = 0;
  _LUCIA_sample_var._parameters.thickness = 0;
  _LUCIA_sample_var._parameters.xwidth = 100e-6;
  _LUCIA_sample_var._parameters.yheight = 100e-6;
  _LUCIA_sample_var._parameters.zdepth = 50e-6;
  _LUCIA_sample_var._parameters.concentric = 0;
  if(_instrument_var._parameters.LUCIA_sample_material && strlen(_instrument_var._parameters.LUCIA_sample_material))
    stracpy(_LUCIA_sample_var._parameters.material, _instrument_var._parameters.LUCIA_sample_material ? _instrument_var._parameters.LUCIA_sample_material : "", 16384);
  else 
  _LUCIA_sample_var._parameters.material[0]='\0';
  _LUCIA_sample_var._parameters.packing_factor = 0;
  _LUCIA_sample_var._parameters.rho = 0;
  _LUCIA_sample_var._parameters.density = 0;
  _LUCIA_sample_var._parameters.weight = 0;
  _LUCIA_sample_var._parameters.p_interact = 0.9;
  _LUCIA_sample_var._parameters.target_x = 0;
  _LUCIA_sample_var._parameters.target_y = 0;
  _LUCIA_sample_var._parameters.target_z = 0;
  _LUCIA_sample_var._parameters.focus_r = 0;
  _LUCIA_sample_var._parameters.focus_xw = 0;
  _LUCIA_sample_var._parameters.focus_yh = 0;
  _LUCIA_sample_var._parameters.focus_aw = 0;
  _LUCIA_sample_var._parameters.focus_ah = 0;
  _LUCIA_sample_var._parameters.target_index = 0;
  _LUCIA_sample_var._parameters.flag_compton = 1;
  _LUCIA_sample_var._parameters.flag_rayleigh = 1;
  _LUCIA_sample_var._parameters.flag_lorentzian = 0;
  _LUCIA_sample_var._parameters.flag_kissel = 0;
  _LUCIA_sample_var._parameters.flag_low_z = 0;
  _LUCIA_sample_var._parameters.order = 1;


  /* component LUCIA_sample=Fluorescence() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_sample_stage_var._rotation_absolute, _LUCIA_sample_var._rotation_absolute);
    rot_transpose(_LUCIA_sample_stage_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_sample_var._rotation_absolute, tr1, _LUCIA_sample_var._rotation_relative);
    _LUCIA_sample_var._rotation_is_identity =  rot_test_identity(_LUCIA_sample_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_sample_var._position_absolute = coords_add(_LUCIA_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_sample_stage_var._position_absolute, _LUCIA_sample_var._position_absolute);
    _LUCIA_sample_var._position_relative = rot_apply(_LUCIA_sample_var._rotation_absolute, tc1);
  } /* LUCIA_sample=Fluorescence() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_sample", _LUCIA_sample_var._position_absolute, _LUCIA_sample_var._rotation_absolute);
  instrument->_position_absolute[566] = _LUCIA_sample_var._position_absolute;
  instrument->_position_relative[566] = _LUCIA_sample_var._position_relative;
    _LUCIA_sample_var._position_relative_is_zero =  coords_test_zero(_LUCIA_sample_var._position_relative);
  instrument->counter_N[566]  = instrument->counter_P[566] = instrument->counter_P2[566] = 0;
  instrument->counter_AbsorbProp[566]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0565_LUCIA_sample", _LUCIA_sample_var._position_absolute, _LUCIA_sample_var._rotation_absolute, "Fluorescence");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "geometry", 0, _instrument_var._parameters.LUCIA_sample_geometry, "char*");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "xwidth", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "yheight", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "zdepth", "0", "50e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "concentric", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "material", "LaB6", _instrument_var._parameters.LUCIA_sample_material, "char*");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "packing_factor", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "rho", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "density", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "weight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "p_interact", "0", "0.9","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "target_x", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "target_y", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "target_z", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "focus_r", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "focus_xw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "focus_yh", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "focus_aw", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "focus_ah", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "target_index", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "flag_compton", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "flag_rayleigh", "1", "1","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "flag_lorentzian", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "flag_kissel", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "flag_low_z", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0565_LUCIA_sample", "order", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_sample_setpos */

/* component LUCIA_transmission=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_transmission_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_transmission_setpos] component LUCIA_transmission=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_transmission_var._name, "LUCIA_transmission", 16384);
  stracpy(_LUCIA_transmission_var._type, "Monitor_nD", 16384);
  _LUCIA_transmission_var._index=567;
  int current_setpos_index = 567;
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_transmission_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.user9[0]='\0';
  _LUCIA_transmission_var._parameters.xwidth = 100e-6;
  _LUCIA_transmission_var._parameters.yheight = 100e-6;
  _LUCIA_transmission_var._parameters.zdepth = 0;
  _LUCIA_transmission_var._parameters.bins = 128;
  _LUCIA_transmission_var._parameters.min = -1e40;
  _LUCIA_transmission_var._parameters.max = 1e40;
  _LUCIA_transmission_var._parameters.restore_xray = 1;
  _LUCIA_transmission_var._parameters.radius = 0;
  if("x y" && strlen("x y"))
    stracpy(_LUCIA_transmission_var._parameters.options, "x y" ? "x y" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.geometry[0]='\0';
  _LUCIA_transmission_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_transmission_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_transmission_var._parameters.username9[0]='\0';


  /* component LUCIA_transmission=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_sample_stage_var._rotation_absolute, _LUCIA_transmission_var._rotation_absolute);
    rot_transpose(_LUCIA_sample_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_transmission_var._rotation_absolute, tr1, _LUCIA_transmission_var._rotation_relative);
    _LUCIA_transmission_var._rotation_is_identity =  rot_test_identity(_LUCIA_transmission_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_LUCIA_sample_stage_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_transmission_var._position_absolute = coords_add(_LUCIA_sample_stage_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_sample_var._position_absolute, _LUCIA_transmission_var._position_absolute);
    _LUCIA_transmission_var._position_relative = rot_apply(_LUCIA_transmission_var._rotation_absolute, tc1);
  } /* LUCIA_transmission=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_transmission", _LUCIA_transmission_var._position_absolute, _LUCIA_transmission_var._rotation_absolute);
  instrument->_position_absolute[567] = _LUCIA_transmission_var._position_absolute;
  instrument->_position_relative[567] = _LUCIA_transmission_var._position_relative;
    _LUCIA_transmission_var._position_relative_is_zero =  coords_test_zero(_LUCIA_transmission_var._position_relative);
  instrument->counter_N[567]  = instrument->counter_P[567] = instrument->counter_P2[567] = 0;
  instrument->counter_AbsorbProp[567]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0566_LUCIA_transmission", _LUCIA_transmission_var._position_absolute, _LUCIA_transmission_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "xwidth", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "yheight", "0", "100e-6","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "bins", "0", "128","int");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "min", "-1e40", "-1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "max", "1e40", "1e40","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "options", "NULL", "x y", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0566_LUCIA_transmission", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_transmission_setpos */

/* component LUCIA_mon_spl_SDD=Fluo_detector() SETTING, POSITION/ROTATION */
int _LUCIA_mon_spl_SDD_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_mon_spl_SDD_setpos] component LUCIA_mon_spl_SDD=Fluo_detector() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Fluo_detector.comp:110]");
  stracpy(_LUCIA_mon_spl_SDD_var._name, "LUCIA_mon_spl_SDD", 16384);
  stracpy(_LUCIA_mon_spl_SDD_var._type, "Fluo_detector", 16384);
  _LUCIA_mon_spl_SDD_var._index=568;
  int current_setpos_index = 568;
  _LUCIA_mon_spl_SDD_var._parameters.radius = 0.1;
  _LUCIA_mon_spl_SDD_var._parameters.xwidth = 0;
  _LUCIA_mon_spl_SDD_var._parameters.yheight = 0;
  _LUCIA_mon_spl_SDD_var._parameters.Emin = 0;
  _LUCIA_mon_spl_SDD_var._parameters.Emax = _instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.5;
  _LUCIA_mon_spl_SDD_var._parameters.nE = 512;
  _LUCIA_mon_spl_SDD_var._parameters.filename[0]='\0';
  _LUCIA_mon_spl_SDD_var._parameters.restore_xray = 1;
  _LUCIA_mon_spl_SDD_var._parameters.escape_ratio = 0.01;
  _LUCIA_mon_spl_SDD_var._parameters.escape_energy = 1.739;
  _LUCIA_mon_spl_SDD_var._parameters.pileup_ratio = 0.01;
  _LUCIA_mon_spl_SDD_var._parameters.electronic_noise = 0.1;
  _LUCIA_mon_spl_SDD_var._parameters.resolution_energy = 6;
  _LUCIA_mon_spl_SDD_var._parameters.resolution = 0.2;
  _LUCIA_mon_spl_SDD_var._parameters.flag_lorentzian = 0;


  /* component LUCIA_mon_spl_SDD=Fluo_detector() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_sample_var._rotation_absolute, _LUCIA_mon_spl_SDD_var._rotation_absolute);
    rot_transpose(_LUCIA_transmission_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_mon_spl_SDD_var._rotation_absolute, tr1, _LUCIA_mon_spl_SDD_var._rotation_relative);
    _LUCIA_mon_spl_SDD_var._rotation_is_identity =  rot_test_identity(_LUCIA_mon_spl_SDD_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_sample_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_mon_spl_SDD_var._position_absolute = coords_add(_LUCIA_sample_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_transmission_var._position_absolute, _LUCIA_mon_spl_SDD_var._position_absolute);
    _LUCIA_mon_spl_SDD_var._position_relative = rot_apply(_LUCIA_mon_spl_SDD_var._rotation_absolute, tc1);
  } /* LUCIA_mon_spl_SDD=Fluo_detector() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_mon_spl_SDD", _LUCIA_mon_spl_SDD_var._position_absolute, _LUCIA_mon_spl_SDD_var._rotation_absolute);
  instrument->_position_absolute[568] = _LUCIA_mon_spl_SDD_var._position_absolute;
  instrument->_position_relative[568] = _LUCIA_mon_spl_SDD_var._position_relative;
    _LUCIA_mon_spl_SDD_var._position_relative_is_zero =  coords_test_zero(_LUCIA_mon_spl_SDD_var._position_relative);
  instrument->counter_N[568]  = instrument->counter_P[568] = instrument->counter_P2[568] = 0;
  instrument->counter_AbsorbProp[568]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", _LUCIA_mon_spl_SDD_var._position_absolute, _LUCIA_mon_spl_SDD_var._rotation_absolute, "Fluo_detector");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "radius", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "Emin", "1", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "Emax", "39", "_instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.5","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "nE", "2000", "512","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "filename", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "escape_ratio", "0.01", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "escape_energy", "1.739", "1.739","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "pileup_ratio", "0.01", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "electronic_noise", "0.1", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "resolution_energy", "6", "6","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "resolution", "0.2", "0.2","MCNUM");
        mccomp_param_nexus(nxhandle,"0567_LUCIA_mon_spl_SDD", "flag_lorentzian", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_mon_spl_SDD_setpos */

/* component LUCIA_mon_spl_fluo=Monitor_nD() SETTING, POSITION/ROTATION */
int _LUCIA_mon_spl_fluo_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_LUCIA_mon_spl_fluo_setpos] component LUCIA_mon_spl_fluo=Monitor_nD() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");
  stracpy(_LUCIA_mon_spl_fluo_var._name, "LUCIA_mon_spl_fluo", 16384);
  stracpy(_LUCIA_mon_spl_fluo_var._type, "Monitor_nD", 16384);
  _LUCIA_mon_spl_fluo_var._index=569;
  int current_setpos_index = 569;
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user0, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user0[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user1, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user1[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user2, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user2[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user3, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user3[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user4, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user4[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user5, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user5[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user6, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user6[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user7, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user7[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user8, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user8[0]='\0';
  if("" && strlen(""))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.user9, "" ? "" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.user9[0]='\0';
  _LUCIA_mon_spl_fluo_var._parameters.xwidth = 0.1;
  _LUCIA_mon_spl_fluo_var._parameters.yheight = 0.1;
  _LUCIA_mon_spl_fluo_var._parameters.zdepth = 0;
  _LUCIA_mon_spl_fluo_var._parameters.bins = 1000;
  _LUCIA_mon_spl_fluo_var._parameters.min = 0;
  _LUCIA_mon_spl_fluo_var._parameters.max = _instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.1;
  _LUCIA_mon_spl_fluo_var._parameters.restore_xray = 1;
  _LUCIA_mon_spl_fluo_var._parameters.radius = 0;
  if("energy" && strlen("energy"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.options, "energy" ? "energy" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.options[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.filename, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.filename[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.geometry, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.geometry[0]='\0';
  _LUCIA_mon_spl_fluo_var._parameters.nowritefile = 0;
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username0, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username0[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username1, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username1[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username2, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username2[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username3, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username3[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username4, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username4[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username5, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username5[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username6, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username6[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username7, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username7[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username8, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username8[0]='\0';
  if("NULL" && strlen("NULL"))
    stracpy(_LUCIA_mon_spl_fluo_var._parameters.username9, "NULL" ? "NULL" : "", 16384);
  else 
  _LUCIA_mon_spl_fluo_var._parameters.username9[0]='\0';


  /* component LUCIA_mon_spl_fluo=Monitor_nD() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_fluo_rotated_var._rotation_absolute, _LUCIA_mon_spl_fluo_var._rotation_absolute);
    rot_transpose(_LUCIA_mon_spl_SDD_var._rotation_absolute, tr1);
    rot_mul(_LUCIA_mon_spl_fluo_var._rotation_absolute, tr1, _LUCIA_mon_spl_fluo_var._rotation_relative);
    _LUCIA_mon_spl_fluo_var._rotation_is_identity =  rot_test_identity(_LUCIA_mon_spl_fluo_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0.1);
    rot_transpose(_LUCIA_fluo_rotated_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _LUCIA_mon_spl_fluo_var._position_absolute = coords_add(_LUCIA_fluo_rotated_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_mon_spl_SDD_var._position_absolute, _LUCIA_mon_spl_fluo_var._position_absolute);
    _LUCIA_mon_spl_fluo_var._position_relative = rot_apply(_LUCIA_mon_spl_fluo_var._rotation_absolute, tc1);
  } /* LUCIA_mon_spl_fluo=Monitor_nD() AT ROTATED */
  DEBUG_COMPONENT("LUCIA_mon_spl_fluo", _LUCIA_mon_spl_fluo_var._position_absolute, _LUCIA_mon_spl_fluo_var._rotation_absolute);
  instrument->_position_absolute[569] = _LUCIA_mon_spl_fluo_var._position_absolute;
  instrument->_position_relative[569] = _LUCIA_mon_spl_fluo_var._position_relative;
    _LUCIA_mon_spl_fluo_var._position_relative_is_zero =  coords_test_zero(_LUCIA_mon_spl_fluo_var._position_relative);
  instrument->counter_N[569]  = instrument->counter_P[569] = instrument->counter_P2[569] = 0;
  instrument->counter_AbsorbProp[569]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", _LUCIA_mon_spl_fluo_var._position_absolute, _LUCIA_mon_spl_fluo_var._rotation_absolute, "Monitor_nD");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user0", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user1", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user2", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user3", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user4", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user5", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user6", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user7", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user8", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "user9", "", "", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "xwidth", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "bins", "0", "1000","int");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "min", "-1e40", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "max", "1e40", "_instrument_var._parameters.LUCIA_E0 + _instrument_var._parameters.LUCIA_dE * 1.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "restore_xray", "0", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "options", "NULL", "energy", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "filename", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "geometry", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "nowritefile", "0", "0","int");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username0", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username1", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username2", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username3", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username4", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username5", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username6", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username7", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username8", "NULL", "NULL", "char*");
        mccomp_param_nexus(nxhandle,"0568_LUCIA_mon_spl_fluo", "username9", "NULL", "NULL", "char*");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _LUCIA_mon_spl_fluo_setpos */

/* component beamdump_588=Beamstop() SETTING, POSITION/ROTATION */
int _beamdump_588_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_beamdump_588_setpos] component beamdump_588=Beamstop() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");
  stracpy(_beamdump_588_var._name, "beamdump_588", 16384);
  stracpy(_beamdump_588_var._type, "Beamstop", 16384);
  _beamdump_588_var._index=570;
  int current_setpos_index = 570;
  _beamdump_588_var._parameters.xmin = -0.05;
  _beamdump_588_var._parameters.xmax = 0.05;
  _beamdump_588_var._parameters.ymin = -0.05;
  _beamdump_588_var._parameters.ymax = 0.05;
  _beamdump_588_var._parameters.xwidth = 0;
  _beamdump_588_var._parameters.yheight = 0;
  _beamdump_588_var._parameters.radius = 0;

  /* component beamdump_588=Beamstop() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _LUCIA_mon_spl_fluo_var._rotation_absolute, _beamdump_588_var._rotation_absolute);
    rot_transpose(_LUCIA_mon_spl_fluo_var._rotation_absolute, tr1);
    rot_mul(_beamdump_588_var._rotation_absolute, tr1, _beamdump_588_var._rotation_relative);
    _beamdump_588_var._rotation_is_identity =  rot_test_identity(_beamdump_588_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_LUCIA_mon_spl_fluo_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _beamdump_588_var._position_absolute = coords_add(_LUCIA_mon_spl_fluo_var._position_absolute, tc2);
    tc1 = coords_sub(_LUCIA_mon_spl_fluo_var._position_absolute, _beamdump_588_var._position_absolute);
    _beamdump_588_var._position_relative = rot_apply(_beamdump_588_var._rotation_absolute, tc1);
  } /* beamdump_588=Beamstop() AT ROTATED */
  DEBUG_COMPONENT("beamdump_588", _beamdump_588_var._position_absolute, _beamdump_588_var._rotation_absolute);
  instrument->_position_absolute[570] = _beamdump_588_var._position_absolute;
  instrument->_position_relative[570] = _beamdump_588_var._position_relative;
    _beamdump_588_var._position_relative_is_zero =  coords_test_zero(_beamdump_588_var._position_relative);
  instrument->counter_N[570]  = instrument->counter_P[570] = instrument->counter_P2[570] = 0;
  instrument->counter_AbsorbProp[570]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0569_beamdump_588", _beamdump_588_var._position_absolute, _beamdump_588_var._rotation_absolute, "Beamstop");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "xmin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "xmax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "ymin", "-0.05", "-0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "ymax", "0.05", "0.05","MCNUM");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "yheight", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0569_beamdump_588", "radius", "0", "0","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _beamdump_588_setpos */

/* component storage=Shape() SETTING, POSITION/ROTATION */
int _storage_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_storage_setpos] component storage=Shape() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:79]");
  stracpy(_storage_var._name, "storage", 16384);
  stracpy(_storage_var._type, "Shape", 16384);
  _storage_var._index=571;
  int current_setpos_index = 571;
  _storage_var._parameters.geometry[0]='\0';
  _storage_var._parameters.radius = 56.34;
  _storage_var._parameters.xwidth = 0;
  _storage_var._parameters.yheight = 0.01;
  _storage_var._parameters.zdepth = 0;
  _storage_var._parameters.thickness = 0.01;
  _storage_var._parameters.nx = 0;
  _storage_var._parameters.ny = 1;
  _storage_var._parameters.nz = 0;
  _storage_var._parameters.center = 1;


  /* component storage=Shape() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _storage_var._rotation_absolute);
    rot_transpose(_beamdump_588_var._rotation_absolute, tr1);
    rot_mul(_storage_var._rotation_absolute, tr1, _storage_var._rotation_relative);
    _storage_var._rotation_is_identity =  rot_test_identity(_storage_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _storage_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_beamdump_588_var._position_absolute, _storage_var._position_absolute);
    _storage_var._position_relative = rot_apply(_storage_var._rotation_absolute, tc1);
  } /* storage=Shape() AT ROTATED */
  DEBUG_COMPONENT("storage", _storage_var._position_absolute, _storage_var._rotation_absolute);
  instrument->_position_absolute[571] = _storage_var._position_absolute;
  instrument->_position_relative[571] = _storage_var._position_relative;
    _storage_var._position_relative_is_zero =  coords_test_zero(_storage_var._position_relative);
  instrument->counter_N[571]  = instrument->counter_P[571] = instrument->counter_P2[571] = 0;
  instrument->counter_AbsorbProp[571]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0570_storage", _storage_var._position_absolute, _storage_var._rotation_absolute, "Shape");
        mccomp_param_nexus(nxhandle,"0570_storage", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0570_storage", "radius", "0", "56.34","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "yheight", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "thickness", "0", "0.01","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "nx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "ny", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "nz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0570_storage", "center", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _storage_setpos */

/* component hall0=Shape() SETTING, POSITION/ROTATION */
int _hall0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_hall0_setpos] component hall0=Shape() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:79]");
  stracpy(_hall0_var._name, "hall0", 16384);
  stracpy(_hall0_var._type, "Shape", 16384);
  _hall0_var._index=572;
  int current_setpos_index = 572;
  _hall0_var._parameters.geometry[0]='\0';
  _hall0_var._parameters.radius = 80;
  _hall0_var._parameters.xwidth = 0;
  _hall0_var._parameters.yheight = 0.1;
  _hall0_var._parameters.zdepth = 0;
  _hall0_var._parameters.thickness = 0.1;
  _hall0_var._parameters.nx = 0;
  _hall0_var._parameters.ny = 1;
  _hall0_var._parameters.nz = 0;
  _hall0_var._parameters.center = 1;


  /* component hall0=Shape() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _hall0_var._rotation_absolute);
    rot_transpose(_storage_var._rotation_absolute, tr1);
    rot_mul(_hall0_var._rotation_absolute, tr1, _hall0_var._rotation_relative);
    _hall0_var._rotation_is_identity =  rot_test_identity(_hall0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _hall0_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_storage_var._position_absolute, _hall0_var._position_absolute);
    _hall0_var._position_relative = rot_apply(_hall0_var._rotation_absolute, tc1);
  } /* hall0=Shape() AT ROTATED */
  DEBUG_COMPONENT("hall0", _hall0_var._position_absolute, _hall0_var._rotation_absolute);
  instrument->_position_absolute[572] = _hall0_var._position_absolute;
  instrument->_position_relative[572] = _hall0_var._position_relative;
    _hall0_var._position_relative_is_zero =  coords_test_zero(_hall0_var._position_relative);
  instrument->counter_N[572]  = instrument->counter_P[572] = instrument->counter_P2[572] = 0;
  instrument->counter_AbsorbProp[572]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0571_hall0", _hall0_var._position_absolute, _hall0_var._rotation_absolute, "Shape");
        mccomp_param_nexus(nxhandle,"0571_hall0", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0571_hall0", "radius", "0", "80","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "thickness", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "nx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "ny", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "nz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0571_hall0", "center", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _hall0_setpos */

/* component hall1=Shape() SETTING, POSITION/ROTATION */
int _hall1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_hall1_setpos] component hall1=Shape() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:79]");
  stracpy(_hall1_var._name, "hall1", 16384);
  stracpy(_hall1_var._type, "Shape", 16384);
  _hall1_var._index=573;
  int current_setpos_index = 573;
  _hall1_var._parameters.geometry[0]='\0';
  _hall1_var._parameters.radius = 40;
  _hall1_var._parameters.xwidth = 0;
  _hall1_var._parameters.yheight = 0.1;
  _hall1_var._parameters.zdepth = 0;
  _hall1_var._parameters.thickness = 0.1;
  _hall1_var._parameters.nx = 0;
  _hall1_var._parameters.ny = 1;
  _hall1_var._parameters.nz = 0;
  _hall1_var._parameters.center = 1;


  /* component hall1=Shape() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _hall1_var._rotation_absolute);
    rot_transpose(_hall0_var._rotation_absolute, tr1);
    rot_mul(_hall1_var._rotation_absolute, tr1, _hall1_var._rotation_relative);
    _hall1_var._rotation_is_identity =  rot_test_identity(_hall1_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _hall1_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_hall0_var._position_absolute, _hall1_var._position_absolute);
    _hall1_var._position_relative = rot_apply(_hall1_var._rotation_absolute, tc1);
  } /* hall1=Shape() AT ROTATED */
  DEBUG_COMPONENT("hall1", _hall1_var._position_absolute, _hall1_var._rotation_absolute);
  instrument->_position_absolute[573] = _hall1_var._position_absolute;
  instrument->_position_relative[573] = _hall1_var._position_relative;
    _hall1_var._position_relative_is_zero =  coords_test_zero(_hall1_var._position_relative);
  instrument->counter_N[573]  = instrument->counter_P[573] = instrument->counter_P2[573] = 0;
  instrument->counter_AbsorbProp[573]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0572_hall1", _hall1_var._position_absolute, _hall1_var._rotation_absolute, "Shape");
        mccomp_param_nexus(nxhandle,"0572_hall1", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0572_hall1", "radius", "0", "40","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "xwidth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "zdepth", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "thickness", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "nx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "ny", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "nz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0572_hall1", "center", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _hall1_setpos */

/* component entrance_0=Arm() SETTING, POSITION/ROTATION */
int _entrance_0_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_entrance_0_setpos] component entrance_0=Arm() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:53]");
  stracpy(_entrance_0_var._name, "entrance_0", 16384);
  stracpy(_entrance_0_var._type, "Arm", 16384);
  _entrance_0_var._index=574;
  int current_setpos_index = 574;
  /* component entrance_0=Arm() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0)*DEG2RAD, (-65.736)*DEG2RAD, (0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _entrance_0_var._rotation_absolute);
    rot_transpose(_hall1_var._rotation_absolute, tr1);
    rot_mul(_entrance_0_var._rotation_absolute, tr1, _entrance_0_var._rotation_relative);
    _entrance_0_var._rotation_is_identity =  rot_test_identity(_entrance_0_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _entrance_0_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_hall1_var._position_absolute, _entrance_0_var._position_absolute);
    _entrance_0_var._position_relative = rot_apply(_entrance_0_var._rotation_absolute, tc1);
  } /* entrance_0=Arm() AT ROTATED */
  DEBUG_COMPONENT("entrance_0", _entrance_0_var._position_absolute, _entrance_0_var._rotation_absolute);
  instrument->_position_absolute[574] = _entrance_0_var._position_absolute;
  instrument->_position_relative[574] = _entrance_0_var._position_relative;
    _entrance_0_var._position_relative_is_zero =  coords_test_zero(_entrance_0_var._position_relative);
  instrument->counter_N[574]  = instrument->counter_P[574] = instrument->counter_P2[574] = 0;
  instrument->counter_AbsorbProp[574]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0573_entrance_0", _entrance_0_var._position_absolute, _entrance_0_var._rotation_absolute, "Arm");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _entrance_0_setpos */

/* component entrance_1=Shape() SETTING, POSITION/ROTATION */
int _entrance_1_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_entrance_1_setpos] component entrance_1=Shape() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:79]");
  stracpy(_entrance_1_var._name, "entrance_1", 16384);
  stracpy(_entrance_1_var._type, "Shape", 16384);
  _entrance_1_var._index=575;
  int current_setpos_index = 575;
  _entrance_1_var._parameters.geometry[0]='\0';
  _entrance_1_var._parameters.radius = 0;
  _entrance_1_var._parameters.xwidth = 30;
  _entrance_1_var._parameters.yheight = 3;
  _entrance_1_var._parameters.zdepth = 3;
  _entrance_1_var._parameters.thickness = 0;
  _entrance_1_var._parameters.nx = 0;
  _entrance_1_var._parameters.ny = 1;
  _entrance_1_var._parameters.nz = 0;
  _entrance_1_var._parameters.center = 1;


  /* component entrance_1=Shape() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _entrance_0_var._rotation_absolute, _entrance_1_var._rotation_absolute);
    rot_transpose(_hall1_var._rotation_absolute, tr1);
    rot_mul(_entrance_1_var._rotation_absolute, tr1, _entrance_1_var._rotation_relative);
    _entrance_1_var._rotation_is_identity =  rot_test_identity(_entrance_1_var._rotation_relative);
    tc1 = coords_set(
      95, 0, 0);
    rot_transpose(_entrance_0_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _entrance_1_var._position_absolute = coords_add(_entrance_0_var._position_absolute, tc2);
    tc1 = coords_sub(_hall1_var._position_absolute, _entrance_1_var._position_absolute);
    _entrance_1_var._position_relative = rot_apply(_entrance_1_var._rotation_absolute, tc1);
  } /* entrance_1=Shape() AT ROTATED */
  DEBUG_COMPONENT("entrance_1", _entrance_1_var._position_absolute, _entrance_1_var._rotation_absolute);
  instrument->_position_absolute[575] = _entrance_1_var._position_absolute;
  instrument->_position_relative[575] = _entrance_1_var._position_relative;
    _entrance_1_var._position_relative_is_zero =  coords_test_zero(_entrance_1_var._position_relative);
  instrument->counter_N[575]  = instrument->counter_P[575] = instrument->counter_P2[575] = 0;
  instrument->counter_AbsorbProp[575]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0574_entrance_1", _entrance_1_var._position_absolute, _entrance_1_var._rotation_absolute, "Shape");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "xwidth", "0", "30","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "yheight", "0", "3","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "zdepth", "0", "3","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "thickness", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "nx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "ny", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "nz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0574_entrance_1", "center", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _entrance_1_setpos */

/* component ANATOMIX_building=Shape() SETTING, POSITION/ROTATION */
int _ANATOMIX_building_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_ANATOMIX_building_setpos] component ANATOMIX_building=Shape() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:79]");
  stracpy(_ANATOMIX_building_var._name, "ANATOMIX_building", 16384);
  stracpy(_ANATOMIX_building_var._type, "Shape", 16384);
  _ANATOMIX_building_var._index=576;
  int current_setpos_index = 576;
  _ANATOMIX_building_var._parameters.geometry[0]='\0';
  _ANATOMIX_building_var._parameters.radius = 0;
  _ANATOMIX_building_var._parameters.xwidth = 15;
  _ANATOMIX_building_var._parameters.yheight = 0.1;
  _ANATOMIX_building_var._parameters.zdepth = 150;
  _ANATOMIX_building_var._parameters.thickness = 0.1;
  _ANATOMIX_building_var._parameters.nx = 0;
  _ANATOMIX_building_var._parameters.ny = 1;
  _ANATOMIX_building_var._parameters.nz = 0;
  _ANATOMIX_building_var._parameters.center = 1;


  /* component ANATOMIX_building=Shape() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _ANATOMIX_var._rotation_absolute, _ANATOMIX_building_var._rotation_absolute);
    rot_transpose(_entrance_1_var._rotation_absolute, tr1);
    rot_mul(_ANATOMIX_building_var._rotation_absolute, tr1, _ANATOMIX_building_var._rotation_relative);
    _ANATOMIX_building_var._rotation_is_identity =  rot_test_identity(_ANATOMIX_building_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 140);
    rot_transpose(_ANATOMIX_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _ANATOMIX_building_var._position_absolute = coords_add(_ANATOMIX_var._position_absolute, tc2);
    tc1 = coords_sub(_entrance_1_var._position_absolute, _ANATOMIX_building_var._position_absolute);
    _ANATOMIX_building_var._position_relative = rot_apply(_ANATOMIX_building_var._rotation_absolute, tc1);
  } /* ANATOMIX_building=Shape() AT ROTATED */
  DEBUG_COMPONENT("ANATOMIX_building", _ANATOMIX_building_var._position_absolute, _ANATOMIX_building_var._rotation_absolute);
  instrument->_position_absolute[576] = _ANATOMIX_building_var._position_absolute;
  instrument->_position_relative[576] = _ANATOMIX_building_var._position_relative;
    _ANATOMIX_building_var._position_relative_is_zero =  coords_test_zero(_ANATOMIX_building_var._position_relative);
  instrument->counter_N[576]  = instrument->counter_P[576] = instrument->counter_P2[576] = 0;
  instrument->counter_AbsorbProp[576]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0575_ANATOMIX_building", _ANATOMIX_building_var._position_absolute, _ANATOMIX_building_var._rotation_absolute, "Shape");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "geometry", 0, 0, "char*");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "radius", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "xwidth", "0", "15","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "yheight", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "zdepth", "0", "150","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "thickness", "0", "0.1","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "nx", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "ny", "1", "1","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "nz", "0", "0","MCNUM");
        mccomp_param_nexus(nxhandle,"0575_ANATOMIX_building", "center", "1", "1","int");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _ANATOMIX_building_setpos */

/* component soleil_label=Text() SETTING, POSITION/ROTATION */
int _soleil_label_setpos(void)
{ /* sets initial component parameters, position and rotation */
  SIG_MESSAGE("[_soleil_label_setpos] component soleil_label=Text() SETTING [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");
  stracpy(_soleil_label_var._name, "soleil_label", 16384);
  stracpy(_soleil_label_var._type, "Text", 16384);
  _soleil_label_var._index=577;
  int current_setpos_index = 577;
  if("SOLEIL" && strlen("SOLEIL"))
    stracpy(_soleil_label_var._parameters.text, "SOLEIL" ? "SOLEIL" : "", 16384);
  else 
  _soleil_label_var._parameters.text[0]='\0';
  _soleil_label_var._parameters.size = 10;
  if("XZ" && strlen("XZ"))
    stracpy(_soleil_label_var._parameters.plane, "XZ" ? "XZ" : "", 16384);
  else 
  _soleil_label_var._parameters.plane[0]='\0';
  _soleil_label_var._parameters.pen_thickness = 0.1;


  /* component soleil_label=Text() AT ROTATED */
  {
    Coords tc1, tc2;
    tc1 = coords_set(0,0,0);
    tc2 = coords_set(0,0,0);
    Rotation tr1;
    rot_set_rotation(tr1,0,0,0);
    rot_set_rotation(tr1,
      (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD);
    rot_mul(tr1, _origin_var._rotation_absolute, _soleil_label_var._rotation_absolute);
    rot_transpose(_ANATOMIX_building_var._rotation_absolute, tr1);
    rot_mul(_soleil_label_var._rotation_absolute, tr1, _soleil_label_var._rotation_relative);
    _soleil_label_var._rotation_is_identity =  rot_test_identity(_soleil_label_var._rotation_relative);
    tc1 = coords_set(
      0, 0, 0);
    rot_transpose(_origin_var._rotation_absolute, tr1);
    tc2 = rot_apply(tr1, tc1);
    _soleil_label_var._position_absolute = coords_add(_origin_var._position_absolute, tc2);
    tc1 = coords_sub(_ANATOMIX_building_var._position_absolute, _soleil_label_var._position_absolute);
    _soleil_label_var._position_relative = rot_apply(_soleil_label_var._rotation_absolute, tc1);
  } /* soleil_label=Text() AT ROTATED */
  DEBUG_COMPONENT("soleil_label", _soleil_label_var._position_absolute, _soleil_label_var._rotation_absolute);
  instrument->_position_absolute[577] = _soleil_label_var._position_absolute;
  instrument->_position_relative[577] = _soleil_label_var._position_relative;
    _soleil_label_var._position_relative_is_zero =  coords_test_zero(_soleil_label_var._position_relative);
  instrument->counter_N[577]  = instrument->counter_P[577] = instrument->counter_P2[577] = 0;
  instrument->counter_AbsorbProp[577]= 0;
  #ifdef USE_NEXUS
  if(nxhandle) {
    if ((!mcdotrace) && mcformat && strcasestr(mcformat, "NeXus")) {
    MPI_MASTER(
        mccomp_placement_type_nexus(nxhandle,"0576_soleil_label", _soleil_label_var._position_absolute, _soleil_label_var._rotation_absolute, "Text");
        mccomp_param_nexus(nxhandle,"0576_soleil_label", "text", "NONE", "SOLEIL", "char*");
        mccomp_param_nexus(nxhandle,"0576_soleil_label", "size", "0.5", "10","MCNUM");
        mccomp_param_nexus(nxhandle,"0576_soleil_label", "plane", "XY", "XZ", "char*");
        mccomp_param_nexus(nxhandle,"0576_soleil_label", "pen_thickness", "0.1", "0.1","MCNUM");
      );
    }
  } else {
    // fprintf(stderr,"NO NEXUS FILE");
  }
  #endif
  return(0);
} /* _soleil_label_setpos */

_class_Beamstop *class_Beamstop_init(_class_Beamstop *_comp
) {
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  SIG_MESSAGE("[_beamdump_init] component beamdump=Beamstop() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:52]");

  if (xwidth > 0) {
    xmax = xwidth / 2;
    xmin = -xmax;
  }
  if (yheight > 0) {
    ymax = yheight / 2;
    ymin = -ymax;
  }

  if (xmin == 0 && xmax == 0 && ymin == 0 & ymax == 0 && radius == 0) {
    fprintf (stderr, "Beamstop: %s: Error: give geometry\n", NAME_CURRENT_COMP);
    exit (-1);
  }
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  #undef xwidth
  #undef yheight
  #undef radius
  return(_comp);
} /* class_Beamstop_init */

_class_Text *class_Text_init(_class_Text *_comp
) {
  #define text (_comp->_parameters.text)
  #define size (_comp->_parameters.size)
  #define plane (_comp->_parameters.plane)
  #define pen_thickness (_comp->_parameters.pen_thickness)
  #define pl (_comp->_parameters.pl)
  SIG_MESSAGE("[_ODE_pos_init] component ODE_pos=Text() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:108]");

  if (!text || !plane || size <= 0.0f || pen_thickness < 0) {
    exit(-fprintf (stderr, "Error (%s): Text has invalid parameters.\n", NAME_CURRENT_COMP));
    exit (-1);
  }
  if (strlen(plane) != 2)
    exit(-fprintf (stderr, "Error (%s): Invalid plane.\n", NAME_CURRENT_COMP));
    
  if      (plane[0] == 'X' && plane[1] == 'Y') pl = 0;
  else if (plane[0] == 'Y' && plane[1] == 'Z') pl = 1;
  else if (plane[0] == 'X' && plane[1] == 'Z') pl = 2;
  else if (plane[1] == 'X' && plane[0] == 'Z') pl = 2;
  else 
    exit(-fprintf (stderr, "Error (%s): Invalid plane specification. Must be XY, YZ or XZ\n", NAME_CURRENT_COMP));

  if (mcdotrace==1) {
    /* For legacy mcdisplay line-mode, run with 0 thickness */
    pen_thickness=0;
  }
  #undef text
  #undef size
  #undef plane
  #undef pen_thickness
  #undef pl
  return(_comp);
} /* class_Text_init */

_class_Bending_magnet *class_Bending_magnet_init(_class_Bending_magnet *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define lambda0 (_comp->_parameters.lambda0)
  #define dlambda (_comp->_parameters.dlambda)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define gauss_t (_comp->_parameters.gauss_t)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define kc (_comp->_parameters.kc)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define p0 (_comp->_parameters.p0)
  SIG_MESSAGE("[_MARS_Source_init] component MARS_Source=Bending_magnet() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:102]");


  // fprintf(stderr,"Warning (%s): Bending_magnet is an experimental component - testing is ongoing\n",NAME_CURRENT_COMP);

  if (B <= 0 || Ee <= 0 || Ie <= 0) {
    fprintf (stderr, "Error (%s): B, Ee, and Ie must all be >= 0. Found (%g %g %g). Aborting.\n", NAME_CURRENT_COMP, B, Ee, Ie);
    exit (1);
  }

  if (sigex < 0 || sigey < 0) {
    fprintf (stderr, "Error (%s): sigex and sigey must be > 0. Negative beam size isn't meaningful. Aborting.\n", NAME_CURRENT_COMP);
    exit (1);
  }
  if (dist <= 0) {
    fprintf (stderr, "Error (%s): Target undefined.\n", NAME_CURRENT_COMP);
    exit (1);
  }

  /*compute gamma*/
  gamma = (Ee * 1e9) / (MELECTRON / CELE * M_C * M_C); /*the extra CELE is to convert to eV*/
  gamma2 = gamma * gamma;
  igamma = 1.0 / gamma;

  // printf("Bending_magnet (%s): gamma=%g, divergence is 1/gamma=%g rad.\n",NAME_CURRENT_COMP,gamma,igamma);
  /*compute characteristic energy in keV*/
  double Ec = 0.665 * Ee * Ee * B;
  // double Ec=1.5*gamma2*HBAR*CELE*B/MELECTRON *1e-3; /*check units on this one. The 1e-3 factor is because energy is assumed to be in keV*/
  /*We normally do computations in k so use that for transfer*/
  kc = E2K * Ec;

  s1x = sqrt (sigex * sigex + igamma * igamma * dist * dist);
  s1y = sqrt (sigey * sigey + igamma * igamma * dist * dist);
  p0 = 1.0 / mcget_ncount ();
  #undef E0
  #undef dE
  #undef lambda0
  #undef dlambda
  #undef phase
  #undef randomphase
  #undef Ee
  #undef Ie
  #undef B
  #undef sigey
  #undef sigex
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef gauss_t
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef kc
  #undef s1x
  #undef s1y
  #undef p0
  return(_comp);
} /* class_Bending_magnet_init */

_class_Monitor_nD *class_Monitor_nD_init(_class_Monitor_nD *_comp
) {
  #define user0 (_comp->_parameters.user0)
  #define user1 (_comp->_parameters.user1)
  #define user2 (_comp->_parameters.user2)
  #define user3 (_comp->_parameters.user3)
  #define user4 (_comp->_parameters.user4)
  #define user5 (_comp->_parameters.user5)
  #define user6 (_comp->_parameters.user6)
  #define user7 (_comp->_parameters.user7)
  #define user8 (_comp->_parameters.user8)
  #define user9 (_comp->_parameters.user9)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define bins (_comp->_parameters.bins)
  #define min (_comp->_parameters.min)
  #define max (_comp->_parameters.max)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define radius (_comp->_parameters.radius)
  #define options (_comp->_parameters.options)
  #define filename (_comp->_parameters.filename)
  #define geometry (_comp->_parameters.geometry)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define username0 (_comp->_parameters.username0)
  #define username1 (_comp->_parameters.username1)
  #define username2 (_comp->_parameters.username2)
  #define username3 (_comp->_parameters.username3)
  #define username4 (_comp->_parameters.username4)
  #define username5 (_comp->_parameters.username5)
  #define username6 (_comp->_parameters.username6)
  #define username7 (_comp->_parameters.username7)
  #define username8 (_comp->_parameters.username8)
  #define username9 (_comp->_parameters.username9)
  #define DEFS (_comp->_parameters.DEFS)
  #define Vars (_comp->_parameters.Vars)
  #define detector (_comp->_parameters.detector)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_MARS_displaySourceLength_init] component MARS_displaySourceLength=Monitor_nD() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:261]");

  char tmp[CHAR_BUF_LENGTH];
  strcpy (Vars.compcurname, NAME_CURRENT_COMP);
  Vars.compcurindex = INDEX_CURRENT_COMP;
  if (options != NULL)
    strncpy (Vars.option, options, CHAR_BUF_LENGTH);
  else {
    strcpy (Vars.option, "x y");
    printf ("Monitor_nD: %s has no option specified. Setting to PSD ('x y') monitor.\n", NAME_CURRENT_COMP);
  }
  Vars.compcurpos = POS_A_CURRENT_COMP;

  if (strstr (Vars.option, "source"))
    strcat (Vars.option, " list, x y z kx ky kz phi t Ex Ey Ez ");

  if (bins) {
    sprintf (tmp, " all bins=%ld ", (long)bins);
    strcat (Vars.option, tmp);
  }
  if (min > -FLT_MAX && max < FLT_MAX) {
    sprintf (tmp, " all limits=[%g %g]", min, max);
    strcat (Vars.option, tmp);
  } else if (min > -FLT_MAX) {
    sprintf (tmp, " all min=%g", min);
    strcat (Vars.option, tmp);
  } else if (max < FLT_MAX) {
    sprintf (tmp, " all max=%g", max);
    strcat (Vars.option, tmp);
  }

  /* transfer, "zero", and check username- and user variable strings to Vars struct*/
  strncpy (Vars.UserName0, username1&& strlen (username0) && strcmp (username0, "0") && strcmp (username0, "NULL") ? username0 : "", 128);
  strncpy (Vars.UserName1, username1&& strlen (username1) && strcmp (username1, "0") && strcmp (username1, "NULL") ? username1 : "", 128);
  strncpy (Vars.UserName2, username2&& strlen (username2) && strcmp (username2, "0") && strcmp (username2, "NULL") ? username2 : "", 128);
  strncpy (Vars.UserName3, username3&& strlen (username3) && strcmp (username3, "0") && strcmp (username3, "NULL") ? username3 : "", 128);
  strncpy (Vars.UserName4, username4&& strlen (username4) && strcmp (username4, "0") && strcmp (username4, "NULL") ? username4 : "", 128);
  strncpy (Vars.UserName5, username5&& strlen (username5) && strcmp (username5, "0") && strcmp (username5, "NULL") ? username5 : "", 128);
  strncpy (Vars.UserName6, username6&& strlen (username6) && strcmp (username6, "0") && strcmp (username6, "NULL") ? username6 : "", 128);
  strncpy (Vars.UserName7, username7&& strlen (username7) && strcmp (username7, "0") && strcmp (username7, "NULL") ? username7 : "", 128);
  strncpy (Vars.UserName8, username8&& strlen (username8) && strcmp (username8, "0") && strcmp (username8, "NULL") ? username8 : "", 128);
  strncpy (Vars.UserName9, username9&& strlen (username9) && strcmp (username9, "0") && strcmp (username9, "NULL") ? username9 : "", 128);
  if (user0 && strlen (user0) && strcmp (user0, "0") && strcmp (user0, "NULL")) {
    strncpy (Vars.UserVariable0, user0, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable0, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user0=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user0);
    }
  }
  if (user1 && strlen (user1) && strcmp (user1, "0") && strcmp (user1, "NULL")) {
    strncpy (Vars.UserVariable1, user1, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable1, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user1=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user1);
    }
  }
  if (user2 && strlen (user2) && strcmp (user2, "0") && strcmp (user2, "NULL")) {
    strncpy (Vars.UserVariable2, user2, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable2, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user2=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user2);
    }
  }
  if (user3 && strlen (user3) && strcmp (user3, "0") && strcmp (user3, "NULL")) {
    strncpy (Vars.UserVariable3, user3, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable3, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user3=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user3);
    }
  }
  if (user4 && strlen (user4) && strcmp (user4, "0") && strcmp (user4, "NULL")) {
    strncpy (Vars.UserVariable4, user4, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable4, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user4=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user4);
    }
  }
  if (user5 && strlen (user5) && strcmp (user5, "0") && strcmp (user5, "NULL")) {
    strncpy (Vars.UserVariable5, user5, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable5, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user5=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user5);
    }
  }
  if (user6 && strlen (user6) && strcmp (user6, "0") && strcmp (user6, "NULL")) {
    strncpy (Vars.UserVariable6, user6, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable6, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user6=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user6);
    }
  }
  if (user7 && strlen (user7) && strcmp (user7, "0") && strcmp (user7, "NULL")) {
    strncpy (Vars.UserVariable7, user7, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable7, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user7=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user7);
    }
  }
  if (user8 && strlen (user8) && strcmp (user8, "0") && strcmp (user8, "NULL")) {
    strncpy (Vars.UserVariable8, user8, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable8, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user8=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user8);
    }
  }
  if (user9 && strlen (user9) && strcmp (user9, "0") && strcmp (user9, "NULL")) {
    strncpy (Vars.UserVariable9, user9, 128);
    int fail;
    _class_particle testparticle;
    particle_getvar (&testparticle, Vars.UserVariable9, &fail);
    if (fail) {
      fprintf (stderr, "Warning (%s): user9=%s is unknown. The signal will not be resolved - this is likely not what you intended.\n", NAME_CURRENT_COMP, user9);
    }
  }

  /*sanitize parameters set for curved shapes*/
  if (strstr (Vars.option, "cylinder") || strstr (Vars.option, "banana") || strstr (Vars.option, "sphere")) {
    /*this _is_ an explicit curved shape. Should have a radius. Inherit from xwidth or zdepth (diameters), x has precedence.*/
    if (!radius) {
      if (xwidth) {
        radius = xwidth / 2.0;
      } else {
        radius = zdepth / 2.0;
      }
    } else {
      /*radius is set - propagate to xwidth. It is used inside monitor_nd-lib*/
      xwidth = 2 * radius;
    }
    if (!yheight) {
      /*if not set - use the diameter as height for the curved object. This will likely only happen for spheres*/
      yheight = 2 * radius;
    }
  } else if (radius) {
    /*radius is set - this must be curved shape then. Infer shape from yheight*/
    xwidth = zdepth = 2 * radius;
    if (yheight) {
      /*a height is given (and no shape explitly set - assume cylinder*/
      strcat (Vars.option, " banana");
    } else {
      strcat (Vars.option, " sphere");
      yheight = 2 * radius;
    }
  }

  int offflag = 0;
  if (geometry && strlen (geometry) && strcmp (geometry, "0") && strcmp (geometry, "NULL")) {
    #ifndef USE_OFF
    fprintf (stderr, "Error: You are attempting to use an OFF geometry without -DUSE_OFF. You will need to recompile with that define set!\n");
    exit (-1);
    #else
    if (!off_init (geometry, xwidth, yheight, zdepth, 1, &offdata)) {
      printf ("Monitor_nD: %s could not initiate the OFF geometry %s. \n"
              "            Defaulting to normal Monitor dimensions.\n",
              NAME_CURRENT_COMP, geometry);
      strcpy (geometry, "");
    } else {
      offflag = 1;
    }
    #endif
  }
  if (!radius && !xwidth && !yheight && !zdepth && !strstr (Vars.option, "previous") && (!geometry || !strlen (geometry)))
    exit (printf ("Monitor_nD: %s has no dimension specified. Aborting (radius, xwidth, yheight, zdepth, previous, geometry).\n", NAME_CURRENT_COMP));

  Monitor_nD_Init (&DEFS, &Vars, xwidth, yheight, zdepth, 0, 0, 0, 0, 0, 0, offflag);

  if (filename && strlen (filename) && strcmp (filename, "NULL") && strcmp (filename, "0"))
    strncpy (Vars.Mon_File, filename, 128);

  /* check if user given filename with ext will be used more than once */
  if (((Vars.Flag_Multiple && Vars.Coord_Number > 1) || Vars.Flag_List) && strchr (Vars.Mon_File, '.')) {
    char* XY;
    XY = strrchr (Vars.Mon_File, '.');
    *XY = '_';
  }

  if (restore_xray)
    Vars.Flag_parallel = 1;
  detector.m = 0;

  #ifdef USE_MPI
  MPI_MASTER (if (strstr (Vars.option, "auto") && mpi_node_count > 1)
                  printf ("Monitor_nD: %s is using automatic limits option 'auto' together with MPI.\n"
                          "WARNING     this may create incorrect distributions (but integrated flux will be right).\n",
                          NAME_CURRENT_COMP););
  #else
  #ifdef OPENACC
  if (strstr (Vars.option, "auto"))
    printf ("Monitor_nD: %s is requesting automatic limits option 'auto' together with OpenACC.\n"
            "WARNING     this feature is NOT supported using OpenACC and has been disabled!\n",
            NAME_CURRENT_COMP);
  #endif
  #endif
  #undef user0
  #undef user1
  #undef user2
  #undef user3
  #undef user4
  #undef user5
  #undef user6
  #undef user7
  #undef user8
  #undef user9
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef bins
  #undef min
  #undef max
  #undef restore_xray
  #undef radius
  #undef options
  #undef filename
  #undef geometry
  #undef nowritefile
  #undef username0
  #undef username1
  #undef username2
  #undef username3
  #undef username4
  #undef username5
  #undef username6
  #undef username7
  #undef username8
  #undef username9
  #undef DEFS
  #undef Vars
  #undef detector
  #undef offdata
  return(_comp);
} /* class_Monitor_nD_init */

_class_PSD_monitor *class_PSD_monitor_init(_class_PSD_monitor *_comp
) {
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nr (_comp->_parameters.nr)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_displaySource_init] component MARS_displaySource=PSD_monitor() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:61]");

  int i, j;
  double *p1, *p2, *p3;

  xmax = xwidth / 2;
  xmin = -xmax;
  ymax = yheight / 2;
  ymin = -ymax;

  if (((xmin >= xmax) || (ymin >= ymax)) && !radius) {
    fprintf (stderr, "ERROR (%s): Null detection area! Aborting.\n", NAME_CURRENT_COMP);
    exit (-1);
  }
  if (!radius) {
    PSD_N = create_darr2d (nx, ny);
    PSD_p = create_darr2d (nx, ny);
    PSD_p2 = create_darr2d (nx, ny);
  } else {
    PSD_N = create_darr2d (1, nr);
    PSD_p = create_darr2d (1, nr);
    PSD_p2 = create_darr2d (1, nr);
  }

  // Use instance name for monitor output if no input was given
  if (!strcmp (filename, "\0"))
    sprintf (filename, "%s", NAME_CURRENT_COMP);
  #undef filename
  #undef xwidth
  #undef yheight
  #undef radius
  #undef restore_xray
  #undef nowritefile
  #undef nx
  #undef ny
  #undef nr
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_init */

_class_Slit *class_Slit_init(_class_Slit *_comp
) {
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define dist (_comp->_parameters.dist)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_x0 (_comp->_parameters.focus_x0)
  #define focus_y0 (_comp->_parameters.focus_y0)
  SIG_MESSAGE("[_MARS_slit1_init] component MARS_slit1=Slit() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:59]");

  if (xwidth > 0) {
    if (!xmin && !xmax) {
      xmax = xwidth / 2;
      xmin = -xmax;
    } else {
      fprintf (stderr, "Slit: %s: Error: please specify EITHER xmin & xmax or xwidth\n", NAME_CURRENT_COMP);
      exit (-1);
    }
  }
  if (yheight > 0) {
    if (!ymin && !ymax) {
      ymax = yheight / 2;
      ymin = -ymax;
    } else {
      fprintf (stderr, "Slit: %s: Error: please specify EITHER ymin & ymax or ywidth\n", NAME_CURRENT_COMP);
      exit (-1);
    }
  }
  if (xmin == 0 && xmax == 0 && ymin == 0 && ymax == 0 && radius == 0) {
    fprintf (stderr, "Slit: %s: Warning: Running with CLOSED slit - is this intentional?? \n", NAME_CURRENT_COMP);
  }

  if ((focus_xw || focus_yh) && !((focus_xw && dist) || (focus_yh && dist))) {
    fprintf (stderr, "Error (%s): Inconsistent target definition\n", NAME_CURRENT_COMP);
    exit (-1);
  }
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  #undef radius
  #undef xwidth
  #undef yheight
  #undef dist
  #undef focus_xw
  #undef focus_yh
  #undef focus_x0
  #undef focus_y0
  return(_comp);
} /* class_Slit_init */

_class_Mirror_curved *class_Mirror_curved_init(_class_Mirror_curved *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define zdepth (_comp->_parameters.zdepth)
  #define yheight (_comp->_parameters.yheight)
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define Z (_comp->_parameters.Z)
  #define At (_comp->_parameters.At)
  #define rho (_comp->_parameters.rho)
  #define T (_comp->_parameters.T)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_MARS_mirror_M1_init] component MARS_mirror_M1=Mirror_curved() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:56]");

  int status;

  if (coating && strlen (coating) && strcmp (coating, "NULL")) {
    status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
  } else {
    /*assume a constant reflectivity*/
    status = reflec_Init (&re, CONSTANT, NULL, &(R0));
  }
  if (!radius)
    radius = 1e6;
  // compatibility with older use
  if (length)
    zdepth = length;
  if (width)
    yheight = width;
  #undef radius
  #undef R0
  #undef coating
  #undef zdepth
  #undef yheight
  #undef length
  #undef width
  #undef Z
  #undef At
  #undef rho
  #undef T
  #undef re
  return(_comp);
} /* class_Mirror_curved_init */

_class_Bragg_crystal *class_Bragg_crystal_init(_class_Bragg_crystal *_comp
) {
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define V (_comp->_parameters.V)
  #define form_factors (_comp->_parameters.form_factors)
  #define material (_comp->_parameters.material)
  #define alpha (_comp->_parameters.alpha)
  #define R0 (_comp->_parameters.R0)
  #define debye_waller_B (_comp->_parameters.debye_waller_B)
  #define crystal_type (_comp->_parameters.crystal_type)
  #define h (_comp->_parameters.h)
  #define k (_comp->_parameters.k)
  #define l (_comp->_parameters.l)
  #define structure_factor_scale_r (_comp->_parameters.structure_factor_scale_r)
  #define structure_factor_scale_i (_comp->_parameters.structure_factor_scale_i)
  #define Z (_comp->_parameters.Z)
  #define rho (_comp->_parameters.rho)
  #define At (_comp->_parameters.At)
  #define f_rel (_comp->_parameters.f_rel)
  #define f_nt (_comp->_parameters.f_nt)
  #define m_t (_comp->_parameters.m_t)
  #define f0_t (_comp->_parameters.f0_t)
  SIG_MESSAGE("[_MARS_dcm_xtal0_init] component MARS_dcm_xtal0=Bragg_crystal() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:99]");

  int status;
  if (material) {
    if ((status = Table_Read (&(m_t), material, 0)) == -1) {
      fprintf (stderr, "Error(%s): Could not parse file \"%s\"\n", NAME_CURRENT_COMP, material);
      exit (-1);
    }
    char** header_parsed;
    header_parsed = Table_ParseHeader (m_t.header, "Z", "A[r]", "rho", "Z/A", "sigma[a]", NULL);
    if (header_parsed[2]) {
      rho = strtod (header_parsed[2], NULL);
    }
    if (header_parsed[0]) {
      Z = strtod (header_parsed[0], NULL);
    }
    if (header_parsed[1]) {
      At = strtod (header_parsed[1], NULL);
    }
  } else {
    fprintf (stderr, "Error(%s): No material file specified\n", NAME_CURRENT_COMP);
  }
  if (form_factors) {
    if ((status = Table_Read (&(f0_t), form_factors, 0)) == -1) {
      fprintf (stderr, "Error(%s): Could not parse file \"%s\"\n", NAME_CURRENT_COMP, form_factors);
      exit (-1);
    }
  }
  #undef length
  #undef width
  #undef V
  #undef form_factors
  #undef material
  #undef alpha
  #undef R0
  #undef debye_waller_B
  #undef crystal_type
  #undef h
  #undef k
  #undef l
  #undef structure_factor_scale_r
  #undef structure_factor_scale_i
  #undef Z
  #undef rho
  #undef At
  #undef f_rel
  #undef f_nt
  #undef m_t
  #undef f0_t
  return(_comp);
} /* class_Bragg_crystal_init */

_class_E_monitor *class_E_monitor_init(_class_E_monitor *_comp
) {
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_emon_dcm0_init] component MARS_emon_dcm0=E_monitor() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:63]");

  int i;

  xmax = xwidth / 2;
  xmin = -xmax;
  ymax = yheight / 2;
  ymin = -ymax;

  if ((xmin >= xmax) || (ymin >= ymax)) {
    printf ("E_monitor (%s): Null detection area !\n"
            "ERROR      (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting",
            NAME_CURRENT_COMP);
    exit (0);
  }

  E_N = create_darr1d (nE);
  E_p = create_darr1d (nE);
  E_p2 = create_darr1d (nE);

  // Use instance name for monitor output if no input was given
  if (!strcmp (filename, "\0"))
    sprintf (filename, "%s", NAME_CURRENT_COMP);
  #undef nE
  #undef filename
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef restore_xray
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_E_monitor_init */

_class_FluoPowder *class_FluoPowder_init(_class_FluoPowder *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_powder (_comp->_parameters.flag_powder)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define powder_refl (_comp->_parameters.powder_refl)
  #define powder_format (_comp->_parameters.powder_format)
  #define Vc (_comp->_parameters.Vc)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define DW (_comp->_parameters.DW)
  #define d_phi (_comp->_parameters.d_phi)
  #define nb_atoms (_comp->_parameters.nb_atoms)
  #define barns (_comp->_parameters.barns)
  #define tth_sign (_comp->_parameters.tth_sign)
  #define order (_comp->_parameters.order)
  #define line_info (_comp->_parameters.line_info)
  #define columns (_comp->_parameters.columns)
  #define mat_columns (_comp->_parameters.mat_columns)
  #define offdata (_comp->_parameters.offdata)
  #define tgt_x (_comp->_parameters.tgt_x)
  #define tgt_y (_comp->_parameters.tgt_y)
  #define tgt_z (_comp->_parameters.tgt_z)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_Nq (_comp->_parameters.reuse_Nq)
  #define reuse_my_s_k2_sum (_comp->_parameters.reuse_my_s_k2_sum)
  SIG_MESSAGE("[_MARS_Sample_init] component MARS_Sample=FluoPowder() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:224]");


  /* energies en [keV], angles in [radians], XRL CSb cross sections are in [barn/atom] */
  xrl_error *error = NULL;
  int        i;

  XRayInit();

  shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere, 3:any-shape  */
  if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
    #ifndef USE_OFF
    fprintf(stderr,"Error: You are attempting to use an OFF geometry without -DUSE_OFF."
                   "You will need to recompile with that define set!\n");
    exit(-1);
    #else
    if (off_init(geometry, xwidth, yheight, zdepth, 0, &offdata)) {
      shape=3; thickness=0; concentric=0;
    }
    #endif
  }
  else if (xwidth && yheight && zdepth)  shape=1; /* box */
  else if (radius > 0 &&  yheight)       shape=0; /* cylinder */
  else if (radius > 0 && !yheight)       shape=2; /* sphere */

  if (shape < 0)
    exit(fprintf(stderr,"FluoPowder: %s: sample has invalid dimensions.\n"
                        "ERROR       Please check parameter values (xwidth, yheight, zdepth, radius).\n", NAME_CURRENT_COMP));

  if (!material || !strlen(material) || !strcmp(material, "NULL") || !strcmp(material, "0"))
    exit(fprintf(stderr, "ERROR: FluoPowder: %s: Null material specification.\n", NAME_CURRENT_COMP));

  if (order > 1 && flag_lorentzian)
    fprintf(stderr, "FluoPowder: WARNING: %s: Using flag_lorentzian=1 Lorentzian line-shape with order>1 may create artifacts.\n", NAME_CURRENT_COMP);

  // test if the material is given as a file
  char formula[16384];
  formula[0]='\0';
  FILE *file = Open_File(material, "r", NULL);
  if (file != NULL) {
    fclose(file);
    // open the material structure file (laz/lau/cif...)
    // search (case sensitive) along lines
    if (!fluo_get_material(material, formula))
      exit(fprintf(stderr, "ERROR: FluoPowder: %s: file %s does not contain material formulae.\n", NAME_CURRENT_COMP, material));

    MPI_MASTER(
    fprintf(stderr, "INFO: FluoPowder: %s: found material %s from file %s\n",
            NAME_CURRENT_COMP, formula, material);
    );

    // load Powder lines, when given as a valid file
    // set powder variable default before reading file
    if (flag_powder) {
      columns             = powder_format;
      line_info.V_0       = Vc;
      for (i=0; i< 8; i++) {
        line_info.column_order[i] = (int)columns[i];
      }
      line_info.DWfactor  = DW;
      line_info.Dd        = delta_d_d;
      line_info.rho       = density;
      line_info.at_weight = weight;
      line_info.at_nb     = nb_atoms;
      line_info.flag_barns= barns;
      strncpy(line_info.compname, NAME_CURRENT_COMP, 256);
      if (!powder_refl || !strlen(powder_refl) || !strcmp(powder_refl, "NULL") || !strcmp(powder_refl, "0"))
        strcpy(powder_refl, material);
      i = read_line_data(powder_refl, &line_info);
      if (i == 0) {
        MPI_MASTER(
        fprintf(stderr,"WARNING: FluoPowder: %s: reflection file %s is not valid (CIF/LAU/LAZ). Ignoring diffraction process.\n",
                      NAME_CURRENT_COMP, powder_refl);
        );
        flag_powder=0;
      }
    }
    if (flag_powder) {
      /* compute the scattering unit density from material weight and density */
      /* the weight of the scattering element is the chemical formula molecular weight
       * times the nb of chemical formulae in the scattering element (nb_atoms) */
      if (!line_info.V_0 && line_info.at_nb > 0
        && line_info.at_weight > 0 && line_info.rho > 0) {
        /* molar volume [cm^3/mol] = weight [g/mol] / density [g/cm^3] */
        /* atom density per Angs^3 = [mol/cm^3] * N_Avogadro *(1e-8)^3 */
        line_info.V_0 = line_info.at_nb
        /(line_info.rho/line_info.at_weight/1e24*6.02214199e23);
        }

        /* Factor 100 to convert from barns to fm^2 */
        line_info.XsectionFactor = line_info.flag_barns ? 100 : 1;

      if (line_info.V_0 <= 0) {
        MPI_MASTER(
          printf("WARNING: FluoPowder: %s: density/unit cell volume is NULL (Vc). Ignoring diffraction process.\n", NAME_CURRENT_COMP);
        );
        flag_powder=0;
      } else {

        struct line_data *L;
        L = line_info.list;

        line_info.q = malloc(line_info.count*sizeof(double));
        line_info.w = malloc(line_info.count*sizeof(double));
        line_info.my_s_k2 = malloc(line_info.count*sizeof(double));
        if (!line_info.q || !line_info.w || !line_info.my_s_k2)
          exit(fprintf(stderr,"ERROR: FluoPowder: %s: allocating memory (init)\n", NAME_CURRENT_COMP));
        for(i=0; i<line_info.count; i++)
        {
          line_info.my_s_k2[i] = 4*PI*PI*PI* 1.0 *(L[i].DWfactor ? L[i].DWfactor : 1)
            /(line_info.V_0*line_info.V_0)
            *(L[i].j * L[i].F2 / L[i].q)*line_info.XsectionFactor; // fm^2 based
          line_info.q[i] = L[i].q;
          line_info.w[i] = L[i].w;
        }
      }
    }

    strncpy(material, formula, 16384);
    // CIF: _chemical_formula_structural 'chemical_formulae'
    // CIF: _chemical_formula_sum 'chemical_formulae'
    // LAZ/LAU: # ATOM <at> <trailing>
    // LAZ/LAU: # Atom <at> <trailing>
    // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
    // CFL: Title <chemical_formulae>
    // CFL: Atom <at> <trailing>

  }

  compound = CompoundParser(material, &error); /* XRayLib */
  if (error != NULL) {
    exit(fprintf(stderr, "ERROR: %s: Invalid material %s: %s\n",
      NAME_CURRENT_COMP, material, error->message));
  }
  xrl_error_free(error);

  /* compute total density for raw material and display information ========= */
  if (weight <= 0) weight = compound->molarMass; /* g/mol */
  MPI_MASTER(
    printf("%s: Material %s mass fractions:\n",
      NAME_CURRENT_COMP, material);
  )

  double mat_density       = 0; /* g/cm3 */
  double sum_massFractions = 0;
  cum_massFractions        = create_darr1d(compound->nElements+1);
  cum_xs_fluo              = create_darr1d(compound->nElements+1);
  cum_xs_Compton           = create_darr1d(compound->nElements+1);
  cum_xs_Rayleigh          = create_darr1d(compound->nElements+1);
  cum_massFractions[0]     = 0;

  /* print material information, and check for elements */
  for (i=0; i< compound->nElements; i++) {
    int    Z      = compound->Elements[i];
    error = NULL;
    double Z_dens = ElementDensity(Z, &error);
    if (error != NULL)
      exit(fprintf(stderr, "ERROR: %s: Z=%i %s\n", NAME_CURRENT_COMP, Z, error->message));
    mat_density           += compound->massFractions[i]*Z_dens;
    sum_massFractions     += compound->massFractions[i];
    cum_massFractions[i+1] = sum_massFractions;
    MPI_MASTER(
      printf("  | %6.2g %%: Z=%3i %3s %8.3g [g/mol] %8.3g [g/cm3]\n",
        compound->massFractions[i]*100, Z, AtomicNumberToSymbol(Z,NULL), AtomicWeight(Z, NULL),
        Z_dens);
    )
  }
  xrl_error_free(error);
  if (density <= 0)        density        = mat_density;   /* g/cm3 */
  if (packing_factor <= 0) packing_factor = density/mat_density;

  /* molar volume [cm^3/mol] = weight [g/mol] / density [g/cm^3] */
  /* atom density per Angs^3 = [mol/cm^3] * N_Avogadro *(1e-8)^3 */
  fluo_rho = density/weight/1e24*NA; // atom density [at/Angs-3]
  MPI_MASTER(
    printf("%s: Material %s M=%g [g/mol] density=%g [g/cm3] rho=%g [at/Angs-3]",
      NAME_CURRENT_COMP, material, weight, density, fluo_rho);
    if (fabs(packing_factor-1) > 1e-2)
      printf(" packing_factor=%g", packing_factor);
    printf("\n");
  );
  if (0 < packing_factor && packing_factor < 1) fluo_rho *= packing_factor;

  /* target for scattering ================================================== */
  if (!target_index && !target_x && !target_y && !target_z) target_index=1;
  if (target_index)
  {
    Coords ToTarget;
    ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP);
    ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget);
    coords_get(ToTarget, &target_x, &target_y, &target_z);
  }
  if (!(target_x || target_y || target_z)) {
    MPI_MASTER(
    printf("WARNING: FluoPowder: %s: The target is not defined. Using 4PI for fluorescence.\n",
      NAME_CURRENT_COMP);
    );
  }
  // checks for d_pĥi focusing
  if (flag_powder && !d_phi) {
    if (focus_ah) d_phi=focus_ah;
    else if (focus_yh && (target_x || target_y || target_z)) {
      double target_dist2=target_x*target_x+target_y*target_y+target_z*target_z;
      d_phi = atan2(focus_yh,sqrt(target_dist2));
    }
  }

  n_fluo = n_Compton = n_Rayleigh = n_diff = 0;
  p_fluo = p_Compton = p_Rayleigh = p_diff = 0;

  // cached variables set to 0 (for SPLIT)
  reuse_nb=0;
  reuse_ki=reuse_l0=reuse_l1=reuse_l2=reuse_l3=reuse_sigma_barn=0;
  reuse_cum_xs_fluo              = create_darr1d(compound->nElements+1);
  reuse_cum_xs_Compton           = create_darr1d(compound->nElements+1);
  reuse_cum_xs_Rayleigh          = create_darr1d(compound->nElements+1);
  reuse_cum_xs_fluo[0]=reuse_cum_xs_Compton[0]=reuse_cum_xs_Rayleigh[0]=0;
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_powder
  #undef flag_kissel
  #undef powder_refl
  #undef powder_format
  #undef Vc
  #undef delta_d_d
  #undef DW
  #undef d_phi
  #undef nb_atoms
  #undef barns
  #undef tth_sign
  #undef order
  #undef line_info
  #undef columns
  #undef mat_columns
  #undef offdata
  #undef tgt_x
  #undef tgt_y
  #undef tgt_z
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef n_diff
  #undef p_diff
  #undef fluo_rho
  #undef reuse_cum_xs_diffraction
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_Nq
  #undef reuse_my_s_k2_sum
  return(_comp);
} /* class_FluoPowder_init */

_class_Wiggler *class_Wiggler_init(_class_Wiggler *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define lambda0 (_comp->_parameters.lambda0)
  #define dlambda (_comp->_parameters.dlambda)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define length (_comp->_parameters.length)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define gauss_t (_comp->_parameters.gauss_t)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define kc (_comp->_parameters.kc)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define lu (_comp->_parameters.lu)
  #define gap (_comp->_parameters.gap)
  #define p0 (_comp->_parameters.p0)
  SIG_MESSAGE("[_PSICHE_source_init] component PSICHE_source=Wiggler() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Wiggler.comp:107]");

  // fprintf(stderr,"Warning (%s): Wiggler is an experimental component - testing is ongoing\n",NAME_CURRENT_COMP);

  lu = length / Nper;

  if (K <= 0 || B <= 0 || Ee <= 0 || Ie <= 0 || E0 <= 0 || length <= 0 || Nper <= 0) {
    fprintf (stderr, "Wiggler Error (%s): (K, B, Ee, Ie, E0, length, Nper) do not have a sane set of values. Found (%g %g %g %g %g). Aborting.\n",
             NAME_CURRENT_COMP, K, B, Ee, Ie, E0);
    exit (1);
  }

  if (K) {
    B = 2 * M_PI * MELECTRON * M_C * K / CELE / lu;
  } else if (B > 0) {
    K = CELE * B * lu / (2 * M_PI * MELECTRON * M_C);
  }

  if (sigex < 0 || sigey < 0) {
    fprintf (stderr, "Error (%s): sigex and sigey must be > 0. Negative beam size isn't meaningful. Aborting.\n", NAME_CURRENT_COMP);
    exit (1);
  }
  if (dist <= 0) {
    fprintf (stderr, "Error (%s): Target undefined.\n", NAME_CURRENT_COMP);
    exit (1);
  }

  /*compute gamma*/
  gamma = (Ee * 1e9) / (MELECTRON / CELE * M_C * M_C); /*the extra CELE is to convert to eV*/
  gamma2 = gamma * gamma;
  igamma = 1.0 / gamma;

  // printf("Wiggler (%s): gamma=%g, divergence is 1/gamma=%g rad.\n",NAME_CURRENT_COMP,gamma,igamma);
  /*compute characteristic energy in keV*/
  double Ec = 0.665 * Ee * Ee * B;
  // double Ec=1.5*gamma2*HBAR*CELE*B/MELE *1e-3; /*check units on this one. The 1e-3 factor is because energy is assumed to be in keV*/
  /*We normally do computations in k so use that for transfer*/
  kc = E2K * Ec;

  /* compute gap estimate */
  if (Br > B) {
    double a = 0.55 * Br + 2.835;
    double b = -1.95 * Br + 7.22;
    double c = -1.3 * Br + 2.97;
    gap = -log (B / a) * lu / b;
  } else
    gap = 3e-3;

  if (verbose)
    printf ("Wiggler (%s): K=%g B=%g[T] lambda_u=%g[m] E0=%g[keV]\n", NAME_CURRENT_COMP, K, B, lu, E0);

  p0 = 1.0 / mcget_ncount ();
  #undef E0
  #undef dE
  #undef lambda0
  #undef dlambda
  #undef phase
  #undef randomphase
  #undef Ee
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef length
  #undef sigey
  #undef sigex
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef gauss_t
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef kc
  #undef s1x
  #undef s1y
  #undef lu
  #undef gap
  #undef p0
  return(_comp);
} /* class_Wiggler_init */

_class_Mask *class_Mask_init(_class_Mask *_comp
) {
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define mask (_comp->_parameters.mask)
  #define invert (_comp->_parameters.invert)
  #define virtual (_comp->_parameters.virtual)
  #define table (_comp->_parameters.table)
  #define ny (_comp->_parameters.ny)
  #define nx (_comp->_parameters.nx)
  #define xmin (_comp->_parameters.xmin)
  #define ymin (_comp->_parameters.ymin)
  #define xmax (_comp->_parameters.xmax)
  #define ymax (_comp->_parameters.ymax)
  #define filter_row (_comp->_parameters.filter_row)
  #define maskval (_comp->_parameters.maskval)
  SIG_MESSAGE("[_DISCO_ColdFinger_init] component DISCO_ColdFinger=Mask() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mask.comp:87]");


  /*do some checks on input parameters*/
  if (invert) {
    /*invert should be either 0 or one*/
    invert = 1;
  }

  do {
    #if USE_PNG
    if (strstr (mask + strlen (mask) - 4, ".png") != NULL) {
      /*filename ends with .png - use libpng to read the mask*/
      /*read file and insert mask values into table*/
      /*copied form libpng docs*/
      int is_png = 0;
      const int number = 1;
      char header[8];
      const int ERROR = 1;
      const int NOT_PNG = 2;

      FILE* fp = Open_File (mask, "rb", NULL);
      if (!fp) {
        fprintf (stderr, "Error(%s): cant open file %s for reading\n", NAME_CURRENT_COMP, mask);
        exit (1);
      }
      fread (header, 1, number, fp);
      is_png = !png_sig_cmp (header, 0, number);

      if (!is_png) {
        fprintf (stderr, "Error(%s): %s does not appear to be a png file\n", NAME_CURRENT_COMP, mask);
        exit (1);
      }

      // png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,user_error_fn, user_warning_fn);
      png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
      /*last two arguments are error handling functions*/

      if (!png_ptr) {
        fprintf (stderr, "Error(%s): Could not set up the png reading buffer structure\n", NAME_CURRENT_COMP);
        exit (1);
      }

      png_init_io (png_ptr, fp);
      /*we used number bytes of the png file to indentify it as being png*/
      png_set_sig_bytes (png_ptr, number);

      png_infop info_ptr = png_create_info_struct (png_ptr);
      if (!info_ptr) {
        png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
        exit (1);
      }

      /*do read the image using the high level interface and apply the transform
       * toexpand 1, 2, and 4 bits to bytes*/
      png_read_png (png_ptr, info_ptr, PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL);
      /*image is now available in png_ptr - extfact dimensions*/
      int height = png_get_image_height (png_ptr, info_ptr);
      int width = png_get_image_width (png_ptr, info_ptr);
      int bd = png_get_bit_depth (png_ptr, info_ptr);
      if (bd < 8) {
        bd = 8;
      }
      unsigned int ct = png_get_color_type (png_ptr, info_ptr);

      Table_Init (&(table), height, width);

      png_bytep* row_pointers = png_get_rows (png_ptr, info_ptr);
      printf ("I just read a png image with size %d by %d, bit depth %d, and color type %d\n", width, height, bd, ct);
      fclose (fp);

      int j, r, c, tuplelen;
      unsigned long tuple_normalizer;
      switch (ct) {
      case PNG_COLOR_TYPE_GRAY:
        if (bd == 8) {
          tuplelen = 1;
          tuple_normalizer = 0xFF;
        } else if (bd == 16) {
          tuplelen = 2;
          tuple_normalizer = 0xFFFF;
        }
        break;
      case PNG_COLOR_TYPE_GRAY_ALPHA:
        if (bd == 8) {
          tuplelen = 2;
          tuple_normalizer = 0xFFFF;
        } else if (bd == 16) {
          tuplelen = 2;
          tuple_normalizer = 0xFFFFFFFF;
        }
        break;
      case PNG_COLOR_TYPE_RGB:
        if (bd == 8) {
          tuplelen = 3;
          tuple_normalizer = 0xFFFFFF;
        } else if (bd == 16) {
          tuplelen = 3;
          tuple_normalizer = 0xFFFFFFFFFFFF;
        }
        break;
      case PNG_COLOR_TYPE_RGB_ALPHA:
        if (bd == 8) {
          tuplelen = 4;
          tuple_normalizer = 0xFFFFFFFF;
        } else if (bd == 16) {
          tuplelen = 4;
          tuple_normalizer = 0xFFFFFFFFFFFFFFFF;
        }
        break;
      default:
        fprintf (stderr, "Error (%s): Unsupported type of png image (allowed are GRAY, GRAY_ALPHA, RGB, RGB_ALPHA)\n", "NAME_CURRENT_COMP");
        exit (1);
      }
      for (r = 0; r < height; r++) {
        for (c = 0; c < width; c++) {
          unsigned long pixel = 0;
          for (j = 0; j < tuplelen; j++) {
            pixel |= (row_pointers[r][c * tuplelen + j] << 8 * j);
          }
          /*Data table should contain opacity values. Possibly invert the image*/
          /*Also png images are stored top-to-bottom, i.e. the first stored row corresponds to y=-yheight/2. Hence, switch the order.*/
          table.data[(height - r - 1) * width + c] = ((double)pixel) / tuple_normalizer;
        }
      }
      break;
    }
    #endif
    #if USEPBM
    if ((strstr (mask + strlen (mask) - 4, ".pnm") != NULL) || (strstr (mask + strlen (mask) - 4, ".pam") != NULL)
        || (strstr (mask + strlen (mask) - 4, ".pbm") != NULL)) {
      /*filename ends with .pnm, .pam, or .pbm - its a pnm file*/
      fprintf (stderr, "Many apologies(%s): pnm formats are not supported yet\n");
      exit (1);
    }
    #endif
    /*read the masking file*/
    int status;
    if ((status = Table_Read (&(table), mask, 0)) == -1) {
      fprintf (stderr, "Error: Could not parse file \"%s\" in COMP %s\n", mask, NAME_CURRENT_COMP);
      exit (-1);
    }
  } while (0); /*this is to allow breaking out so .png and .pnm will take precedence*/

  /*set some image vals*/
  xmax = xwidth / 2.0;
  xmin = -xwidth / 2.0;
  ymax = yheight / 2.0;
  ymin = -yheight / 2.0;
  nx = table.columns;
  ny = table.rows;
  #undef xwidth
  #undef yheight
  #undef mask
  #undef invert
  #undef virtual
  #undef table
  #undef ny
  #undef nx
  #undef xmin
  #undef ymin
  #undef xmax
  #undef ymax
  #undef filter_row
  #undef maskval
  return(_comp);
} /* class_Mask_init */

_class_Mirror_toroid_pothole *class_Mirror_toroid_pothole_init(_class_Mirror_toroid_pothole *_comp
) {
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define radius (_comp->_parameters.radius)
  #define radius_o (_comp->_parameters.radius_o)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define prms (_comp->_parameters.prms)
  #define reflec_table (_comp->_parameters.reflec_table)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_DISCO_M2_init] component DISCO_M2=Mirror_toroid_pothole() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:64]");

  if (coating && strlen (coating) && strcmp (coating, "NULL")) {
    char** header_parsed;
    t_Table* tp = &reflec_table;
    /* read 1st block data from file into tp */
    if (Table_Read (tp, coating, 1) <= 0) {
      exit (fprintf (stderr, "Error: %s: cannot read file %s\n", NAME_CURRENT_COMP, coating));
    }
    header_parsed = Table_ParseHeader (tp->header, "e_min=", "e_max=", "e_step=", "theta_min=", "theta_max=", "theta_step=", NULL);
    if (header_parsed[0] && header_parsed[1] && header_parsed[2] && header_parsed[3] && header_parsed[4] && header_parsed[5]) {
      prms.e_min = strtod (header_parsed[0], NULL);
      prms.e_max = strtod (header_parsed[1], NULL);
      prms.e_step = strtod (header_parsed[2], NULL);
      prms.theta_min = strtod (header_parsed[3], NULL);
      prms.theta_max = strtod (header_parsed[4], NULL);
      prms.theta_step = strtod (header_parsed[5], NULL);
    } else {
      exit (fprintf (stderr, "Error: %s: wrong/missing header line(s) in file %s\n", NAME_CURRENT_COMP, coating));
    }
    if (((tp->rows - 2) * prms.e_step) > (prms.e_max - prms.e_min)) {
      exit (fprintf (stderr, "Error: %s: e_step does not match e_min and e_max in file %s (<)\n", NAME_CURRENT_COMP, coating));
    }
    if ((prms.e_max - prms.e_min) > ((tp->rows) * prms.e_step)) {
      exit (fprintf (stderr, "Error: %s: e_step does not match e_min and e_max in file %s (>)\n", NAME_CURRENT_COMP, coating));
    }
    if (((tp->columns - 2) * prms.theta_step) > (prms.theta_max - prms.theta_min)) {
      exit (fprintf (stderr, "Error: %s: theta_step does not match theta_min and theta_max in file %s (<)\n", NAME_CURRENT_COMP, coating));
    }
    if ((prms.theta_max - prms.theta_min) > ((tp->columns) * prms.theta_step)) {
      exit (fprintf (stderr, "Error: %s: theta_step does not match theta_min and theta_max in file %s (>)\n", NAME_CURRENT_COMP, coating));
    }
    prms.use_reflec_table = 1;
  } else {
    prms.use_reflec_table = 0;
  }
  #undef zdepth
  #undef xwidth
  #undef radius
  #undef radius_o
  #undef R0
  #undef coating
  #undef prms
  #undef reflec_table
  #undef re
  return(_comp);
} /* class_Mirror_toroid_pothole_init */

_class_Mirror *class_Mirror_init(_class_Mirror *_comp
) {
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define coating (_comp->_parameters.coating)
  #define R0 (_comp->_parameters.R0)
  #define geometry (_comp->_parameters.geometry)
  #define re (_comp->_parameters.re)
  #define offdata (_comp->_parameters.offdata)
  #define shape (_comp->_parameters.shape)
  SIG_MESSAGE("[_DISCO_M4_init] component DISCO_M4=Mirror() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:69]");

  int status = 0;

  if (coating && strlen (coating) && strcmp (coating, "NULL") && strcmp (coating, "0")) {
    status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
  } else {
    /*assume a constant reflectivity*/
    status = reflec_Init_const (&re, R0);
  }

  if (status != 0) {
    fprintf (stderr, "ERROR (%s): Could not interpret reflectivity. Aborting.\n", NAME_CURRENT_COMP);
    exit (-1);
  }

  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) {
    if (off_init (geometry, xwidth, yheight, zdepth, 0, &(offdata)))
      shape = ANY;
    else
      exit (fprintf (stderr, "ERROR (%s): Could not import geometry file %s\n", NAME_CURRENT_COMP, geometry));
  } else if (yheight || xwidth)
    shape = CUBE;
  else
    exit (fprintf (stderr, "ERROR (%s): invalid Mirror dimensions. Aborting.\n", NAME_CURRENT_COMP));
  #undef zdepth
  #undef xwidth
  #undef yheight
  #undef coating
  #undef R0
  #undef geometry
  #undef re
  #undef offdata
  #undef shape
  return(_comp);
} /* class_Mirror_init */

_class_Mirror_elliptic *class_Mirror_elliptic_init(_class_Mirror_elliptic *_comp
) {
  #define x_a (_comp->_parameters.x_a)
  #define y_b (_comp->_parameters.y_b)
  #define z_c (_comp->_parameters.z_c)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define radius (_comp->_parameters.radius)
  #define a2inv (_comp->_parameters.a2inv)
  #define b2inv (_comp->_parameters.b2inv)
  #define c2inv (_comp->_parameters.c2inv)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_DISCO_M51_init] component DISCO_M51=Mirror_elliptic() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_elliptic.comp:71]");

  int status;

  if (radius)
    x_a = y_b = z_c = radius;

  if (coating && strlen (coating) && strcmp (coating, "NULL")) {
    status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
  } else {
    /*assume a constant reflectivity*/
    status = reflec_Init (&re, CONSTANT, NULL, &(R0));
  }

  a2inv = (x_a) ? 1 / (x_a * x_a) : 0; /* 0 really means infinity for x direction */
  b2inv = (y_b) ? 1 / (y_b * y_b) : 0;
  c2inv = (z_c) ? 1 / (z_c * z_c) : 0;

  printf ("Component %s: initialized\n", NAME_CURRENT_COMP);

  fflush (NULL); // put diagnostics in order!

  // compatibility with older use
  if (zdepth)
    length = zdepth;
  if (xwidth)
    width = xwidth;
  #undef x_a
  #undef y_b
  #undef z_c
  #undef zdepth
  #undef xwidth
  #undef R0
  #undef coating
  #undef length
  #undef width
  #undef radius
  #undef a2inv
  #undef b2inv
  #undef c2inv
  #undef re
  return(_comp);
} /* class_Mirror_elliptic_init */

_class_Grating_reflect *class_Grating_reflect_init(_class_Grating_reflect *_comp
) {
  #define d_phi (_comp->_parameters.d_phi)
  #define R0 (_comp->_parameters.R0)
  #define rho_l (_comp->_parameters.rho_l)
  #define order (_comp->_parameters.order)
  #define phi0 (_comp->_parameters.phi0)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define verbose (_comp->_parameters.verbose)
  #define pdir (_comp->_parameters.pdir)
  #define d (_comp->_parameters.d)
  #define b (_comp->_parameters.b)
  #define nslits (_comp->_parameters.nslits)
  SIG_MESSAGE("[_DISCO_reflective_grating_init] component DISCO_reflective_grating=Grating_reflect() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Grating_reflect.comp:79]");

  int status;
  if (R0 < 0 || R0 > 1) {
    fprintf (stderr, "ERROR: (%s) reflectivity (%f) is specified but is not in [0:1]. \n", NAME_CURRENT_COMP, R0);
    exit (-1);
  }

  d = 1e7 / rho_l;                 /*grating pitch in Angstrom*/
  nslits = (zdepth * 1e3) * rho_l; /*the relative width of openings*/

  if (!b) {
    /* Approximated slit-width in Angstrom*/
    b = d / 3;
  }

  if (verbose) {
    printf ("INFO: (%s): Line width, d=%f [AA]. Number of slits,  N=%f. Slit width, b=%f [AA].\n \n", NAME_CURRENT_COMP, d, nslits, b);
  }

  /*We are not sampling the full 2pi range*/
  pdir = (((d_phi * DEG2RAD)) / (2 * M_PI));
  #undef d_phi
  #undef R0
  #undef rho_l
  #undef order
  #undef phi0
  #undef zdepth
  #undef xwidth
  #undef verbose
  #undef pdir
  #undef d
  #undef b
  #undef nslits
  return(_comp);
} /* class_Grating_reflect_init */

_class_Undulator *class_Undulator_init(_class_Undulator *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define dEe (_comp->_parameters.dEe)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define lu (_comp->_parameters.lu)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define sigepx (_comp->_parameters.sigepx)
  #define sigepy (_comp->_parameters.sigepy)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define quick_integ (_comp->_parameters.quick_integ)
  #define E1st (_comp->_parameters.E1st)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define length (_comp->_parameters.length)
  #define kc (_comp->_parameters.kc)
  #define pmul (_comp->_parameters.pmul)
  #define gap (_comp->_parameters.gap)
  #define Bsig (_comp->_parameters.Bsig)
  #define Bpi (_comp->_parameters.Bpi)
  #define gsl_int_ws (_comp->_parameters.gsl_int_ws)
  #define alpha (_comp->_parameters.alpha)
  #define MELE (_comp->_parameters.MELE)
  SIG_MESSAGE("[_CRISTAL_Source_init] component CRISTAL_Source=Undulator() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:129]");

  /*fine structure constant from CODATA*/
  alpha = 7.2973525698e-3;
  /*electron mass from CODATA in kg*/
  MELE = 9.10938291e-31;

  length = lu * Nper;

  if ((!E1st && !K && B <= 0) || Ee <= 0 || Ie <= 0) {
    fprintf (stderr, "Error (%s): E1st, K, B, Ee, and Ie do not have a sane set of values. Found (%g %g %g %g %g). Aborting.\n", NAME_CURRENT_COMP, E1st, K, B,
             Ee, Ie);
    exit (1);
  }

  /*compute gamma*/
  gamma = (Ee * 1e9) / (MELE / CELE * M_C * M_C); /*the extra CELE is to convert to eV*/
  gamma2 = gamma * gamma;
  igamma = 1.0 / gamma;

  if (E1st && lu && !K) {
    /*compute K and B from desired target energy*/
    K = 2 * (4 * M_PI * gamma2 / (E2K * E1st * lu * 1e10) - 1);
    if (K > 0)
      K = sqrt (K);
    else
      K = 0;
  } else if (!lu && E1st && K) {
    lu = 4 * M_PI * gamma2 / (K * K / 2 + 1) / (E2K * E1st * 1e10);
  }
  if (!K && B && lu) {
    K = CELE * B * lu / (2 * M_PI * MELE * M_C);
  } else if (!B && K && lu) {
    B = 2 * M_PI * MELE * M_C * K / CELE / lu;
  }
  if (!E1st && K && lu) {
    E1st = 4 * M_PI * gamma2 / (K * K / 2 + 1) / (E2K * lu * 1e10);
  }
  if (!E0 && E1st)
    E0 = E1st;

  if (E1st <= 0 || K <= 0 || B <= 0 || Ee <= 0 || Ie <= 0 || lu <= 0 || E0 <= 0) {
    fprintf (stderr, "Error (%s): (E1st, K, B, Ee, Ie, lu, E0) do not have a sane set of values. Found (%g %g %g %g %g %g %g). Aborting.\n", NAME_CURRENT_COMP,
             E1st, K, B, Ee, Ie, lu, E0);
    exit (1);
  }

  /* compute gap estimate */
  if (Br > B) { // remanent field, rather usual for Nd2Fe14B
    double a = 0.55 * Br + 2.835;
    double b = -1.95 * Br + 7.22;
    double c = -1.3 * Br + 2.97;
    gap = -log (B / a) * lu / b;
  } else
    gap = 3e-3;

  if (verbose)
    printf ("Undulator (%s) K=%g B=%g[T] lu=%g[m] E1st=%g[keV] E0=%g[keV] gap=%g[m]\n", NAME_CURRENT_COMP, K, B, lu, E1st, E0, gap);

  if (sigex < 0 || sigey < 0) {
    fprintf (stderr, "Error (%s): sigex (= %g) and sigey (= %g) must both be >= 0. Negative beam size isn't meaningful. Aborting.\n", NAME_CURRENT_COMP, sigex,
             sigey);
    exit (1);
  }
  if (dist <= 0 || focus_xw < 0 || focus_yh < 0) {
    fprintf (stderr, "Error (%s): Target undefined. Set dist, focus_xw and focus_yh.\n", NAME_CURRENT_COMP);
    exit (1);
  }

  // printf("Undulator (%s): gamma=%g, divergence is 1/gamma=%g rad.\n",NAME_CURRENT_COMP,gamma,igamma);
  /*compute characteristic energy in keV*/
  double Ec = 0.665 * Ee * Ee * B;
  // double Ec=1.5*gamma2*HBAR*CELE*B/MELE *1e-3; /*check units on this one. The 1e-3 factor is because energy is assumed to be in keV*/
  /*We normally do computations in k so use that for transfer*/
  kc = E2K * Ec;

  /*allocate an integration workspace*/
  if (!quick_integ) {
    gsl_int_ws = gsl_integration_workspace_alloc (1000);
  }
  Bsig.function = &mxundulator_Bsig_integrand;
  Bpi.function = &mxundulator_Bpi_integrand;
  gsl_set_error_handler_off ();

  /*correct for number of rays*/
  pmul = 1.0 / ((double)mcget_ncount ());

  /*correct for finite energy interval*/
  if (dE) {
    pmul *= dE * 2.0;
  }
  #undef E0
  #undef dE
  #undef phase
  #undef randomphase
  #undef Ee
  #undef dEe
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef lu
  #undef sigey
  #undef sigex
  #undef sigepx
  #undef sigepy
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef quick_integ
  #undef E1st
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef s1x
  #undef s1y
  #undef length
  #undef kc
  #undef pmul
  #undef gap
  #undef Bsig
  #undef Bpi
  #undef gsl_int_ws
  #undef alpha
  #undef MELE
  return(_comp);
} /* class_Undulator_init */

_class_Mirror_toroid *class_Mirror_toroid_init(_class_Mirror_toroid *_comp
) {
  #define coating (_comp->_parameters.coating)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define radius (_comp->_parameters.radius)
  #define radius_o (_comp->_parameters.radius_o)
  #define R0 (_comp->_parameters.R0)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_GALAXIES_M2A_init] component GALAXIES_M2A=Mirror_toroid() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_toroid.comp:60]");

  int status;
  if (coating && strlen (coating) && strcmp (coating, "NULL")) {
    status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
  } else {
    status = reflec_Init_const (&re, R0);
  }
  if (status != 0) {
    fprintf (stderr, "ERROR (%s): Could not interpret reflectivity. Aborting.\n", NAME_CURRENT_COMP);
    exit (-1);
  }
  #undef coating
  #undef zdepth
  #undef xwidth
  #undef radius
  #undef radius_o
  #undef R0
  #undef re
  return(_comp);
} /* class_Mirror_toroid_init */

_class_FluoCrystal *class_FluoCrystal_init(_class_FluoCrystal *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define sx_refl (_comp->_parameters.sx_refl)
  #define flag_sx (_comp->_parameters.flag_sx)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define barns (_comp->_parameters.barns)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define order (_comp->_parameters.order)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_coh_refl (_comp->_parameters.reuse_coh_refl)
  #define reuse_coh_xsect (_comp->_parameters.reuse_coh_xsect)
  #define reuse_tau_count (_comp->_parameters.reuse_tau_count)
  SIG_MESSAGE("[_GALAXIES_sample_init] component GALAXIES_sample=FluoCrystal() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoCrystal.comp:240]");


  /* energies en [keV], angles in [radians], XRL CSb cross sections are in [barn/atom] */
  double     E0, dE;
  xrl_error *error = NULL;
  int        i;

  XRayInit();

  shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere, 3:any-shape  */
  if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
    #ifndef USE_OFF
    fprintf(stderr,"Error: You are attempting to use an OFF geometry without -DUSE_OFF."
                   "You will need to recompile with that define set!\n");
    exit(-1);
    #else
    if (off_init(geometry, xwidth, yheight, zdepth, 0, &offdata)) {
      shape=3; thickness=0; concentric=0;
    }
    #endif
  }
  else if (xwidth && yheight && zdepth)  shape=1; /* box */
  else if (radius > 0 &&  yheight)       shape=0; /* cylinder */
  else if (radius > 0 && !yheight)       shape=2; /* sphere */

  if (shape < 0)
    exit(fprintf(stderr,"FluoCrystal: %s: sample has invalid dimensions.\n"
                        "ERROR       Please check parameter values (xwidth, yheight, zdepth, radius).\n", NAME_CURRENT_COMP));

  if (!material || !strlen(material) || !strcmp(material, "NULL") || !strcmp(material, "0"))
    exit(fprintf(stderr, "ERROR: FluoCrystal: %s: Null material specification.\n", NAME_CURRENT_COMP));

  if (order > 1 && flag_lorentzian)
    fprintf(stderr, "FluoCrystal: WARNING: %s: Using flag_lorentzian=1 Lorentzian line-shape with order>1 may create artifacts.\n", NAME_CURRENT_COMP);

  // test if the material is given as a file
  char formula[16384];
  formula[0]='\0';
  FILE *file = Open_File(material, "r", NULL);
  if (file != NULL) {
    fclose(file);
    // open the material structure file (laz/lau/cif...)
    // search (case sensitive) along lines
    if (!fluo_get_material(material, formula))
      exit(fprintf(stderr, "ERROR: FluoCrystal: %s: file %s does not contain material formulae.\n", NAME_CURRENT_COMP, material));

    MPI_MASTER(
    fprintf(stderr, "FluoCrystal: %s: found material %s from file %s\n",
            NAME_CURRENT_COMP, formula, material);
    );

    // load SX lines, when given as a valid file
    // set SX variables to default before reading file
    if (flag_sx) {
      strncpy(hkl_info.compname, NAME_CURRENT_COMP, 256);
      hkl_info.ctr_size=0;
      hkl_info.ctr_k   =NULL;
      hkl_info.ctr_FT2 =NULL;
      hkl_info.ctr_dir =NULL;
      /* transfer input parameters */
      hkl_info.m_delta_d_d = delta_d_d;
      hkl_info.m_a  = 0;
      hkl_info.m_b  = 0;
      hkl_info.m_c  = 0;
      hkl_info.m_aa = aa;
      hkl_info.m_bb = bb;
      hkl_info.m_cc = cc;
      hkl_info.m_ax = ax;
      hkl_info.m_ay = ay;
      hkl_info.m_az = az;
      hkl_info.m_bx = bx;
      hkl_info.m_by = by;
      hkl_info.m_bz = bz;
      hkl_info.m_cx = cx;
      hkl_info.m_cy = cy;
      hkl_info.m_cz = cz;
      hkl_info.recip= recip_cell;

      /* default format h,k,l,F,F2  */
      hkl_info.column_order[0]=1;
      hkl_info.column_order[1]=2;
      hkl_info.column_order[2]=3;
      hkl_info.column_order[3]=0;
      hkl_info.column_order[4]=7;
      hkl_info.kix = hkl_info.kiy = hkl_info.kiz = 0;
      hkl_info.nb_reuses = hkl_info.nb_refl = hkl_info.nb_refl_count = 0;
      hkl_info.tau_count = 0;
      hkl_info.flag_barns= barns;
      double* mosaic_ABin = mosaic_AB;

      if (!sx_refl || !strlen(sx_refl) || !strcmp(sx_refl, "NULL") || !strcmp(sx_refl, "0"))
        strcpy(sx_refl, material);
      i = read_hkl_data(sx_refl, &hkl_info, &hkl_list, mosaic, mosaic_a, mosaic_b, mosaic_c, mosaic_ABin,
                        hkl_info.ctr_size,hkl_info.ctr_k,hkl_info.ctr_FT2,hkl_info.ctr_dir); // returns hkl_info.count
      if (i == 0) {
        MPI_MASTER(
        fprintf(stderr,"WARNING: FluoCrystal: %s: mosaic or material file %s is not valid (CIF/LAU). Ignoring diffraction process.\n",
                      NAME_CURRENT_COMP, sx_refl);
        );
        flag_sx=0; // The failed read_hkl_data has set hkl_info.count = 0
      } else {
        MPI_MASTER(
          printf("FluoCrystal: %s: Read %d reflections from file '%s'\n",
                          NAME_CURRENT_COMP, hkl_info.count, sx_refl);
          printf("Direct space lattice orientation: Vc=%g [Angs^3]\n", hkl_info.V0);
          printf("  a  = [%g %g %g]\n", hkl_info.m_ax, hkl_info.m_ay, hkl_info.m_az);
          printf("  b  = [%g %g %g]\n", hkl_info.m_bx, hkl_info.m_by, hkl_info.m_bz);
          printf("  c  = [%g %g %g]\n", hkl_info.m_cx, hkl_info.m_cy, hkl_info.m_cz);
          printf("Reciprocal space lattice orientation:\n");
          printf("  a* = [%g %g %g]\n", hkl_info.asx, hkl_info.asy, hkl_info.asz);
          printf("  b* = [%g %g %g]\n", hkl_info.bsx, hkl_info.bsy, hkl_info.bsz);
          printf("  c* = [%g %g %g]\n", hkl_info.csx, hkl_info.csy, hkl_info.csz);
        );
      }
    }

    strncpy(material, formula, 16384);
    // CIF: _chemical_formula_structural 'chemical_formulae'
    // CIF: _chemical_formula_sum 'chemical_formulae'
    // LAZ/LAU: # ATOM <at> <trailing>
    // LAZ/LAU: # Atom <at> <trailing>
    // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
    // CFL: Title <chemical_formulae>
    // CFL: Atom <at> <trailing>

  }

  compound = CompoundParser(material, &error); /* XRayLib */
  if (error != NULL) {
    exit(fprintf(stderr, "ERROR: %s: Invalid material %s: %s\n",
      NAME_CURRENT_COMP, material, error->message));
  }
  xrl_error_free(error);

  /* compute total density for raw material and display information ========= */
  if (weight <= 0) weight = compound->molarMass; /* g/mol */
  MPI_MASTER(
    printf("%s: Material %s mass fractions:\n",
      NAME_CURRENT_COMP, material);
  )

  double mat_density       = 0; /* g/cm3 */
  double sum_massFractions = 0;
  cum_massFractions        = create_darr1d(compound->nElements+1);
  cum_xs_fluo              = create_darr1d(compound->nElements+1);
  cum_xs_Compton           = create_darr1d(compound->nElements+1);
  cum_xs_Rayleigh          = create_darr1d(compound->nElements+1);
  cum_massFractions[0]     = 0;

  /* print material information, and check for elements */
  for (i=0; i< compound->nElements; i++) {
    int    Z      = compound->Elements[i];
    error = NULL;
    double Z_dens = ElementDensity(Z, &error);
    if (error != NULL)
      exit(fprintf(stderr, "ERROR: %s: Z=%i %s\n", NAME_CURRENT_COMP, Z, error->message));
    mat_density           += compound->massFractions[i]*Z_dens;
    sum_massFractions     += compound->massFractions[i];
    cum_massFractions[i+1] = sum_massFractions;
    MPI_MASTER(
      printf("  | %6.2g %%: Z=%3i %3s %8.3g [g/mol] %8.3g [g/cm3]\n",
        compound->massFractions[i]*100, Z, AtomicNumberToSymbol(Z,NULL), AtomicWeight(Z, NULL),
        Z_dens);
    )
  }
  xrl_error_free(error);
  if (density <= 0)        density        = mat_density;   /* g/cm3 */
  if (packing_factor <= 0) packing_factor = density/mat_density;

  /* molar volume [cm^3/mol] = weight [g/mol] / density [g/cm^3] */
  /* atom density per Angs^3 = [mol/cm^3] * N_Avogadro *(1e-8)^3 */
  fluo_rho = density/weight/1e24*NA; // atom density [at/Angs-3]
  MPI_MASTER(
    printf("%s: Material %s M=%g [g/mol] density=%g [g/cm3] rho=%g [at/Angs-3]",
      NAME_CURRENT_COMP, material, weight, density, fluo_rho);
    if (fabs(packing_factor-1) > 1e-2)
      printf(" packing_factor=%g", packing_factor);
    printf("\n");
  );
  if (0 < packing_factor && packing_factor < 1) fluo_rho *= packing_factor;

  /* target for scattering ================================================== */
  if (!target_index && !target_x && !target_y && !target_z) target_index=1;
  if (target_index)
  {
    Coords ToTarget;
    ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP);
    ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget);
    coords_get(ToTarget, &target_x, &target_y, &target_z);
  }
  if (!(target_x || target_y || target_z)) {
    MPI_MASTER(
    printf("WARNING: FluoCrystal: %s: The target is not defined. Using 4PI for fluorescence.\n",
      NAME_CURRENT_COMP);
    );
  }

  n_fluo = n_Compton = n_Rayleigh = n_diff = 0;
  p_fluo = p_Compton = p_Rayleigh = p_diff = 0;

  // cached variables set to 0 (for SPLIT)
  reuse_nb=0;
  reuse_ki=reuse_l0=reuse_l1=reuse_l2=reuse_l3=reuse_sigma_barn=0;
  reuse_cum_xs_fluo              = create_darr1d(compound->nElements+1);
  reuse_cum_xs_Compton           = create_darr1d(compound->nElements+1);
  reuse_cum_xs_Rayleigh          = create_darr1d(compound->nElements+1);
  reuse_cum_xs_fluo[0]=reuse_cum_xs_Compton[0]=reuse_cum_xs_Rayleigh[0]=0;
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef sx_refl
  #undef flag_sx
  #undef delta_d_d
  #undef barns
  #undef recip_cell
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef aa
  #undef bb
  #undef cc
  #undef mosaic_AB
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef order
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef n_diff
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef p_diff
  #undef fluo_rho
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_cum_xs_diffraction
  #undef reuse_coh_refl
  #undef reuse_coh_xsect
  #undef reuse_tau_count
  return(_comp);
} /* class_FluoCrystal_init */

_class_Single_crystal *class_Single_crystal_init(_class_Single_crystal *_comp
) {
  #define reflections (_comp->_parameters.reflections)
  #define geometry (_comp->_parameters.geometry)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define barns (_comp->_parameters.barns)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define p_transmit (_comp->_parameters.p_transmit)
  #define sigma_inc (_comp->_parameters.sigma_inc)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define order (_comp->_parameters.order)
  #define extra_order (_comp->_parameters.extra_order)
  #define RX (_comp->_parameters.RX)
  #define RY (_comp->_parameters.RY)
  #define powder (_comp->_parameters.powder)
  #define deltak (_comp->_parameters.deltak)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define surf_size (_comp->_parameters.surf_size)
  #define surf_k (_comp->_parameters.surf_k)
  #define surf_FT2 (_comp->_parameters.surf_FT2)
  #define surf_dir (_comp->_parameters.surf_dir)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  SIG_MESSAGE("[_PX1_sample_init] component PX1_sample=Single_crystal() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1265]");


  double as, bs, cs;
  int i = 0;

  /* transfer input parameters */
  strncpy (hkl_info.compname, NAME_CURRENT_COMP, 256);
  hkl_info.m_delta_d_d = delta_d_d;
  hkl_info.m_a = 0;
  hkl_info.m_b = 0;
  hkl_info.m_c = 0;
  hkl_info.m_aa = aa;
  hkl_info.m_bb = bb;
  hkl_info.m_cc = cc;
  hkl_info.m_ax = ax;
  hkl_info.m_ay = ay;
  hkl_info.m_az = az;
  hkl_info.m_bx = bx;
  hkl_info.m_by = by;
  hkl_info.m_bz = bz;
  hkl_info.m_cx = cx;
  hkl_info.m_cy = cy;
  hkl_info.m_cz = cz;

  hkl_info.sigma_i = sigma_inc;
  hkl_info.recip = recip_cell;

  /* default format h,k,l,F,F2  */
  hkl_info.column_order[0] = 1;
  hkl_info.column_order[1] = 2;
  hkl_info.column_order[2] = 3;
  hkl_info.column_order[3] = 0;
  hkl_info.column_order[4] = 7;
  hkl_info.kix = hkl_info.kiy = hkl_info.kiz = 0;
  hkl_info.nb_reuses = hkl_info.nb_refl = hkl_info.nb_refl_count = 0;
  hkl_info.tau_count = 0;
  hkl_info.flag_barns = barns;

  // initial tests/warnings
  if (powder && !(order == 1)) {
    MPI_MASTER (fprintf (stderr,
                         "Single_crystal: %s: powder mode means implicit choice of no multiple scattering!\n"
                         "WARNING setting order=1\n",
                         NAME_CURRENT_COMP););
    order = 1;
  }
  if (powder && (RX || RY)) {
    exit (fprintf (stderr, "Single_crystal: %s: powder mode can not be used together with crystal curvature.\n", NAME_CURRENT_COMP));
  }

  /*this should not be in hkl_info*/
  hkl_info.shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere, 3:any-shape  */
  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) {
    #ifndef USE_OFF
    MPI_MASTER (
        fprintf (stderr,
                 "Single_crystal: %s: ERROR: You are attempting to use an OFF/PLY geometry without -DUSE_OFF. You will need to recompile with that define set!\n",
                 NAME_CURRENT_COMP););
    exit (-1);
    #else
    if (off_init (geometry, xwidth, yheight, zdepth, 0, &offdata)) {
      hkl_info.shape = 3;
    }
    #endif
  } else if (xwidth && yheight && zdepth)
    hkl_info.shape = 1; /* box */
  else if (radius > 0 && yheight)
    hkl_info.shape = 0; /* cylinder */
  else if (radius > 0 && !yheight)
    hkl_info.shape = 2; /* sphere */

  if (hkl_info.shape < 0)
    MPI_MASTER (fprintf (stderr,
                   "Single_crystal: %s: sample has invalid dimensions.\n"
                   "WARNING         Please check parameter values (xwidth, yheight, zdepth, radius).\n"
                   "                Component will be ignored.\n",
                   NAME_CURRENT_COMP););

  /* determine if we have a surface broadening/truncation rods (CTR) */
  hkl_info.ctr_size = surf_size;
  hkl_info.ctr_k = surf_k;
  hkl_info.ctr_FT2 = surf_FT2;
  hkl_info.ctr_dir = surf_dir;
  if (hkl_info.ctr_size < 0) { /* CTR automatic mode */
    double surf_dir_sum = 0;
    double surf_thickness = 0;
    for (i = 0; i < 3; hkl_info.ctr_dir[i++] = 0)
      ;
    if (hkl_info.shape == 1) {
      if (xwidth <= yheight && xwidth <= zdepth) {
        hkl_info.ctr_dir[0] = 1;
        surf_thickness = xwidth;
      } else if (yheight <= xwidth && yheight <= zdepth) {
        hkl_info.ctr_dir[1] = 1;
        surf_thickness = yheight;
      } else {
        hkl_info.ctr_dir[2] = 1;
        surf_thickness = zdepth;
      }
    } else if (hkl_info.shape == 0 && yheight <= radius) {
      hkl_info.ctr_dir[1] = 1;
      surf_thickness = yheight;
    }
    // surf_size=-1: set automatically the k and FT2 vectors
    if (0 < surf_thickness) {
      hkl_info.ctr_size = 21;                        // nb of satellite peaks
      double range_k = 1.0;                          // k range [1/Angs], k=[-range/2 : +range/2]
      double dk = range_k / (hkl_info.ctr_size - 1); // delta-k for btw satellites
      DArray1d s_k = create_darr1d (hkl_info.ctr_size);
      DArray1d s_F = create_darr1d (hkl_info.ctr_size);
      hkl_info.ctr_k = (double*)s_k;
      hkl_info.ctr_FT2 = (double*)s_F;
      for (i = 0; i < hkl_info.ctr_size; i++) {
        hkl_info.ctr_k[i] = -range_k / 2 + i * dk;                   // 1/Angs, symmetric around 0 [1/Angs]
        if (surf_thickness < 1e-7) {                                 // thin layer thickness < 0.1 um -> sinc^2
          double x = PI * hkl_info.ctr_k[i] * surf_thickness * 1e10; // 1e10 [m -> Angs]
          hkl_info.ctr_FT2[i] = hkl_info.ctr_k[i] ? sin (x) / x : 1;
        } else {                                                                               // assume a half-bulk -> 1/k^2 [in rlu]
          hkl_info.ctr_FT2[i] = hkl_info.ctr_k[i] ? 1 / (hkl_info.ctr_k[i] * 2 * PI) : 4 * PI; // we assume a=2PI
        }
        hkl_info.ctr_FT2[i] *= hkl_info.ctr_FT2[i]; // squared
      }
      MPI_MASTER (printf ("Single_crystal: %s: Info: Setting CTR surface normal XYZ=[%g,%g,%g], as a %s.\n", NAME_CURRENT_COMP, hkl_info.ctr_dir[0],
                          hkl_info.ctr_dir[1], hkl_info.ctr_dir[2], surf_thickness < 1e-7 ? "thin layer (sinc^2)" : "half-bulk (1/k^2)"););
    }
  }
  if (hkl_info.ctr_size > 1 && (!hkl_info.ctr_dir || !hkl_info.ctr_dir[0] && !hkl_info.ctr_dir[1] && !hkl_info.ctr_dir[2])) { // no CTR normal ?
    MPI_MASTER (printf ("Single_crystal: %s: Warning: No surf_dir surface normal set. Ignoring CTR.\n", i, NAME_CURRENT_COMP););
    hkl_info.ctr_size = 1;
  }
  if (hkl_info.ctr_size > 1 && hkl_info.ctr_FT2 && hkl_info.ctr_k) { // do some CTR tests
    double sum_FT2 = 0, min_k = FLT_MAX, max_k = -FLT_MAX;
    for (i = 0; i < hkl_info.ctr_size; i++) {
      if (hkl_info.ctr_FT2[i] < 0) {
        MPI_MASTER (printf ("Single_crystal: %s: Warning: surf_FT2[%i] < 0. Must all be >= 0. Ignoring CTR.\n", i, NAME_CURRENT_COMP););
        hkl_info.ctr_size = 1;
        break;
      }
      sum_FT2 += hkl_info.ctr_FT2[i];
      if (hkl_info.ctr_k[i] < min_k)
        min_k = hkl_info.ctr_k[i];
      if (max_k < hkl_info.ctr_k[i])
        max_k = hkl_info.ctr_k[i];
    }
    if (hkl_info.ctr_size > 1 && min_k * max_k >= 0) { // k vector not around 0 ?
      MPI_MASTER (printf ("Single_crystal: %s: Warning: surf_k = [%g:%g]. Must be around 0. Ignoring CTR.\n", min_k, max_k, NAME_CURRENT_COMP););
      hkl_info.ctr_size = 1;
    }
    if (hkl_info.ctr_size > 1 && sum_FT2 <= 0) { // no positive FT2 value ?
      MPI_MASTER (printf ("Single_crystal: %s: Warning: sum(surf_FT2) <= 0. Must be > 0. Ignoring CTR.\n", min_k, max_k, NAME_CURRENT_COMP););
      hkl_info.ctr_size = 1;
    }
    if (hkl_info.ctr_size > 1 && sum_FT2) {                                 // all is fine. Normalize CTR.
      NORM (hkl_info.ctr_dir[0], hkl_info.ctr_dir[1], hkl_info.ctr_dir[2]); // normal vector |u|=1
      // normalize surf_FT2 (distribute Bragg scattering along all satellites)
      for (i = 0; i < hkl_info.ctr_size; hkl_info.ctr_FT2[i++] /= sum_FT2)
        ;
    }
  } // if (CTR)

  /* ought to be cleaned up as mosaic_AB now is a proper vector/array and not a define */
  double* mosaic_ABin = mosaic_AB;
  /* Read in structure factors, and do some pre-calculations. */
  if (!read_hkl_data (reflections, &hkl_info, &hkl_list, 
       mosaic, mosaic_a, mosaic_b, mosaic_c, mosaic_ABin, 
       hkl_info.ctr_size, hkl_info.ctr_k, hkl_info.ctr_FT2,
       hkl_info.ctr_dir)) {
    MPI_MASTER (printf ("Single_crystal: %s: Can not set crystal structure.\n"
                        "WARNING             Check file and mosaic. Ignoring.\n", NAME_CURRENT_COMP););
    hkl_info.shape = -1; // ignore component. The failed read_hkl_data has set hkl_info.count = 0
  }
  if (!sx_read_abs_data (material_datafile, &abs_info, hkl_info))
    abs_info.muc = 0;

  if (hkl_info.sigma_i < 0)
    hkl_info.sigma_i = 0;

  // final information
  MPI_MASTER (
    if (hkl_info.count) { 
      printf ("Single_crystal: %s: Read %d reflections from file '%s'\n", 
        NAME_CURRENT_COMP, hkl_info.count, reflections); 
    }

    printf ("Single_crystal: %s: Vc=%g [Angs^3] sigma_inc=%g [barn] reflections=%s\n", 
            NAME_CURRENT_COMP, hkl_info.V0, hkl_info.sigma_i,
            reflections&& strlen (reflections) ? reflections : "NULL");
    printf ("Direct space lattice orientation:\n"); printf ("  a  = [%g %g %g]\n", hkl_info.m_ax, hkl_info.m_ay, hkl_info.m_az);
    printf ("  b  = [%g %g %g]\n", hkl_info.m_bx, hkl_info.m_by, hkl_info.m_bz);
    printf ("  c  = [%g %g %g]\n", hkl_info.m_cx, hkl_info.m_cy, hkl_info.m_cz); printf ("Reciprocal space lattice orientation:\n");
    printf ("  a* = [%g %g %g]\n", hkl_info.asx, hkl_info.asy, hkl_info.asz); printf ("  b* = [%g %g %g]\n", hkl_info.bsx, hkl_info.bsy, hkl_info.bsz);
    printf ("  c* = [%g %g %g]\n", hkl_info.csx, hkl_info.csy, hkl_info.csz);
  );
  #undef reflections
  #undef geometry
  #undef mosaic_AB
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef delta_d_d
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef recip_cell
  #undef barns
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef p_transmit
  #undef sigma_inc
  #undef aa
  #undef bb
  #undef cc
  #undef order
  #undef extra_order
  #undef RX
  #undef RY
  #undef powder
  #undef deltak
  #undef material_datafile
  #undef surf_size
  #undef surf_k
  #undef surf_FT2
  #undef surf_dir
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  return(_comp);
} /* class_Single_crystal_init */

_class_PSD_monitor_4PI *class_PSD_monitor_4PI_init(_class_PSD_monitor_4PI *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  SIG_MESSAGE("[_PX1_psd4pi_init] component PX1_psd4pi=PSD_monitor_4PI() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:55]");

  PSD_N = create_darr2d (nx, ny);
  PSD_p = create_darr2d (nx, ny);
  PSD_p2 = create_darr2d (nx, ny);

  // Use instance name for monitor output if no input was given
  if (!strcmp (filename, "\0"))
    sprintf (filename, "%s", NAME_CURRENT_COMP);
  #undef radius
  #undef restore_xray
  #undef nx
  #undef ny
  #undef filename
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  return(_comp);
} /* class_PSD_monitor_4PI_init */

_class_Saxs_spheres *class_Saxs_spheres_init(_class_Saxs_spheres *_comp
) {
  #define sphere_mtrl (_comp->_parameters.sphere_mtrl)
  #define R (_comp->_parameters.R)
  #define Phi (_comp->_parameters.Phi)
  #define Delta_rho (_comp->_parameters.Delta_rho)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define target_index (_comp->_parameters.target_index)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define focus_r (_comp->_parameters.focus_r)
  #define mu_c (_comp->_parameters.mu_c)
  #define my_s_pre (_comp->_parameters.my_s_pre)
  #define shape (_comp->_parameters.shape)
  #define Z (_comp->_parameters.Z)
  #define At (_comp->_parameters.At)
  #define rho (_comp->_parameters.rho)
  #define T (_comp->_parameters.T)
  #define mu_ci (_comp->_parameters.mu_ci)
  #define abs_data (_comp->_parameters.abs_data)
  SIG_MESSAGE("[_SWING_sample_test_init] component SWING_sample_test=Saxs_spheres() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Saxs_spheres.comp:74]");

  shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere  */
  if (xwidth && yheight && zdepth)
    shape = 1; /* box */
  else if (radius > 0 && yheight)
    shape = 0; /* cylinder */
  else if (radius > 0 && !yheight)
    shape = 2; /* sphere */

  if (shape < 0)
    exit (fprintf (stderr,
                   "Saxs_spheres: %s: sample has invalid dimensions.\n"
                   "ERROR     Please check parameter values.\n",
                   NAME_CURRENT_COMP));

  /* now compute target coords if a component index is supplied */
  if (!target_index && !target_x && !target_y && !target_z)
    target_index = 1;
  if (target_index) {
    Coords ToTarget;
    ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP);
    ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget);
    coords_get (ToTarget, &target_x, &target_y, &target_z);
  }

  if (!(target_x || target_y || target_z)) {
    printf ("Saxs_spheres: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP);
    target_z = 1;
  }
  /*check for existance of a sphere material datafile. If none is given absorption will be neglected.*/
  if (sphere_mtrl && strlen (sphere_mtrl) && strcmp (sphere_mtrl, "NULL")) {
    int status;
    if (sphere_mtrl && (status = Table_Read (&(T), sphere_mtrl, 0)) == -1) {
      fprintf (stderr, "Error(%s): Could not parse file \"%s\"\n", NAME_CURRENT_COMP, sphere_mtrl);
      exit (-1);
    }
    char** header_parsed;
    header_parsed = Table_ParseHeader (T.header, "Z", "A[r]", "rho", "Z/A", "sigma[a]", NULL);
    if (header_parsed[2]) {
      rho = strtod (header_parsed[2], NULL);
    }
    if (header_parsed[0]) {
      Z = strtod (header_parsed[0], NULL);
    }
    if (header_parsed[1]) {
      At = strtod (header_parsed[1], NULL);
    }
    /*which columns holds the mus*/
    if (mu_c) {
      mu_ci = mu_c;
    } else {
      /*not given so take a guess*/
      mu_ci = 5;
      if (T.columns == 3)
        mu_ci = 1;
    }
    abs_data = 1;
  } else {
    abs_data = 0;
  }
  my_s_pre = Phi * 4 * PI * R * R * R / 3 * Delta_rho * Delta_rho;
  #undef sphere_mtrl
  #undef R
  #undef Phi
  #undef Delta_rho
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef target_x
  #undef target_y
  #undef target_z
  #undef target_index
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef focus_r
  #undef mu_c
  #undef my_s_pre
  #undef shape
  #undef Z
  #undef At
  #undef rho
  #undef T
  #undef mu_ci
  #undef abs_data
  return(_comp);
} /* class_Saxs_spheres_init */

_class_SAXSPDBFast *class_SAXSPDBFast_init(_class_SAXSPDBFast *_comp
) {
  #define RhoSolvent (_comp->_parameters.RhoSolvent)
  #define Concentration (_comp->_parameters.Concentration)
  #define AbsorptionCrosssection (_comp->_parameters.AbsorptionCrosssection)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define SampleToDetectorDistance (_comp->_parameters.SampleToDetectorDistance)
  #define DetectorRadius (_comp->_parameters.DetectorRadius)
  #define qMin (_comp->_parameters.qMin)
  #define qMax (_comp->_parameters.qMax)
  #define NumberOfQBins (_comp->_parameters.NumberOfQBins)
  #define PDBFilepath (_comp->_parameters.PDBFilepath)
  #define Absorption (_comp->_parameters.Absorption)
  #define NumberDensity (_comp->_parameters.NumberDensity)
  #define qArray (_comp->_parameters.qArray)
  #define IArray (_comp->_parameters.IArray)
  SIG_MESSAGE("[_SWING_sample_init] component SWING_sample=SAXSPDBFast() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSPDBFast.comp:356]");

  // Protein properties
  ProteinStruct Protein;
  int qbin;

  // Rescale concentration into number of aggregates per m^3 times 10^-4
  NumberDensity = Concentration * 6.02214129e19;

  // Standard sample handling
  if (!xwidth || !yheight || !zdepth) {
    exit (fprintf (stderr, "SAXSPDBFast: %s: ERROR: Sample has no volume - check parameters.\n", NAME_CURRENT_COMP));
  }

  // count the number of residues
  Absorption = AbsorptionCrosssection;
  Protein.NumberOfResidues = CountResidues (PDBFilepath);
  Protein.Beads = calloc (Protein.NumberOfResidues, sizeof (BeadStruct));
  if (Protein.Beads == NULL)
    exit (fprintf (stderr, "SAXSPDB: %s: ERROR: memory allocation\n", NAME_CURRENT_COMP));

  qArray = create_darr1d (NumberOfQBins);
  IArray = create_darr1d (NumberOfQBins);

  // initialize the protein from the PDB
  ReadAminoPDB (PDBFilepath, &Protein);
  MPI_MASTER (printf ("SAXSPDBFast: %s: Initializing scattering from %s with %d residues on %d Q-values\n", NAME_CURRENT_COMP, PDBFilepath,
                      Protein.NumberOfResidues, NumberOfQBins););

  // Computing scattering profile I(q)
  for (qbin = 0; qbin < NumberOfQBins; ++qbin) {
    int i, j, ResidueID;
    double qStep = (qMax - qMin) / (1.0 * NumberOfQBins);
    double q = qMin + qStep * (qbin + 0.5);
    cdouble** Matrix = (cdouble**)matrix2d_new (sizeof (cdouble), SAXSPDBOrderOfHarmonics + 1, SAXSPDBOrderOfHarmonics + 1);
    // init Matrix = 0
    // ResetMatrix(Matrix, SAXSPDBOrderOfHarmonics);
    for (i = 0; i <= SAXSPDBOrderOfHarmonics; ++i)
      for (j = 0; j <= SAXSPDBOrderOfHarmonics; ++j)
        Matrix[i][j] = cplx (0, 0);

    for (ResidueID = 0; ResidueID < Protein.NumberOfResidues; ++ResidueID) {
      // ExpandStructure(Matrix, &Protein, ResidueID, qDummy, RhoSolvent);
      double Legendre[SAXSPDBOrderOfHarmonics + 1];
      double Bessel[SAXSPDBOrderOfHarmonics + 1];

      // Residue information
      const double Volume = Protein.Beads[ResidueID].Volume;
      const double DeltaRhoProtein = Protein.Beads[ResidueID].ScatteringLength - Volume * RhoSolvent;

      const double x
          = (Protein.Beads[ResidueID].x * Protein.Beads[ResidueID].ScatteringLength - RhoSolvent * Volume * Protein.Beads[ResidueID].xv) / DeltaRhoProtein;

      const double y
          = (Protein.Beads[ResidueID].y * Protein.Beads[ResidueID].ScatteringLength - RhoSolvent * Volume * Protein.Beads[ResidueID].yv) / DeltaRhoProtein;

      const double z
          = (Protein.Beads[ResidueID].z * Protein.Beads[ResidueID].ScatteringLength - RhoSolvent * Volume * Protein.Beads[ResidueID].zv) / DeltaRhoProtein;

      // Convert bead position to spherical coordinates
      const double Radius = sqrt (pow (x, 2) + pow (y, 2) + pow (z, 2));
      const double Theta = acos (z / Radius);
      const double C = acos (x / (Radius * sin (Theta))) * Sign (y);

      // Expand protein structure on harmonics
      gsl_sf_bessel_jl_array (SAXSPDBOrderOfHarmonics, q * Radius, Bessel);

      for (i = 0; i <= SAXSPDBOrderOfHarmonics; ++i) {
        gsl_sf_legendre_sphPlm_array (SAXSPDBOrderOfHarmonics, i, cos (Theta), &Legendre[i]);

        for (j = 0; j <= SAXSPDBOrderOfHarmonics; ++j) {
          if (j < i)
            Matrix[j][i] = cplx (0, 0);
          else
            Matrix[j][i] = cadd (Matrix[j][i],
                                 rmul (sqrt (4.0 * PI) * DeltaRhoProtein * Bessel[j] * Legendre[j], cmul (cpow (cplx (0, 1), cplx (j, 0)), Polar (1.0, -i * C))));
        }
      }

    } // for ResidueID

    qArray[qbin] = q;
    // IArray[qbin] = ComputeIntensity(Matrix, SAXSPDBOrderOfHarmonics);
    IArray[qbin] = 0;
    for (i = 0; i <= SAXSPDBOrderOfHarmonics; ++i) {
      for (j = 0; j <= i; ++j) {
        IArray[qbin] += ((j > 0) + 1.0) * pow (cabs (Matrix[i][j]), 2);
      }
    }
    // printf("I(q=%g) = %g\n", q, IArray[qbin]);
  } // for qbin
  MPI_MASTER (printf ("SAXSPDBFast: %s: %s initialization I(q) done\n", NAME_CURRENT_COMP, PDBFilepath););
  #undef RhoSolvent
  #undef Concentration
  #undef AbsorptionCrosssection
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef SampleToDetectorDistance
  #undef DetectorRadius
  #undef qMin
  #undef qMax
  #undef NumberOfQBins
  #undef PDBFilepath
  #undef Absorption
  #undef NumberDensity
  #undef qArray
  #undef IArray
  return(_comp);
} /* class_SAXSPDBFast_init */

_class_SAXSQMonitor *class_SAXSQMonitor_init(_class_SAXSQMonitor *_comp
) {
  #define RFilename (_comp->_parameters.RFilename)
  #define qFilename (_comp->_parameters.qFilename)
  #define NumberOfBins (_comp->_parameters.NumberOfBins)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define RadiusDetector (_comp->_parameters.RadiusDetector)
  #define DistanceFromSample (_comp->_parameters.DistanceFromSample)
  #define LambdaMin (_comp->_parameters.LambdaMin)
  #define Lambda0 (_comp->_parameters.Lambda0)
  #define qMax (_comp->_parameters.qMax)
  #define Nofq (_comp->_parameters.Nofq)
  #define Iofq (_comp->_parameters.Iofq)
  #define IofqSquared (_comp->_parameters.IofqSquared)
  #define NofR (_comp->_parameters.NofR)
  #define IofR (_comp->_parameters.IofR)
  #define IofRSquared (_comp->_parameters.IofRSquared)
  SIG_MESSAGE("[_SWING_QMonitor_init] component SWING_QMonitor=SAXSQMonitor() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSQMonitor.comp:63]");

  Nofq = create_darr1d (NumberOfBins);
  Iofq = create_darr1d (NumberOfBins);
  IofqSquared = create_darr1d (NumberOfBins);
  NofR = create_darr1d (NumberOfBins);
  IofR = create_darr1d (NumberOfBins);
  IofRSquared = create_darr1d (NumberOfBins);

  if (DistanceFromSample <= 0)
    exit (fprintf (stderr, "%s: ERROR: you must set the DistanceFromSample > 0.\n", NAME_CURRENT_COMP));

  if (qMax <= 0 && LambdaMin) {
    double TwoThetaMax = atan (RadiusDetector / DistanceFromSample);
    qMax = 4 * PI * sin (TwoThetaMax / 2.0) / LambdaMin;
  }

  // Use instance name for monitor output if no input was given
  if (!strcmp (RFilename, "\0"))
    sprintf (RFilename, "%s_R", NAME_CURRENT_COMP);
  if (!strcmp (qFilename, "\0"))
    sprintf (qFilename, "%s_Q", NAME_CURRENT_COMP);
  #undef RFilename
  #undef qFilename
  #undef NumberOfBins
  #undef restore_xray
  #undef RadiusDetector
  #undef DistanceFromSample
  #undef LambdaMin
  #undef Lambda0
  #undef qMax
  #undef Nofq
  #undef Iofq
  #undef IofqSquared
  #undef NofR
  #undef IofR
  #undef IofRSquared
  return(_comp);
} /* class_SAXSQMonitor_init */

_class_Divergence_monitor *class_Divergence_monitor_init(_class_Divergence_monitor *_comp
) {
  #define nh (_comp->_parameters.nh)
  #define nv (_comp->_parameters.nv)
  #define rad (_comp->_parameters.rad)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define maxdiv_h (_comp->_parameters.maxdiv_h)
  #define maxdiv_v (_comp->_parameters.maxdiv_v)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define Div_N (_comp->_parameters.Div_N)
  #define Div_p (_comp->_parameters.Div_p)
  #define Div_p2 (_comp->_parameters.Div_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_ROCK_slit3_div_init] component ROCK_slit3_div=Divergence_monitor() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Divergence_monitor.comp:69]");

  int i, j;

  xmax = xwidth / 2;
  xmin = -xmax;
  ymax = yheight / 2;
  ymin = -ymax;

  if ((xmin >= xmax) || (ymin >= ymax)) {
    printf ("ERROR: (%s): Null detection area! Exiting.\n", NAME_CURRENT_COMP);
    exit (-1);
  }

  Div_N = create_darr2d (nh, nv);
  Div_p = create_darr2d (nh, nv);
  Div_p2 = create_darr2d (nh, nv);

  NORM (nx, ny, nz);

  // Use instance name for monitor output if no input was given
  if (!strcmp (filename, "\0"))
    sprintf (filename, "%s", NAME_CURRENT_COMP);
  #undef nh
  #undef nv
  #undef rad
  #undef filename
  #undef xwidth
  #undef yheight
  #undef maxdiv_h
  #undef maxdiv_v
  #undef restore_xray
  #undef nx
  #undef ny
  #undef nz
  #undef nowritefile
  #undef Div_N
  #undef Div_p
  #undef Div_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_Divergence_monitor_init */

_class_Fluorescence *class_Fluorescence_init(_class_Fluorescence *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define rho (_comp->_parameters.rho)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define flag_low_z (_comp->_parameters.flag_low_z)
  #define order (_comp->_parameters.order)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define xs_fluo (_comp->_parameters.xs_fluo)
  #define xs_Compton (_comp->_parameters.xs_Compton)
  #define xs_Rayleigh (_comp->_parameters.xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_xs_fluo (_comp->_parameters.reuse_xs_fluo)
  #define reuse_xs_Compton (_comp->_parameters.reuse_xs_Compton)
  #define reuse_xs_Rayleigh (_comp->_parameters.reuse_xs_Rayleigh)
  SIG_MESSAGE("[_ROCK_absorption_sample_init] component ROCK_absorption_sample=Fluorescence() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:440]");


  /* energies en [keV], angles in [radians], XRL CSb cross sections are in [barn/atom] */
  xrl_error *error = NULL;
  int        i;
  
  XRayInit();
  
  shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere, 3:any-shape  */
  if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
    #ifndef USE_OFF
    fprintf(stderr,"Error: You are attempting to use an OFF geometry without -DUSE_OFF. You will need to recompile with that define set!\n");
    exit(-1);
    #else
    if (off_init(geometry, xwidth, yheight, zdepth, 0, &offdata)) {
      shape=3; thickness=0; concentric=0;
    }
    #endif
  }
  else if (xwidth && yheight && zdepth)  shape=1; /* box */
  else if (radius > 0 &&  yheight)       shape=0; /* cylinder */
  else if (radius > 0 && !yheight)       shape=2; /* sphere */

  if (shape < 0)
    exit(fprintf(stderr,"Fluorescence: %s: sample has invalid dimensions.\n"
                        "ERROR       Please check parameter values (xwidth, yheight, zdepth, radius).\n", NAME_CURRENT_COMP));
  
  if (!material || !strlen(material) || !strcmp(material, "NULL") || !strcmp(material, "0")) 
    exit(fprintf(stderr, "Fluorescence: ERROR: %s: Null material specification.\n", NAME_CURRENT_COMP));

  if (order > 1 && flag_lorentzian)
    fprintf(stderr, "Fluorescence: WARNING: %s: Using flag_lorentzian=1 Lorentzian line-shape with order>1 may create artifacts.\n", NAME_CURRENT_COMP);
    
  // test if the material is given as a file
  char path[1024];
  char formula[65536];
  formula[0]='\0';
  FILE *file = Open_File(material, "r", path);
  if (file != NULL) {
    fclose(file);
    // open the material structure file (laz/lau/cif...)
    // search (case sensitive) along lines
    if (!fluo_get_material(material, formula))
      exit(fprintf(stderr, "ERROR: %s: file %s does not contain material formulae.\n", NAME_CURRENT_COMP, material));
    
    MPI_MASTER(
    fprintf(stderr, "Fluorescence: INFO: %s: found material %s from file %s\n", NAME_CURRENT_COMP, formula, material);
    );
    strcpy(material, formula);
    // CIF: _chemical_formula_structural 'chemical_formulae'
    // CIF: _chemical_formula_sum 'chemical_formulae'
    // LAZ/LAU: # ATOM <at> <trailing>
    // LAZ/LAU: # Atom <at> <trailing>
    // LAZ/LAU: # TITLE <at> <at> ... [ trailing...]
    // CFL: Title <chemical_formulae>
    // CFL: Atom <at> <trailing>
    
  }
    
  compound = CompoundParser(material, &error); /* XRayLib */
  if (error != NULL) {
    exit(fprintf(stderr, "ERROR: %s: Invalid material %s: %s\n",
      NAME_CURRENT_COMP, material, error->message));
  }
  xrl_error_free(error);
  
  /* compute total density for raw material and display information ========= */  
  if (weight <= 0) weight = compound->molarMass; /* g/mol */
  MPI_MASTER(
    printf("%s: Material %s mass fractions:\n", 
      NAME_CURRENT_COMP, material);
  )
  
  double mat_density       = 0; /* g/cm3 */
  double sum_massFractions = 0;
  cum_massFractions        = create_darr1d(compound->nElements+1);
  cum_xs_fluo              = create_darr1d(compound->nElements+1);
  cum_xs_Compton           = create_darr1d(compound->nElements+1);
  cum_xs_Rayleigh          = create_darr1d(compound->nElements+1);
  xs_fluo                  = create_darr1d(compound->nElements+1);
  xs_Compton               = create_darr1d(compound->nElements+1);
  xs_Rayleigh              = create_darr1d(compound->nElements+1);
  cum_massFractions[0]     = 0;
  
  /* print material information, and check for elements */
  for (i=0; i< compound->nElements; i++) {
    int    Z      = compound->Elements[i];
    error = NULL;
    double Z_dens = ElementDensity(Z, &error);
    if (error != NULL)
      exit(fprintf(stderr, "ERROR: %s: Z=%i %s\n", NAME_CURRENT_COMP, Z, error->message));
    mat_density           += compound->massFractions[i]*Z_dens;
    sum_massFractions     += compound->massFractions[i];
    cum_massFractions[i+1] = sum_massFractions;
    MPI_MASTER(
      printf("  | %6.2g %%: Z=%3i %3s %8.3g [g/mol] %8.3g [g/cm3]\n",
        compound->massFractions[i]*100, Z, AtomicNumberToSymbol(Z,NULL), AtomicWeight(Z, NULL),
        Z_dens);
    )
  }
  xrl_error_free(error);
  if (density <= 0)        density        = mat_density;   /* g/cm3 */
  if (packing_factor <= 0) packing_factor = density/mat_density;
  
  /* molar volume [cm^3/mol] = weight [g/mol] / density [g/cm^3] */
  /* atom density per Angs^3 = [mol/cm^3] * N_Avogadro *(1e-8)^3 */
  if (!rho) rho = density/weight/1e24*NA; // atom density [at/Angs-3]
  MPI_MASTER(
    printf("%s: Material %s M=%g [g/mol] density=%g [g/cm3] rho=%g [at/Angs-3]",
      NAME_CURRENT_COMP, material, weight, density, rho);
    if (fabs(packing_factor-1) > 1e-2)
      printf(" packing_factor=%g", packing_factor);
    printf("\n");
  )
  if (0 < packing_factor && packing_factor < 1) rho *= packing_factor;
  
  /* target for scattering ================================================== */
  if (!target_index && !target_x && !target_y && !target_z) target_index=1;
  if (target_index)
  {
    Coords ToTarget;
    ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP);
    ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget);
    coords_get(ToTarget, &target_x, &target_y, &target_z);
  }
  if (!(target_x || target_y || target_z)) {
    MPI_MASTER(
    printf("Fluorescence: %s: The target is not defined. Using 4PI.\n",
      NAME_CURRENT_COMP);
    );
  }
  
  n_fluo = n_Compton = n_Rayleigh = 0;
  p_fluo = p_Compton = p_Rayleigh = 0;
  
  // cached variables set to 0 (for SPLIT)
  reuse_nb=0;
  reuse_ki=reuse_l0=reuse_l1=reuse_l2=reuse_l3=reuse_sigma_barn=0;
  reuse_cum_xs_fluo              = create_darr1d(compound->nElements+1);
  reuse_cum_xs_Compton           = create_darr1d(compound->nElements+1);
  reuse_cum_xs_Rayleigh          = create_darr1d(compound->nElements+1);
  reuse_xs_fluo                  = create_darr1d(compound->nElements+1);
  reuse_xs_Compton               = create_darr1d(compound->nElements+1);
  reuse_xs_Rayleigh              = create_darr1d(compound->nElements+1);
  reuse_cum_xs_fluo[0]=reuse_cum_xs_Compton[0]=reuse_cum_xs_Rayleigh[0]=0;
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef rho
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef flag_low_z
  #undef order
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef xs_fluo
  #undef xs_Compton
  #undef xs_Rayleigh
  #undef shape
  #undef offdata
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_xs_fluo
  #undef reuse_xs_Compton
  #undef reuse_xs_Rayleigh
  return(_comp);
} /* class_Fluorescence_init */

_class_Filter *class_Filter_init(_class_Filter *_comp
) {
  #define refraction (_comp->_parameters.refraction)
  #define fixed_delta (_comp->_parameters.fixed_delta)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define geometry (_comp->_parameters.geometry)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define mu_col (_comp->_parameters.mu_col)
  #define Z (_comp->_parameters.Z)
  #define mu_c (_comp->_parameters.mu_c)
  #define Ar (_comp->_parameters.Ar)
  #define rho (_comp->_parameters.rho)
  #define delta_prefactor (_comp->_parameters.delta_prefactor)
  #define betafact (_comp->_parameters.betafact)
  #define table (_comp->_parameters.table)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define filter_row (_comp->_parameters.filter_row)
  SIG_MESSAGE("[_ANATOMIX_sample_init] component ANATOMIX_sample=Filter() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Filter.comp:126]");

  int status = 0;

  /*if geometry is specified - try to read the off/ply file and set shape*/
  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) {
    if (off_init (geometry, xwidth, yheight, zdepth, 0, &(offdata)))
      shape = ANY;
  } else if (radius && yheight) {
    shape = CYLINDER;
  } else if (radius) {
    shape = SPHERE;
  } else if (xwidth && yheight && zdepth) {
    shape = CUBE;
  } else {
    fprintf (stderr, "Error (%s): Filter has zero effective volume\n", NAME_CURRENT_COMP);
    exit (-1);
  }

  if ((status = Table_Read (&(table), material_datafile, 0)) == -1) {
    fprintf (stderr, "Error (%s): Could not parse file \"%s\".\n", NAME_CURRENT_COMP, material_datafile);
    exit (-1);
  }
  char** header_parsed;
  header_parsed = Table_ParseHeader (table.header, "Z", "A[r]", "rho", "Z/A", "sigma[a]", NULL);
  if (header_parsed[0]) {
    Z = strtol (header_parsed[0], NULL, 10);
  }
  if (header_parsed[1]) {
    Ar = strtod (header_parsed[1], NULL);
  }
  if (header_parsed[2]) {
    rho = strtod (header_parsed[2], NULL);
  } else {
    fprintf (stderr, "Warning(%s): %s not found in header of %s, set to 1\n", NAME_CURRENT_COMP, "rho", material_datafile);
    rho = 1;
  }
  if (table.columns < 6) {
    // "Few or many" columns, use mu_col to pinpoint mu column location
    if (mu_col == -1 || mu_col >= table.columns) {
      fprintf (stderr,
               "Error(%s): Found %i columns in %s. Did NOT detect known NIST file format. Please give a relevant mu_col value to define the mu-column! Exit!\n",
               NAME_CURRENT_COMP, table.columns, material_datafile);
      exit (-1);
    } else {
      mu_c = mu_col;
      delta_prefactor = 0;
    }
  } else if (table.columns >= 6) {
    // ... fingers crossed this is "Legacy" NIST format
    if (mu_col == -1) {
      mu_c = 5;
    } else if (mu_col < table.columns) {
      mu_c = mu_col;
    } else {
      fprintf (stderr, "Error(%s): Found %i columns in %s and you gave a mu_col of %i. Please correct. Exit!\n", NAME_CURRENT_COMP, table.columns,
               material_datafile, mu_col);
      exit (-1);
    }
    delta_prefactor = NA * (rho * 1e-24) / Ar * 2.0 * M_PI * RE;
  }
  if (10 * (double)mcget_ncount () > (table.max_x - table.min_x) / (table.step_x)) {
    /*it is probably worth Rebinning*/
    printf ("%s: Rebinning material data (%s) for faster tracing...", NAME_CURRENT_COMP, material_datafile);
    Table_Rebin (&(table));
    printf ("done\n");
  }
  if (shape != CUBE) {
    if (refraction) {
      fprintf (stderr, "Warning(%s): refraction=1 not supported with chosen geometry\n", NAME_CURRENT_COMP);
      refraction = 0;
    }
  }
  #undef refraction
  #undef fixed_delta
  #undef material_datafile
  #undef geometry
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef mu_col
  #undef Z
  #undef mu_c
  #undef Ar
  #undef rho
  #undef delta_prefactor
  #undef betafact
  #undef table
  #undef shape
  #undef offdata
  #undef filter_row
  return(_comp);
} /* class_Filter_init */

_class_PSD_monitor_coh *class_PSD_monitor_coh_init(_class_PSD_monitor_coh *_comp
) {
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define ratio (_comp->_parameters.ratio)
  #define centering (_comp->_parameters.centering)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define PSD_phi_real (_comp->_parameters.PSD_phi_real)
  #define PSD_phi_imag (_comp->_parameters.PSD_phi_imag)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_NANO_psd_source_init] component NANO_psd_source=PSD_monitor_coh() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_coh.comp:77]");

  int i, j;

  xmax = xwidth / 2;
  xmin = -xmax;
  ymax = yheight / 2;
  ymin = -ymax;

  if ((xmin >= xmax) || (ymin >= ymax)) {
    fprintf (stderr, "ERROR (%s): Null detection area! Aborting.\n", NAME_CURRENT_COMP);
    exit (-1);
  }

  PSD_N = create_darr2d (nx, ny);
  PSD_p2 = create_darr2d (nx, ny);
  PSD_phi_real = create_darr2d (nx, ny);
  PSD_phi_imag = create_darr2d (nx, ny);

  // Use instance name for monitor output if no input was given
  if (!strcmp (filename, "\0"))
    sprintf (filename, "%s", NAME_CURRENT_COMP);
  #undef nx
  #undef ny
  #undef filename
  #undef restore_xray
  #undef xwidth
  #undef yheight
  #undef ratio
  #undef centering
  #undef nowritefile
  #undef PSD_N
  #undef PSD_p2
  #undef PSD_phi_real
  #undef PSD_phi_imag
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_coh_init */

_class_Fluo_detector *class_Fluo_detector_init(_class_Fluo_detector *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define escape_ratio (_comp->_parameters.escape_ratio)
  #define escape_energy (_comp->_parameters.escape_energy)
  #define pileup_ratio (_comp->_parameters.pileup_ratio)
  #define electronic_noise (_comp->_parameters.electronic_noise)
  #define resolution_energy (_comp->_parameters.resolution_energy)
  #define resolution (_comp->_parameters.resolution)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define E_N_pileup (_comp->_parameters.E_N_pileup)
  #define E_p_pileup (_comp->_parameters.E_p_pileup)
  #define E_p2_pileup (_comp->_parameters.E_p2_pileup)
  #define E_N_escape (_comp->_parameters.E_N_escape)
  #define E_p_escape (_comp->_parameters.E_p_escape)
  #define E_p2_escape (_comp->_parameters.E_p2_escape)
  #define shape (_comp->_parameters.shape)
  #define K (_comp->_parameters.K)
  #define p_sum (_comp->_parameters.p_sum)
  #define N_sum (_comp->_parameters.N_sum)
  SIG_MESSAGE("[_LUCIA_mon_spl_SDD_init] component LUCIA_mon_spl_SDD=Fluo_detector() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Fluo_detector.comp:110]");


  shape=-1; /* 0:cyl, 1:box, 2:sphere  */

  if (xwidth && yheight)            shape=1; /* rectangle */
  else if (radius > 0)              shape=0; /* disk      */
  else if (radius < 0)              shape=2; /* sphere    */
  else
    exit(fprintf(stderr,"Fluo_detector: %s: detector has invalid dimensions.\n"
                        "ERROR          Please check parameter values (xwidth, yheight, zdepth, radius).\n", NAME_CURRENT_COMP));

  // Use instance name for monitor output if no input was given
  if (!strcmp(filename,"\0")) sprintf(filename,"%s",NAME_CURRENT_COMP);

  // storage
  E_N        = create_darr1d(nE);
  E_p        = create_darr1d(nE);
  E_p2       = create_darr1d(nE);
  E_N_pileup = create_darr1d(nE);
  E_p_pileup = create_darr1d(nE);
  E_p2_pileup= create_darr1d(nE);
  E_N_escape = create_darr1d(nE);
  E_p_escape = create_darr1d(nE);
  E_p2_escape= create_darr1d(nE);
  p_sum=N_sum=0;

  // constant for resolution calculation
  if (resolution > electronic_noise && resolution_energy > 0)
    K = (resolution*resolution-electronic_noise*electronic_noise)/resolution_energy;
  else K=0;

  #undef radius
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef nE
  #undef filename
  #undef restore_xray
  #undef escape_ratio
  #undef escape_energy
  #undef pileup_ratio
  #undef electronic_noise
  #undef resolution_energy
  #undef resolution
  #undef flag_lorentzian
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef E_N_pileup
  #undef E_p_pileup
  #undef E_p2_pileup
  #undef E_N_escape
  #undef E_p_escape
  #undef E_p2_escape
  #undef shape
  #undef K
  #undef p_sum
  #undef N_sum
  return(_comp);
} /* class_Fluo_detector_init */

_class_Shape *class_Shape_init(_class_Shape *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define thickness (_comp->_parameters.thickness)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define center (_comp->_parameters.center)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_storage_init] component storage=Shape() INITIALISE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:79]");

  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) {
    if (off_init (geometry, xwidth, yheight, zdepth, !center, &offdata)) {
      thickness = 0;
    }
  }
  #undef geometry
  #undef radius
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef thickness
  #undef nx
  #undef ny
  #undef nz
  #undef center
  #undef offdata
  return(_comp);
} /* class_Shape_init */



int init(void) { /* called by mccode_main for SOLEIL:INITIALISE */
  DEBUG_INSTR();
  // Initialise rng
  srandom(_hash(mcseed-1));

  /* code_main/parseoptions/readparams sets instrument parameters value */
  stracpy(instrument->_name, "SOLEIL", 256);

  /* Instrument 'SOLEIL' INITIALISE */
  SIG_MESSAGE("[SOLEIL] INITIALISE [SOLEIL/SOLEIL_MARS/SOLEIL_MARS.instr:125]");
  #define splits (instrument->_parameters.splits)
  #define MARS_E0 (instrument->_parameters.MARS_E0)
  #define MARS_reflec_material_M12 (instrument->_parameters.MARS_reflec_material_M12)
  #define MARS_reflections (instrument->_parameters.MARS_reflections)
  #define MARS_dEr (instrument->_parameters.MARS_dEr)
  #define MARS_alpha (instrument->_parameters.MARS_alpha)
  #define PSICHE_E0 (instrument->_parameters.PSICHE_E0)
  #define PSICHE_dE (instrument->_parameters.PSICHE_dE)
  #define PSICHE_DCM_present (instrument->_parameters.PSICHE_DCM_present)
  #define PSICHE_sample_theta (instrument->_parameters.PSICHE_sample_theta)
  #define PSICHE_sample_material (instrument->_parameters.PSICHE_sample_material)
  #define PSICHE_sample_geometry (instrument->_parameters.PSICHE_sample_geometry)
  #define PSICHE_dcm_theta (instrument->_parameters.PSICHE_dcm_theta)
  #define DISCO_grazing_angle_one (instrument->_parameters.DISCO_grazing_angle_one)
  #define DISCO_HFP_shift (instrument->_parameters.DISCO_HFP_shift)
  #define DISCO_VFP_shift (instrument->_parameters.DISCO_VFP_shift)
  #define DISCO_second_HFP_shift (instrument->_parameters.DISCO_second_HFP_shift)
  #define DISCO_x_screw (instrument->_parameters.DISCO_x_screw)
  #define DISCO_scan (instrument->_parameters.DISCO_scan)
  #define PUMA_E0 (instrument->_parameters.PUMA_E0)
  #define PUMA_dE (instrument->_parameters.PUMA_dE)
  #define PUMA_DCM_theta (instrument->_parameters.PUMA_DCM_theta)
  #define PUMA_HFM_angle (instrument->_parameters.PUMA_HFM_angle)
  #define PUMA_HFM_focal (instrument->_parameters.PUMA_HFM_focal)
  #define PUMA_KB_angle (instrument->_parameters.PUMA_KB_angle)
  #define PUMA_KB_coating (instrument->_parameters.PUMA_KB_coating)
  #define PUMA_h (instrument->_parameters.PUMA_h)
  #define PUMA_k (instrument->_parameters.PUMA_k)
  #define PUMA_l (instrument->_parameters.PUMA_l)
  #define CRISTAL_E0 (instrument->_parameters.CRISTAL_E0)
  #define CRISTAL_dE (instrument->_parameters.CRISTAL_dE)
  #define CRISTAL_M1_angle (instrument->_parameters.CRISTAL_M1_angle)
  #define CRISTAL_M2_angle (instrument->_parameters.CRISTAL_M2_angle)
  #define CRISTAL_M1_radius (instrument->_parameters.CRISTAL_M1_radius)
  #define CRISTAL_M2_radius (instrument->_parameters.CRISTAL_M2_radius)
  #define CRISTAL_M_coating (instrument->_parameters.CRISTAL_M_coating)
  #define CRISTAL_reflections (instrument->_parameters.CRISTAL_reflections)
  #define GALAXIES_E0 (instrument->_parameters.GALAXIES_E0)
  #define GALAXIES_dE (instrument->_parameters.GALAXIES_dE)
  #define GALAXIES_hrm (instrument->_parameters.GALAXIES_hrm)
  #define GALAXIES_hrm_ref (instrument->_parameters.GALAXIES_hrm_ref)
  #define GALAXIES_sec_slits (instrument->_parameters.GALAXIES_sec_slits)
  #define GALAXIES_ana_R (instrument->_parameters.GALAXIES_ana_R)
  #define GALAXIES_ana_deg (instrument->_parameters.GALAXIES_ana_deg)
  #define GALAXIES_sample (instrument->_parameters.GALAXIES_sample)
  #define SAMBA_E0 (instrument->_parameters.SAMBA_E0)
  #define SAMBA_dE (instrument->_parameters.SAMBA_dE)
  #define SAMBA_M1_angle (instrument->_parameters.SAMBA_M1_angle)
  #define SAMBA_M2_angle (instrument->_parameters.SAMBA_M2_angle)
  #define SAMBA_sample (instrument->_parameters.SAMBA_sample)
  #define PX1_E0 (instrument->_parameters.PX1_E0)
  #define PX1_dE (instrument->_parameters.PX1_dE)
  #define PX1_K (instrument->_parameters.PX1_K)
  #define PX1_vfm_radius (instrument->_parameters.PX1_vfm_radius)
  #define PX1_hfm_radius (instrument->_parameters.PX1_hfm_radius)
  #define PX1_mirror_grazing_angle (instrument->_parameters.PX1_mirror_grazing_angle)
  #define PX1_det_dist (instrument->_parameters.PX1_det_dist)
  #define PX1_sample (instrument->_parameters.PX1_sample)
  #define PX1_rotX (instrument->_parameters.PX1_rotX)
  #define PX1_rotY (instrument->_parameters.PX1_rotY)
  #define PX1_rotZ (instrument->_parameters.PX1_rotZ)
  #define PX2a_E0 (instrument->_parameters.PX2a_E0)
  #define PX2a_hfm_radius (instrument->_parameters.PX2a_hfm_radius)
  #define PX2a_vfm_radius (instrument->_parameters.PX2a_vfm_radius)
  #define PX2a_mirror_grazing_angle (instrument->_parameters.PX2a_mirror_grazing_angle)
  #define PX2a_sample (instrument->_parameters.PX2a_sample)
  #define PX2a_rotX (instrument->_parameters.PX2a_rotX)
  #define PX2a_rotY (instrument->_parameters.PX2a_rotY)
  #define PX2a_rotZ (instrument->_parameters.PX2a_rotZ)
  #define SWING_E0 (instrument->_parameters.SWING_E0)
  #define SWING_dE (instrument->_parameters.SWING_dE)
  #define SWING_dcm_theta (instrument->_parameters.SWING_dcm_theta)
  #define SWING_hfm_radius (instrument->_parameters.SWING_hfm_radius)
  #define SWING_vfm_radius (instrument->_parameters.SWING_vfm_radius)
  #define SWING_mirror_grazing_angle (instrument->_parameters.SWING_mirror_grazing_angle)
  #define SWING_sample (instrument->_parameters.SWING_sample)
  #define SWING_sample_det (instrument->_parameters.SWING_sample_det)
  #define ROCK_E0 (instrument->_parameters.ROCK_E0)
  #define ROCK_dE (instrument->_parameters.ROCK_dE)
  #define ROCK_scan (instrument->_parameters.ROCK_scan)
  #define ROCK_angle_m2a_m2b (instrument->_parameters.ROCK_angle_m2a_m2b)
  #define ROCK_angle_m1 (instrument->_parameters.ROCK_angle_m1)
  #define ROCK_sample_file (instrument->_parameters.ROCK_sample_file)
  #define ROCK_reflec_material_M1 (instrument->_parameters.ROCK_reflec_material_M1)
  #define ROCK_reflec_material_M2A_M2B (instrument->_parameters.ROCK_reflec_material_M2A_M2B)
  #define ROCK_cc (instrument->_parameters.ROCK_cc)
  #define ANATOMIX_E0 (instrument->_parameters.ANATOMIX_E0)
  #define ANATOMIX_Emono (instrument->_parameters.ANATOMIX_Emono)
  #define ANATOMIX_dE (instrument->_parameters.ANATOMIX_dE)
  #define ANATOMIX_ANGLE (instrument->_parameters.ANATOMIX_ANGLE)
  #define ANATOMIX_sample (instrument->_parameters.ANATOMIX_sample)
  #define NANO_E0 (instrument->_parameters.NANO_E0)
  #define NANO_dE (instrument->_parameters.NANO_dE)
  #define NANO_Emono (instrument->_parameters.NANO_Emono)
  #define NANO_coating_m2 (instrument->_parameters.NANO_coating_m2)
  #define NANO_angle_m1_m2 (instrument->_parameters.NANO_angle_m1_m2)
  #define NANO_angle_kb1 (instrument->_parameters.NANO_angle_kb1)
  #define NANO_angle_kb2 (instrument->_parameters.NANO_angle_kb2)
  #define DIFFABS_E0 (instrument->_parameters.DIFFABS_E0)
  #define DIFFABS_dE (instrument->_parameters.DIFFABS_dE)
  #define DIFFABS_M1_angle (instrument->_parameters.DIFFABS_M1_angle)
  #define DIFFABS_M1_radius (instrument->_parameters.DIFFABS_M1_radius)
  #define DIFFABS_M2_radius (instrument->_parameters.DIFFABS_M2_radius)
  #define DIFFABS_DCM_theta (instrument->_parameters.DIFFABS_DCM_theta)
  #define DIFFABS_sample (instrument->_parameters.DIFFABS_sample)
  #define SIXS_E0 (instrument->_parameters.SIXS_E0)
  #define SIXS_dE (instrument->_parameters.SIXS_dE)
  #define SIXS_dcm_theta (instrument->_parameters.SIXS_dcm_theta)
  #define SIXS_M1_angle (instrument->_parameters.SIXS_M1_angle)
  #define SIXS_M1_radius (instrument->_parameters.SIXS_M1_radius)
  #define SIXS_M2_radius (instrument->_parameters.SIXS_M2_radius)
  #define SIXS_sample_coating (instrument->_parameters.SIXS_sample_coating)
  #define SIXS_sample_bulk (instrument->_parameters.SIXS_sample_bulk)
  #define SIXS_sample_thickness (instrument->_parameters.SIXS_sample_thickness)
  #define SIXS_sample_angle (instrument->_parameters.SIXS_sample_angle)
  #define CASSIOPEE_mirror_material (instrument->_parameters.CASSIOPEE_mirror_material)
  #define CASSIOPEE_undulator_index (instrument->_parameters.CASSIOPEE_undulator_index)
  #define CASSIOPEE_M1_angle (instrument->_parameters.CASSIOPEE_M1_angle)
  #define CASSIOPEE_PG_angle (instrument->_parameters.CASSIOPEE_PG_angle)
  #define CASSIOPEE_PM_angle (instrument->_parameters.CASSIOPEE_PM_angle)
  #define CASSIOPEE_E0 (instrument->_parameters.CASSIOPEE_E0)
  #define CASSIOPEE_dE (instrument->_parameters.CASSIOPEE_dE)
  #define CASSIOPEE_lambda (instrument->_parameters.CASSIOPEE_lambda)
  #define CASSIOPEE_beta_mono (instrument->_parameters.CASSIOPEE_beta_mono)
  #define CASSIOPEE_r_rho (instrument->_parameters.CASSIOPEE_r_rho)
  #define SIRIUS_E0 (instrument->_parameters.SIRIUS_E0)
  #define SIRIUS_dE (instrument->_parameters.SIRIUS_dE)
  #define SIRIUS_M1_angle (instrument->_parameters.SIRIUS_M1_angle)
  #define SIRIUS_M2_angle (instrument->_parameters.SIRIUS_M2_angle)
  #define SIRIUS_def_angle (instrument->_parameters.SIRIUS_def_angle)
  #define SIRIUS_sample_pos (instrument->_parameters.SIRIUS_sample_pos)
  #define SIRIUS_sample (instrument->_parameters.SIRIUS_sample)
  #define LUCIA_E0 (instrument->_parameters.LUCIA_E0)
  #define LUCIA_dE (instrument->_parameters.LUCIA_dE)
  #define LUCIA_dcm_theta (instrument->_parameters.LUCIA_dcm_theta)
  #define LUCIA_sample_material (instrument->_parameters.LUCIA_sample_material)
  #define LUCIA_sample_geometry (instrument->_parameters.LUCIA_sample_geometry)
{
    MARS_calculated_angle=RAD2DEG*asin(12398.42*sqrt(8)/(2*5.4309*(MARS_E0*1e3)));
    fprintf(stdout,"%s: Energy %g [keV] Mono Angle %g [deg]\n", NAME_INSTRUMENT, MARS_E0, MARS_calculated_angle);
    
   {
     double DM= 5.4909;     // Si d-spacing
     double d = DM/sqrt(3); // <111> reflection |<111>|=3
     PSICHE_dcm_gap  = 0.02;       // gap between the 2 monochromator crystals
     PSICHE_dcm_scatter = PSICHE_DCM_present;
     #pragma acc update device(PSICHE_dcm_scatter)
     
     if (PSICHE_DCM_present) {
       if (!PSICHE_dcm_theta && PSICHE_E0) {
         // n.lambda = 2 d sin(PSICHE_dcm_theta) = 2*PI/E2K / PSICHE_E0 with n=ORDER=1
         double sin_theta = 2*PI/E2K/PSICHE_E0 / 2 / d;
         if (fabs(sin_theta) < 1)
           PSICHE_dcm_theta = asin(sin_theta)*RAD2DEG;
       } else if (PSICHE_dcm_theta && !PSICHE_E0)
         PSICHE_E0 = 2*PI/E2K / (2*d*sin(PSICHE_dcm_theta*DEG2RAD));
       if (!PSICHE_dcm_theta || !PSICHE_E0 || PSICHE_dE <=0)
         exit(fprintf(stderr, "%s: ERROR: Monochromator can not reflect PSICHE_E0=%g +/- %g [keV]. Aborting.\n", NAME_INSTRUMENT, PSICHE_E0, PSICHE_dE));
       printf("%s: PSICHE_E0=%g [keV] Monochromator PSICHE_dcm_theta=%g [deg] \n", NAME_INSTRUMENT, PSICHE_E0, PSICHE_dcm_theta);
       if (fabs(PSICHE_dE/PSICHE_E0)>0.1) PSICHE_dE = 3e-2*PSICHE_E0;
     } else {
       PSICHE_dcm_gap=PSICHE_dcm_theta=0;
       printf("%s: PSICHE_E0=%g [keV] Monochromator OFF\n", NAME_INSTRUMENT, PSICHE_E0);
     }
   }
    //Our source ranges from 1.2 to 6.2 eV (imaging branch, other branches to come at a later date)
    DISCO_E0 = 0.0037;
    DISCO_dE = 0.0025;
    //For more information on the following see the Czerny_turner instrument
    DISCO_number_lines_per_mm = 1200;
    DISCO_theta_calculated = RAD2DEG*asin(DISCO_x_screw/164.61);
    DISCO_order=1;
    if (DISCO_theta_calculated<9){
      DISCO_order=-1;
    }
    DISCO_period = 1/(1e3*DISCO_number_lines_per_mm);    
    PUMA_HFM_angle *= RAD2DEG/1000;
    PUMA_KB_angle *= RAD2DEG/1000;

    {
      // HFM mirror
      double p_HFM = 21.0;
      PUMA_HFM_radius = 2*p_HFM*PUMA_HFM_focal / ((p_HFM+PUMA_HFM_focal) * (sin(PUMA_HFM_angle*DEG2RAD)));

      // DCM
      double DM = 5.4309;
      PUMA_d_hkl = DM/sqrt((PUMA_h*PUMA_h) + (PUMA_k*PUMA_k) + (PUMA_l*PUMA_l));
      PUMA_DCM_gap = 0.02;

      if(!PUMA_DCM_theta && PUMA_E0){
          double sin_theta = 2 * PI/E2K/PUMA_E0 /2 /PUMA_d_hkl;
          if(fabs(sin_theta) < 1)
              PUMA_DCM_theta = asin(sin_theta)*RAD2DEG;
      }
      else if (PUMA_DCM_theta && !PUMA_E0)
          PUMA_E0 = 2*PI/E2K / (2*PUMA_d_hkl*sin(PUMA_DCM_theta*DEG2RAD));

      if(!PUMA_DCM_theta || !PUMA_E0 || PUMA_dE <= 0)
          exit(fprintf(stderr, "%s: ERROR: Monochromator can't reflect PUMA_E0=%g +/- %g [Kev].\n",
              NAME_INSTRUMENT, PUMA_E0, PUMA_dE));

      MPI_MASTER(printf("%s: PUMA_E0=%g [keV] PUMA_DCM_theta=%g [deg] (hkl)=(%d %d %d) d=%g [A]\n",
              NAME_INSTRUMENT, PUMA_E0, PUMA_DCM_theta, PUMA_h,PUMA_k,PUMA_l, PUMA_d_hkl));
      
      if (fabs(PUMA_dE/PUMA_E0) > 0.1)
          PUMA_dE = 3e-2*PUMA_E0;

      // KB VFM
      double p_KB_VFM = 62.515, q_KB_VFM = 0.785;
      PUMA_KB_VFM_radius = 2*p_KB_VFM*q_KB_VFM / ((p_KB_VFM+q_KB_VFM) * (sin(PUMA_KB_angle*DEG2RAD)));

      // KB HFM
      double p_KB_HFM = 62.975, q_KB_HFM = 0.325;
      PUMA_KB_HFM_radius = 2*p_KB_HFM*q_KB_HFM / ((p_KB_HFM+q_KB_HFM) * (sin(PUMA_KB_angle*DEG2RAD)));
    }
  // Si(111): a=5.4309 Angs, d111 = a/sqrt(3)
  {
    double d = 5.4309/sqrt(3);
    double sin_theta = 12.398/(2*d*CRISTAL_E0);

    if (fabs(sin_theta) >= 1 || CRISTAL_E0 < 5 || CRISTAL_E0 > 30)
      exit(fprintf(stderr,
        "%s: ERROR: Si(111) can not reflect CRISTAL_E0=%g keV (valid range ~5-30 keV). Aborting.\n",
        NAME_INSTRUMENT, CRISTAL_E0));

    CRISTAL_DCM_theta = asin(sin_theta)*RAD2DEG;
  }

  MPI_MASTER(
  printf("%s: CRISTAL_E0=%g [keV] CRISTAL_dE=%g [keV]\n", NAME_INSTRUMENT, CRISTAL_E0, CRISTAL_dE);
  printf("%s: DCM theta=%g [deg]\n",   NAME_INSTRUMENT, CRISTAL_DCM_theta);
  printf("%s: Mirrors M1=%g [mrad] M2=%g [mrad]\n", NAME_INSTRUMENT, CRISTAL_M1_angle, CRISTAL_M2_angle);
  );

  CRISTAL_M1_angle *= RAD2DEG/1000;
  CRISTAL_M2_angle *= RAD2DEG/1000;
  {
    // --- DCM Si(111) Bragg angle from GALAXIES_E0
    double DM = 5.4909;      // Si d-spacing
    double d111 = DM/sqrt(3);
    double sin_theta = 2*PI/E2K/GALAXIES_E0 / 2 / d111;
    if (fabs(sin_theta) >= 1)
      exit(fprintf(stderr, "%s: ERROR: DCM Si(111) can not reflect E0=%g keV. Aborting.\n", NAME_INSTRUMENT, GALAXIES_E0));
    GALAXIES_dcm_theta = asin(sin_theta)*RAD2DEG;

    // --- KB mirrors: spherical approximation of the ellipse, R = 2 p q / (p+q)
    GALAXIES_vfm_radius = 2*GALAXIES_VFM_p*GALAXIES_VFM_q/(GALAXIES_VFM_p+GALAXIES_VFM_q);
    GALAXIES_hfm_radius = 2*GALAXIES_HFM_p*GALAXIES_HFM_q/(GALAXIES_HFM_p+GALAXIES_HFM_q);

    if (fabs(GALAXIES_dE/GALAXIES_E0) > 0.1) GALAXIES_dE = 0.1*GALAXIES_E0;
    MPI_MASTER(
      printf("%s: E0=%g [keV] DCM Si(111) theta=%g [deg]\n", NAME_INSTRUMENT, GALAXIES_E0, GALAXIES_dcm_theta);
      printf("%s: hrm=%d (%s) ana_R=%g m 2theta=%g deg\n",
        NAME_INSTRUMENT, GALAXIES_hrm, GALAXIES_hrm_ref, GALAXIES_ana_R, GALAXIES_ana_deg);
    );
  }
  {
  // 1. Monochromator Setup (Si 111)
  double DM= 5.4909; // Si d-spacing
  SAMBA_d_si = DM/sqrt(3); // Si(111) d-spacing
  SAMBA_dcm_gap  = 0.01;       // gap between the 2 monochromator crystals

  // Bragg angle calculation
  double lambda = 12.3984 / SAMBA_E0;
  double sin_theta = 2*PI/E2K/SAMBA_E0 / 2 / SAMBA_d_si;
  SAMBA_DCM_theta = asin(sin_theta)*RAD2DEG;

  // 2. Mirror Radii (Simplified model based on doc formulas)
  // R_M * sin(theta_M) = 2 * d (where d is distance to focus)
  // For collimation/focusing, we use the provided approximate values or angles.
  // Here we allow the user to set angles, and we estimate radius.
  SAMBA_M1_radius = (2.0 * 14.0) / sin(SAMBA_M1_angle * DEG2RAD);
  SAMBA_M2_radius = (2.0 * 11.5) / sin(SAMBA_M2_angle * DEG2RAD);

  MPI_MASTER(
    printf("%s: SAMBA_E0=%g [keV] SAMBA_DCM_theta=%g [deg]\n", NAME_INSTRUMENT, SAMBA_E0, SAMBA_DCM_theta);
    printf("%s: SAMBA_M1_angle=%g [mrad] SAMBA_M2_angle=%g [mrad]\n", NAME_INSTRUMENT, SAMBA_M1_angle, SAMBA_M2_angle);
  );
  
  SAMBA_M1_angle *= RAD2DEG/1000;
  SAMBA_M2_angle *= RAD2DEG/1000;
  }
  /* Si(111) Bragg angle for the channel-cut monochromator */
  {
    double arg=  12398.42*sqrt(3)/(2*5.4309*PX1_E0*1e3);
    if (fabs(arg) > 1)
      exit(fprintf(stderr, "ERROR: Monochromator can not reach this energy (arg=%g > 1)\n",
        arg));
    PX1_calculated_angle = RAD2DEG*asin(arg);
  }
  {
    double arg=  12398.42*sqrt(3)/(2*5.4309*PX2a_E0*1e3);
    if (fabs(arg) > 1)
      exit(fprintf(stderr, "ERROR: Monochromator can not reach this energy (arg=%g > 1)\n",
        arg));
    PX2a_calculated_angle = RAD2DEG*asin(arg);
    /* Ensure that we are running with at least 1e7 neutrons/core if not 'displaying' */
    #ifndef USE_MPI
    #define mpi_node_count 1
    #endif
    if (!mcdotrace) {
      if (mcget_ncount()<=1e7) {
        MPI_MASTER(printf("WARNING: This instrument needs at least %llu statistics to converge. Currently ncount=%llu to ",mpi_node_count*1e7, mcget_ncount()));
      }
    }
  }
  {
  double DM= 5.4909;     // Si d-spacing for the Monochromator
  double d = DM/sqrt(3); // <111> reflection |<111>|=3
  SWING_dcm_gap  = 0.02;       // gap between the 2 monochromator crystals
   
  if (!SWING_dcm_theta && SWING_E0) {
    // n.lambda = 2 d sin(SWING_dcm_theta) = 2*PI/E2K / SWING_E0 with n=ORDER=1
    double sin_theta = 2*PI/E2K/SWING_E0 / 2 / d;
    if (fabs(sin_theta) < 1)
      SWING_dcm_theta = asin(sin_theta)*RAD2DEG;
  } else if (SWING_dcm_theta && !SWING_E0)
    SWING_E0 = 2*PI/E2K / (2*d*sin(SWING_dcm_theta*DEG2RAD));
  if (!SWING_dcm_theta || !SWING_E0 || SWING_dE <=0)
    exit(fprintf(stderr, "%s: ERROR: Monochromator can not reflect SWING_E0=%g +/- %g [keV]. Aborting.\n", NAME_INSTRUMENT, SWING_E0, SWING_dE));
  SWING_Ki     = SWING_E0*E2K;
  SWING_Lambda = 2*PI/SWING_Ki;
  MPI_MASTER(
    printf("%s: SWING_E0=%g [keV] SWING_Ki=%g [1/Angs] SWING_Lambda=%g [Angs] Monochromator SWING_dcm_theta=%g [deg]\n", 
      NAME_INSTRUMENT, SWING_E0, SWING_dcm_theta, SWING_Ki, SWING_Lambda);
    if (!strlen(SWING_sample) || !strcmp(SWING_sample,"0") || !strcmp(SWING_sample,"NULL")) {
      SWING_flag_sample_sphere=1;
      printf("%s: Using ideal sample %s\n", NAME_INSTRUMENT, "Sphere colloid");
      strcpy(SWING_sample, "6lyz.pdb"); // avoid stop at init of SAXSPDBFast
    } else {
      SWING_flag_sample_sphere=0;
      printf("%s: Using PDB sample %s\n", NAME_INSTRUMENT, SWING_sample);
    }
  );
  if (fabs(SWING_dE/SWING_E0)>0.1) SWING_dE = 3e-2*SWING_E0;
  }
    ROCK_i_h=1;
    ROCK_i_k=1;
    ROCK_i_l=1;
    
    if(ROCK_cc>=3){ //automatically select the right ROCK_cc for the energy ROCK_E0
        if(ROCK_E0<=15.516){ 
            ROCK_cc = 2;
        }
        else if (ROCK_E0<=17.439){
            ROCK_cc = 1;
        }
        else if (ROCK_E0<=34.055){
            ROCK_cc = 0;	
        }
    }

    if(ROCK_cc<=0){ //ROCK_cc 220
        ROCK_Eminkev=5.62883;
        ROCK_Emaxkev=46.2834;
        ROCK_incr=0.995/(ROCK_Emaxkev-ROCK_Eminkev);
        ROCK_n=8;
        ROCK_i_h=2;
        ROCK_i_k=2;
        ROCK_i_l=0;
        ROCK_length_first_crystal=70e-3;
        ROCK_length_second_crystal=70e-3;
        ROCK_center_first_crystal=20;
        ROCK_dist_center_to_center = sqrt(0.01*0.01+0.07*0.07);
        /// ROCK_center_to_c_mono_angle is arctan(e/(ROCK_length_first_crystal/2 + ROCK_length_second_crystal/2))
        ROCK_center_to_c_mono_angle=0.14189;
    }
    else if (ROCK_cc<=1){ //ROCK_cc long 111
        ROCK_Eminkev=3.44694;
        ROCK_Emaxkev=28.3427;
        ROCK_incr=0.995/(ROCK_Emaxkev-ROCK_Eminkev);
        ROCK_n=3;
        ROCK_length_first_crystal=70e-3;
        ROCK_length_second_crystal=70e-3;
        ROCK_center_first_crystal=18.92;
        ROCK_dist_center_to_center = sqrt(0.01*0.01+0.07*0.07);
        ROCK_center_to_c_mono_angle=0.14189;
    } else if (ROCK_cc<=2){ //ROCK_cc short 111
        ROCK_Eminkev=3.44694;
        ROCK_Emaxkev=18.9143;
        ROCK_incr=0.995/(ROCK_Emaxkev-ROCK_Eminkev);
        ROCK_n=3;
        ROCK_length_first_crystal=50e-3;
        ROCK_length_second_crystal=70e-3;
        ROCK_center_first_crystal=19.25;
        ROCK_dist_center_to_center = sqrt(0.01*0.01+0.06*0.06);
        ROCK_center_to_c_mono_angle=0.1651;
    }

    ROCK_calculated_angle=RAD2DEG*asin(12.39842*sqrt(ROCK_n)/(2*5.4309*ROCK_E0));
    
    if (!ROCK_reflec_material_M2A_M2B || !strlen(ROCK_reflec_material_M2A_M2B) 
        || !strcmp(ROCK_reflec_material_M2A_M2B, "NULL") || !strcmp(ROCK_reflec_material_M2A_M2B, "0")) {

      if(ROCK_E0<=7.98){
          ROCK_reflec_material_M2A_M2B="B4C.dat";
      }
      else if (ROCK_E0<=16.46){
          ROCK_reflec_material_M2A_M2B="Pd.dat";
      }
      else if (ROCK_E0>16.46){
          ROCK_reflec_material_M2A_M2B="Pt.dat";
      }
    }
    
    MPI_MASTER(
    fprintf(stdout,"%s: Energy=%g [keV]n"
      "\tM2 mirror=%sn"
      "\tMonochromator Si<%i %i %i> angle %g [deg], config=%i\n", 
      NAME_INSTRUMENT, ROCK_E0, ROCK_reflec_material_M2A_M2B, ROCK_i_h,ROCK_i_k,ROCK_i_l, ROCK_calculated_angle, ROCK_cc);
    );

    sprintf(ROCK_e_repartition_options,"energy limits=[%g %g], y",
        ROCK_E0-0.02*ROCK_E0, ROCK_E0+0.02*ROCK_E0);  
    if (ANATOMIX_Emono==0) ANATOMIX_Emono=ANATOMIX_E0;
    
    if (ANATOMIX_E0-ANATOMIX_dE < ANATOMIX_Emono && ANATOMIX_Emono < ANATOMIX_E0+ANATOMIX_dE) {
    
      double arg=12398.42*sqrt(3)/(2*5.4309*ANATOMIX_Emono*1e3);
      if (fabs(arg) > 1)
        exit(printf("%s: ERROR: Monochromator can not reach this energy.\n", NAME_INSTRUMENT));
      ANATOMIX_calculated_angle = RAD2DEG*asin(arg);
    } else {
      exit(printf("%s: ERROR: Monochromator energy is outside the Undulator bandwidth.\n", NAME_INSTRUMENT));
    }
    sprintf(ANATOMIX_emonopts,"energy limits=[%g %g], y",ANATOMIX_E0-ANATOMIX_dE,ANATOMIX_E0+ANATOMIX_dE);
  {
    // COMPUTE THE BRAGG ANGLE -------------------------------------------------------------
    if (NANO_Emono==0) NANO_Emono=NANO_E0;
    
    // check if NANO_Emono is accessible and calculate the coresponding Bragg angle (if possible)
    if (NANO_E0-NANO_dE < NANO_Emono && NANO_Emono < NANO_E0+NANO_dE) {

      double arg= (12.39842*sqrt(3)) / (2*5.4309*NANO_Emono);
      if (fabs(arg) > 1)
        exit(printf("%s: ERROR: Monochromator can not reach this energy.\n", NAME_INSTRUMENT));
       NANO_angle_dcm = RAD2DEG*asin(arg);
       NANO_delta_dcm = 0.02 / tan(2.0*DEG2RAD*NANO_angle_dcm);
    } else {
      exit(printf("%s: ERROR: Monochromator energy is outside the Undulator bandwidth.\n", NAME_INSTRUMENT));
    }

    // COMPUTE THE 1st HARMONIC FOR UNDULATOR ---------------------------------------------
    // search the largest odd harmonic so that K is valid (K>0 and K<K_max)
    double K_max = 1.95;
    int harmonic=1;
    double K=0;
    double Ee=2.75; // in GeV
    double lambda_u = 18; // in cm

    while ((K<=0 || K>K_max ) && harmonic < 51) {  // check if K is valid for the undulator
        NANO_E1_target = NANO_E0 / harmonic;
        double K2 = 2.0*( (0.95*Ee*Ee)/(NANO_E1_target*lambda_u) - 1);

        if (K2>=0) K = sqrt(K2);
        harmonic += 2;
    }
    harmonic -=2;
    if (harmonic==51) {printf("Harmonic = %d, has stopped. NANO_E1_target = %g and K = %g \n", harmonic,NANO_E1_target, K);}
    printf("With the selected energy %g keV, the calculated first harmonic is : harmonic %d = %g keV. \n", NANO_E0, harmonic, NANO_E1_target);
    printf("The corresponding K is : %g\n", K);

    // SET STRIPE USED IN M2 MIRROR --------------------------------------------------------
    if (NANO_coating_m2==0) {
        // uncoated surface_
        sprintf(NANO_material_coating_m2,"Si.txt");
    } else if (NANO_coating_m2==1) {
        // coated surface
        sprintf(NANO_material_coating_m2,"Rh.txt");
    } else {
        exit(printf("%s: ERROR: Invalid coating for M2, must be 0 (uncoated) or 1 (coated).\n", NAME_INSTRUMENT));
    }
    /*
    // COMPUTE FOCAL LENGTH OF ZONE PLATE
    // the beam is approximately 100micrometers extended while entering in the zone plate -> diameter will be 100e-6m. We want a 50nm beam after the zone plate (Rayleigh criterion) delta_r_N = 40nm.
    f_fresnel = (100e-6 * 40e-9 * NANO_E0) / 12.39842;
    */
  }
  
  // DCM
  {
    double DM= 5.4909;     // Si d-spacing
    double d = DM/sqrt(3); // <111> reflection |<111>|=3
    DIFFABS_dcm_gap  = 0.01;       // gap between the 2 monochromator crystals

    if (!DIFFABS_DCM_theta && DIFFABS_E0) {
    // n.lambda = 2 d sin(theta) = 2*PI/E2K / DIFFABS_E0 with n=ORDER=1
    double sin_theta = 2*PI/E2K/DIFFABS_E0 / 2 / d;
    if (fabs(sin_theta) < 1)
      DIFFABS_DCM_theta = asin(sin_theta)*RAD2DEG;
    } else if (DIFFABS_DCM_theta && !DIFFABS_E0)
      DIFFABS_E0 = 2*PI/E2K / (2*d*sin(DIFFABS_DCM_theta*DEG2RAD));
      
    // M1 mirror
    if (!DIFFABS_M1_angle) {
      if (19   <= DIFFABS_E0)               DIFFABS_M1_angle=2.4;
      if (12.5 <= DIFFABS_E0 && DIFFABS_E0 < 19)    DIFFABS_M1_angle=3;
      if (6.5  <= DIFFABS_E0 && DIFFABS_E0 < 12.5)  DIFFABS_M1_angle=5;
      if (DIFFABS_E0   < 6.5)               DIFFABS_M1_angle=6;
    }
  }
  
  if (!DIFFABS_DCM_theta || !DIFFABS_E0 || DIFFABS_dE <=0)
     exit(fprintf(stderr, "%s: ERROR: Monochromator can not reflect DIFFABS_E0=%g +/- %g [keV]. Aborting.\n", NAME_INSTRUMENT, DIFFABS_E0, DIFFABS_dE));
  MPI_MASTER(
  printf("%s: DIFFABS_E0=%g [keV] DIFFABS_M1_angle=%g [mrad] %g [deg]\n", NAME_INSTRUMENT, DIFFABS_E0, DIFFABS_M1_angle, DIFFABS_M1_angle*RAD2DEG/1000);
  printf("%s: Monochromator theta=%g [deg]\n",            NAME_INSTRUMENT, DIFFABS_DCM_theta);
  );
  
  DIFFABS_M1_angle *= RAD2DEG/1000;
  {
    double DM= 5.4909;     // Si d-spacing for the Monochromator
    double d = DM/sqrt(3); // <111> reflection |<111>|=3
    SIXS_dcm_gap  = 0.02;       // gap between the 2 monochromator crystals
     
    if (!SIXS_dcm_theta && SIXS_E0) {
      // n.lambda = 2 d sin(SIXS_dcm_theta) = 2*PI/E2K / SIXS_E0 with n=ORDER=1
      double sin_theta = 2*PI/E2K/SIXS_E0 / 2 / d;
      if (fabs(sin_theta) < 1)
        SIXS_dcm_theta = asin(sin_theta)*RAD2DEG;
    } else if (SIXS_dcm_theta && !SIXS_E0)
      SIXS_E0 = 2*PI/E2K / (2*d*sin(SIXS_dcm_theta*DEG2RAD));
    if (!SIXS_dcm_theta || !SIXS_E0 || SIXS_dE <=0)
      exit(fprintf(stderr, "%s: ERROR: Monochromator can not reflect SIXS_E0=%g +/- %g [keV]. Aborting.\n", NAME_INSTRUMENT, SIXS_E0, SIXS_dE));
    MPI_MASTER(
    printf("%s: SIXS_E0=%g [keV] Monochromator SIXS_dcm_theta=%g [deg] \n", NAME_INSTRUMENT, SIXS_E0, SIXS_dcm_theta);
    );
    if (fabs(SIXS_dE/SIXS_E0)>0.1) SIXS_dE = 3e-2*SIXS_E0;
    SIXS_M1_angle *= RAD2DEG/1000;
    
    if (!strlen(SIXS_sample_coating) || strcmp(SIXS_sample_coating,"0") || strcmp(SIXS_sample_coating,"NULL")) {
      SIXS_sample_thickness=0;
    }
  }
#define sqr(x) ((x)*(x))

double cos_alpha= 0;
double c        = 0.2;  // Petersen law coefficient sin(b) / sin(a) = c = 0.2 */
double order    = 1;

{ // use block to protect local variables
  // source choice
  if (!CASSIOPEE_E0 && !CASSIOPEE_lambda) {
    if (CASSIOPEE_undulator_index == 1)      CASSIOPEE_E0 = 300e-3;
    else if (CASSIOPEE_undulator_index == 2) CASSIOPEE_E0 = 40e-3;
  }

  if (CASSIOPEE_lambda && !CASSIOPEE_E0) CASSIOPEE_E0     = 1.24125e-6/CASSIOPEE_lambda;
  else if (!CASSIOPEE_lambda && CASSIOPEE_E0) CASSIOPEE_lambda = 1.24125e-6/CASSIOPEE_E0;

  if (!CASSIOPEE_M1_angle) CASSIOPEE_M1_angle = (CASSIOPEE_undulator_index == 1 ? 2.44 : 5.02); // degrees
  if (!CASSIOPEE_r_rho)    CASSIOPEE_r_rho    = (CASSIOPEE_undulator_index == 1 ? 1600 : 400 ); // lines/mm

  /* grating deviation angles */
  cos_alpha = (-CASSIOPEE_r_rho*CASSIOPEE_lambda + sqrt( sqr(c*CASSIOPEE_r_rho*CASSIOPEE_lambda) + sqr(1 - sqr(c)) ))/(1 - sqr(c) );

  if (!CASSIOPEE_PG_angle)  // alpha angle = incoming, order = 0
    CASSIOPEE_PG_angle  = RAD2DEG*acos( cos_alpha );
    
  if (!CASSIOPEE_beta_mono) // beta angle  = outging,  order = 1
    CASSIOPEE_beta_mono = RAD2DEG*acos( cos_alpha + order*CASSIOPEE_r_rho*CASSIOPEE_lambda );

  if (!CASSIOPEE_PM_angle) 
    CASSIOPEE_PM_angle = (CASSIOPEE_PG_angle + CASSIOPEE_beta_mono)/2;
}

MPI_MASTER(
printf("%s: Undulator %s CASSIOPEE_E0=%g [eV] CASSIOPEE_lambda=%g [Angs] CASSIOPEE_M1_angle=%g [deg] CASSIOPEE_PG_angle=%g [deg] CASSIOPEE_PM_angle=%g [deg]\n", 
  NAME_INSTRUMENT,
  CASSIOPEE_undulator_index == 1 ? "HU60":"HU256",
  CASSIOPEE_E0, CASSIOPEE_lambda, 
  CASSIOPEE_M1_angle, CASSIOPEE_PG_angle, CASSIOPEE_PM_angle);
);

  {
  // 1. Monochromator Setup (Si 111)
  double DM= 5.4909;     // Si d-spacing
  double d = DM/sqrt(3); // <111> reflection |<111>|=3
  double sin_theta = 2*PI/E2K/SIRIUS_E0 / 2 / d;
  SIRIUS_DCM_theta = asin(sin_theta)*RAD2DEG;
  SIRIUS_dcm_gap  = 0.01;       // gap between the 2 monochromator crystals

  // 2. Mirror Radii (Approximation based on typical vertical focusing)
  SIRIUS_M1_radius = 1000.0; 
  SIRIUS_M2_radius = 1000.0;
  SIRIUS_def_mirror_radius = 1000.0;

  MPI_MASTER(
    printf("%s: SIRIUS_E0=%g [keV] SIRIUS_DCM_theta=%g [deg]\n", NAME_INSTRUMENT, SIRIUS_E0, SIRIUS_DCM_theta);
    printf("%s: SIRIUS_M1_angle=%g [mrad] SIRIUS_M2_angle=%g [mrad] Deflect=%g [mrad]\n", NAME_INSTRUMENT, SIRIUS_M1_angle, SIRIUS_M2_angle, SIRIUS_def_angle);
  );
  
  SIRIUS_M1_angle *= RAD2DEG/1000;
  SIRIUS_M2_angle *= RAD2DEG/1000;
  SIRIUS_def_angle *= RAD2DEG/1000;
  }
  {
    double DM= 5.4909;     // Si d-spacing
    double d = DM/sqrt(3); // <111> reflection |<111>|=3
    LUCIA_dcm_gap  = 0.02;       // gap between the 2 monochromator crystals
     
    if (!LUCIA_dcm_theta && LUCIA_E0) {
      // n.lambda = 2 d sin(LUCIA_dcm_theta) = 2*PI/E2K / LUCIA_E0 with n=ORDER=1
      double sin_theta = 2*PI/E2K/LUCIA_E0 / 2 / d;
      if (fabs(sin_theta) < 1)
        LUCIA_dcm_theta = asin(sin_theta)*RAD2DEG;
    } else if (LUCIA_dcm_theta && !LUCIA_E0)
      LUCIA_E0 = 2*PI/E2K / (2*d*sin(LUCIA_dcm_theta*DEG2RAD));
  }
  if (!LUCIA_dcm_theta || !LUCIA_E0 || LUCIA_dE <=0)
    exit(fprintf(stderr, "%s: ERROR: Monochromator can not reflect LUCIA_E0=%g +/- %g [keV]. Aborting.\n", NAME_INSTRUMENT, LUCIA_E0, LUCIA_dE));
  MPI_MASTER(
    printf("%s: LUCIA_E0=%g [keV] Monochromator LUCIA_dcm_theta=%g [deg] \n", NAME_INSTRUMENT, LUCIA_E0, LUCIA_dcm_theta);
  );
  if (fabs(LUCIA_dE/LUCIA_E0)>0.1) LUCIA_dE = 3e-2*LUCIA_E0;
}
  #undef splits
  #undef MARS_E0
  #undef MARS_reflec_material_M12
  #undef MARS_reflections
  #undef MARS_dEr
  #undef MARS_alpha
  #undef PSICHE_E0
  #undef PSICHE_dE
  #undef PSICHE_DCM_present
  #undef PSICHE_sample_theta
  #undef PSICHE_sample_material
  #undef PSICHE_sample_geometry
  #undef PSICHE_dcm_theta
  #undef DISCO_grazing_angle_one
  #undef DISCO_HFP_shift
  #undef DISCO_VFP_shift
  #undef DISCO_second_HFP_shift
  #undef DISCO_x_screw
  #undef DISCO_scan
  #undef PUMA_E0
  #undef PUMA_dE
  #undef PUMA_DCM_theta
  #undef PUMA_HFM_angle
  #undef PUMA_HFM_focal
  #undef PUMA_KB_angle
  #undef PUMA_KB_coating
  #undef PUMA_h
  #undef PUMA_k
  #undef PUMA_l
  #undef CRISTAL_E0
  #undef CRISTAL_dE
  #undef CRISTAL_M1_angle
  #undef CRISTAL_M2_angle
  #undef CRISTAL_M1_radius
  #undef CRISTAL_M2_radius
  #undef CRISTAL_M_coating
  #undef CRISTAL_reflections
  #undef GALAXIES_E0
  #undef GALAXIES_dE
  #undef GALAXIES_hrm
  #undef GALAXIES_hrm_ref
  #undef GALAXIES_sec_slits
  #undef GALAXIES_ana_R
  #undef GALAXIES_ana_deg
  #undef GALAXIES_sample
  #undef SAMBA_E0
  #undef SAMBA_dE
  #undef SAMBA_M1_angle
  #undef SAMBA_M2_angle
  #undef SAMBA_sample
  #undef PX1_E0
  #undef PX1_dE
  #undef PX1_K
  #undef PX1_vfm_radius
  #undef PX1_hfm_radius
  #undef PX1_mirror_grazing_angle
  #undef PX1_det_dist
  #undef PX1_sample
  #undef PX1_rotX
  #undef PX1_rotY
  #undef PX1_rotZ
  #undef PX2a_E0
  #undef PX2a_hfm_radius
  #undef PX2a_vfm_radius
  #undef PX2a_mirror_grazing_angle
  #undef PX2a_sample
  #undef PX2a_rotX
  #undef PX2a_rotY
  #undef PX2a_rotZ
  #undef SWING_E0
  #undef SWING_dE
  #undef SWING_dcm_theta
  #undef SWING_hfm_radius
  #undef SWING_vfm_radius
  #undef SWING_mirror_grazing_angle
  #undef SWING_sample
  #undef SWING_sample_det
  #undef ROCK_E0
  #undef ROCK_dE
  #undef ROCK_scan
  #undef ROCK_angle_m2a_m2b
  #undef ROCK_angle_m1
  #undef ROCK_sample_file
  #undef ROCK_reflec_material_M1
  #undef ROCK_reflec_material_M2A_M2B
  #undef ROCK_cc
  #undef ANATOMIX_E0
  #undef ANATOMIX_Emono
  #undef ANATOMIX_dE
  #undef ANATOMIX_ANGLE
  #undef ANATOMIX_sample
  #undef NANO_E0
  #undef NANO_dE
  #undef NANO_Emono
  #undef NANO_coating_m2
  #undef NANO_angle_m1_m2
  #undef NANO_angle_kb1
  #undef NANO_angle_kb2
  #undef DIFFABS_E0
  #undef DIFFABS_dE
  #undef DIFFABS_M1_angle
  #undef DIFFABS_M1_radius
  #undef DIFFABS_M2_radius
  #undef DIFFABS_DCM_theta
  #undef DIFFABS_sample
  #undef SIXS_E0
  #undef SIXS_dE
  #undef SIXS_dcm_theta
  #undef SIXS_M1_angle
  #undef SIXS_M1_radius
  #undef SIXS_M2_radius
  #undef SIXS_sample_coating
  #undef SIXS_sample_bulk
  #undef SIXS_sample_thickness
  #undef SIXS_sample_angle
  #undef CASSIOPEE_mirror_material
  #undef CASSIOPEE_undulator_index
  #undef CASSIOPEE_M1_angle
  #undef CASSIOPEE_PG_angle
  #undef CASSIOPEE_PM_angle
  #undef CASSIOPEE_E0
  #undef CASSIOPEE_dE
  #undef CASSIOPEE_lambda
  #undef CASSIOPEE_beta_mono
  #undef CASSIOPEE_r_rho
  #undef SIRIUS_E0
  #undef SIRIUS_dE
  #undef SIRIUS_M1_angle
  #undef SIRIUS_M2_angle
  #undef SIRIUS_def_angle
  #undef SIRIUS_sample_pos
  #undef SIRIUS_sample
  #undef LUCIA_E0
  #undef LUCIA_dE
  #undef LUCIA_dcm_theta
  #undef LUCIA_sample_material
  #undef LUCIA_sample_geometry
  _origin_setpos(); /* type Arm */
  _jumper_setpos(); /* type Arm */
  _beamdump_setpos(); /* type Beamstop */
  _ODE_pos_setpos(); /* type Text */
  _SMIS_pos_setpos(); /* type Text */
  _AILES_pos_setpos(); /* type Text */
  _MARS_pos_setpos(); /* type Text */
  _MARS_setpos(); /* type Arm */
  _MARS_Source_setpos(); /* type Bending_magnet */
  _MARS_displaySourceLength_setpos(); /* type Monitor_nD */
  _MARS_displaySource_setpos(); /* type PSD_monitor */
  _MARS_slit1_setpos(); /* type Slit */
  _MARS_slit2_setpos(); /* type Slit */
  _MARS_M1_arm_translation_setpos(); /* type Arm */
  _MARS_M1_arm_rotation_1_setpos(); /* type Arm */
  _MARS_mirror_M1_setpos(); /* type Mirror_curved */
  _MARS_M1_arm_rotation_2_setpos(); /* type Arm */
  _MARS_M1_arm_rotation_2_undo_setpos(); /* type Arm */
  _MARS_beam_arm_before_crystal_setpos(); /* type Arm */
  _MARS_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _MARS_dcm0_setpos(); /* type Arm */
  _MARS_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _MARS_dcm1_setpos(); /* type Arm */
  _MARS_emon_dcm0_setpos(); /* type E_monitor */
  _MARS_displayMono_setpos(); /* type PSD_monitor */
  _MARS_displayMonoLength_setpos(); /* type E_monitor */
  _MARS_M2_arm_translation_setpos(); /* type Arm */
  _MARS_M2_arm_rotation_1_setpos(); /* type Arm */
  _MARS_mirror_M2_setpos(); /* type Mirror_curved */
  _MARS_M2_arm_rotation_2_setpos(); /* type Arm */
  _MARS_M2_arm_rotation_2_undo_setpos(); /* type Arm */
  _MARS_slitSecon1_setpos(); /* type Slit */
  _MARS_slitSecon2_setpos(); /* type Slit */
  _MARS_emon_dcm1_setpos(); /* type E_monitor */
  _MARS_displaySlit2_setpos(); /* type PSD_monitor */
  _MARS_Sample_setpos(); /* type FluoPowder */
  _MARS_detector_diffraction_setpos(); /* type Monitor_nD */
  _MARS_detector_fluo_setpos(); /* type Monitor_nD */
  _beamdump_40_setpos(); /* type Beamstop */
  _PSICHE_pos_setpos(); /* type Text */
  _PSICHE_setpos(); /* type Arm */
  _PSICHE_source_setpos(); /* type Wiggler */
  _PSICHE_mon_src_e_setpos(); /* type Monitor_nD */
  _PSICHE_mon_src_xy_setpos(); /* type Monitor_nD */
  _PSICHE_DCM_location_setpos(); /* type Arm */
  _PSICHE_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _PSICHE_dcm0_setpos(); /* type Arm */
  _PSICHE_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _PSICHE_dcm1_setpos(); /* type Arm */
  _PSICHE_mon_dcm_e_setpos(); /* type Monitor_nD */
  _PSICHE_mon_dcm_xy_setpos(); /* type Monitor_nD */
  _PSICHE_slit_setpos(); /* type Slit */
  _PSICHE_sample_stage_setpos(); /* type Arm */
  _PSICHE_sample_setpos(); /* type FluoPowder */
  _PSICHE_fluo_holder_setpos(); /* type Arm */
  _PSICHE_mon_spl_fluo_setpos(); /* type Monitor_nD */
  _PSICHE_mon_spl_e_setpos(); /* type Monitor_nD */
  _PSICHE_mon_spl_xy_setpos(); /* type Monitor_nD */
  _beamdump_61_setpos(); /* type Beamstop */
  _PLEIADES_pos_setpos(); /* type Text */
  _DISCO_pos_setpos(); /* type Text */
  _DISCO_setpos(); /* type Arm */
  _DISCO_Source_setpos(); /* type Bending_magnet */
  _DISCO_ColdFinger_setpos(); /* type Mask */
  _DISCO_M1_location_setpos(); /* type Arm */
  _DISCO_M1_rotated_setpos(); /* type Arm */
  _DISCO_M1_x_setpos(); /* type Arm */
  _DISCO_M1_setpos(); /* type Mirror_curved */
  _DISCO_M1_takeoff_setpos(); /* type Arm */
  _DISCO_M1_x_takeoff_setpos(); /* type Arm */
  _DISCO_M2_location_setpos(); /* type Arm */
  _DISCO_M2_rotated_x_setpos(); /* type Arm */
  _DISCO_M2_rotated_setpos(); /* type Arm */
  _DISCO_M2_other_side_setpos(); /* type Arm */
  _DISCO_M2_setpos(); /* type Mirror_toroid_pothole */
  _DISCO_M2_other_side_back_setpos(); /* type Arm */
  _DISCO_M2_takeoff_setpos(); /* type Arm */
  _DISCO_HFP_location_setpos(); /* type Arm */
  _DISCO_HFP_setpos(); /* type PSD_monitor */
  _DISCO_M3_arm_setpos(); /* type Arm */
  _DISCO_M3_setpos(); /* type Mirror_curved */
  _DISCO_M3_takeoff_setpos(); /* type Arm */
  _DISCO_M3_yz_setpos(); /* type Arm */
  _DISCO_M4_yz_setpos(); /* type Arm */
  _DISCO_M4_setpos(); /* type Mirror */
  _DISCO_M4_takeoff_setpos(); /* type Arm */
  _DISCO_M4_arm_back_setpos(); /* type Arm */
  _DISCO_VFP_location_setpos(); /* type Arm */
  _DISCO_VFP_setpos(); /* type PSD_monitor */
  _DISCO_M51_position_setpos(); /* type Arm */
  _DISCO_M51_rotation_setpos(); /* type Arm */
  _DISCO_M51_setpos(); /* type Mirror_elliptic */
  _DISCO_arm_setpos(); /* type Arm */
  _DISCO_M51_arm_back_setpos(); /* type Arm */
  _DISCO_M52_position_setpos(); /* type Arm */
  _DISCO_M52_x_setpos(); /* type Arm */
  _DISCO_M52_setpos(); /* type Mirror_curved */
  _DISCO_M52_takeoff_setpos(); /* type Arm */
  _DISCO_M52_x_takeoff_setpos(); /* type Arm */
  _DISCO_second_HFP_location_setpos(); /* type Arm */
  _DISCO_second_HFP_setpos(); /* type PSD_monitor */
  _DISCO_M53_location_setpos(); /* type Arm */
  _DISCO_M53_rotated_setpos(); /* type Arm */
  _DISCO_M53_setpos(); /* type Mirror_toroid_pothole */
  _DISCO_M53_takeoff_setpos(); /* type Arm */
  _DISCO_M54_location_setpos(); /* type Arm */
  _DISCO_M54_rotated_setpos(); /* type Arm */
  _DISCO_M54_setpos(); /* type Mirror_toroid_pothole */
  _DISCO_M54_takeoff_setpos(); /* type Arm */
  _DISCO_Mtoroids_arm_back_setpos(); /* type Arm */
  _DISCO_M1_position_setpos(); /* type Arm */
  _DISCO_M1_rotation_setpos(); /* type Arm */
  _DISCO_mirror_m1_setpos(); /* type Mirror_elliptic */
  _DISCO_armm_setpos(); /* type Arm */
  _DISCO_M1_arm_back_setpos(); /* type Arm */
  _DISCO_Grating_position_setpos(); /* type Arm */
  _DISCO_Grating_rotation_setpos(); /* type Arm */
  _DISCO_Grating_rotation_lines_grating_setpos(); /* type Arm */
  _DISCO_Grating_rotation_nine_degrees_setpos(); /* type Arm */
  _DISCO_reflective_grating_setpos(); /* type Grating_reflect */
  _DISCO_Grating_rotation_lines_grating_back_setpos(); /* type Arm */
  _DISCO_Grating_arm_back_setpos(); /* type Arm */
  _DISCO_Grating_arm_back_2_setpos(); /* type Arm */
  _DISCO_Grating_arm_back_3_setpos(); /* type Arm */
  _DISCO_M22_location_setpos(); /* type Arm */
  _DISCO_M22_rotated_setpos(); /* type Arm */
  _DISCO_mirror_m2_setpos(); /* type Mirror_elliptic */
  _DISCO_arm2_setpos(); /* type Arm */
  _DISCO_M44_arm_back_setpos(); /* type Arm */
  _DISCO_arm3_setpos(); /* type Arm */
  _DISCO_psd_before_slit_setpos(); /* type PSD_monitor */
  _DISCO_slit_setpos(); /* type Slit */
  _DISCO_psd_monitor_setpos(); /* type PSD_monitor */
  _DISCO_psd_giant_after_grating_setpos(); /* type PSD_monitor */
  _DISCO_e_monitor_setpos(); /* type Monitor_nD */
  _DISCO_w_monitor_setpos(); /* type Monitor_nD */
  _beamdump_140_setpos(); /* type Beamstop */
  _DESIRS_pos_setpos(); /* type Text */
  _METRO_pos_setpos(); /* type Text */
  _PUMA_pos_setpos(); /* type Text */
  _PUMA_setpos(); /* type Arm */
  _PUMA_Source_setpos(); /* type Wiggler */
  _PUMA_slit1_setpos(); /* type Slit */
  _PUMA_slit2_setpos(); /* type Slit */
  _PUMA_mon_src_e_setpos(); /* type E_monitor */
  _PUMA_mon_src_xy_setpos(); /* type PSD_monitor */
  _PUMA_HFM_location_setpos(); /* type Arm */
  _PUMA_HFM_rotated_setpos(); /* type Arm */
  _PUMA_mirror_HFM_setpos(); /* type Mirror_curved */
  _PUMA_HFM_out_setpos(); /* type Arm */
  _PUMA_mon_HFM_out_xy_setpos(); /* type PSD_monitor */
  _PUMA_DCM_location_setpos(); /* type Arm */
  _PUMA_DCM_xtal1_setpos(); /* type Bragg_crystal */
  _PUMA_DCM_xtal1_out_setpos(); /* type Arm */
  _PUMA_mon_DCM_xtal1_only_xy_setpos(); /* type PSD_monitor */
  _PUMA_DCM_xtal2_setpos(); /* type Bragg_crystal */
  _PUMA_DCM_xtal2_out_setpos(); /* type Arm */
  _PUMA_mon_DCM_out_e_setpos(); /* type E_monitor */
  _PUMA_mon_DCM_out_xy_setpos(); /* type PSD_monitor */
  _PUMA_slit3_setpos(); /* type Slit */
  _PUMA_slit4_setpos(); /* type Slit */
  _PUMA_slit5_setpos(); /* type Slit */
  _PUMA_KB_VFM_location_setpos(); /* type Arm */
  _PUMA_mon_KB_in_xy_setpos(); /* type PSD_monitor */
  _PUMA_KB_VFM_rotated_setpos(); /* type Arm */
  _PUMA_mirror_KB_VFM_setpos(); /* type Mirror_curved */
  _PUMA_KB_VFM_out_setpos(); /* type Arm */
  _PUMA_mon_KB_VFM_out_xy_setpos(); /* type PSD_monitor */
  _PUMA_KB_HFM_location_setpos(); /* type Arm */
  _PUMA_KB_HFM_rotated_setpos(); /* type Arm */
  _PUMA_mirror_KB_HFM_setpos(); /* type Mirror_curved */
  _PUMA_KB_HFM_out_setpos(); /* type Arm */
  _PUMA_mon_KB_HFM_out_xy_setpos(); /* type PSD_monitor */
  _PUMA_sample_location_setpos(); /* type Arm */
  _PUMA_mon_sample_xy_setpos(); /* type PSD_monitor */
  _PUMA_mon_sample_e_setpos(); /* type E_monitor */
  _beamdump_181_setpos(); /* type Beamstop */
  _CRISTAL_pos_setpos(); /* type Text */
  _CRISTAL_setpos(); /* type Arm */
  _CRISTAL_Source_setpos(); /* type Undulator */
  _CRISTAL_slit1_setpos(); /* type Slit */
  _CRISTAL_dcm_location_setpos(); /* type Arm */
  _CRISTAL_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _CRISTAL_arm_xtal0_setpos(); /* type Arm */
  _CRISTAL_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _CRISTAL_arm_xtal1_setpos(); /* type Arm */
  _CRISTAL_emon_dcm_setpos(); /* type E_monitor */
  _CRISTAL_M1_location_setpos(); /* type Arm */
  _CRISTAL_M1_rotated_setpos(); /* type Arm */
  _CRISTAL_M1_setpos(); /* type Mirror_curved */
  _CRISTAL_M1_out_setpos(); /* type Arm */
  _CRISTAL_M2_location_setpos(); /* type Arm */
  _CRISTAL_M2_rotated_setpos(); /* type Arm */
  _CRISTAL_M2_setpos(); /* type Mirror_curved */
  _CRISTAL_M2_out_setpos(); /* type Arm */
  _CRISTAL_slit2_setpos(); /* type Slit */
  _CRISTAL_psd_slit2_setpos(); /* type PSD_monitor */
  _CRISTAL_sample_stage_setpos(); /* type Arm */
  _CRISTAL_fluo_setpos(); /* type FluoPowder */
  _CRISTAL_detector_diffraction_setpos(); /* type Monitor_nD */
  _CRISTAL_detector_fluo_setpos(); /* type Monitor_nD */
  _beamdump_207_setpos(); /* type Beamstop */
  _DEIMOS_pos_setpos(); /* type Text */
  _GALAXIES_pos_setpos(); /* type Text */
  _GALAXIES_setpos(); /* type Arm */
  _GALAXIES_Source_U20_setpos(); /* type Undulator */
  _GALAXIES_mon_src_xy_setpos(); /* type Monitor_nD */
  _GALAXIES_mon_src_e_setpos(); /* type Monitor_nD */
  _GALAXIES_absorber_setpos(); /* type Slit */
  _GALAXIES_diaphragme_setpos(); /* type Slit */
  _GALAXIES_fentes_primaires_setpos(); /* type Slit */
  _GALAXIES_mon_prim_xy_setpos(); /* type Monitor_nD */
  _GALAXIES_DCM_location_setpos(); /* type Arm */
  _GALAXIES_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _GALAXIES_dcm0_setpos(); /* type Arm */
  _GALAXIES_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _GALAXIES_dcm1_setpos(); /* type Arm */
  _GALAXIES_mon_dcm_e_setpos(); /* type Monitor_nD */
  _GALAXIES_mon_dcm_xy_setpos(); /* type Monitor_nD */
  _GALAXIES_M1_location_setpos(); /* type Arm */
  _GALAXIES_M1_rotated_setpos(); /* type Arm */
  _GALAXIES_M1_setpos(); /* type Mirror_curved */
  _GALAXIES_M1_out_setpos(); /* type Arm */
  _GALAXIES_HRM_gate_in_setpos(); /* type Slit */
  _GALAXIES_M2A_location_setpos(); /* type Arm */
  _GALAXIES_M2A_rotated_setpos(); /* type Arm */
  _GALAXIES_M2A_setpos(); /* type Mirror_toroid */
  _GALAXIES_M2A_out_setpos(); /* type Arm */
  _GALAXIES_secondary_slits_setpos(); /* type Slit */
  _GALAXIES_mon_sec_xy_setpos(); /* type Monitor_nD */
  _GALAXIES_M2B_location_setpos(); /* type Arm */
  _GALAXIES_M2B_rotated_setpos(); /* type Arm */
  _GALAXIES_M2B_setpos(); /* type Mirror_toroid */
  _GALAXIES_M2B_out_setpos(); /* type Arm */
  _GALAXIES_VFM_location_setpos(); /* type Arm */
  _GALAXIES_VFM_rotated_setpos(); /* type Arm */
  _GALAXIES_VFM_setpos(); /* type Mirror_curved */
  _GALAXIES_VFM_out_setpos(); /* type Arm */
  _GALAXIES_HFM_rotated_setpos(); /* type Arm */
  _GALAXIES_HFM_setpos(); /* type Mirror_curved */
  _GALAXIES_HFM_out_setpos(); /* type Arm */
  _GALAXIES_mon_sample_xy_kb_setpos(); /* type Monitor_nD */
  _GALAXIES_mon_sample_e_setpos(); /* type Monitor_nD */
  _GALAXIES_sample_stage_setpos(); /* type Arm */
  _GALAXIES_sample_setpos(); /* type FluoCrystal */
  _GALAXIES_sample_out_setpos(); /* type Arm */
  _GALAXIES_ana_arm_setpos(); /* type Arm */
  _GALAXIES_analyzer_setpos(); /* type Bragg_crystal */
  _GALAXIES_ana_out_setpos(); /* type Arm */
  _GALAXIES_IXS_det_setpos(); /* type Monitor_nD */
  _beamdump_257_setpos(); /* type Beamstop */
  _TEMPO_pos_setpos(); /* type Text */
  _SAMBA_pos_setpos(); /* type Text */
  _SAMBA_setpos(); /* type Arm */
  _SAMBA_BM_source_setpos(); /* type Bending_magnet */
  _SAMBA_M1_location_setpos(); /* type Arm */
  _SAMBA_M1_rotated_setpos(); /* type Arm */
  _SAMBA_M1_setpos(); /* type Mirror_curved */
  _SAMBA_M1_out_setpos(); /* type Monitor_nD */
  _SAMBA_DCM_location_setpos(); /* type Arm */
  _SAMBA_bragg_crystal_setpos(); /* type Bragg_crystal */
  _SAMBA_arm_crystal1_setpos(); /* type Arm */
  _SAMBA_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _SAMBA_arm_crystal2_setpos(); /* type Arm */
  _SAMBA_DCM_out_setpos(); /* type Monitor_nD */
  _SAMBA_DCM_out_div_setpos(); /* type Monitor_nD */
  _SAMBA_DCM_out_e_setpos(); /* type Monitor_nD */
  _SAMBA_M2_loc_setpos(); /* type Arm */
  _SAMBA_M2_rotated_setpos(); /* type Arm */
  _SAMBA_M2_setpos(); /* type Mirror_curved */
  _SAMBA_M2_out_setpos(); /* type Monitor_nD */
  _SAMBA_sample_stage_setpos(); /* type Monitor_nD */
  _SAMBA_fluo_setpos(); /* type FluoPowder */
  _SAMBA_det_trans_setpos(); /* type Monitor_nD */
  _SAMBA_det_fluo_setpos(); /* type Monitor_nD */
  _beamdump_283_setpos(); /* type Beamstop */
  _HERMES_pos_setpos(); /* type Text */
  _PX1_pos_setpos(); /* type Text */
  _PX1_setpos(); /* type Arm */
  _PX1_undulator_setpos(); /* type Undulator */
  _PX1_bragg_crystal_location_setpos(); /* type Arm */
  _PX1_bragg_crystal_setpos(); /* type Bragg_crystal */
  _PX1_arm_setpos(); /* type Arm */
  _PX1_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _PX1_arm_two_setpos(); /* type Arm */
  _PX1_bragg_crystal_out_setpos(); /* type E_monitor */
  _PX1_secondary_slits_setpos(); /* type Slit */
  _PX1_vfm_location_setpos(); /* type Monitor_nD */
  _PX1_vfm_in_xz_plane_setpos(); /* type Arm */
  _PX1_vfm_setpos(); /* type Mirror_curved */
  _PX1_vfm_takeoff_setpos(); /* type Monitor_nD */
  _PX1_hfm_location_setpos(); /* type Monitor_nD */
  _PX1_hfm_setpos(); /* type Mirror_curved */
  _PX1_hfm_takeoff_setpos(); /* type Monitor_nD */
  _PX1_sample_stage_setpos(); /* type Arm */
  _PX1_sample_monitor_setpos(); /* type Monitor_nD */
  _PX1_sample_setpos(); /* type Single_crystal */
  _PX1_psd4pi_setpos(); /* type PSD_monitor_4PI */
  _PX1_EigerX16M_setpos(); /* type PSD_monitor */
  _beamdump_308_setpos(); /* type Beamstop */
  _PX2a_pos_setpos(); /* type Text */
  _PX2a_setpos(); /* type Arm */
  _PX2a_undulator_setpos(); /* type Undulator */
  _PX2a_bragg_crystal_location_setpos(); /* type Arm */
  _PX2a_bragg_crystal_setpos(); /* type Bragg_crystal */
  _PX2a_arm_setpos(); /* type Arm */
  _PX2a_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _PX2a_arm_two_setpos(); /* type Arm */
  _PX2a_bragg_crystal_out_setpos(); /* type E_monitor */
  _PX2a_hpm_location_setpos(); /* type Arm */
  _PX2a_hpm_in_yz_plane_setpos(); /* type Arm */
  _PX2a_hpm_setpos(); /* type Mirror_toroid */
  _PX2a_hpm_takeoff_setpos(); /* type Arm */
  _PX2a_vfm_location_setpos(); /* type Monitor_nD */
  _PX2a_vfm_in_xz_plane_setpos(); /* type Arm */
  _PX2a_vfm_setpos(); /* type Mirror_curved */
  _PX2a_vfm_takeoff_setpos(); /* type Monitor_nD */
  _PX2a_hfm_location_setpos(); /* type Monitor_nD */
  _PX2a_hfm_setpos(); /* type Mirror_curved */
  _PX2a_hfm_takeoff_setpos(); /* type Monitor_nD */
  _PX2a_sample_stage_setpos(); /* type Arm */
  _PX2a_sample_monitor_setpos(); /* type Monitor_nD */
  _PX2a_sample_setpos(); /* type Single_crystal */
  _PX2a_psd4pi_setpos(); /* type PSD_monitor_4PI */
  _PX2a_Eiger9M_setpos(); /* type PSD_monitor */
  _beamdump_335_setpos(); /* type Beamstop */
  _SWING_pos_setpos(); /* type Text */
  _SWING_setpos(); /* type Arm */
  _SWING_Source_U20_setpos(); /* type Undulator */
  _SWING_mon_src_xy_setpos(); /* type Monitor_nD */
  _SWING_mon_src_e_setpos(); /* type Monitor_nD */
  _SWING_slit_setpos(); /* type Slit */
  _SWING_slit_mon_xy_setpos(); /* type Monitor_nD */
  _SWING_DCM_location_setpos(); /* type Arm */
  _SWING_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _SWING_dcm0_setpos(); /* type Arm */
  _SWING_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _SWING_dcm1_setpos(); /* type Arm */
  _SWING_mon_dcm_e_setpos(); /* type Monitor_nD */
  _SWING_mon_dcm_xy_setpos(); /* type Monitor_nD */
  _SWING_vfm_location_setpos(); /* type Monitor_nD */
  _SWING_vfm_in_xz_plane_setpos(); /* type Arm */
  _SWING_vfm_setpos(); /* type Mirror_curved */
  _SWING_vfm_takeoff_setpos(); /* type Monitor_nD */
  _SWING_hfm_location_setpos(); /* type Monitor_nD */
  _SWING_hfm_setpos(); /* type Mirror_curved */
  _SWING_hfm_takeoff_setpos(); /* type Monitor_nD */
  _SWING_sample_stage_setpos(); /* type Monitor_nD */
  _SWING_sample_test_setpos(); /* type Saxs_spheres */
  _SWING_sample_setpos(); /* type SAXSPDBFast */
  _SWING_sample_out_setpos(); /* type Arm */
  _SWING_Eiger4M_setpos(); /* type Monitor_nD */
  _SWING_QMonitor_setpos(); /* type SAXSQMonitor */
  _beamdump_364_setpos(); /* type Beamstop */
  _ANTARES_pos_setpos(); /* type Text */
  _ROCK_pos_setpos(); /* type Text */
  _ROCK_setpos(); /* type Arm */
  _ROCK_Source_setpos(); /* type Bending_magnet */
  _ROCK_slit1_setpos(); /* type Slit */
  _ROCK_slit2_setpos(); /* type Slit */
  _ROCK_mirror_m1_setpos(); /* type Mirror_toroid_pothole */
  _ROCK_mirror_m1_out_setpos(); /* type Arm */
  _ROCK_slit3_xy_setpos(); /* type PSD_monitor */
  _ROCK_slit3_div_setpos(); /* type Divergence_monitor */
  _ROCK_slit3_setpos(); /* type Slit */
  _ROCK_mirror_m2a_setpos(); /* type Mirror */
  _ROCK_mirror_m2a_out_setpos(); /* type Arm */
  _ROCK_slit4_in_setpos(); /* type PSD_monitor */
  _ROCK_slit4_setpos(); /* type Slit */
  _ROCK_arm_crystal0_setpos(); /* type Arm */
  _ROCK_bragg_crystal_setpos(); /* type Bragg_crystal */
  _ROCK_arm_crystal1_setpos(); /* type Arm */
  _ROCK_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _ROCK_arm_crystal2_setpos(); /* type Arm */
  _ROCK_bragg_crystal_out_setpos(); /* type PSD_monitor */
  _ROCK_slit5_setpos(); /* type Slit */
  _ROCK_slit6_setpos(); /* type Slit */
  _ROCK_mirror_m2b_setpos(); /* type Mirror_curved */
  _ROCK_mirror_m2b_out_setpos(); /* type Arm */
  _ROCK_EnergyMonitor_before_sample_setpos(); /* type Monitor_nD */
  _ROCK_e_repartition_after_m2b_setpos(); /* type Monitor_nD */
  _ROCK_sample_in_setpos(); /* type PSD_monitor */
  _ROCK_absorption_sample_setpos(); /* type Fluorescence */
  _ROCK_fluo_monitor_setpos(); /* type Monitor_nD */
  _ROCK_EnergyMonitor_after_sample_setpos(); /* type Monitor_nD */
  _ROCK_psd_monitor_setpos(); /* type PSD_monitor */
  _beamdump_398_setpos(); /* type Beamstop */
  _ANATOMIX_pos_setpos(); /* type Text */
  _ANATOMIX_setpos(); /* type Arm */
  _ANATOMIX_source_setpos(); /* type Undulator */
  _ANATOMIX_e_repartition_before_cc_setpos(); /* type Monitor_nD */
  _ANATOMIX_psd_monitor_before_cc_setpos(); /* type PSD_monitor */
  _ANATOMIX_bragg_crystal_setpos(); /* type Bragg_crystal */
  _ANATOMIX_arm_setpos(); /* type Arm */
  _ANATOMIX_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _ANATOMIX_arm_two_setpos(); /* type Arm */
  _ANATOMIX_psd_after_cc_setpos(); /* type PSD_monitor */
  _ANATOMIX_e_monitor_before_sample_setpos(); /* type E_monitor */
  _ANATOMIX_psd_repartition_after_cc_setpos(); /* type PSD_monitor */
  _ANATOMIX_sample_rotation_stage_setpos(); /* type Arm */
  _ANATOMIX_sample_setpos(); /* type Filter */
  _ANATOMIX_e_monitor_after_sample_setpos(); /* type E_monitor */
  _ANATOMIX_psd_monitor_after_cc_setpos(); /* type PSD_monitor */
  _beamdump_416_setpos(); /* type Beamstop */
  _NANOSCOPIUM_pos_setpos(); /* type Text */
  _NANOSCOPIUM_setpos(); /* type Arm */
  _NANO_source_setpos(); /* type Undulator */
  _NANO_e_monitor_source_setpos(); /* type E_monitor */
  _NANO_psd_source_setpos(); /* type PSD_monitor_coh */
  _NANO_slit_1_setpos(); /* type Slit */
  _NANO_m1_in_setpos(); /* type Arm */
  _NANO_m1_roll_setpos(); /* type Arm */
  _NANO_mirror_m1_setpos(); /* type Mirror_curved */
  _NANO_beam_deviation_setpos(); /* type Arm */
  _NANO_m2_in_setpos(); /* type Arm */
  _NANO_mirror_m2_setpos(); /* type Mirror_curved */
  _NANO_mirror_m2_out_setpos(); /* type Arm */
  _NANO_slit_2_setpos(); /* type Slit */
  _NANO_dcm_in_setpos(); /* type Arm */
  _NANO_PSD_dcm_in_setpos(); /* type PSD_monitor */
  _NANO_bragg_roll_setpos(); /* type Arm */
  _NANO_bragg_crystal_1_setpos(); /* type Bragg_crystal */
  _NANO_dcm2_rot_setpos(); /* type Arm */
  _NANO_dcm_transl_setpos(); /* type Arm */
  _NANO_bragg_crystal_2_setpos(); /* type Bragg_crystal */
  _NANO_bragg2_out_setpos(); /* type Arm */
  _NANO_dcm_out_setpos(); /* type Arm */
  _NANO_e_dcm_out_setpos(); /* type E_monitor */
  _NANO_secondary_source_slits_setpos(); /* type Arm */
  _NANO_psd_ss_in_setpos(); /* type PSD_monitor */
  _NANO_slit_3_setpos(); /* type Slit */
  _NANO_psd_ss_out_setpos(); /* type PSD_monitor */
  _NANO_jjxray2_slits_setpos(); /* type Arm */
  _NANO_slit_5_setpos(); /* type Slit */
  _NANO_kb_in_setpos(); /* type Arm */
  _NANO_kb_1_setpos(); /* type Mirror_curved */
  _NANO_kb_beam_deviation_setpos(); /* type Arm */
  _NANO_kb1_out_setpos(); /* type Arm */
  _NANO_kb2_setpos(); /* type Mirror_curved */
  _NANO_kb_out_setpos(); /* type Arm */
  _NANO_slit_setpos(); /* type Slit */
  _NANO_psd_sample_stage_setpos(); /* type PSD_monitor */
  _beamdump_456_setpos(); /* type Beamstop */
  _DIFFABS_pos_setpos(); /* type Text */
  _DIFFABS_setpos(); /* type Arm */
  _DIFFABS_BM_D13_1_setpos(); /* type Bending_magnet */
  _DIFFABS_primary_slit_setpos(); /* type Slit */
  _DIFFABS_M1_location_setpos(); /* type Arm */
  _DIFFABS_M1_rotated_setpos(); /* type Arm */
  _DIFFABS_M1_setpos(); /* type Mirror_curved */
  _DIFFABS_M1_out_setpos(); /* type Arm */
  _DIFFABS_DCM_slit_in_setpos(); /* type Slit */
  _DIFFABS_DCM_in_setpos(); /* type Monitor_nD */
  _DIFFABS_DCM_in_div_setpos(); /* type Monitor_nD */
  _DIFFABS_DCM_location_setpos(); /* type Arm */
  _DIFFABS_bragg_crystal_setpos(); /* type Bragg_crystal */
  _DIFFABS_arm_crystal1_setpos(); /* type Arm */
  _DIFFABS_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _DIFFABS_arm_crystal2_setpos(); /* type Arm */
  _DIFFABS_DCM_out_setpos(); /* type Monitor_nD */
  _DIFFABS_DCM_out_div_setpos(); /* type Monitor_nD */
  _DIFFABS_DCM_out_e_setpos(); /* type Monitor_nD */
  _DIFFABS_DCM_slit_out_setpos(); /* type Slit */
  _DIFFABS_M2_location_setpos(); /* type Arm */
  _DIFFABS_M2_rotated_setpos(); /* type Arm */
  _DIFFABS_M2_setpos(); /* type Mirror_curved */
  _DIFFABS_M2_out_setpos(); /* type Arm */
  _DIFFABS_sample_stage_setpos(); /* type Monitor_nD */
  _DIFFABS_fluo_setpos(); /* type FluoPowder */
  _DIFFABS_fluo_monitor_setpos(); /* type Monitor_nD */
  _DIFFABS_det_angle_setpos(); /* type Monitor_nD */
  _DIFFABS_xpad_setpos(); /* type Monitor_nD */
  _beamdump_487_setpos(); /* type Beamstop */
  _SEXTANTS_setpos(); /* type Text */
  _SIXS_pos_setpos(); /* type Text */
  _SIXS_setpos(); /* type Arm */
  _SIXS_Source_U20_setpos(); /* type Undulator */
  _SIXS_mon_src_xy_setpos(); /* type Monitor_nD */
  _SIXS_mon_src_e_setpos(); /* type Monitor_nD */
  _SIXS_slit_setpos(); /* type Slit */
  _SIXS_slit_mon_xy_setpos(); /* type Monitor_nD */
  _SIXS_DCM_location_setpos(); /* type Arm */
  _SIXS_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _SIXS_dcm0_setpos(); /* type Arm */
  _SIXS_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _SIXS_dcm1_setpos(); /* type Arm */
  _SIXS_mon_dcm_e_setpos(); /* type Monitor_nD */
  _SIXS_mon_dcm_xy_setpos(); /* type Monitor_nD */
  _SIXS_M1_location_setpos(); /* type Arm */
  _SIXS_M1_rotated_setpos(); /* type Arm */
  _SIXS_M1_setpos(); /* type Mirror_curved */
  _SIXS_M1_out_setpos(); /* type Arm */
  _SIXS_M2_location_setpos(); /* type Arm */
  _SIXS_M2_rotated_setpos(); /* type Arm */
  _SIXS_M2_setpos(); /* type Mirror_curved */
  _SIXS_M2_out_setpos(); /* type Arm */
  _SIXS_sample_stage_setpos(); /* type Monitor_nD */
  _SIXS_sx_layer_setpos(); /* type Single_crystal */
  _SIXS_sx_bulk_setpos(); /* type Single_crystal */
  _SIXS_sample_out_setpos(); /* type Arm */
  _SIXS_det4pi_setpos(); /* type Monitor_nD */
  _SIXS_detector_layer_setpos(); /* type Monitor_nD */
  _SIXS_detector_bulk_setpos(); /* type Monitor_nD */
  _beamdump_519_setpos(); /* type Beamstop */
  _CASSIOPEE_pos_setpos(); /* type Text */
  _CASSIOPEE_setpos(); /* type Arm */
  _CASSIOPEE_Source_HU60_setpos(); /* type Undulator */
  _CASSIOPEE_Source_HU256_setpos(); /* type Undulator */
  _CASSIOPEE_M1a_location_setpos(); /* type Arm */
  _CASSIOPEE_M1a_setpos(); /* type Mirror_curved */
  _CASSIOPEE_M1a_out_setpos(); /* type Arm */
  _CASSIOPEE_M1b_setpos(); /* type Mirror_curved */
  _CASSIOPEE_M1c_setpos(); /* type Mirror_curved */
  _CASSIOPEE_M1bc_out_setpos(); /* type Arm */
  _CASSIOPEE_PSD_M1out_setpos(); /* type Monitor_nD */
  _CASSIOPEE_PG_location_setpos(); /* type Arm */
  _CASSIOPEE_PG_setpos(); /* type Grating_reflect */
  _CASSIOPEE_M2_rotation_axis_setpos(); /* type Monitor_nD */
  _CASSIOPEE_M2_setpos(); /* type Mirror */
  _CASSIOPEE_PM_takeoff_setpos(); /* type Arm */
  _CASSIOPEE_slit_setpos(); /* type Slit */
  _CASSIOPEE_M4_setpos(); /* type Mirror_curved */
  _CASSIOPEE_PSD_setpos(); /* type Monitor_nD */
  _beamdump_540_setpos(); /* type Beamstop */
  _SIRIUS_pos_setpos(); /* type Text */
  _SIRIUS_setpos(); /* type Arm */
  _SIRIUS_source_setpos(); /* type Bending_magnet */
  _SIRIUS_M1_loc_setpos(); /* type Monitor_nD */
  _SIRIUS_M1_rot_setpos(); /* type Arm */
  _SIRIUS_M1_setpos(); /* type Mirror_curved */
  _SIRIUS_M1_out_setpos(); /* type Arm */
  _SIRIUS_DCM_location_setpos(); /* type Monitor_nD */
  _SIRIUS_bragg_crystal_setpos(); /* type Bragg_crystal */
  _SIRIUS_arm_crystal1_setpos(); /* type Arm */
  _SIRIUS_bragg_crystal_two_setpos(); /* type Bragg_crystal */
  _SIRIUS_arm_crystal2_setpos(); /* type Arm */
  _SIRIUS_DCM_out_setpos(); /* type Monitor_nD */
  _SIRIUS_DCM_out_div_setpos(); /* type Monitor_nD */
  _SIRIUS_DCM_out_e_setpos(); /* type Monitor_nD */
  _SIRIUS_def_loc_setpos(); /* type Monitor_nD */
  _SIRIUS_def_rot_setpos(); /* type Arm */
  _SIRIUS_def_mirror_setpos(); /* type Mirror */
  _SIRIUS_def_out_setpos(); /* type Arm */
  _SIRIUS_sample_stage_setpos(); /* type Monitor_nD */
  _SIRIUS_fluo_setpos(); /* type FluoPowder */
  _SIRIUS_det_2d_setpos(); /* type Monitor_nD */
  _SIRIUS_det_fluo_setpos(); /* type Monitor_nD */
  _beamdump_565_setpos(); /* type Beamstop */
  _LUCIA_pos_setpos(); /* type Text */
  _LUCIA_setpos(); /* type Arm */
  _LUCIA_source_setpos(); /* type Undulator */
  _LUCIA_mon_src_xy_setpos(); /* type Monitor_nD */
  _LUCIA_mon_src_e_setpos(); /* type Monitor_nD */
  _LUCIA_slit_setpos(); /* type Slit */
  _LUCIA_slit_mon_xy_setpos(); /* type Monitor_nD */
  _LUCIA_DCM_location_setpos(); /* type Arm */
  _LUCIA_dcm_xtal0_setpos(); /* type Bragg_crystal */
  _LUCIA_dcm0_setpos(); /* type Arm */
  _LUCIA_dcm_xtal1_setpos(); /* type Bragg_crystal */
  _LUCIA_dcm1_setpos(); /* type Arm */
  _LUCIA_mon_dcm_e_setpos(); /* type Monitor_nD */
  _LUCIA_mon_dcm_xy_setpos(); /* type Monitor_nD */
  _LUCIA_diaphragm_setpos(); /* type Slit */
  _LUCIA_sample_stage_setpos(); /* type Monitor_nD */
  _LUCIA_fluo_rotated_setpos(); /* type Arm */
  _LUCIA_sample_setpos(); /* type Fluorescence */
  _LUCIA_transmission_setpos(); /* type Monitor_nD */
  _LUCIA_mon_spl_SDD_setpos(); /* type Fluo_detector */
  _LUCIA_mon_spl_fluo_setpos(); /* type Monitor_nD */
  _beamdump_588_setpos(); /* type Beamstop */
  _storage_setpos(); /* type Shape */
  _hall0_setpos(); /* type Shape */
  _hall1_setpos(); /* type Shape */
  _entrance_0_setpos(); /* type Arm */
  _entrance_1_setpos(); /* type Shape */
  _ANATOMIX_building_setpos(); /* type Shape */
  _soleil_label_setpos(); /* type Text */

  /* call iteratively all components INITIALISE */


  class_Beamstop_init(&_beamdump_var);

  class_Text_init(&_ODE_pos_var);

  class_Text_init(&_SMIS_pos_var);

  class_Text_init(&_AILES_pos_var);

  class_Text_init(&_MARS_pos_var);


  class_Bending_magnet_init(&_MARS_Source_var);

  class_Monitor_nD_init(&_MARS_displaySourceLength_var);

  class_PSD_monitor_init(&_MARS_displaySource_var);

  class_Slit_init(&_MARS_slit1_var);

  class_Slit_init(&_MARS_slit2_var);



  class_Mirror_curved_init(&_MARS_mirror_M1_var);




  class_Bragg_crystal_init(&_MARS_dcm_xtal0_var);


  class_Bragg_crystal_init(&_MARS_dcm_xtal1_var);


  class_E_monitor_init(&_MARS_emon_dcm0_var);

  class_PSD_monitor_init(&_MARS_displayMono_var);

  class_E_monitor_init(&_MARS_displayMonoLength_var);



  class_Mirror_curved_init(&_MARS_mirror_M2_var);



  class_Slit_init(&_MARS_slitSecon1_var);

  class_Slit_init(&_MARS_slitSecon2_var);

  class_E_monitor_init(&_MARS_emon_dcm1_var);

  class_PSD_monitor_init(&_MARS_displaySlit2_var);

  class_FluoPowder_init(&_MARS_Sample_var);

  class_Monitor_nD_init(&_MARS_detector_diffraction_var);

  class_Monitor_nD_init(&_MARS_detector_fluo_var);

  class_Beamstop_init(&_beamdump_40_var);

  class_Text_init(&_PSICHE_pos_var);


  class_Wiggler_init(&_PSICHE_source_var);

  class_Monitor_nD_init(&_PSICHE_mon_src_e_var);

  class_Monitor_nD_init(&_PSICHE_mon_src_xy_var);


  class_Bragg_crystal_init(&_PSICHE_dcm_xtal0_var);


  class_Bragg_crystal_init(&_PSICHE_dcm_xtal1_var);


  class_Monitor_nD_init(&_PSICHE_mon_dcm_e_var);

  class_Monitor_nD_init(&_PSICHE_mon_dcm_xy_var);

  class_Slit_init(&_PSICHE_slit_var);


  class_FluoPowder_init(&_PSICHE_sample_var);


  class_Monitor_nD_init(&_PSICHE_mon_spl_fluo_var);

  class_Monitor_nD_init(&_PSICHE_mon_spl_e_var);

  class_Monitor_nD_init(&_PSICHE_mon_spl_xy_var);

  class_Beamstop_init(&_beamdump_61_var);

  class_Text_init(&_PLEIADES_pos_var);

  class_Text_init(&_DISCO_pos_var);


  class_Bending_magnet_init(&_DISCO_Source_var);

  class_Mask_init(&_DISCO_ColdFinger_var);




  class_Mirror_curved_init(&_DISCO_M1_var);







  class_Mirror_toroid_pothole_init(&_DISCO_M2_var);




  class_PSD_monitor_init(&_DISCO_HFP_var);


  class_Mirror_curved_init(&_DISCO_M3_var);




  class_Mirror_init(&_DISCO_M4_var);




  class_PSD_monitor_init(&_DISCO_VFP_var);



  class_Mirror_elliptic_init(&_DISCO_M51_var);





  class_Mirror_curved_init(&_DISCO_M52_var);




  class_PSD_monitor_init(&_DISCO_second_HFP_var);



  class_Mirror_toroid_pothole_init(&_DISCO_M53_var);




  class_Mirror_toroid_pothole_init(&_DISCO_M54_var);





  class_Mirror_elliptic_init(&_DISCO_mirror_m1_var);







  class_Grating_reflect_init(&_DISCO_reflective_grating_var);







  class_Mirror_elliptic_init(&_DISCO_mirror_m2_var);




  class_PSD_monitor_init(&_DISCO_psd_before_slit_var);

  class_Slit_init(&_DISCO_slit_var);

  class_PSD_monitor_init(&_DISCO_psd_monitor_var);

  class_PSD_monitor_init(&_DISCO_psd_giant_after_grating_var);

  class_Monitor_nD_init(&_DISCO_e_monitor_var);

  class_Monitor_nD_init(&_DISCO_w_monitor_var);

  class_Beamstop_init(&_beamdump_140_var);

  class_Text_init(&_DESIRS_pos_var);

  class_Text_init(&_METRO_pos_var);

  class_Text_init(&_PUMA_pos_var);


  class_Wiggler_init(&_PUMA_Source_var);

  class_Slit_init(&_PUMA_slit1_var);

  class_Slit_init(&_PUMA_slit2_var);

  class_E_monitor_init(&_PUMA_mon_src_e_var);

  class_PSD_monitor_init(&_PUMA_mon_src_xy_var);



  class_Mirror_curved_init(&_PUMA_mirror_HFM_var);


  class_PSD_monitor_init(&_PUMA_mon_HFM_out_xy_var);


  class_Bragg_crystal_init(&_PUMA_DCM_xtal1_var);


  class_PSD_monitor_init(&_PUMA_mon_DCM_xtal1_only_xy_var);

  class_Bragg_crystal_init(&_PUMA_DCM_xtal2_var);


  class_E_monitor_init(&_PUMA_mon_DCM_out_e_var);

  class_PSD_monitor_init(&_PUMA_mon_DCM_out_xy_var);

  class_Slit_init(&_PUMA_slit3_var);

  class_Slit_init(&_PUMA_slit4_var);

  class_Slit_init(&_PUMA_slit5_var);


  class_PSD_monitor_init(&_PUMA_mon_KB_in_xy_var);


  class_Mirror_curved_init(&_PUMA_mirror_KB_VFM_var);


  class_PSD_monitor_init(&_PUMA_mon_KB_VFM_out_xy_var);



  class_Mirror_curved_init(&_PUMA_mirror_KB_HFM_var);


  class_PSD_monitor_init(&_PUMA_mon_KB_HFM_out_xy_var);


  class_PSD_monitor_init(&_PUMA_mon_sample_xy_var);

  class_E_monitor_init(&_PUMA_mon_sample_e_var);

  class_Beamstop_init(&_beamdump_181_var);

  class_Text_init(&_CRISTAL_pos_var);


  class_Undulator_init(&_CRISTAL_Source_var);

  class_Slit_init(&_CRISTAL_slit1_var);


  class_Bragg_crystal_init(&_CRISTAL_dcm_xtal0_var);


  class_Bragg_crystal_init(&_CRISTAL_dcm_xtal1_var);


  class_E_monitor_init(&_CRISTAL_emon_dcm_var);



  class_Mirror_curved_init(&_CRISTAL_M1_var);




  class_Mirror_curved_init(&_CRISTAL_M2_var);


  class_Slit_init(&_CRISTAL_slit2_var);

  class_PSD_monitor_init(&_CRISTAL_psd_slit2_var);


  class_FluoPowder_init(&_CRISTAL_fluo_var);

  class_Monitor_nD_init(&_CRISTAL_detector_diffraction_var);

  class_Monitor_nD_init(&_CRISTAL_detector_fluo_var);

  class_Beamstop_init(&_beamdump_207_var);

  class_Text_init(&_DEIMOS_pos_var);

  class_Text_init(&_GALAXIES_pos_var);


  class_Undulator_init(&_GALAXIES_Source_U20_var);

  class_Monitor_nD_init(&_GALAXIES_mon_src_xy_var);

  class_Monitor_nD_init(&_GALAXIES_mon_src_e_var);

  class_Slit_init(&_GALAXIES_absorber_var);

  class_Slit_init(&_GALAXIES_diaphragme_var);

  class_Slit_init(&_GALAXIES_fentes_primaires_var);

  class_Monitor_nD_init(&_GALAXIES_mon_prim_xy_var);


  class_Bragg_crystal_init(&_GALAXIES_dcm_xtal0_var);


  class_Bragg_crystal_init(&_GALAXIES_dcm_xtal1_var);


  class_Monitor_nD_init(&_GALAXIES_mon_dcm_e_var);

  class_Monitor_nD_init(&_GALAXIES_mon_dcm_xy_var);



  class_Mirror_curved_init(&_GALAXIES_M1_var);


  class_Slit_init(&_GALAXIES_HRM_gate_in_var);



  class_Mirror_toroid_init(&_GALAXIES_M2A_var);


  class_Slit_init(&_GALAXIES_secondary_slits_var);

  class_Monitor_nD_init(&_GALAXIES_mon_sec_xy_var);



  class_Mirror_toroid_init(&_GALAXIES_M2B_var);




  class_Mirror_curved_init(&_GALAXIES_VFM_var);



  class_Mirror_curved_init(&_GALAXIES_HFM_var);


  class_Monitor_nD_init(&_GALAXIES_mon_sample_xy_kb_var);

  class_Monitor_nD_init(&_GALAXIES_mon_sample_e_var);


  class_FluoCrystal_init(&_GALAXIES_sample_var);



  class_Bragg_crystal_init(&_GALAXIES_analyzer_var);


  class_Monitor_nD_init(&_GALAXIES_IXS_det_var);

  class_Beamstop_init(&_beamdump_257_var);

  class_Text_init(&_TEMPO_pos_var);

  class_Text_init(&_SAMBA_pos_var);


  class_Bending_magnet_init(&_SAMBA_BM_source_var);



  class_Mirror_curved_init(&_SAMBA_M1_var);

  class_Monitor_nD_init(&_SAMBA_M1_out_var);


  class_Bragg_crystal_init(&_SAMBA_bragg_crystal_var);


  class_Bragg_crystal_init(&_SAMBA_bragg_crystal_two_var);


  class_Monitor_nD_init(&_SAMBA_DCM_out_var);

  class_Monitor_nD_init(&_SAMBA_DCM_out_div_var);

  class_Monitor_nD_init(&_SAMBA_DCM_out_e_var);



  class_Mirror_curved_init(&_SAMBA_M2_var);

  class_Monitor_nD_init(&_SAMBA_M2_out_var);

  class_Monitor_nD_init(&_SAMBA_sample_stage_var);

  class_FluoPowder_init(&_SAMBA_fluo_var);

  class_Monitor_nD_init(&_SAMBA_det_trans_var);

  class_Monitor_nD_init(&_SAMBA_det_fluo_var);

  class_Beamstop_init(&_beamdump_283_var);

  class_Text_init(&_HERMES_pos_var);

  class_Text_init(&_PX1_pos_var);


  class_Undulator_init(&_PX1_undulator_var);


  class_Bragg_crystal_init(&_PX1_bragg_crystal_var);


  class_Bragg_crystal_init(&_PX1_bragg_crystal_two_var);


  class_E_monitor_init(&_PX1_bragg_crystal_out_var);

  class_Slit_init(&_PX1_secondary_slits_var);

  class_Monitor_nD_init(&_PX1_vfm_location_var);


  class_Mirror_curved_init(&_PX1_vfm_var);

  class_Monitor_nD_init(&_PX1_vfm_takeoff_var);

  class_Monitor_nD_init(&_PX1_hfm_location_var);

  class_Mirror_curved_init(&_PX1_hfm_var);

  class_Monitor_nD_init(&_PX1_hfm_takeoff_var);


  class_Monitor_nD_init(&_PX1_sample_monitor_var);

  class_Single_crystal_init(&_PX1_sample_var);

  class_PSD_monitor_4PI_init(&_PX1_psd4pi_var);

  class_PSD_monitor_init(&_PX1_EigerX16M_var);

  class_Beamstop_init(&_beamdump_308_var);

  class_Text_init(&_PX2a_pos_var);


  class_Undulator_init(&_PX2a_undulator_var);


  class_Bragg_crystal_init(&_PX2a_bragg_crystal_var);


  class_Bragg_crystal_init(&_PX2a_bragg_crystal_two_var);


  class_E_monitor_init(&_PX2a_bragg_crystal_out_var);



  class_Mirror_toroid_init(&_PX2a_hpm_var);


  class_Monitor_nD_init(&_PX2a_vfm_location_var);


  class_Mirror_curved_init(&_PX2a_vfm_var);

  class_Monitor_nD_init(&_PX2a_vfm_takeoff_var);

  class_Monitor_nD_init(&_PX2a_hfm_location_var);

  class_Mirror_curved_init(&_PX2a_hfm_var);

  class_Monitor_nD_init(&_PX2a_hfm_takeoff_var);


  class_Monitor_nD_init(&_PX2a_sample_monitor_var);

  class_Single_crystal_init(&_PX2a_sample_var);

  class_PSD_monitor_4PI_init(&_PX2a_psd4pi_var);

  class_PSD_monitor_init(&_PX2a_Eiger9M_var);

  class_Beamstop_init(&_beamdump_335_var);

  class_Text_init(&_SWING_pos_var);


  class_Undulator_init(&_SWING_Source_U20_var);

  class_Monitor_nD_init(&_SWING_mon_src_xy_var);

  class_Monitor_nD_init(&_SWING_mon_src_e_var);

  class_Slit_init(&_SWING_slit_var);

  class_Monitor_nD_init(&_SWING_slit_mon_xy_var);


  class_Bragg_crystal_init(&_SWING_dcm_xtal0_var);


  class_Bragg_crystal_init(&_SWING_dcm_xtal1_var);


  class_Monitor_nD_init(&_SWING_mon_dcm_e_var);

  class_Monitor_nD_init(&_SWING_mon_dcm_xy_var);

  class_Monitor_nD_init(&_SWING_vfm_location_var);


  class_Mirror_curved_init(&_SWING_vfm_var);

  class_Monitor_nD_init(&_SWING_vfm_takeoff_var);

  class_Monitor_nD_init(&_SWING_hfm_location_var);

  class_Mirror_curved_init(&_SWING_hfm_var);

  class_Monitor_nD_init(&_SWING_hfm_takeoff_var);

  class_Monitor_nD_init(&_SWING_sample_stage_var);

  class_Saxs_spheres_init(&_SWING_sample_test_var);

  class_SAXSPDBFast_init(&_SWING_sample_var);


  class_Monitor_nD_init(&_SWING_Eiger4M_var);

  class_SAXSQMonitor_init(&_SWING_QMonitor_var);

  class_Beamstop_init(&_beamdump_364_var);

  class_Text_init(&_ANTARES_pos_var);

  class_Text_init(&_ROCK_pos_var);


  class_Bending_magnet_init(&_ROCK_Source_var);

  class_Slit_init(&_ROCK_slit1_var);

  class_Slit_init(&_ROCK_slit2_var);

  class_Mirror_toroid_pothole_init(&_ROCK_mirror_m1_var);


  class_PSD_monitor_init(&_ROCK_slit3_xy_var);

  class_Divergence_monitor_init(&_ROCK_slit3_div_var);

  class_Slit_init(&_ROCK_slit3_var);

  class_Mirror_init(&_ROCK_mirror_m2a_var);


  class_PSD_monitor_init(&_ROCK_slit4_in_var);

  class_Slit_init(&_ROCK_slit4_var);


  class_Bragg_crystal_init(&_ROCK_bragg_crystal_var);


  class_Bragg_crystal_init(&_ROCK_bragg_crystal_two_var);


  class_PSD_monitor_init(&_ROCK_bragg_crystal_out_var);

  class_Slit_init(&_ROCK_slit5_var);

  class_Slit_init(&_ROCK_slit6_var);

  class_Mirror_curved_init(&_ROCK_mirror_m2b_var);


  class_Monitor_nD_init(&_ROCK_EnergyMonitor_before_sample_var);

  class_Monitor_nD_init(&_ROCK_e_repartition_after_m2b_var);

  class_PSD_monitor_init(&_ROCK_sample_in_var);

  class_Fluorescence_init(&_ROCK_absorption_sample_var);

  class_Monitor_nD_init(&_ROCK_fluo_monitor_var);

  class_Monitor_nD_init(&_ROCK_EnergyMonitor_after_sample_var);

  class_PSD_monitor_init(&_ROCK_psd_monitor_var);

  class_Beamstop_init(&_beamdump_398_var);

  class_Text_init(&_ANATOMIX_pos_var);


  class_Undulator_init(&_ANATOMIX_source_var);

  class_Monitor_nD_init(&_ANATOMIX_e_repartition_before_cc_var);

  class_PSD_monitor_init(&_ANATOMIX_psd_monitor_before_cc_var);

  class_Bragg_crystal_init(&_ANATOMIX_bragg_crystal_var);


  class_Bragg_crystal_init(&_ANATOMIX_bragg_crystal_two_var);


  class_PSD_monitor_init(&_ANATOMIX_psd_after_cc_var);

  class_E_monitor_init(&_ANATOMIX_e_monitor_before_sample_var);

  class_PSD_monitor_init(&_ANATOMIX_psd_repartition_after_cc_var);


  class_Filter_init(&_ANATOMIX_sample_var);

  class_E_monitor_init(&_ANATOMIX_e_monitor_after_sample_var);

  class_PSD_monitor_init(&_ANATOMIX_psd_monitor_after_cc_var);

  class_Beamstop_init(&_beamdump_416_var);

  class_Text_init(&_NANOSCOPIUM_pos_var);


  class_Undulator_init(&_NANO_source_var);

  class_E_monitor_init(&_NANO_e_monitor_source_var);

  class_PSD_monitor_coh_init(&_NANO_psd_source_var);

  class_Slit_init(&_NANO_slit_1_var);



  class_Mirror_curved_init(&_NANO_mirror_m1_var);



  class_Mirror_curved_init(&_NANO_mirror_m2_var);


  class_Slit_init(&_NANO_slit_2_var);


  class_PSD_monitor_init(&_NANO_PSD_dcm_in_var);


  class_Bragg_crystal_init(&_NANO_bragg_crystal_1_var);



  class_Bragg_crystal_init(&_NANO_bragg_crystal_2_var);



  class_E_monitor_init(&_NANO_e_dcm_out_var);


  class_PSD_monitor_init(&_NANO_psd_ss_in_var);

  class_Slit_init(&_NANO_slit_3_var);

  class_PSD_monitor_init(&_NANO_psd_ss_out_var);


  class_Slit_init(&_NANO_slit_5_var);


  class_Mirror_curved_init(&_NANO_kb_1_var);



  class_Mirror_curved_init(&_NANO_kb2_var);


  class_Slit_init(&_NANO_slit_var);

  class_PSD_monitor_init(&_NANO_psd_sample_stage_var);

  class_Beamstop_init(&_beamdump_456_var);

  class_Text_init(&_DIFFABS_pos_var);


  class_Bending_magnet_init(&_DIFFABS_BM_D13_1_var);

  class_Slit_init(&_DIFFABS_primary_slit_var);



  class_Mirror_curved_init(&_DIFFABS_M1_var);


  class_Slit_init(&_DIFFABS_DCM_slit_in_var);

  class_Monitor_nD_init(&_DIFFABS_DCM_in_var);

  class_Monitor_nD_init(&_DIFFABS_DCM_in_div_var);


  class_Bragg_crystal_init(&_DIFFABS_bragg_crystal_var);


  class_Bragg_crystal_init(&_DIFFABS_bragg_crystal_two_var);


  class_Monitor_nD_init(&_DIFFABS_DCM_out_var);

  class_Monitor_nD_init(&_DIFFABS_DCM_out_div_var);

  class_Monitor_nD_init(&_DIFFABS_DCM_out_e_var);

  class_Slit_init(&_DIFFABS_DCM_slit_out_var);



  class_Mirror_curved_init(&_DIFFABS_M2_var);


  class_Monitor_nD_init(&_DIFFABS_sample_stage_var);

  class_FluoPowder_init(&_DIFFABS_fluo_var);

  class_Monitor_nD_init(&_DIFFABS_fluo_monitor_var);

  class_Monitor_nD_init(&_DIFFABS_det_angle_var);

  class_Monitor_nD_init(&_DIFFABS_xpad_var);

  class_Beamstop_init(&_beamdump_487_var);

  class_Text_init(&_SEXTANTS_var);

  class_Text_init(&_SIXS_pos_var);


  class_Undulator_init(&_SIXS_Source_U20_var);

  class_Monitor_nD_init(&_SIXS_mon_src_xy_var);

  class_Monitor_nD_init(&_SIXS_mon_src_e_var);

  class_Slit_init(&_SIXS_slit_var);

  class_Monitor_nD_init(&_SIXS_slit_mon_xy_var);


  class_Bragg_crystal_init(&_SIXS_dcm_xtal0_var);


  class_Bragg_crystal_init(&_SIXS_dcm_xtal1_var);


  class_Monitor_nD_init(&_SIXS_mon_dcm_e_var);

  class_Monitor_nD_init(&_SIXS_mon_dcm_xy_var);



  class_Mirror_curved_init(&_SIXS_M1_var);




  class_Mirror_curved_init(&_SIXS_M2_var);


  class_Monitor_nD_init(&_SIXS_sample_stage_var);

  class_Single_crystal_init(&_SIXS_sx_layer_var);

  class_Single_crystal_init(&_SIXS_sx_bulk_var);


  class_Monitor_nD_init(&_SIXS_det4pi_var);

  class_Monitor_nD_init(&_SIXS_detector_layer_var);

  class_Monitor_nD_init(&_SIXS_detector_bulk_var);

  class_Beamstop_init(&_beamdump_519_var);

  class_Text_init(&_CASSIOPEE_pos_var);


  class_Undulator_init(&_CASSIOPEE_Source_HU60_var);

  class_Undulator_init(&_CASSIOPEE_Source_HU256_var);


  class_Mirror_curved_init(&_CASSIOPEE_M1a_var);


  class_Mirror_curved_init(&_CASSIOPEE_M1b_var);

  class_Mirror_curved_init(&_CASSIOPEE_M1c_var);


  class_Monitor_nD_init(&_CASSIOPEE_PSD_M1out_var);


  class_Grating_reflect_init(&_CASSIOPEE_PG_var);

  class_Monitor_nD_init(&_CASSIOPEE_M2_rotation_axis_var);

  class_Mirror_init(&_CASSIOPEE_M2_var);


  class_Slit_init(&_CASSIOPEE_slit_var);

  class_Mirror_curved_init(&_CASSIOPEE_M4_var);

  class_Monitor_nD_init(&_CASSIOPEE_PSD_var);

  class_Beamstop_init(&_beamdump_540_var);

  class_Text_init(&_SIRIUS_pos_var);


  class_Bending_magnet_init(&_SIRIUS_source_var);

  class_Monitor_nD_init(&_SIRIUS_M1_loc_var);


  class_Mirror_curved_init(&_SIRIUS_M1_var);


  class_Monitor_nD_init(&_SIRIUS_DCM_location_var);

  class_Bragg_crystal_init(&_SIRIUS_bragg_crystal_var);


  class_Bragg_crystal_init(&_SIRIUS_bragg_crystal_two_var);


  class_Monitor_nD_init(&_SIRIUS_DCM_out_var);

  class_Monitor_nD_init(&_SIRIUS_DCM_out_div_var);

  class_Monitor_nD_init(&_SIRIUS_DCM_out_e_var);

  class_Monitor_nD_init(&_SIRIUS_def_loc_var);


  class_Mirror_init(&_SIRIUS_def_mirror_var);


  class_Monitor_nD_init(&_SIRIUS_sample_stage_var);

  class_FluoPowder_init(&_SIRIUS_fluo_var);

  class_Monitor_nD_init(&_SIRIUS_det_2d_var);

  class_Monitor_nD_init(&_SIRIUS_det_fluo_var);

  class_Beamstop_init(&_beamdump_565_var);

  class_Text_init(&_LUCIA_pos_var);


  class_Undulator_init(&_LUCIA_source_var);

  class_Monitor_nD_init(&_LUCIA_mon_src_xy_var);

  class_Monitor_nD_init(&_LUCIA_mon_src_e_var);

  class_Slit_init(&_LUCIA_slit_var);

  class_Monitor_nD_init(&_LUCIA_slit_mon_xy_var);


  class_Bragg_crystal_init(&_LUCIA_dcm_xtal0_var);


  class_Bragg_crystal_init(&_LUCIA_dcm_xtal1_var);


  class_Monitor_nD_init(&_LUCIA_mon_dcm_e_var);

  class_Monitor_nD_init(&_LUCIA_mon_dcm_xy_var);

  class_Slit_init(&_LUCIA_diaphragm_var);

  class_Monitor_nD_init(&_LUCIA_sample_stage_var);


  class_Fluorescence_init(&_LUCIA_sample_var);

  class_Monitor_nD_init(&_LUCIA_transmission_var);

  class_Fluo_detector_init(&_LUCIA_mon_spl_SDD_var);

  class_Monitor_nD_init(&_LUCIA_mon_spl_fluo_var);

  class_Beamstop_init(&_beamdump_588_var);

  class_Shape_init(&_storage_var);

  class_Shape_init(&_hall0_var);

  class_Shape_init(&_hall1_var);


  class_Shape_init(&_entrance_1_var);

  class_Shape_init(&_ANATOMIX_building_var);

  class_Text_init(&_soleil_label_var);

  if (mcdotrace) display();
  DEBUG_INSTR_END();

#ifdef OPENACC
#include <openacc.h>
#pragma acc update device(_origin_var)
#pragma acc update device(_jumper_var)
#pragma acc update device(_beamdump_var)
#pragma acc update device(_ODE_pos_var)
#pragma acc update device(_SMIS_pos_var)
#pragma acc update device(_AILES_pos_var)
#pragma acc update device(_MARS_pos_var)
#pragma acc update device(_MARS_var)
#pragma acc update device(_MARS_Source_var)
#pragma acc update device(_MARS_displaySourceLength_var)
#pragma acc update device(_MARS_displaySource_var)
#pragma acc update device(_MARS_slit1_var)
#pragma acc update device(_MARS_slit2_var)
#pragma acc update device(_MARS_M1_arm_translation_var)
#pragma acc update device(_MARS_M1_arm_rotation_1_var)
#pragma acc update device(_MARS_mirror_M1_var)
#pragma acc update device(_MARS_M1_arm_rotation_2_var)
#pragma acc update device(_MARS_M1_arm_rotation_2_undo_var)
#pragma acc update device(_MARS_beam_arm_before_crystal_var)
#pragma acc update device(_MARS_dcm_xtal0_var)
#pragma acc update device(_MARS_dcm0_var)
#pragma acc update device(_MARS_dcm_xtal1_var)
#pragma acc update device(_MARS_dcm1_var)
#pragma acc update device(_MARS_emon_dcm0_var)
#pragma acc update device(_MARS_displayMono_var)
#pragma acc update device(_MARS_displayMonoLength_var)
#pragma acc update device(_MARS_M2_arm_translation_var)
#pragma acc update device(_MARS_M2_arm_rotation_1_var)
#pragma acc update device(_MARS_mirror_M2_var)
#pragma acc update device(_MARS_M2_arm_rotation_2_var)
#pragma acc update device(_MARS_M2_arm_rotation_2_undo_var)
#pragma acc update device(_MARS_slitSecon1_var)
#pragma acc update device(_MARS_slitSecon2_var)
#pragma acc update device(_MARS_emon_dcm1_var)
#pragma acc update device(_MARS_displaySlit2_var)
#pragma acc update device(_MARS_Sample_var)
#pragma acc update device(_MARS_detector_diffraction_var)
#pragma acc update device(_MARS_detector_fluo_var)
#pragma acc update device(_beamdump_40_var)
#pragma acc update device(_PSICHE_pos_var)
#pragma acc update device(_PSICHE_var)
#pragma acc update device(_PSICHE_source_var)
#pragma acc update device(_PSICHE_mon_src_e_var)
#pragma acc update device(_PSICHE_mon_src_xy_var)
#pragma acc update device(_PSICHE_DCM_location_var)
#pragma acc update device(_PSICHE_dcm_xtal0_var)
#pragma acc update device(_PSICHE_dcm0_var)
#pragma acc update device(_PSICHE_dcm_xtal1_var)
#pragma acc update device(_PSICHE_dcm1_var)
#pragma acc update device(_PSICHE_mon_dcm_e_var)
#pragma acc update device(_PSICHE_mon_dcm_xy_var)
#pragma acc update device(_PSICHE_slit_var)
#pragma acc update device(_PSICHE_sample_stage_var)
#pragma acc update device(_PSICHE_sample_var)
#pragma acc update device(_PSICHE_fluo_holder_var)
#pragma acc update device(_PSICHE_mon_spl_fluo_var)
#pragma acc update device(_PSICHE_mon_spl_e_var)
#pragma acc update device(_PSICHE_mon_spl_xy_var)
#pragma acc update device(_beamdump_61_var)
#pragma acc update device(_PLEIADES_pos_var)
#pragma acc update device(_DISCO_pos_var)
#pragma acc update device(_DISCO_var)
#pragma acc update device(_DISCO_Source_var)
#pragma acc update device(_DISCO_ColdFinger_var)
#pragma acc update device(_DISCO_M1_location_var)
#pragma acc update device(_DISCO_M1_rotated_var)
#pragma acc update device(_DISCO_M1_x_var)
#pragma acc update device(_DISCO_M1_var)
#pragma acc update device(_DISCO_M1_takeoff_var)
#pragma acc update device(_DISCO_M1_x_takeoff_var)
#pragma acc update device(_DISCO_M2_location_var)
#pragma acc update device(_DISCO_M2_rotated_x_var)
#pragma acc update device(_DISCO_M2_rotated_var)
#pragma acc update device(_DISCO_M2_other_side_var)
#pragma acc update device(_DISCO_M2_var)
#pragma acc update device(_DISCO_M2_other_side_back_var)
#pragma acc update device(_DISCO_M2_takeoff_var)
#pragma acc update device(_DISCO_HFP_location_var)
#pragma acc update device(_DISCO_HFP_var)
#pragma acc update device(_DISCO_M3_arm_var)
#pragma acc update device(_DISCO_M3_var)
#pragma acc update device(_DISCO_M3_takeoff_var)
#pragma acc update device(_DISCO_M3_yz_var)
#pragma acc update device(_DISCO_M4_yz_var)
#pragma acc update device(_DISCO_M4_var)
#pragma acc update device(_DISCO_M4_takeoff_var)
#pragma acc update device(_DISCO_M4_arm_back_var)
#pragma acc update device(_DISCO_VFP_location_var)
#pragma acc update device(_DISCO_VFP_var)
#pragma acc update device(_DISCO_M51_position_var)
#pragma acc update device(_DISCO_M51_rotation_var)
#pragma acc update device(_DISCO_M51_var)
#pragma acc update device(_DISCO_arm_var)
#pragma acc update device(_DISCO_M51_arm_back_var)
#pragma acc update device(_DISCO_M52_position_var)
#pragma acc update device(_DISCO_M52_x_var)
#pragma acc update device(_DISCO_M52_var)
#pragma acc update device(_DISCO_M52_takeoff_var)
#pragma acc update device(_DISCO_M52_x_takeoff_var)
#pragma acc update device(_DISCO_second_HFP_location_var)
#pragma acc update device(_DISCO_second_HFP_var)
#pragma acc update device(_DISCO_M53_location_var)
#pragma acc update device(_DISCO_M53_rotated_var)
#pragma acc update device(_DISCO_M53_var)
#pragma acc update device(_DISCO_M53_takeoff_var)
#pragma acc update device(_DISCO_M54_location_var)
#pragma acc update device(_DISCO_M54_rotated_var)
#pragma acc update device(_DISCO_M54_var)
#pragma acc update device(_DISCO_M54_takeoff_var)
#pragma acc update device(_DISCO_Mtoroids_arm_back_var)
#pragma acc update device(_DISCO_M1_position_var)
#pragma acc update device(_DISCO_M1_rotation_var)
#pragma acc update device(_DISCO_mirror_m1_var)
#pragma acc update device(_DISCO_armm_var)
#pragma acc update device(_DISCO_M1_arm_back_var)
#pragma acc update device(_DISCO_Grating_position_var)
#pragma acc update device(_DISCO_Grating_rotation_var)
#pragma acc update device(_DISCO_Grating_rotation_lines_grating_var)
#pragma acc update device(_DISCO_Grating_rotation_nine_degrees_var)
#pragma acc update device(_DISCO_reflective_grating_var)
#pragma acc update device(_DISCO_Grating_rotation_lines_grating_back_var)
#pragma acc update device(_DISCO_Grating_arm_back_var)
#pragma acc update device(_DISCO_Grating_arm_back_2_var)
#pragma acc update device(_DISCO_Grating_arm_back_3_var)
#pragma acc update device(_DISCO_M22_location_var)
#pragma acc update device(_DISCO_M22_rotated_var)
#pragma acc update device(_DISCO_mirror_m2_var)
#pragma acc update device(_DISCO_arm2_var)
#pragma acc update device(_DISCO_M44_arm_back_var)
#pragma acc update device(_DISCO_arm3_var)
#pragma acc update device(_DISCO_psd_before_slit_var)
#pragma acc update device(_DISCO_slit_var)
#pragma acc update device(_DISCO_psd_monitor_var)
#pragma acc update device(_DISCO_psd_giant_after_grating_var)
#pragma acc update device(_DISCO_e_monitor_var)
#pragma acc update device(_DISCO_w_monitor_var)
#pragma acc update device(_beamdump_140_var)
#pragma acc update device(_DESIRS_pos_var)
#pragma acc update device(_METRO_pos_var)
#pragma acc update device(_PUMA_pos_var)
#pragma acc update device(_PUMA_var)
#pragma acc update device(_PUMA_Source_var)
#pragma acc update device(_PUMA_slit1_var)
#pragma acc update device(_PUMA_slit2_var)
#pragma acc update device(_PUMA_mon_src_e_var)
#pragma acc update device(_PUMA_mon_src_xy_var)
#pragma acc update device(_PUMA_HFM_location_var)
#pragma acc update device(_PUMA_HFM_rotated_var)
#pragma acc update device(_PUMA_mirror_HFM_var)
#pragma acc update device(_PUMA_HFM_out_var)
#pragma acc update device(_PUMA_mon_HFM_out_xy_var)
#pragma acc update device(_PUMA_DCM_location_var)
#pragma acc update device(_PUMA_DCM_xtal1_var)
#pragma acc update device(_PUMA_DCM_xtal1_out_var)
#pragma acc update device(_PUMA_mon_DCM_xtal1_only_xy_var)
#pragma acc update device(_PUMA_DCM_xtal2_var)
#pragma acc update device(_PUMA_DCM_xtal2_out_var)
#pragma acc update device(_PUMA_mon_DCM_out_e_var)
#pragma acc update device(_PUMA_mon_DCM_out_xy_var)
#pragma acc update device(_PUMA_slit3_var)
#pragma acc update device(_PUMA_slit4_var)
#pragma acc update device(_PUMA_slit5_var)
#pragma acc update device(_PUMA_KB_VFM_location_var)
#pragma acc update device(_PUMA_mon_KB_in_xy_var)
#pragma acc update device(_PUMA_KB_VFM_rotated_var)
#pragma acc update device(_PUMA_mirror_KB_VFM_var)
#pragma acc update device(_PUMA_KB_VFM_out_var)
#pragma acc update device(_PUMA_mon_KB_VFM_out_xy_var)
#pragma acc update device(_PUMA_KB_HFM_location_var)
#pragma acc update device(_PUMA_KB_HFM_rotated_var)
#pragma acc update device(_PUMA_mirror_KB_HFM_var)
#pragma acc update device(_PUMA_KB_HFM_out_var)
#pragma acc update device(_PUMA_mon_KB_HFM_out_xy_var)
#pragma acc update device(_PUMA_sample_location_var)
#pragma acc update device(_PUMA_mon_sample_xy_var)
#pragma acc update device(_PUMA_mon_sample_e_var)
#pragma acc update device(_beamdump_181_var)
#pragma acc update device(_CRISTAL_pos_var)
#pragma acc update device(_CRISTAL_var)
#pragma acc update device(_CRISTAL_Source_var)
#pragma acc update device(_CRISTAL_slit1_var)
#pragma acc update device(_CRISTAL_dcm_location_var)
#pragma acc update device(_CRISTAL_dcm_xtal0_var)
#pragma acc update device(_CRISTAL_arm_xtal0_var)
#pragma acc update device(_CRISTAL_dcm_xtal1_var)
#pragma acc update device(_CRISTAL_arm_xtal1_var)
#pragma acc update device(_CRISTAL_emon_dcm_var)
#pragma acc update device(_CRISTAL_M1_location_var)
#pragma acc update device(_CRISTAL_M1_rotated_var)
#pragma acc update device(_CRISTAL_M1_var)
#pragma acc update device(_CRISTAL_M1_out_var)
#pragma acc update device(_CRISTAL_M2_location_var)
#pragma acc update device(_CRISTAL_M2_rotated_var)
#pragma acc update device(_CRISTAL_M2_var)
#pragma acc update device(_CRISTAL_M2_out_var)
#pragma acc update device(_CRISTAL_slit2_var)
#pragma acc update device(_CRISTAL_psd_slit2_var)
#pragma acc update device(_CRISTAL_sample_stage_var)
#pragma acc update device(_CRISTAL_fluo_var)
#pragma acc update device(_CRISTAL_detector_diffraction_var)
#pragma acc update device(_CRISTAL_detector_fluo_var)
#pragma acc update device(_beamdump_207_var)
#pragma acc update device(_DEIMOS_pos_var)
#pragma acc update device(_GALAXIES_pos_var)
#pragma acc update device(_GALAXIES_var)
#pragma acc update device(_GALAXIES_Source_U20_var)
#pragma acc update device(_GALAXIES_mon_src_xy_var)
#pragma acc update device(_GALAXIES_mon_src_e_var)
#pragma acc update device(_GALAXIES_absorber_var)
#pragma acc update device(_GALAXIES_diaphragme_var)
#pragma acc update device(_GALAXIES_fentes_primaires_var)
#pragma acc update device(_GALAXIES_mon_prim_xy_var)
#pragma acc update device(_GALAXIES_DCM_location_var)
#pragma acc update device(_GALAXIES_dcm_xtal0_var)
#pragma acc update device(_GALAXIES_dcm0_var)
#pragma acc update device(_GALAXIES_dcm_xtal1_var)
#pragma acc update device(_GALAXIES_dcm1_var)
#pragma acc update device(_GALAXIES_mon_dcm_e_var)
#pragma acc update device(_GALAXIES_mon_dcm_xy_var)
#pragma acc update device(_GALAXIES_M1_location_var)
#pragma acc update device(_GALAXIES_M1_rotated_var)
#pragma acc update device(_GALAXIES_M1_var)
#pragma acc update device(_GALAXIES_M1_out_var)
#pragma acc update device(_GALAXIES_HRM_gate_in_var)
#pragma acc update device(_GALAXIES_M2A_location_var)
#pragma acc update device(_GALAXIES_M2A_rotated_var)
#pragma acc update device(_GALAXIES_M2A_var)
#pragma acc update device(_GALAXIES_M2A_out_var)
#pragma acc update device(_GALAXIES_secondary_slits_var)
#pragma acc update device(_GALAXIES_mon_sec_xy_var)
#pragma acc update device(_GALAXIES_M2B_location_var)
#pragma acc update device(_GALAXIES_M2B_rotated_var)
#pragma acc update device(_GALAXIES_M2B_var)
#pragma acc update device(_GALAXIES_M2B_out_var)
#pragma acc update device(_GALAXIES_VFM_location_var)
#pragma acc update device(_GALAXIES_VFM_rotated_var)
#pragma acc update device(_GALAXIES_VFM_var)
#pragma acc update device(_GALAXIES_VFM_out_var)
#pragma acc update device(_GALAXIES_HFM_rotated_var)
#pragma acc update device(_GALAXIES_HFM_var)
#pragma acc update device(_GALAXIES_HFM_out_var)
#pragma acc update device(_GALAXIES_mon_sample_xy_kb_var)
#pragma acc update device(_GALAXIES_mon_sample_e_var)
#pragma acc update device(_GALAXIES_sample_stage_var)
#pragma acc update device(_GALAXIES_sample_var)
#pragma acc update device(_GALAXIES_sample_out_var)
#pragma acc update device(_GALAXIES_ana_arm_var)
#pragma acc update device(_GALAXIES_analyzer_var)
#pragma acc update device(_GALAXIES_ana_out_var)
#pragma acc update device(_GALAXIES_IXS_det_var)
#pragma acc update device(_beamdump_257_var)
#pragma acc update device(_TEMPO_pos_var)
#pragma acc update device(_SAMBA_pos_var)
#pragma acc update device(_SAMBA_var)
#pragma acc update device(_SAMBA_BM_source_var)
#pragma acc update device(_SAMBA_M1_location_var)
#pragma acc update device(_SAMBA_M1_rotated_var)
#pragma acc update device(_SAMBA_M1_var)
#pragma acc update device(_SAMBA_M1_out_var)
#pragma acc update device(_SAMBA_DCM_location_var)
#pragma acc update device(_SAMBA_bragg_crystal_var)
#pragma acc update device(_SAMBA_arm_crystal1_var)
#pragma acc update device(_SAMBA_bragg_crystal_two_var)
#pragma acc update device(_SAMBA_arm_crystal2_var)
#pragma acc update device(_SAMBA_DCM_out_var)
#pragma acc update device(_SAMBA_DCM_out_div_var)
#pragma acc update device(_SAMBA_DCM_out_e_var)
#pragma acc update device(_SAMBA_M2_loc_var)
#pragma acc update device(_SAMBA_M2_rotated_var)
#pragma acc update device(_SAMBA_M2_var)
#pragma acc update device(_SAMBA_M2_out_var)
#pragma acc update device(_SAMBA_sample_stage_var)
#pragma acc update device(_SAMBA_fluo_var)
#pragma acc update device(_SAMBA_det_trans_var)
#pragma acc update device(_SAMBA_det_fluo_var)
#pragma acc update device(_beamdump_283_var)
#pragma acc update device(_HERMES_pos_var)
#pragma acc update device(_PX1_pos_var)
#pragma acc update device(_PX1_var)
#pragma acc update device(_PX1_undulator_var)
#pragma acc update device(_PX1_bragg_crystal_location_var)
#pragma acc update device(_PX1_bragg_crystal_var)
#pragma acc update device(_PX1_arm_var)
#pragma acc update device(_PX1_bragg_crystal_two_var)
#pragma acc update device(_PX1_arm_two_var)
#pragma acc update device(_PX1_bragg_crystal_out_var)
#pragma acc update device(_PX1_secondary_slits_var)
#pragma acc update device(_PX1_vfm_location_var)
#pragma acc update device(_PX1_vfm_in_xz_plane_var)
#pragma acc update device(_PX1_vfm_var)
#pragma acc update device(_PX1_vfm_takeoff_var)
#pragma acc update device(_PX1_hfm_location_var)
#pragma acc update device(_PX1_hfm_var)
#pragma acc update device(_PX1_hfm_takeoff_var)
#pragma acc update device(_PX1_sample_stage_var)
#pragma acc update device(_PX1_sample_monitor_var)
#pragma acc update device(_PX1_sample_var)
#pragma acc update device(_PX1_psd4pi_var)
#pragma acc update device(_PX1_EigerX16M_var)
#pragma acc update device(_beamdump_308_var)
#pragma acc update device(_PX2a_pos_var)
#pragma acc update device(_PX2a_var)
#pragma acc update device(_PX2a_undulator_var)
#pragma acc update device(_PX2a_bragg_crystal_location_var)
#pragma acc update device(_PX2a_bragg_crystal_var)
#pragma acc update device(_PX2a_arm_var)
#pragma acc update device(_PX2a_bragg_crystal_two_var)
#pragma acc update device(_PX2a_arm_two_var)
#pragma acc update device(_PX2a_bragg_crystal_out_var)
#pragma acc update device(_PX2a_hpm_location_var)
#pragma acc update device(_PX2a_hpm_in_yz_plane_var)
#pragma acc update device(_PX2a_hpm_var)
#pragma acc update device(_PX2a_hpm_takeoff_var)
#pragma acc update device(_PX2a_vfm_location_var)
#pragma acc update device(_PX2a_vfm_in_xz_plane_var)
#pragma acc update device(_PX2a_vfm_var)
#pragma acc update device(_PX2a_vfm_takeoff_var)
#pragma acc update device(_PX2a_hfm_location_var)
#pragma acc update device(_PX2a_hfm_var)
#pragma acc update device(_PX2a_hfm_takeoff_var)
#pragma acc update device(_PX2a_sample_stage_var)
#pragma acc update device(_PX2a_sample_monitor_var)
#pragma acc update device(_PX2a_sample_var)
#pragma acc update device(_PX2a_psd4pi_var)
#pragma acc update device(_PX2a_Eiger9M_var)
#pragma acc update device(_beamdump_335_var)
#pragma acc update device(_SWING_pos_var)
#pragma acc update device(_SWING_var)
#pragma acc update device(_SWING_Source_U20_var)
#pragma acc update device(_SWING_mon_src_xy_var)
#pragma acc update device(_SWING_mon_src_e_var)
#pragma acc update device(_SWING_slit_var)
#pragma acc update device(_SWING_slit_mon_xy_var)
#pragma acc update device(_SWING_DCM_location_var)
#pragma acc update device(_SWING_dcm_xtal0_var)
#pragma acc update device(_SWING_dcm0_var)
#pragma acc update device(_SWING_dcm_xtal1_var)
#pragma acc update device(_SWING_dcm1_var)
#pragma acc update device(_SWING_mon_dcm_e_var)
#pragma acc update device(_SWING_mon_dcm_xy_var)
#pragma acc update device(_SWING_vfm_location_var)
#pragma acc update device(_SWING_vfm_in_xz_plane_var)
#pragma acc update device(_SWING_vfm_var)
#pragma acc update device(_SWING_vfm_takeoff_var)
#pragma acc update device(_SWING_hfm_location_var)
#pragma acc update device(_SWING_hfm_var)
#pragma acc update device(_SWING_hfm_takeoff_var)
#pragma acc update device(_SWING_sample_stage_var)
#pragma acc update device(_SWING_sample_test_var)
#pragma acc update device(_SWING_sample_var)
#pragma acc update device(_SWING_sample_out_var)
#pragma acc update device(_SWING_Eiger4M_var)
#pragma acc update device(_SWING_QMonitor_var)
#pragma acc update device(_beamdump_364_var)
#pragma acc update device(_ANTARES_pos_var)
#pragma acc update device(_ROCK_pos_var)
#pragma acc update device(_ROCK_var)
#pragma acc update device(_ROCK_Source_var)
#pragma acc update device(_ROCK_slit1_var)
#pragma acc update device(_ROCK_slit2_var)
#pragma acc update device(_ROCK_mirror_m1_var)
#pragma acc update device(_ROCK_mirror_m1_out_var)
#pragma acc update device(_ROCK_slit3_xy_var)
#pragma acc update device(_ROCK_slit3_div_var)
#pragma acc update device(_ROCK_slit3_var)
#pragma acc update device(_ROCK_mirror_m2a_var)
#pragma acc update device(_ROCK_mirror_m2a_out_var)
#pragma acc update device(_ROCK_slit4_in_var)
#pragma acc update device(_ROCK_slit4_var)
#pragma acc update device(_ROCK_arm_crystal0_var)
#pragma acc update device(_ROCK_bragg_crystal_var)
#pragma acc update device(_ROCK_arm_crystal1_var)
#pragma acc update device(_ROCK_bragg_crystal_two_var)
#pragma acc update device(_ROCK_arm_crystal2_var)
#pragma acc update device(_ROCK_bragg_crystal_out_var)
#pragma acc update device(_ROCK_slit5_var)
#pragma acc update device(_ROCK_slit6_var)
#pragma acc update device(_ROCK_mirror_m2b_var)
#pragma acc update device(_ROCK_mirror_m2b_out_var)
#pragma acc update device(_ROCK_EnergyMonitor_before_sample_var)
#pragma acc update device(_ROCK_e_repartition_after_m2b_var)
#pragma acc update device(_ROCK_sample_in_var)
#pragma acc update device(_ROCK_absorption_sample_var)
#pragma acc update device(_ROCK_fluo_monitor_var)
#pragma acc update device(_ROCK_EnergyMonitor_after_sample_var)
#pragma acc update device(_ROCK_psd_monitor_var)
#pragma acc update device(_beamdump_398_var)
#pragma acc update device(_ANATOMIX_pos_var)
#pragma acc update device(_ANATOMIX_var)
#pragma acc update device(_ANATOMIX_source_var)
#pragma acc update device(_ANATOMIX_e_repartition_before_cc_var)
#pragma acc update device(_ANATOMIX_psd_monitor_before_cc_var)
#pragma acc update device(_ANATOMIX_bragg_crystal_var)
#pragma acc update device(_ANATOMIX_arm_var)
#pragma acc update device(_ANATOMIX_bragg_crystal_two_var)
#pragma acc update device(_ANATOMIX_arm_two_var)
#pragma acc update device(_ANATOMIX_psd_after_cc_var)
#pragma acc update device(_ANATOMIX_e_monitor_before_sample_var)
#pragma acc update device(_ANATOMIX_psd_repartition_after_cc_var)
#pragma acc update device(_ANATOMIX_sample_rotation_stage_var)
#pragma acc update device(_ANATOMIX_sample_var)
#pragma acc update device(_ANATOMIX_e_monitor_after_sample_var)
#pragma acc update device(_ANATOMIX_psd_monitor_after_cc_var)
#pragma acc update device(_beamdump_416_var)
#pragma acc update device(_NANOSCOPIUM_pos_var)
#pragma acc update device(_NANOSCOPIUM_var)
#pragma acc update device(_NANO_source_var)
#pragma acc update device(_NANO_e_monitor_source_var)
#pragma acc update device(_NANO_psd_source_var)
#pragma acc update device(_NANO_slit_1_var)
#pragma acc update device(_NANO_m1_in_var)
#pragma acc update device(_NANO_m1_roll_var)
#pragma acc update device(_NANO_mirror_m1_var)
#pragma acc update device(_NANO_beam_deviation_var)
#pragma acc update device(_NANO_m2_in_var)
#pragma acc update device(_NANO_mirror_m2_var)
#pragma acc update device(_NANO_mirror_m2_out_var)
#pragma acc update device(_NANO_slit_2_var)
#pragma acc update device(_NANO_dcm_in_var)
#pragma acc update device(_NANO_PSD_dcm_in_var)
#pragma acc update device(_NANO_bragg_roll_var)
#pragma acc update device(_NANO_bragg_crystal_1_var)
#pragma acc update device(_NANO_dcm2_rot_var)
#pragma acc update device(_NANO_dcm_transl_var)
#pragma acc update device(_NANO_bragg_crystal_2_var)
#pragma acc update device(_NANO_bragg2_out_var)
#pragma acc update device(_NANO_dcm_out_var)
#pragma acc update device(_NANO_e_dcm_out_var)
#pragma acc update device(_NANO_secondary_source_slits_var)
#pragma acc update device(_NANO_psd_ss_in_var)
#pragma acc update device(_NANO_slit_3_var)
#pragma acc update device(_NANO_psd_ss_out_var)
#pragma acc update device(_NANO_jjxray2_slits_var)
#pragma acc update device(_NANO_slit_5_var)
#pragma acc update device(_NANO_kb_in_var)
#pragma acc update device(_NANO_kb_1_var)
#pragma acc update device(_NANO_kb_beam_deviation_var)
#pragma acc update device(_NANO_kb1_out_var)
#pragma acc update device(_NANO_kb2_var)
#pragma acc update device(_NANO_kb_out_var)
#pragma acc update device(_NANO_slit_var)
#pragma acc update device(_NANO_psd_sample_stage_var)
#pragma acc update device(_beamdump_456_var)
#pragma acc update device(_DIFFABS_pos_var)
#pragma acc update device(_DIFFABS_var)
#pragma acc update device(_DIFFABS_BM_D13_1_var)
#pragma acc update device(_DIFFABS_primary_slit_var)
#pragma acc update device(_DIFFABS_M1_location_var)
#pragma acc update device(_DIFFABS_M1_rotated_var)
#pragma acc update device(_DIFFABS_M1_var)
#pragma acc update device(_DIFFABS_M1_out_var)
#pragma acc update device(_DIFFABS_DCM_slit_in_var)
#pragma acc update device(_DIFFABS_DCM_in_var)
#pragma acc update device(_DIFFABS_DCM_in_div_var)
#pragma acc update device(_DIFFABS_DCM_location_var)
#pragma acc update device(_DIFFABS_bragg_crystal_var)
#pragma acc update device(_DIFFABS_arm_crystal1_var)
#pragma acc update device(_DIFFABS_bragg_crystal_two_var)
#pragma acc update device(_DIFFABS_arm_crystal2_var)
#pragma acc update device(_DIFFABS_DCM_out_var)
#pragma acc update device(_DIFFABS_DCM_out_div_var)
#pragma acc update device(_DIFFABS_DCM_out_e_var)
#pragma acc update device(_DIFFABS_DCM_slit_out_var)
#pragma acc update device(_DIFFABS_M2_location_var)
#pragma acc update device(_DIFFABS_M2_rotated_var)
#pragma acc update device(_DIFFABS_M2_var)
#pragma acc update device(_DIFFABS_M2_out_var)
#pragma acc update device(_DIFFABS_sample_stage_var)
#pragma acc update device(_DIFFABS_fluo_var)
#pragma acc update device(_DIFFABS_fluo_monitor_var)
#pragma acc update device(_DIFFABS_det_angle_var)
#pragma acc update device(_DIFFABS_xpad_var)
#pragma acc update device(_beamdump_487_var)
#pragma acc update device(_SEXTANTS_var)
#pragma acc update device(_SIXS_pos_var)
#pragma acc update device(_SIXS_var)
#pragma acc update device(_SIXS_Source_U20_var)
#pragma acc update device(_SIXS_mon_src_xy_var)
#pragma acc update device(_SIXS_mon_src_e_var)
#pragma acc update device(_SIXS_slit_var)
#pragma acc update device(_SIXS_slit_mon_xy_var)
#pragma acc update device(_SIXS_DCM_location_var)
#pragma acc update device(_SIXS_dcm_xtal0_var)
#pragma acc update device(_SIXS_dcm0_var)
#pragma acc update device(_SIXS_dcm_xtal1_var)
#pragma acc update device(_SIXS_dcm1_var)
#pragma acc update device(_SIXS_mon_dcm_e_var)
#pragma acc update device(_SIXS_mon_dcm_xy_var)
#pragma acc update device(_SIXS_M1_location_var)
#pragma acc update device(_SIXS_M1_rotated_var)
#pragma acc update device(_SIXS_M1_var)
#pragma acc update device(_SIXS_M1_out_var)
#pragma acc update device(_SIXS_M2_location_var)
#pragma acc update device(_SIXS_M2_rotated_var)
#pragma acc update device(_SIXS_M2_var)
#pragma acc update device(_SIXS_M2_out_var)
#pragma acc update device(_SIXS_sample_stage_var)
#pragma acc update device(_SIXS_sx_layer_var)
#pragma acc update device(_SIXS_sx_bulk_var)
#pragma acc update device(_SIXS_sample_out_var)
#pragma acc update device(_SIXS_det4pi_var)
#pragma acc update device(_SIXS_detector_layer_var)
#pragma acc update device(_SIXS_detector_bulk_var)
#pragma acc update device(_beamdump_519_var)
#pragma acc update device(_CASSIOPEE_pos_var)
#pragma acc update device(_CASSIOPEE_var)
#pragma acc update device(_CASSIOPEE_Source_HU60_var)
#pragma acc update device(_CASSIOPEE_Source_HU256_var)
#pragma acc update device(_CASSIOPEE_M1a_location_var)
#pragma acc update device(_CASSIOPEE_M1a_var)
#pragma acc update device(_CASSIOPEE_M1a_out_var)
#pragma acc update device(_CASSIOPEE_M1b_var)
#pragma acc update device(_CASSIOPEE_M1c_var)
#pragma acc update device(_CASSIOPEE_M1bc_out_var)
#pragma acc update device(_CASSIOPEE_PSD_M1out_var)
#pragma acc update device(_CASSIOPEE_PG_location_var)
#pragma acc update device(_CASSIOPEE_PG_var)
#pragma acc update device(_CASSIOPEE_M2_rotation_axis_var)
#pragma acc update device(_CASSIOPEE_M2_var)
#pragma acc update device(_CASSIOPEE_PM_takeoff_var)
#pragma acc update device(_CASSIOPEE_slit_var)
#pragma acc update device(_CASSIOPEE_M4_var)
#pragma acc update device(_CASSIOPEE_PSD_var)
#pragma acc update device(_beamdump_540_var)
#pragma acc update device(_SIRIUS_pos_var)
#pragma acc update device(_SIRIUS_var)
#pragma acc update device(_SIRIUS_source_var)
#pragma acc update device(_SIRIUS_M1_loc_var)
#pragma acc update device(_SIRIUS_M1_rot_var)
#pragma acc update device(_SIRIUS_M1_var)
#pragma acc update device(_SIRIUS_M1_out_var)
#pragma acc update device(_SIRIUS_DCM_location_var)
#pragma acc update device(_SIRIUS_bragg_crystal_var)
#pragma acc update device(_SIRIUS_arm_crystal1_var)
#pragma acc update device(_SIRIUS_bragg_crystal_two_var)
#pragma acc update device(_SIRIUS_arm_crystal2_var)
#pragma acc update device(_SIRIUS_DCM_out_var)
#pragma acc update device(_SIRIUS_DCM_out_div_var)
#pragma acc update device(_SIRIUS_DCM_out_e_var)
#pragma acc update device(_SIRIUS_def_loc_var)
#pragma acc update device(_SIRIUS_def_rot_var)
#pragma acc update device(_SIRIUS_def_mirror_var)
#pragma acc update device(_SIRIUS_def_out_var)
#pragma acc update device(_SIRIUS_sample_stage_var)
#pragma acc update device(_SIRIUS_fluo_var)
#pragma acc update device(_SIRIUS_det_2d_var)
#pragma acc update device(_SIRIUS_det_fluo_var)
#pragma acc update device(_beamdump_565_var)
#pragma acc update device(_LUCIA_pos_var)
#pragma acc update device(_LUCIA_var)
#pragma acc update device(_LUCIA_source_var)
#pragma acc update device(_LUCIA_mon_src_xy_var)
#pragma acc update device(_LUCIA_mon_src_e_var)
#pragma acc update device(_LUCIA_slit_var)
#pragma acc update device(_LUCIA_slit_mon_xy_var)
#pragma acc update device(_LUCIA_DCM_location_var)
#pragma acc update device(_LUCIA_dcm_xtal0_var)
#pragma acc update device(_LUCIA_dcm0_var)
#pragma acc update device(_LUCIA_dcm_xtal1_var)
#pragma acc update device(_LUCIA_dcm1_var)
#pragma acc update device(_LUCIA_mon_dcm_e_var)
#pragma acc update device(_LUCIA_mon_dcm_xy_var)
#pragma acc update device(_LUCIA_diaphragm_var)
#pragma acc update device(_LUCIA_sample_stage_var)
#pragma acc update device(_LUCIA_fluo_rotated_var)
#pragma acc update device(_LUCIA_sample_var)
#pragma acc update device(_LUCIA_transmission_var)
#pragma acc update device(_LUCIA_mon_spl_SDD_var)
#pragma acc update device(_LUCIA_mon_spl_fluo_var)
#pragma acc update device(_beamdump_588_var)
#pragma acc update device(_storage_var)
#pragma acc update device(_hall0_var)
#pragma acc update device(_hall1_var)
#pragma acc update device(_entrance_0_var)
#pragma acc update device(_entrance_1_var)
#pragma acc update device(_ANATOMIX_building_var)
#pragma acc update device(_soleil_label_var)
#pragma acc update device(_instrument_var)
#endif

  return(0);
} /* init */

/*******************************************************************************
* components TRACE
*******************************************************************************/

#define x (_particle->x)
#define y (_particle->y)
#define z (_particle->z)
#define kx (_particle->kx)
#define ky (_particle->ky)
#define kz (_particle->kz)
#define phi (_particle->phi)
#define t (_particle->t)
#define Ex (_particle->Ex)
#define Ey (_particle->Ey)
#define Ez (_particle->Ez)
#define p (_particle->p)
#define allow_backprop (_particle->allow_backprop)
#define _mctmp_a (_particle->_mctmp_a)
#define _mctmp_b (_particle->_mctmp_b)
#define _mctmp_c (_particle->_mctmp_c)
/* if on GPU, globally nullify sprintf,fprintf,printfs   */
/* (Similar defines are available in each comp trace but */
/*  those are not enough to handle external libs etc. )  */
#ifdef OPENACC
#define fprintf(stderr,...) printf(__VA_ARGS__)
#define sprintf(string,...) printf(__VA_ARGS__)
#define exit(...) noprintf()
#define strcmp(a,b) str_comp(a,b)
#define strlen(a) str_len(a)
#endif
#define SCATTERED (_particle->_scattered)
#define RESTORE (_particle->_restore)
#define RESTORE_XRAY(_index, ...) _particle->_restore = _index;
#define ABSORB0 do { DEBUG_STATE(); DEBUG_ABSORB(); ABSORBED++; return; } while(0)
#define ABSORBED (_particle->_absorbed)
#define mcget_run_num() _particle->_uid
#define ABSORB ABSORB0
#pragma acc routine
void class_Arm_trace(_class_Arm *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  SIG_MESSAGE("[_origin_trace] component origin=Arm() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:57]");

#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 1) { // EXTEND 'origin'
    // set JUMP target: must be Arm  Direct jump in local coordinates
    beamline = mcget_run_num() % BEAMLINE_MAX; // sends in order to all BLs
}
if (_comp->_index == 244) { // EXTEND 'GALAXIES_sample_stage'
  flag_scatt = 0;
}
if (_comp->_index == 246) { // EXTEND 'GALAXIES_sample_out'
  if (!flag_scatt) ABSORB;
}
if (_comp->_index == 295) { // EXTEND 'PX1_sample_stage'
  if (!flag_hfm || !flag_vfm) ABSORB;
}
if (_comp->_index == 321) { // EXTEND 'PX2a_sample_stage'
  if (!PX2a_flag_hfm || !PX2a_flag_vfm) ABSORB;
}
if (_comp->_index == 500) { // EXTEND 'SIXS_sample_out'
  if (!SIXS_flag_scatt) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  return;
} /* class_Arm_trace */

#pragma acc routine
void class_Beamstop_trace(_class_Beamstop *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  SIG_MESSAGE("[_beamdump_trace] component beamdump=Beamstop() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:69]");

  double dz, z0 = z;
  ALLOW_BACKPROP;
  PROP_Z0;
  dz = z - z0; /*dz<0 means photon must travel backwards to hit beamstop*/
  if (((dz >= 0) && ((radius != 0) && (x * x + y * y <= radius * radius))) || ((dz >= 0) && (radius == 0) && (x > xmin && x < xmax && y > ymin && y < ymax))) {
    SCATTER;
    ABSORB;
  } else {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 39) { // EXTEND 'beamdump_40'
    ABSORB; 
}
if (_comp->_index == 59) { // EXTEND 'beamdump_61'
    ABSORB; 
}
if (_comp->_index == 137) { // EXTEND 'beamdump_140'
    ABSORB; 
}
if (_comp->_index == 177) { // EXTEND 'beamdump_181'
    ABSORB; 
}
if (_comp->_index == 202) { // EXTEND 'beamdump_207'
    ABSORB; 
}
if (_comp->_index == 251) { // EXTEND 'beamdump_257'
    ABSORB; 
}
if (_comp->_index == 276) { // EXTEND 'beamdump_283'
    ABSORB; 
}
if (_comp->_index == 300) { // EXTEND 'beamdump_308'
    ABSORB; 
}
if (_comp->_index == 326) { // EXTEND 'beamdump_335'
    ABSORB; 
}
if (_comp->_index == 354) { // EXTEND 'beamdump_364'
    ABSORB; 
}
if (_comp->_index == 387) { // EXTEND 'beamdump_398'
    ABSORB; 
}
if (_comp->_index == 404) { // EXTEND 'beamdump_416'
    ABSORB; 
}
if (_comp->_index == 443) { // EXTEND 'beamdump_456'
    ABSORB; 
}
if (_comp->_index == 473) { // EXTEND 'beamdump_487'
    ABSORB; 
}
if (_comp->_index == 504) { // EXTEND 'beamdump_519'
    ABSORB; 
}
if (_comp->_index == 524) { // EXTEND 'beamdump_540'
    ABSORB; 
}
if (_comp->_index == 548) { // EXTEND 'beamdump_565'
    ABSORB; 
}
if (_comp->_index == 570) { // EXTEND 'beamdump_588'
    ABSORB; 
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  #undef xwidth
  #undef yheight
  #undef radius
  return;
} /* class_Beamstop_trace */

#pragma acc routine
void class_Text_trace(_class_Text *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define text (_comp->_parameters.text)
  #define size (_comp->_parameters.size)
  #define plane (_comp->_parameters.plane)
  #define pen_thickness (_comp->_parameters.pen_thickness)
  #define pl (_comp->_parameters.pl)
  SIG_MESSAGE("[_ODE_pos_trace] component ODE_pos=Text() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:129]");

  /* component Text does nothing */
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef text
  #undef size
  #undef plane
  #undef pen_thickness
  #undef pl
  return;
} /* class_Text_trace */

#pragma acc routine
void class_Bending_magnet_trace(_class_Bending_magnet *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define lambda0 (_comp->_parameters.lambda0)
  #define dlambda (_comp->_parameters.dlambda)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define gauss_t (_comp->_parameters.gauss_t)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define kc (_comp->_parameters.kc)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define p0 (_comp->_parameters.p0)
  SIG_MESSAGE("[_MARS_Source_trace] component MARS_Source=Bending_magnet() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:139]");


  double xx, yy, x1, y1, z1;
  double k, e, l;
  double F1 = 1.0;
  double dx, dy, dz;

  // initial source area
  xx = randnorm ();
  yy = randnorm ();
  x = xx * sigex;
  y = yy * sigey;
  z = 0;

  // Gaussian distribution at origin
  p = p0; /*initial weight is p0*/
  if (E0) {
    if (!dE) {
      e = E0;
    } else {
      e = randpm1 () * dE + E0;
    }
    k = E2K * e;
  } else if (lambda0) {
    if (!dlambda) {
      l = lambda0;
    } else {
      l = randpm1 () * dlambda + lambda0;
    }
    k = (2 * M_PI / l);
  }
  // targeted area calculation
  if (focus_xw) {
    if (!gauss_t) {
      /*sample uniformly but adjust weight*/
      x1 = randpm1 () * focus_xw / 2.0;
      p *= exp (-(x1 * x1) / (2.0 * s1x * s1x));
    } else {
      do {
        x1 = randnorm () * s1x;
      } while (focus_xw != 0 && fabs (x1) > focus_xw / 2.0);
      /*adjust for restricted sampling window*/
      p *= erf (focus_xw * 0.5 * M_SQRT1_2 / s1x);
    }
  } else {
    x1 = randnorm () * igamma;
  }
  if (focus_yh) {
    if (!gauss_t) {
      /*sample uniformly but adjust weight*/
      y1 = randpm1 () * focus_yh / 2.0;
      p *= exp (-(y1 * y1) / (2.0 * s1y * s1y));
    } else {
      do {
        y1 = randnorm () * s1y;
      } while (fabs (y1) > focus_yh / 2.0);
      /*adjust for restricted sampling window*/
      p *= erf (focus_yh * 0.5 * M_SQRT1_2 / s1y);
    }
  } else {
    y1 = randnorm () * igamma;
  }
  z1 = dist;
  dx = x1 - x;
  dy = y1 - y;
  dz = sqrt (dx * dx + dy * dy + dist * dist);

  kx = (k * dx) / dz;
  ky = (k * dy) / dz;
  kz = (k * dist) / dz;

  /*spectral strength of radiation is given by Patterson*/
  double k_kc = k / kc;
  double K2_3 = besselKnu (0.666666666666666666666666667, k_kc * 0.5);
  p *= 1.33e13 * Ee * Ee * Ie * k_kc * k_kc * K2_3 * K2_3;
  // p*=ALPHA/(M_PI*M_PI)*gamma2*Ie/CELE* 1e-4 * 0.75 *k_kc*k_kc*K2_3*K2_3;

  /*randomly pick phase*/
  if (randomphase) {
    phi = rand01 () * 2 * M_PI;
  } else {
    phi = phase;
  }

  /*set polarization vector*/
  Ex = 0;
  Ey = 0;
  Ez = 0;
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef E0
  #undef dE
  #undef lambda0
  #undef dlambda
  #undef phase
  #undef randomphase
  #undef Ee
  #undef Ie
  #undef B
  #undef sigey
  #undef sigex
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef gauss_t
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef kc
  #undef s1x
  #undef s1y
  #undef p0
  return;
} /* class_Bending_magnet_trace */

#pragma acc routine
void class_Monitor_nD_trace(_class_Monitor_nD *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define user0 (_comp->_parameters.user0)
  #define user1 (_comp->_parameters.user1)
  #define user2 (_comp->_parameters.user2)
  #define user3 (_comp->_parameters.user3)
  #define user4 (_comp->_parameters.user4)
  #define user5 (_comp->_parameters.user5)
  #define user6 (_comp->_parameters.user6)
  #define user7 (_comp->_parameters.user7)
  #define user8 (_comp->_parameters.user8)
  #define user9 (_comp->_parameters.user9)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define bins (_comp->_parameters.bins)
  #define min (_comp->_parameters.min)
  #define max (_comp->_parameters.max)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define radius (_comp->_parameters.radius)
  #define options (_comp->_parameters.options)
  #define filename (_comp->_parameters.filename)
  #define geometry (_comp->_parameters.geometry)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define username0 (_comp->_parameters.username0)
  #define username1 (_comp->_parameters.username1)
  #define username2 (_comp->_parameters.username2)
  #define username3 (_comp->_parameters.username3)
  #define username4 (_comp->_parameters.username4)
  #define username5 (_comp->_parameters.username5)
  #define username6 (_comp->_parameters.username6)
  #define username7 (_comp->_parameters.username7)
  #define username8 (_comp->_parameters.username8)
  #define username9 (_comp->_parameters.username9)
  #define DEFS (_comp->_parameters.DEFS)
  #define Vars (_comp->_parameters.Vars)
  #define detector (_comp->_parameters.detector)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_MARS_displaySourceLength_trace] component MARS_displaySourceLength=Monitor_nD() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:473]");

  //  double  XY=0;
  double l0 = 0;
  double l1 = 0;
  int pp;
  int intersect = 0;
  char Flag_Restore = 0;

  #ifdef OPENACC
  #ifdef USE_OFF
  off_struct thread_offdata = offdata;
  #endif
  #else
  #define thread_offdata offdata
  #endif

  /* this is done automatically
    STORE_XRAY(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p);
  */
  #ifdef USE_OFF
  if (geometry && strlen (geometry) && strcmp (geometry, "0") && strcmp (geometry, "NULL")) {
    /* determine intersections with object */
    intersect = off_x_intersect (&l0, &l1, NULL, NULL, x, y, z, kx, ky, kz, offdata);
  } else
    #endif
    if ((abs (Vars.Flag_Shape) == DEFS.SHAPE_SQUARE) || (abs (Vars.Flag_Shape) == DEFS.SHAPE_DISK)) /* square xy or disk xy */
    {
      // propagate to xy plane and find intersection
      // make sure the event is recoverable afterwards
      l0 = z;
      ALLOW_BACKPROP;
      PROP_Z0;
      if ((z >= l0) && (z * copysign (z, 1.0) <= DBL_EPSILON)) // forward propagation to xy plane was successful
      {
        if (abs (Vars.Flag_Shape) == DEFS.SHAPE_SQUARE) {
          // square xy
          intersect = (x >= Vars.mxmin && x <= Vars.mxmax && y >= Vars.mymin && y <= Vars.mymax);
        } else {
          // disk xy
          intersect = (SQR (x) + SQR (y)) <= SQR (Vars.Sphere_Radius);
        }
      } else {
        intersect = 0;
      }
    } else if (abs (Vars.Flag_Shape) == DEFS.SHAPE_SPHERE) /* sphere */
    {
      intersect = sphere_intersect (&l0, &l1, x, y, z, kx, ky, kz, Vars.Sphere_Radius);
      /*      intersect = (intersect && t0 > 0); */
    } else if ((abs (Vars.Flag_Shape) == DEFS.SHAPE_CYLIND) || (abs (Vars.Flag_Shape) == DEFS.SHAPE_BANANA)) /* cylinder */
    {
      intersect = cylinder_intersect (&l0, &l1, x, y, z, kx, ky, kz, Vars.Sphere_Radius, Vars.Cylinder_Height);
    } else if (abs (Vars.Flag_Shape) == DEFS.SHAPE_BOX) /* box */
    {
      intersect = box_intersect (&l0, &l1, x, y, z, kx, ky, kz, fabs (Vars.mxmax - Vars.mxmin), fabs (Vars.mymax - Vars.mymin), fabs (Vars.mzmax - Vars.mzmin));
    } else if (abs (Vars.Flag_Shape) == DEFS.SHAPE_PREVIOUS) /* previous comp */
    {
      intersect = 1;
    }

  if (intersect) {
    if ((abs (Vars.Flag_Shape) == DEFS.SHAPE_SPHERE) || (abs (Vars.Flag_Shape) == DEFS.SHAPE_CYLIND) || (abs (Vars.Flag_Shape) == DEFS.SHAPE_BOX)
        || (abs (Vars.Flag_Shape) == DEFS.SHAPE_BANANA) || (geometry && strlen (geometry) && strcmp (geometry, "0") && strcmp (geometry, "NULL"))) {
      /* check if we have to remove the top/bottom with BANANA shape */
      if ((abs (Vars.Flag_Shape) == DEFS.SHAPE_BANANA) && (intersect != 1)) {
        double y0, y1;
        /* propagate to intersection point as temporary variable to check top/bottom */
        y0 = y + l0;
        y1 = y + l1;
        if (fabs (y0) >= Vars.Cylinder_Height / 2 * 0.99)
          l0 = l1;
        if (fabs (y1) >= Vars.Cylinder_Height / 2 * 0.99)
          l1 = l0;
      }
      if (l0 < 0 && l1 > 0)
        l0 = 0;             /* photon was already inside ! */
      if (l1 < 0 && l0 > 0) /* photon exit before entering !! */
        l1 = 0;
      /* t0 is now time of incoming intersection with the detection area */
      if ((Vars.Flag_Shape < 0) && (l1 > 0))
        PROP_DL (l1); /* l1 outgoing beam */
      else
        PROP_DL (l0); /* l0 incoming beam */
      /* Final test if we are on lid / bottom of banana/sphere */
      if (abs (Vars.Flag_Shape) == DEFS.SHAPE_BANANA || abs (Vars.Flag_Shape) == DEFS.SHAPE_SPHERE) {
        if (Vars.Cylinder_Height && fabs (y) >= Vars.Cylinder_Height / 2 - FLT_EPSILON) {
          intersect = 0;
          Flag_Restore = 1;
        }
      }
    }
  }

  if (intersect) {

    pp = Monitor_nD_Trace (&DEFS, &Vars, _particle);
    if (pp == 0.0) {
      ABSORB;
    } else if (pp == 1) {
      SCATTER;
    }

    if (Vars.Flag_parallel) /* back to photon state before detection */
      Flag_Restore = 1;
  } /* end if intersection */
  else {
    if (Vars.Flag_Absorb && !Vars.Flag_parallel) {
      // restore x-ray before absorbing for correct mcdisplay
      RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
      ABSORB;
    } else
      Flag_Restore = 1; /* no intersection, back to previous state */
  }

  if (Flag_Restore) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 347) { // EXTEND 'SWING_hfm_takeoff'
  if (!SWING_flag_hfm || !SWING_flag_vfm) ABSORB;
}
if (_comp->_index == 497) { // EXTEND 'SIXS_sample_stage'
  SIXS_flag_scatt = 0;
}
if (_comp->_index == 544) { // EXTEND 'SIRIUS_sample_stage'
	if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef user0
  #undef user1
  #undef user2
  #undef user3
  #undef user4
  #undef user5
  #undef user6
  #undef user7
  #undef user8
  #undef user9
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef bins
  #undef min
  #undef max
  #undef restore_xray
  #undef radius
  #undef options
  #undef filename
  #undef geometry
  #undef nowritefile
  #undef username0
  #undef username1
  #undef username2
  #undef username3
  #undef username4
  #undef username5
  #undef username6
  #undef username7
  #undef username8
  #undef username9
  #undef DEFS
  #undef Vars
  #undef detector
  #undef offdata
  return;
} /* class_Monitor_nD_trace */

#pragma acc routine
void class_PSD_monitor_trace(_class_PSD_monitor *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nr (_comp->_parameters.nr)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_displaySource_trace] component MARS_displaySource=PSD_monitor() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:90]");

  int i, j, k;
  double e, p2;

  int backprop = allow_backprop; /* set by caller: also count backward hits */
  double t0 = t;
  ALLOW_BACKPROP;
  PROP_Z0;
  if (!radius) {
    if ((backprop || t >= t0) && x > xmin && x < xmax && y > ymin && y < ymax) {
      i = floor ((x - xmin) * nx / (xmax - xmin));
      j = floor ((y - ymin) * ny / (ymax - ymin));
      p2 = p * p;
      #pragma acc atomic
      PSD_N[i][j] += 1;
      #pragma acc atomic
      PSD_p[i][j] += p;
      #pragma acc atomic
      PSD_p2[i][j] += p2;
      SCATTER;
    }
  } else {
    double r = sqrt (x * x + y * y);
    if ((backprop || t >= t0) && r < radius) {
      i = floor (r * nr / radius);
      p2 = p * p;
      #pragma acc atomic
      PSD_N[0][i] += 1;
      #pragma acc atomic
      PSD_p[0][i] += p;
      #pragma acc atomic
      PSD_p2[0][i] += p2;
      SCATTER;
    }
  }
  if (restore_xray || !SCATTERED) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef filename
  #undef xwidth
  #undef yheight
  #undef radius
  #undef restore_xray
  #undef nowritefile
  #undef nx
  #undef ny
  #undef nr
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return;
} /* class_PSD_monitor_trace */

#pragma acc routine
void class_Slit_trace(_class_Slit *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define dist (_comp->_parameters.dist)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_x0 (_comp->_parameters.focus_x0)
  #define focus_y0 (_comp->_parameters.focus_y0)
  SIG_MESSAGE("[_MARS_slit1_trace] component MARS_slit1=Slit() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:89]");

  PROP_Z0;
  if (((radius == 0) && (x < xmin || x > xmax || y < ymin || y > ymax)) || ((radius != 0) && (x * x + y * y > radius * radius))) {
    ABSORB;
  } else {
    SCATTER;
  }

  if (focus_xw || focus_yh) {
    double posx, posy, posz, pdir, k;
    coords_get (POS_A_CURRENT_COMP, &posx, &posy, &posz);

    /*we have a target behind the slit - so we now consider the ray a Huygens wavelet.*/
    double xf, yf, zf;
    randvec_target_rect_real (&xf, &yf, &zf, &pdir, focus_x0 - posx, focus_y0 - posy, dist, focus_xw, focus_yh, ROT_A_CURRENT_COMP, x, y, z, 0);
    // p*=pdir;
    k = sqrt (scalar_prod (kx, ky, kz, kx, ky, kz));
    kx = (xf - x);
    ky = (yf - y);
    kz = (zf - z);
    NORM (kx, ky, kz);
    kx *= k;
    ky *= k;
    kz *= k;
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  #undef radius
  #undef xwidth
  #undef yheight
  #undef dist
  #undef focus_xw
  #undef focus_yh
  #undef focus_x0
  #undef focus_y0
  return;
} /* class_Slit_trace */

#pragma acc routine
void class_Mirror_curved_trace(_class_Mirror_curved *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define radius (_comp->_parameters.radius)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define zdepth (_comp->_parameters.zdepth)
  #define yheight (_comp->_parameters.yheight)
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define Z (_comp->_parameters.Z)
  #define At (_comp->_parameters.At)
  #define rho (_comp->_parameters.rho)
  #define T (_comp->_parameters.T)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_MARS_mirror_M1_trace] component MARS_mirror_M1=Mirror_curved() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:75]");

  double l0, l1, dl, alpha, n, nx, nz, s, k, knx, knz;
  /* dl init - cppcheck complains about algorithm below */
  dl=0;
  /*do we hit the mirror within range?*/
  // PROP_Z0;
  k = sqrt (scalar_prod (kx, 0, kz, kx, 0, kz));
  knx = kx / k;
  knz = kz / k;
  if (solve_2nd_order (&l0, &l1, knx* knx + knz * knz, 2 * (x * knx + z * knz - radius * knx), x* x - 2 * x * radius + z * z)) {
    if (l0 < 0 && l1 > 0) {
      dl = l1;
    } else if (l1 < 0 && l0 > 0) {
      dl = l0;
    } else if (l0 > 0 && l1 > 0) {
      if (fabs (z + knz * l0) < zdepth / 2.0 && fabs (x + knx * l0) < fabs (radius)) {
        /*this means that the first positive match is on the mirror z-wise
          - this should be picked. This would work even if mirror is hit from behind*/
        dl = l0;
      } else {
        dl = l1;
      }
    } else {
      /*particle misses the mirror completely (l0<0 and l1<0)*/
      RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
    }

    /*correction for only solving in xz-plane*/
    dl *= sqrt (scalar_prod (kx, ky, kz, kx, ky, kz) / scalar_prod (kx, 0, kz, kx, 0, kz));

    PROP_DL (dl);
    alpha = asin (z / radius);
    if ((zdepth < radius * alpha) || (fabs (y) > yheight / 2.0)) {
      RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
    } else {
      SCATTER;
      /*reflection*/
      nx = radius - x;
      nz = -z;
      n = sqrt (nx * nx + nz * nz);
      nx /= n;
      nz /= n;

      s = scalar_prod (kx, 0, kz, nx, 0, nz);
      kx = kx - 2 * s * nx;
      kz = kz - 2 * s * nz;

      double Q;
      /*length of wavevector transfer may be compute from s and n_ above*/
      Q = fabs (2 * s * sqrt (nx * nx + nz * nz));
      cdouble R = refleccq (re, Q, 0, k, fabs (90 - acos (s / k) * RAD2DEG));
      p *= sqrt (creal (cmul(R, conj (R))));
      phi += atan2 (cimag (R), creal (R));
    }
  } else if (fabs (kx) < DBL_EPSILON && fabs (kz) < DBL_EPSILON && ky != 0) {
    /*This to catch the extreme case where k//y.*/
    if (y == 0) {
      /*We hit the "side" of the mirror.*/
      ABSORB;
    }
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 68) { // EXTEND 'DISCO_M1'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 81) { // EXTEND 'DISCO_M3'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 97) { // EXTEND 'DISCO_M52'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 149) { // EXTEND 'PUMA_mirror_HFM'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 166) { // EXTEND 'PUMA_mirror_KB_VFM'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 171) { // EXTEND 'PUMA_mirror_KB_HFM'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 190) { // EXTEND 'CRISTAL_M1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 194) { // EXTEND 'CRISTAL_M2'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 222) { // EXTEND 'GALAXIES_M1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 237) { // EXTEND 'GALAXIES_VFM'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 240) { // EXTEND 'GALAXIES_HFM'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 258) { // EXTEND 'SAMBA_M1'
  if (!SCATTERED) ABSORB; 
}
if (_comp->_index == 270) { // EXTEND 'SAMBA_M2'
  if (!SCATTERED) ABSORB; 
}
if (_comp->_index == 290) { // EXTEND 'PX1_vfm'
  flag_vfm=SCATTERED;
}
if (_comp->_index == 293) { // EXTEND 'PX1_hfm'
  flag_hfm=SCATTERED;
}
if (_comp->_index == 316) { // EXTEND 'PX2a_vfm'
  PX2a_flag_vfm=SCATTERED;
}
if (_comp->_index == 319) { // EXTEND 'PX2a_hfm'
  PX2a_flag_hfm=SCATTERED;
}
if (_comp->_index == 343) { // EXTEND 'SWING_vfm'
  SWING_flag_vfm=SCATTERED;
}
if (_comp->_index == 346) { // EXTEND 'SWING_hfm'
  SWING_flag_hfm=SCATTERED;
}
if (_comp->_index == 378) { // EXTEND 'ROCK_mirror_m2b'
	if (!SCATTERED) ABSORB; 
}
if (_comp->_index == 413) { // EXTEND 'NANO_mirror_m1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 416) { // EXTEND 'NANO_mirror_m2'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 436) { // EXTEND 'NANO_kb_1'
	if (!SCATTERED) ABSORB; 
}
if (_comp->_index == 439) { // EXTEND 'NANO_kb2'
	if (!SCATTERED) ABSORB; 
}
if (_comp->_index == 450) { // EXTEND 'DIFFABS_M1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 466) { // EXTEND 'DIFFABS_M2'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 491) { // EXTEND 'SIXS_M1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 495) { // EXTEND 'SIXS_M2'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 530) { // EXTEND 'SIRIUS_M1'
  if (!SCATTERED) ABSORB; 
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef radius
  #undef R0
  #undef coating
  #undef zdepth
  #undef yheight
  #undef length
  #undef width
  #undef Z
  #undef At
  #undef rho
  #undef T
  #undef re
  return;
} /* class_Mirror_curved_trace */

#pragma acc routine
void class_Bragg_crystal_trace(_class_Bragg_crystal *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define V (_comp->_parameters.V)
  #define form_factors (_comp->_parameters.form_factors)
  #define material (_comp->_parameters.material)
  #define alpha (_comp->_parameters.alpha)
  #define R0 (_comp->_parameters.R0)
  #define debye_waller_B (_comp->_parameters.debye_waller_B)
  #define crystal_type (_comp->_parameters.crystal_type)
  #define h (_comp->_parameters.h)
  #define k (_comp->_parameters.k)
  #define l (_comp->_parameters.l)
  #define structure_factor_scale_r (_comp->_parameters.structure_factor_scale_r)
  #define structure_factor_scale_i (_comp->_parameters.structure_factor_scale_i)
  #define Z (_comp->_parameters.Z)
  #define rho (_comp->_parameters.rho)
  #define At (_comp->_parameters.At)
  #define f_rel (_comp->_parameters.f_rel)
  #define f_nt (_comp->_parameters.f_nt)
  #define m_t (_comp->_parameters.m_t)
  #define f0_t (_comp->_parameters.f0_t)
  SIG_MESSAGE("[_MARS_dcm_xtal0_trace] component MARS_dcm_xtal0=Bragg_crystal() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:129]");

  double E;                   // (keV) x-ray energy
  double K;                   // length of k-vector
  double kxu, kyu, kzu;       // unit vector in the direction of k-vector.
  double tin;                 // 'time' of intersection of ray with y=0 plane (which include the crystal surface)
  double x_int, y_int, z_int; // intersection with the y=0 plane
  double dist;                // distance from position at t=0 to the y=0 plane
  double f00, f0h, fp, fpp;   // atomic form factors for Q=0 is (f00 + fp + i*fpp) and for Q= ha*+kb*+lc* it is (f0h + fp + i*fpp).
  double Thetain;             // (rad) angle between the crystal surface and the incident ray
  double Theta0;              // (rad) angle between the Bragg planes and the incident ray
  double Thetah;              // (rad) angle between the Bragg planes and the reflected ray
  double Thetaout;            // (rad) angle between the crystal surface and the reflected ray
  double DeltaTheta0;         // (rad) the center of the reflectivity curve is at asin(n*lambda/(2*d)) + DeltaTheta0
  double Rpi, Rsig, R;        // Reflectivity value calculated by DarwinReflectivity() function for each incoming photon
  double x0, y0, z0, kx0, ky0, kz0, phi0, t0, Ex0, Ey0, Ez0, p0;

  x0 = x;
  y0 = y;
  z0 = z;
  kx0 = kx;
  ky0 = ky;
  kz0 = kz;
  phi0 = phi;
  t0 = t;
  Ex0 = Ex;
  Ey0 = Ey;
  Ez0 = Ez;
  p0 = p;
  /* get the photon's kvector and energy */
  K = sqrt (kx * kx + ky * ky + kz * kz);
  E = K2E * K; /* use built-in constants for consistency */
  /* make unit vector in the direction of k :*/
  kxu = kx;
  kyu = ky;
  kzu = kz;
  NORM (kxu, kyu, kzu);
  /* printf("incoming kx,ky,kz, Ex, Ey, Ez, k.E: %f %f %f %g %g %g %g\n", kx,ky,kz,Ex,Ey,Ez, kxu*Ex+kyu*Ey+kzu*Ez); */

  /*intersection calculation*/
  tin = -y / kyu;
  if (tin >= 0) {
    /* check whether our intersection lies within the boundaries of the crystal*/
    x_int = x + kxu * tin;
    y_int = y + kyu * tin;
    z_int = z + kzu * tin;

    if (fabs (x_int) <= width / 2 && fabs (z_int) <= length / 2) {
      dist = sqrt (SQR (x - x_int) + SQR (y - y_int) + SQR (z - z_int));
      PROP_DL (dist); /* now the photon is on the crystal surface, ready to be reflected... */
      SCATTER;
      Thetain = fabs (asin (kyu));                          /* k(x,y,z)u is a unit vector, the y component is sin(theta) */
      double d = cbrt (V) / (sqrt (h * h + k * k + l * l)); /*this is valid only for cubic structures*/
      f00 = Z;
      f0h = Table_Value (f0_t, 1 / (2 * d), Z);
      fp = Table_Value (m_t, E, 1) - Z;
      fpp = Table_Value (m_t, E, 2);

      double alpha1 = alpha;
      /* check for 3rd & 1st quadrant hits, backward hit from above or forward hit from below and reverse sense of alpha */
      if ((ky < 0 && kz < 0) || (ky > 0 && kz > 0))
        alpha1 = -alpha1;
      Mx_DarwinReflectivity (&Rpi, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha1, h, k, l, debye_waller_B, E, Thetain, 1, crystal_type,
                             structure_factor_scale_r, structure_factor_scale_i);
      Mx_DarwinReflectivity (&Rsig, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha1, h, k, l, debye_waller_B, E, Thetain, 2, crystal_type,
                             structure_factor_scale_r, structure_factor_scale_i);

      double pi_x, pi_y, pi_z, sig_x, sig_y, sig_z;
      double kx0 = kx, ky0 = ky, kz0 = kz, Ex0 = Ex, Ey0 = Ey, Ez0 = Ez;

      /* sig_x,y,z is k(in) x surface_normal i.e. the direction of sigma polarization */
      vec_prod_func (&sig_x, &sig_y, &sig_z, kx0, ky0, kz0, 0, -1, 0);
      NORM (sig_x, sig_y, sig_z);
      /* pi is a vector perpendicular to k_in and sig i.e. the direction of pi polarization incoming */
      vec_prod_func (&pi_x, &pi_y, &pi_z, kx0, ky0, kz0, sig_x, sig_y, sig_z);
      NORM (pi_x, pi_y, pi_z);

      #ifdef MCDEBUG
      printf ("%s: Thetain: %.3f sigma: (%g, %g, %g) pi: (%g, %g, %g) \n", NAME_CURRENT_COMP, Thetain * 180 / PI, sig_x, sig_y, sig_z, pi_x, pi_y, pi_z);
      #endif

      double sth = sin (Theta0 + Thetah), cth = cos (Theta0 + Thetah);
      if (sig_x * pi_y * pi_z > 0) { /* backwards hit, rotate the other way */
        sth = -sth;
      }
      double sx2 = sig_x * sig_x, sy2 = sig_y * sig_y, sz2 = sig_z * sig_z, r2 = sig_x * sig_x + sig_y * sig_y;

      /* initialize a rotation matrix by the appropriate angle around the sigma axis, this from Mathematica RotationMatrix[] */
      double m[3][3] = { sx2 + (cth * (sy2 + sx2 * sz2)) / r2,
                         sig_x * sig_y - sig_z * sth + (cth * sig_x * sig_y * (-1 + sz2)) / r2,
                         sig_x * sig_z - cth * sig_x * sig_z + sig_y * sth,
                         sig_x * sig_y + sig_z * sth + (cth * sig_x * sig_y * (-1 + sz2)) / r2,
                         sy2 + (cth * (sx2 + sy2 * sz2)) / r2,
                         sig_y * sig_z - cth * sig_y * sig_z - sig_x * sth,
                         sig_x * sig_z - cth * sig_x * sig_z - sig_y * sth,
                         sig_y * sig_z - cth * sig_y * sig_z + sig_x * sth,
                         cth * r2 + sz2 };

      #ifdef MCDEBUG
      printf ("%s matrix=\n%12.3f %12.3f %12.3f\n%12.3f %12.3f %12.3f\n%12.3f %12.3f %12.3f\n", NAME_CURRENT_COMP, m[0][0], m[0][1], m[0][2], m[1][0], m[1][1],
              m[1][2], m[2][0], m[2][1], m[2][2]);
      #endif

      /* execute the rotation about the sigma vector */
      kx = m[0][0] * kx0 + m[0][1] * ky0 + m[0][2] * kz0;
      ky = m[1][0] * kx0 + m[1][1] * ky0 + m[1][2] * kz0;
      kz = m[2][0] * kx0 + m[2][1] * ky0 + m[2][2] * kz0;

      /* resolve incoming polarization into sig and pi bits, and scale by sqrt(reflectivity) which is amplitude scale */
      double Esig = (Ex * sig_x + Ey * sig_y + Ez * sig_z), Epi = (Ex * pi_x + Ey * pi_y + Ez * pi_z);
      if (Esig == 0 && Epi == 0) { /* someone didn't set the polarization direction; set it now to a random value and it will propagate */
        double psi = rand01 () * PI / 2;
        Esig = cos (psi);
        Epi = sin (psi);
      }
      Esig = Esig * sqrt (Rsig);
      Epi = Epi * sqrt (Rpi);
      R = Esig * Esig + Epi * Epi; /* projected reflectivity, squared back to intensity */

      /* pi is now a vector perpendicular to k_out and sig i.e. the direction of pi polarization outgoing */
      vec_prod_func (&pi_x, &pi_y, &pi_z, kx, ky, kz, sig_x, sig_y, sig_z);
      NORM (pi_x, pi_y, pi_z);

      /* a linear combination of these is still perpendicular to k, but has the correct polarization weighting */
      Ex = Epi * pi_x + Esig * sig_x;
      Ey = Epi * pi_y + Esig * sig_y;
      Ez = Epi * pi_z + Esig * sig_z;
      NORM (Ex, Ey, Ez);
      #ifdef MCDEBUG
      printf ("%s: Rsig, Rpi, R, k0, k1, e0, e1: %g %g %g (%g, %g, %g) (%g, %g, %g) (%g, %g, %g) (%g, %g, %g)\n", NAME_CURRENT_COMP, Rsig, Rpi, R, kx0, ky0, kz0,
              kx, ky, kz, Ex0, Ey0, Ez0, Ex, Ey, Ez);
      #endif
      /* apply Darwin reflectivity if not is supplied from outside*/
      if (!R0) {
        p *= R;
      } else {
        p *= R0;
      }
      /*catch dead rays*/
      if (p == 0)
        ABSORB;
    } else {
      // RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);//
      x = x0;
      y = y0;
      z = z0;
      kx = kx0;
      ky = ky0;
      kz = kz0;
      phi = phi0;
      t = t0;
      Ex = Ex0;
      Ey = Ey0;
      Ez = Ez0;
      p = p0;
    }
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 46) { // EXTEND 'PSICHE_dcm_xtal0'
  if (PSICHE_dcm_scatter && !SCATTERED) ABSORB;
}
if (_comp->_index == 48) { // EXTEND 'PSICHE_dcm_xtal1'
  if (PSICHE_dcm_scatter && !SCATTERED) ABSORB;
}
if (_comp->_index == 183) { // EXTEND 'CRISTAL_dcm_xtal0'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 185) { // EXTEND 'CRISTAL_dcm_xtal1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 214) { // EXTEND 'GALAXIES_dcm_xtal0'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 216) { // EXTEND 'GALAXIES_dcm_xtal1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 248) { // EXTEND 'GALAXIES_analyzer'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 261) { // EXTEND 'SAMBA_bragg_crystal'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 263) { // EXTEND 'SAMBA_bragg_crystal_two'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 335) { // EXTEND 'SWING_dcm_xtal0'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 337) { // EXTEND 'SWING_dcm_xtal1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 371) { // EXTEND 'ROCK_bragg_crystal'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 373) { // EXTEND 'ROCK_bragg_crystal_two'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 422) { // EXTEND 'NANO_bragg_crystal_1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 425) { // EXTEND 'NANO_bragg_crystal_2'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 456) { // EXTEND 'DIFFABS_bragg_crystal'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 458) { // EXTEND 'DIFFABS_bragg_crystal_two'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 483) { // EXTEND 'SIXS_dcm_xtal0'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 485) { // EXTEND 'SIXS_dcm_xtal1'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 533) { // EXTEND 'SIRIUS_bragg_crystal'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 535) { // EXTEND 'SIRIUS_bragg_crystal_two'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 557) { // EXTEND 'LUCIA_dcm_xtal0'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 559) { // EXTEND 'LUCIA_dcm_xtal1'
  if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef length
  #undef width
  #undef V
  #undef form_factors
  #undef material
  #undef alpha
  #undef R0
  #undef debye_waller_B
  #undef crystal_type
  #undef h
  #undef k
  #undef l
  #undef structure_factor_scale_r
  #undef structure_factor_scale_i
  #undef Z
  #undef rho
  #undef At
  #undef f_rel
  #undef f_nt
  #undef m_t
  #undef f0_t
  return;
} /* class_Bragg_crystal_trace */

#pragma acc routine
void class_E_monitor_trace(_class_E_monitor *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_emon_dcm0_trace] component MARS_emon_dcm0=E_monitor() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:88]");

  int i;
  double E;

  int backprop = allow_backprop; /* set by caller: also count backward hits */
  double t0 = t;
  ALLOW_BACKPROP;
  PROP_Z0;
  if ((backprop || t >= t0) && x > xmin && x < xmax && y > ymin && y < ymax) {
    E = K2E * sqrt (kx * kx + ky * ky + kz * kz);

    i = floor ((E - Emin) * nE / (Emax - Emin));
    if (i >= 0 && i < nE) {
      #pragma acc atomic
      E_N[i] = E_N[i] + 1;
      #pragma acc atomic
      E_p[i] = E_p[i] + p;
      #pragma acc atomic
      E_p2[i] = E_p2[i] + p * p;
      SCATTER;
    }
  }
  if (restore_xray || !SCATTERED) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef nE
  #undef filename
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef restore_xray
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return;
} /* class_E_monitor_trace */

void class_FluoPowder_trace(_class_FluoPowder *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_powder (_comp->_parameters.flag_powder)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define powder_refl (_comp->_parameters.powder_refl)
  #define powder_format (_comp->_parameters.powder_format)
  #define Vc (_comp->_parameters.Vc)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define DW (_comp->_parameters.DW)
  #define d_phi (_comp->_parameters.d_phi)
  #define nb_atoms (_comp->_parameters.nb_atoms)
  #define barns (_comp->_parameters.barns)
  #define tth_sign (_comp->_parameters.tth_sign)
  #define order (_comp->_parameters.order)
  #define line_info (_comp->_parameters.line_info)
  #define columns (_comp->_parameters.columns)
  #define mat_columns (_comp->_parameters.mat_columns)
  #define offdata (_comp->_parameters.offdata)
  #define tgt_x (_comp->_parameters.tgt_x)
  #define tgt_y (_comp->_parameters.tgt_y)
  #define tgt_z (_comp->_parameters.tgt_z)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_Nq (_comp->_parameters.reuse_Nq)
  #define reuse_my_s_k2_sum (_comp->_parameters.reuse_my_s_k2_sum)
  SIG_MESSAGE("[_MARS_Sample_trace] component MARS_Sample=FluoPowder() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:442]");


int    intersect=0;       /* flag to continue/stop */
int    reuse    =0;       /* flag raised when reusing (SPLIT) */
int    type     =-1;      /* type of interaction */
double l0,  l1,  l2,  l3; /* distances for intersections */
double dl0, dl1, dl2, dl; /* distance intervals */
int    flag_concentric = 0;
int    flag_ishollow   = 0;
int    event_counter   = 0;         /* scattering event counter (multiple fluorescence) */
int    force_transmit  = 0;         /* Flag to handle cross-section weighting in case of finite order */
double sigma_barn=0, xs[5];         /* cross sections [barn/atom] fluo/Compton/Rayleigh/diff/transmit */
double aim_x=0, aim_y=0, aim_z=1;   /* Position of target relative to scattering point */


// powderN add-ons
int    Nq              = line_info.Nq;
double my_s_k2_sum     = 0;

#ifdef OPENACC
#ifdef USE_OFF
off_struct thread_offdata = offdata;
#endif
#else
#define thread_offdata offdata
#endif

double k, E;
double ki,pi;

/* Store Initial photon state */
k  = ki = sqrt(kx*kx+ky*ky+kz*kz); //  Angs-1
E  = K2E*k; // keV
pi = p;      // used to test for multiple fluo weighting and order cutoff

do { /* while (intersect) Loop over multiple scattering events */

  // test for a SPLIT event (same particle comes in)
  l0=l1=l2=l3=dl0=dl1=dl2=0;
  if (!event_counter && fabs(reuse_ki - ki) < 1e-15) {
    reuse     = 1;
    reuse_nb++;
    // use cached values and skip actual computation
    intersect = reuse_intersect;
    l0        = reuse_l0;
    l1        = reuse_l1;
    l2        = reuse_l2;
    l3        = reuse_l3;

  } else {
    // we have a different event: compute intersection lengths

    /* ========================================================================== */
    /*                                   GEOMETRY                                 */
    /* ========================================================================== */

    /* Intersection photon trajectory / sample (sample surface) */
    if (thickness >= 0) {
      if (shape==0)
        intersect=cylinder_intersect(&l0,&l3, x,y,z,kx,ky,kz, radius,yheight);
      else if (shape==1)
        intersect=box_intersect     (&l0,&l3, x,y,z,kx,ky,kz, xwidth,yheight,zdepth);
      else if (shape==2)
        intersect=sphere_intersect  (&l0,&l3, x,y,z,kx,ky,kz, radius);
      #ifdef USE_OFF
      else if (shape == 3)
        intersect=off_x_intersect(&l0, &l3, NULL, NULL, x, y, z, kx,ky,kz, thread_offdata );
      #endif
    } else {
      if (shape==0)
        intersect=cylinder_intersect(&l0,&l3, x,y,z,kx,ky,kz, radius-thickness,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight);
      else if (shape==1)
        intersect=box_intersect     (&l0,&l3, x,y,z,kx,ky,kz,
          xwidth-2*thickness > 0 ?  xwidth-2*thickness : xwidth,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight,
          zdepth-2*thickness > 0 ?  zdepth-2*thickness : zdepth);
      else if (shape==2)
        intersect=sphere_intersect  (&l0,&l3, x,y,z,kx,ky,kz, radius-thickness);
      #ifdef USE_OFF
      else if (shape == 3)
        intersect=off_x_intersect   (&l0, &l3, NULL, NULL, x, y, z, kx,ky,kz, thread_offdata );
      #endif
    }


    /* Computing the intermediate lengths */
    if (intersect && p_interact >= 0) {
      flag_ishollow = 0;
      if (thickness > 0) {
        if (shape==0 && cylinder_intersect(&l1,&l2, x,y,z,kx,ky,kz, radius-thickness,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight))
          flag_ishollow=1;
        else if (shape==2 && sphere_intersect   (&l1,&l2, x,y,z,kx,ky,kz, radius-thickness))
          flag_ishollow=1;
        else if (shape==1 && box_intersect(&l1,&l2, x,y,z,kx,ky,kz,
          xwidth-2*thickness > 0 ? xwidth-2*thickness : xwidth,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight,
          zdepth-2*thickness > 0 ? zdepth-2*thickness : zdepth))
          flag_ishollow=1;
      } else if (thickness<0) {
        if (shape==0 && cylinder_intersect(&l1,&l2, x,y,z,kx,ky,kz, radius,yheight))
          flag_ishollow=1;
        else if (shape==2 && sphere_intersect   (&l1,&l2, x,y,z,kx,ky,kz, radius))
          flag_ishollow=1;
        else if (shape==1 && box_intersect(&l1,&l2, x,y,z,kx,ky,kz, xwidth, yheight, zdepth))
          flag_ishollow=1;
      }
      if (l3 > 1000) l3=0;              // we passed the sample, far away
      if (!flag_ishollow) l1 = l2 = l3; /* no empty space inside */
    } /* if intersect */


    // store values for potential next SPLIT
    if (!event_counter) {
      reuse_intersect = intersect;
      reuse_l0        = l0;
      reuse_l1        = l1;
      reuse_l2        = l2;
      reuse_l3        = l3;
      reuse_ki        = ki;
    }
    reuse           = 0;
  } // if !reuse (SPLIT)

  if (intersect) { /* the photon hits the sample */

    if (l0 > 0) {  /* we are before the sample */
      PROP_DL(l0); /* propagates photon to the entry of the sample */
    } else if (l1 > 0 && l1 > l0) { /* we are inside first part of the sample */
      /* no propagation, stay inside */
    } else if (l2 > 0 && l2 > l1) { /* we are in the hole */
      PROP_DL(l2); /* propagate to inner surface of 2nd part of sample */
    } else if (l3 > 0 && l3 > l2) { /* we are in the 2nd part of sample */
      /* no propagation, stay inside */
    }

    dl0=l1-(l0 > 0 ? l0 : 0); /* Distance in first part of hollow/cylinder/box */
    dl1=l2-(l1 > 0 ? l1 : 0); /* Distance in hole */
    dl2=l3-(l2 > 0 ? l2 : 0); /* Distance in 2nd part of hollow cylinder */

    if (dl0 < 0) dl0 = 0;
    if (dl1 < 0) dl1 = 0;
    if (dl2 < 0) dl2 = 0;

    /* initialize concentric mode */
    if (concentric && !flag_concentric && l0 >= 0
     && shape==0 && thickness) {
      flag_concentric=1;
    }

    if (flag_concentric == 1) {
      dl1=dl2=0; /* force exit when reaching hole/2nd part */
    }

    if (!dl0 && !dl2) {
      intersect = 0; /* the sample was passed entirely */
    }
  } // if intersect (geometry)

  /* ========================================================================== */
  /*                             INTERACTION PROCESS                            */
  /* ========================================================================== */
  xs[FLUORESCENCE]=xs[COMPTON]=xs[RAYLEIGH]=xs[TRANSMISSION]=xs[DIFFRACTION]=sigma_barn=0;
  cum_xs_fluo[0] = cum_xs_Compton[0] = cum_xs_Rayleigh[0] = 0;
  
  if (intersect) {
    double my_s;
    int    i_Z,i;
    int    flag=0;
    double d_path, p_trans, p_scatt, mc_trans, mc_scatt;

    /* actual fluorescence calculation */

    /* compute total scattering cross section for incoming photon energy Ei */
    /* compute each contribution XS */
    if (!reuse) {
      for (i_Z=0; i_Z< compound->nElements; i_Z++) {
        int    Z   = compound->Elements[i_Z];
        double frac= compound->massFractions[i_Z];
        double xs_Z[3];

        // get Fluorescence xs
        XRMC_CrossSections(Z, E, xs_Z, flag_kissel); // [barn/atom]
        cum_xs_fluo[i_Z+1]     = cum_xs_fluo[i_Z]    +frac*xs_Z[FLUORESCENCE];
        cum_xs_Compton[i_Z+1]  = cum_xs_Compton[i_Z] +frac*xs_Z[COMPTON];
        cum_xs_Rayleigh[i_Z+1] = cum_xs_Rayleigh[i_Z]+frac*xs_Z[RAYLEIGH];
        for (i=0; i<3; i++) { xs[i] += frac*xs_Z[i]; }
      } // for Z in compound
      for (i=0; i<3; i++) sigma_barn += xs[i]; // total XS

      if (flag_powder) {
        // we add the diffraction XS
        Nq = calc_xsect(k, line_info.q, line_info.my_s_k2, line_info.count,
                        &my_s_k2_sum, &line_info);
        line_info.my_s_k2_sum = my_s_k2_sum;
        line_info.Nq          = Nq;
        line_info.k           = k;
        xs[DIFFRACTION]       = my_s_k2_sum/(k*k)/100/fluo_rho; // 100: fm^2 -> barn
        sigma_barn           += xs[DIFFRACTION];
      } else {
        xs[DIFFRACTION] = 0;
        Nq              = 0;
        my_s_k2_sum     = 0;
      }

      // store values into cache for SPLIT
      if (!event_counter) {
        for (i_Z=0; i_Z< compound->nElements+1; i_Z++) {
          reuse_cum_xs_fluo[i_Z]     = cum_xs_fluo[i_Z];
          reuse_cum_xs_Compton[i_Z]  = cum_xs_Compton[i_Z];
          reuse_cum_xs_Rayleigh[i_Z] = cum_xs_Rayleigh[i_Z];
        }
        reuse_sigma_barn          = sigma_barn;
        if (flag_powder) {
          reuse_cum_xs_diffraction  = xs[DIFFRACTION];
          reuse_Nq                  = Nq;
          reuse_my_s_k2_sum         = my_s_k2_sum;
        }
      }

    } else {
      // reuse cached values (SPLIT)
      for (i_Z=0; i_Z< compound->nElements+1; i_Z++) {
        cum_xs_fluo[i_Z]     = reuse_cum_xs_fluo[i_Z];
        cum_xs_Compton[i_Z]  = reuse_cum_xs_Compton[i_Z];
        cum_xs_Rayleigh[i_Z] = reuse_cum_xs_Rayleigh[i_Z];
        xs[FLUORESCENCE]      += reuse_cum_xs_fluo[i_Z];
        xs[COMPTON]           += reuse_cum_xs_Compton[i_Z];
        xs[RAYLEIGH]          += reuse_cum_xs_Rayleigh[i_Z];
      }
      sigma_barn   = reuse_sigma_barn;
      if (flag_powder) {
        xs[DIFFRACTION]        = reuse_cum_xs_diffraction;
        my_s_k2_sum= line_info.my_s_k2_sum=reuse_my_s_k2_sum;
        Nq         = line_info.Nq         =reuse_Nq;
      }
    }

    /* probability to absorb/scatter */
    my_s   = fluo_rho*100*sigma_barn; /* mu 100: convert from barns to fm^2. my_s in [1/m] */
    d_path = ( dl0 +dl2 );            /* total path lenght in sample */

    /* Proba of transmission/interaction along length d_path */
    p_trans = exp(-my_s*d_path); /* probability to not-interact (transmit) */
    //printf("sigma_barn=%g p_trans=%g\n", sigma_barn, p_trans);
    p_scatt = 1 - p_trans;       /* portion of beam which scatters */

    /* force a given fraction of the beam to scatter */
    if (!event_counter && p_interact>0 && p_interact<=1) {
      /* we force a portion of the beam to interact */
      /* This is used to improve statistics */
      mc_trans = 1-p_interact;
    } else {
      mc_trans = p_trans; /* 1 - p_scatt */
    }
    mc_scatt = 1 - mc_trans; /* portion of beam to scatter (or force to) */
    if (mc_scatt <= 0) ABSORB;

    if (!force_transmit && mc_scatt > 0 && (mc_scatt >= 1 || rand01() < mc_scatt)) {
      /* we "scatter" with one of the interaction processes */
      dl = -log(1 - rand0max((1 - exp(-my_s*d_path)))) / my_s; /* length */
      /* If t0 is in hole, propagate to next part of the hollow cylinder */
      if (dl1 > 0 && dl0 > 0 && dl > dl0) dl += dl1;
      /* photon propagation to the scattering point */
      PROP_DL(dl);
      p *= fabs(p_scatt/mc_scatt); /* account for p_interact, lower than 1 */

    } else { // force_transmit
      /* we go through the material without interaction, and exit */
      if (type <0) type = TRANSMISSION; // transmission
      intersect = 0;
      PROP_DL(d_path);
      /* attenuate beam by portion which is scattered (and left along) */
      p *= p_trans;
      if (!event_counter && p_interact>0 && p_interact<=1) p /= mc_trans;
      break; // end while (intersect)
    }

  } /* if intersect (propagate) */

  if (intersect) { /* scattering event */
    int    i_Z=-1, Z, line=-1;
    double solid_angle=0;
    double theta=0, dsigma=0, alpha=0;
    double Ef=0, dE=0;
    double kf=k, kf_x, kf_y, kf_z;  // next particle direction

    /* correct for XS total(photo+Compton+Rayleigh+Powder) > sum(fluo+Compton+Rayleigh+Powder) */
    dsigma = (xs[FLUORESCENCE]+xs[RAYLEIGH]+xs[COMPTON]+xs[DIFFRACTION])/sigma_barn;
    if (dsigma < 1) p *= dsigma; // < 1

    /* MC choose process from cross sections 'xs': fluo, Rayleigh, Compton, diff */
    type = XRMC_SelectInteraction(xs, DIFFRACTION+1, rand01()); // up to DIFFRACTION

    /* choose Z (element) on associated XS, taking into account mass-fractions */
    switch (type) {
      case FLUORESCENCE:
        i_Z = XRMC_SelectFromDistribution(cum_xs_fluo,     compound->nElements+1, rand01());
        break;
      case RAYLEIGH:
        if (!flag_rayleigh) ABSORB;
        i_Z = XRMC_SelectFromDistribution(cum_xs_Rayleigh, compound->nElements+1, rand01());
        break;
      case COMPTON:
        if (!flag_compton) ABSORB;
        i_Z = XRMC_SelectFromDistribution(cum_xs_Compton,  compound->nElements+1, rand01());
        break;
      case DIFFRACTION:
        if (!flag_powder) ABSORB;
        if (Nq > 1) {
          // choose a line among those possible, using F2 as relative probability/intensity
          line = XRMC_SelectInteraction(line_info.my_s_k2, Nq, rand01());
        } else line = 0;/* Select between Nq powder lines */
        break;
      default: // should never happen
        // printf("WARNING: %s: process %i unknown. Absorb.\n", NAME_CURRENT_COMP, type);
        ABSORB;
    }

    if (i_Z >= 0) {
      // fluorescence
      Z   = compound->Elements[i_Z];

      /* select outgoing vector */
      if ((target_x || target_y || target_z)) {
        aim_x = target_x-x;       /* Vector pointing at target (anal./det.) */
        aim_y = target_y-y;
        aim_z = target_z-z;
      }
      if(focus_aw && focus_ah) {
        randvec_target_rect_angular(&kf_x, &kf_y, &kf_z, &solid_angle,
          aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP);
      } else if(focus_xw && focus_yh) {
        randvec_target_rect(&kf_x, &kf_y, &kf_z, &solid_angle,
          aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
      } else {
        randvec_target_circle(&kf_x, &kf_y, &kf_z, &solid_angle, aim_x, aim_y, aim_z, focus_r);
      }
      p *= solid_angle/(4*PI); // correct for selected solid-angle

    } else if (line >= 0) {
      // powder diffraction
      double arg, tmp_kx, tmp_ky, tmp_kz, kout_x, kout_y, kout_z, nx, ny, nz, alpha0, sg=1;

      if (line_info.w[line])
        arg = line_info.q[line]*(1+line_info.w[line]*randnorm())/(2.0*k);
      else
        arg = line_info.q[line]/(2.0*k);
      if(fabs(arg) > 1) ABSORB; /* No bragg scattering possible   */
      theta = asin(arg);       /* Bragg scattering law           */
      if (tth_sign == 0) {
        sg = randpm1();
        if (sg > 0) sg = 1; else sg=-1;
      }
      else  {
        sg = tth_sign/fabs(tth_sign);
      }

      /* Choose point on Debye-Scherrer cone */
      if (d_phi)
      { /* relate height of detector to the height on DS cone */
        arg = sin(d_phi*DEG2RAD/2)/sin(2*theta);
        /* If full Debye-Scherrer cone is within d_phi, don't focus */
        if (arg < -1 || arg > 1) d_phi = alpha = 0;
        /* Otherwise, determine alpha to rotate from scattering plane
         *    into d_phi focusing area */
        else alpha = 2*asin(arg);
      }
      if (d_phi && alpha) {
        /* Focusing */
        alpha  = fabs(alpha);
        alpha0 = 0.5*randpm1()*alpha;
      }
      else
        alpha0 = M_PI*randpm1();

      // compute out-going direction
      if (fabs(kx/k) < fabs(kz/k)) {
        nx = 1; ny = 0; nz = 0;
      } else {
        nx = 0; ny = 0; nz = 1;
      }
      vec_prod(tmp_kx,tmp_ky,tmp_kz, kx,ky,kz, nx,ny,nz);

      /* k_out = rotate 'k' by 2*theta around tmp_k: Bragg angle */
      rotate(kout_x,kout_y,kout_z, kx,ky,kz, 2*sg*theta, tmp_kx,tmp_ky,tmp_kz);

      /* tmp_k = rotate k_out by alpha0 around 'k' (Debye-Scherrer cone) */
      rotate(tmp_kx,tmp_ky,tmp_kz, kout_x,kout_y,kout_z, alpha0, kx, ky, kz);
      kf_x = tmp_kx;
      kf_y = tmp_ky;
      kf_z = tmp_kz;

    } else ABSORB; // should never happen

    NORM(kf_x, kf_y, kf_z);  // normalize the outout direction |kf|=1

    // determine final energy
    switch (type) {
      case FLUORESCENCE: /* 0 Fluo: choose line */
        Ef      = XRMC_SelectFluorescenceEnergy(Z, E, &dE, flag_kissel, rand01()); // dE full-width in keV
        if (dE) {
          dE /= 2;  // half-width
          if (flag_lorentzian) dE  *= tan(PI/2*randpm1()); // Lorentzian distribution
          else                 dE  *= randnorm();          // Gaussian distribution
          Ef = Ef + dE;
        }
        kf      = Ef*E2K;
        theta   = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k);
        /* add polarisation factor */
        if (Ex!=0 || Ey!=0 || Ez!=0){
          double EE=sqrt(Ex*Ex+Ey*Ey+Ez*Ez);
          double s=scalar_prod(kf_x,kf_y,kf_z,Ex,Ey,Ez)/EE;
          p *= (1-s)*(1-s);
        } else {
          /*unpolarized light in - means an effective reduction according to only theta*/
          p *= (1+cos(theta)*cos(theta))*0.5;
        }
        n_fluo++;
        p_fluo += p;
        break;

      case RAYLEIGH:     /* 1 Rayleigh: Coherent, elastic    */
        theta      = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k); // k is the previous |k|
        dsigma     = DCSb_Rayl(Z,  E, theta, NULL); // [barn/at/st]
        p         *= 4*PI*dsigma/xs[RAYLEIGH];
        n_Rayleigh++;
        p_Rayleigh+= p;
        break;

      case COMPTON:      /* 2 Compton: Incoherent: choose final energy */
        theta      = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k); // k is the previous |k|
        dsigma     = DCS_Compt(Z,  E, theta, NULL); // [barn/at/st] E is the previous particle energy
        kf         = ComptonEnergy(E, theta, NULL)*E2K; /* XRayLib, fraction of emc2=511 keV */
        p         *= 4*PI*dsigma/xs[COMPTON];
        n_Compton++;
        p_Compton += p;
        break;

      case DIFFRACTION:  /* 3 diffraction: line chosen before */
        /* weight the outgoing signal according to polarization */
        if (Ex!=0 || Ey!=0 || Ez!=0){
          double EE=sqrt(Ex*Ex+Ey*Ey+Ez*Ez);
          double s=scalar_prod(kf_x,kf_y,kf_z,Ex,Ey,Ez)/EE;
          p *= (1-s)*(1-s);
        }else{
          /*unpolarized light in - means an effective reduction according to only theta*/
          p *= (1+cos(theta)*cos(theta))*0.5;
        }
        if (d_phi && alpha) {
          p *= alpha/PI;
        }
        n_diff++;
        p_diff += p;
        break;

      default:  // should never happen
        ABSORB;
    }

    kx = kf*kf_x;
    ky = kf*kf_y;
    kz = kf*kf_z;
    k  = kf;
    E  = K2E*kf;
    SCATTER;
    event_counter++;

    /* exit if multiple scattering order has been reached */
    if (!order) break; // skip final absorption
    // stop when order has been reached, or weighting is very low
    if (order && (event_counter >= order || p/pi < 1e-15)) { force_transmit=1; }

  } // if intersect (scatter)
} while(intersect); /* end do (intersect) (multiple scattering loop) */

#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_powder
  #undef flag_kissel
  #undef powder_refl
  #undef powder_format
  #undef Vc
  #undef delta_d_d
  #undef DW
  #undef d_phi
  #undef nb_atoms
  #undef barns
  #undef tth_sign
  #undef order
  #undef line_info
  #undef columns
  #undef mat_columns
  #undef offdata
  #undef tgt_x
  #undef tgt_y
  #undef tgt_z
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef n_diff
  #undef p_diff
  #undef fluo_rho
  #undef reuse_cum_xs_diffraction
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_Nq
  #undef reuse_my_s_k2_sum
  return;
} /* class_FluoPowder_trace */

#pragma acc routine
void class_Wiggler_trace(_class_Wiggler *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define lambda0 (_comp->_parameters.lambda0)
  #define dlambda (_comp->_parameters.dlambda)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define length (_comp->_parameters.length)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define gauss_t (_comp->_parameters.gauss_t)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define kc (_comp->_parameters.kc)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define lu (_comp->_parameters.lu)
  #define gap (_comp->_parameters.gap)
  #define p0 (_comp->_parameters.p0)
  SIG_MESSAGE("[_PSICHE_source_trace] component PSICHE_source=Wiggler() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Wiggler.comp:162]");


  double xx, yy, x1, y1, z1;
  double k, e, l;
  double F1 = 1.0;
  double dx, dy, dz;

  // initial source area
  xx = randnorm ();
  yy = randnorm ();
  x = xx * sigex;
  y = yy * sigey;
  z = (rand01 () - 0.5) * length;

  // Gaussian distribution at origin
  p = p0; /*initial weight is p0*/
  if (E0) {
    if (!dE) {
      e = E0;
    } else {
      e = randpm1 () * dE + E0;
    }
    k = E2K * e;
  } else if (lambda0) {
    if (!dlambda) {
      l = lambda0;
    } else {
      l = randpm1 () * dlambda + lambda0;
    }
    k = (2 * M_PI / l);
  }

  // targeted area calculation
  s1x = sqrt (sigex * sigex + K * igamma * K * igamma * (dist - z) * (dist - z));
  s1y = sqrt (sigey * sigey + igamma * igamma * (dist - z) * (dist - z));
  if (focus_xw) {
    if (!gauss_t) {
      /*sample uniformly but adjust weight*/
      x1 = randpm1 () * focus_xw / 2.0;
      p *= exp (-(x1 * x1) / (2.0 * s1x * s1x));
    } else {
      do {
        x1 = randnorm () * s1x;
      } while (fabs (x1) > focus_xw / 2.0);
      p *= erf (focus_xw * 0.5 * M_SQRT1_2 / s1x);
    }
  } else {
    x1 = randnorm () * igamma * K;
  }
  if (focus_yh) {
    if (!gauss_t) {
      /*sample uniformly but adjust weight*/
      y1 = randpm1 () * focus_yh / 2.0;
      p *= exp (-(y1 * y1) / (2.0 * s1y * s1y));
    } else {
      do {
        y1 = randnorm () * s1y;
      } while (fabs (y1) > focus_yh / 2.0);
      p *= erf (focus_yh * 0.5 * M_SQRT1_2 / s1y);
    }
  } else {
    y1 = randnorm () * igamma;
  }
  z1 = dist;
  dx = x1 - x;
  dy = y1 - y;
  dz = sqrt (dx * dx + dy * dy + (dist - z) * (dist - z));

  kx = (k * dx) / dz;
  ky = (k * dy) / dz;
  kz = (k * (dist - z)) / dz;

  /*spectral strength of radiation is given by Patterson*/
  double k_kc = k / kc;
  double K2_3 = besselKnu (0.666666666666666666666666667, k_kc * 0.5);
  p *= 2 * Nper * 1.33e13 * Ee * Ee * Ie * k_kc * k_kc * K2_3 * K2_3;
  // p*=2*Nper*ALPHA/(M_PI*M_PI)*gamma2*Ie/CELE* 1e-4 * 0.75 *k_kc*k_kc*K2_3*K2_3;

  /*randomly pick phase*/
  if (randomphase) {
    phi = rand01 () * 2 * M_PI;
  } else {
    phi = phase;
  }

  /*set polarization vector*/
  Ex = 0;
  Ey = 0;
  Ez = 0;
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef E0
  #undef dE
  #undef lambda0
  #undef dlambda
  #undef phase
  #undef randomphase
  #undef Ee
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef length
  #undef sigey
  #undef sigex
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef gauss_t
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef kc
  #undef s1x
  #undef s1y
  #undef lu
  #undef gap
  #undef p0
  return;
} /* class_Wiggler_trace */

#pragma acc routine
void class_Mask_trace(_class_Mask *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define mask (_comp->_parameters.mask)
  #define invert (_comp->_parameters.invert)
  #define virtual (_comp->_parameters.virtual)
  #define table (_comp->_parameters.table)
  #define ny (_comp->_parameters.ny)
  #define nx (_comp->_parameters.nx)
  #define xmin (_comp->_parameters.xmin)
  #define ymin (_comp->_parameters.ymin)
  #define xmax (_comp->_parameters.xmax)
  #define ymax (_comp->_parameters.ymax)
  #define filter_row (_comp->_parameters.filter_row)
  #define maskval (_comp->_parameters.maskval)
  SIG_MESSAGE("[_DISCO_ColdFinger_trace] component DISCO_ColdFinger=Mask() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mask.comp:240]");

  int i, j;

  PROP_Z0;
  if (x > xmin && x < xmax && y > ymin && y < ymax) {
    i = floor ((x - xmin) * nx / (xwidth));
    j = floor ((y - ymin) * ny / (yheight));
    if (invert) {
      maskval = Table_Index (table, j, i);
    } else {
      maskval = 1.0 - Table_Index (table, j, i);
    }
    if (!virtual) {
      p *= maskval;
    }
    SCATTER;
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef xwidth
  #undef yheight
  #undef mask
  #undef invert
  #undef virtual
  #undef table
  #undef ny
  #undef nx
  #undef xmin
  #undef ymin
  #undef xmax
  #undef ymax
  #undef filter_row
  #undef maskval
  return;
} /* class_Mask_trace */

#pragma acc routine
void class_Mirror_toroid_pothole_trace(_class_Mirror_toroid_pothole *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define radius (_comp->_parameters.radius)
  #define radius_o (_comp->_parameters.radius_o)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define prms (_comp->_parameters.prms)
  #define reflec_table (_comp->_parameters.reflec_table)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_DISCO_M2_trace] component DISCO_M2=Mirror_toroid_pothole() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:102]");

  int status;
  double l0, l1, l2, l3, tx, ty, tz;

  do {
    /*TODO check the permutation of coordinates and the actual position of the cylinder.*/
    status = cylinder_intersect (&l0, &l1, x, z, y - radius, kx, kz, ky, radius, zdepth);
    if (!status)
      break; /* no interaction with the cylinder*/
    // if(status & (02|04)) break; /*we exit the top/bottom of the cylinder*/
    if (status & (24))
      break;
    // if(status & (8|16)) break; /*we exit the top/bottom of the cylinder*/
    /*if the first intersection is behind the particle - this means the ray is on the wrong side of the mirror*/
    if (l1 < 0)
      break;
    do {
      /*this to do a test propagation*/
      double op[12];
      op[0] = x;
      op[1] = y;
      op[2] = z;
      op[3] = kx;
      op[4] = ky;
      op[5] = kz;
      op[6] = phi;
      op[7] = t;
      op[8] = Ex;
      op[9] = Ey;
      op[10] = Ez;
      op[11] = p;
      mcPROP_DL (l1);
      (tx) = x;
      (ty) = y;
      (tz) = z;
      x = op[0];
      y = op[1];
      z = op[2];
      kx = op[3];
      ky = op[4];
      kz = op[5];
      phi = op[6];
      t = op[7];
      Ex = op[8];
      Ey = op[9];
      Ez = op[10];
      p = op[11];
    } while (0);
    /*check mirror limits of intersectio point.*/
    if (tz < -zdepth / 2.0 || tz > zdepth / 2.0)
      break;
    /*check if the width is OK*/
    double xmax = sin(xwidth / (2.0 * radius)) * radius;
    if (tx < -xmax || tx > xmax)
      break;

    status = ellipsoid_intersect(&l2, &l3, x, y-radius, z, kx, ky, kz, radius, radius, sqrt(radius*(radius_o+radius)), NULL);
    if (!status)
      break;
    if (l3 < 0)
      break; /*This shouldn't be possible*/
    /*the mirror is indeed hit*/
    PROP_DL (l3);
    SCATTER;

    double nx, ny, nz;
    nx = 2 * x / (radius * radius);
    ny = 2 * (y - radius) / (radius * radius); /*ellipsoid is displaced to put Origin on the surface*/
    nz = 2 * z / (radius*(radius+radius_o));
    NORM (nx, ny, nz);

    /*By definition the normal vector points out from the ellipsoid*/
    double s = scalar_prod (kx, ky, kz, nx, ny, nz);
    double k = sqrt (scalar_prod (kx, ky, kz, kx, ky, kz));

    kx = kx - 2 * s * nx;
    ky = ky - 2 * s * ny;
    kz = kz - 2 * s * nz;

    /*find energy, and glancing angle*/
    if (prms.use_reflec_table) {
      /*the get ref. by call to Table_value2d*/
      double R;
      double theta = RAD2DEG * (acos (s / k) - M_PI_2);
      double e = K2E * k;
      R = Table_Value2d (reflec_table, fabs ((e - prms.e_min) / prms.e_step), fabs (((theta - prms.theta_min) / prms.theta_step)));
      p *= R;
      /*update phase - as an approximation turn by 180 deg.*/
      phi += M_PI;
    } else {
      p *= R0;
    }
  } while (0);
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 75) { // EXTEND 'DISCO_M2'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 104) { // EXTEND 'DISCO_M53'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 108) { // EXTEND 'DISCO_M54'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 361) { // EXTEND 'ROCK_mirror_m1'
	if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef zdepth
  #undef xwidth
  #undef radius
  #undef radius_o
  #undef R0
  #undef coating
  #undef prms
  #undef reflec_table
  #undef re
  return;
} /* class_Mirror_toroid_pothole_trace */

#pragma acc routine
void class_Mirror_trace(_class_Mirror *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define coating (_comp->_parameters.coating)
  #define R0 (_comp->_parameters.R0)
  #define geometry (_comp->_parameters.geometry)
  #define re (_comp->_parameters.re)
  #define offdata (_comp->_parameters.offdata)
  #define shape (_comp->_parameters.shape)
  SIG_MESSAGE("[_DISCO_M4_trace] component DISCO_M4=Mirror() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:96]");

  int intersect = 1;
  double nx = 0, ny = 1, nz = 0;

  if (shape == ANY) { // off/ply
    double l0 = 0, l1 = 0, nn;
    Coords n0, n1;
    intersect = off_x_intersect (&l0, &l1, &n0, &n1, x, y, z, kx, ky, kz, offdata);
    if (intersect && l0 > 0) {
      PROP_DL (l0);
      coords_get (n0, &nx, &ny, &nz);
    } else if (intersect > 1 && l1 > 0) {
      PROP_DL (l1);
      coords_get (n1, &nx, &ny, &nz);
    } else {
      intersect = 0; /* no surface ahead of the x-ray */
    }
    /* the reflection below requires a unit normal */
    nn = sqrt (nx * nx + ny * ny + nz * nz);
    if (intersect && nn > 0) {
      nx /= nn;
      ny /= nn;
      nz /= nn;
    } else
      intersect = 0;
  } else if (yheight) { // YZ plane
    PROP_X0;
    if (y < -yheight / 2.0 || y > yheight / 2.0 || z < -zdepth / 2.0 || z > zdepth / 2.0) {
      intersect = 0;
    } else {
      nx = 1;
      ny = nz = 0;
    }
  } else { // XZ plane
    PROP_Y0;
    if (x < -xwidth / 2.0 || x > xwidth / 2.0 || z < -zdepth / 2.0 || z > zdepth / 2.0) {
      intersect = 0;
    } else {
      nx = 0;
      ny = 1;
      nz = 0;
    }
  }
  if (intersect) {
    double s, k, q, R;

    s = scalar_prod (kx, ky, kz, nx, ny, nz);
    k = sqrt (scalar_prod (kx, ky, kz, kx, ky, kz));

    kx = kx - 2 * s * nx;
    ky = ky - 2 * s * ny;
    kz = kz - 2 * s * nz;
    SCATTER;
    q = 2.0 * fabs (s);
    R = reflecq (re, q, 0.0, k, fabs (90 - acos (s / k) * RAD2DEG));
    p *= R;
    /*update phase - as an approximation turn by 180 deg.*/;
    phi += M_PI;
  } else {
    /*missed mirror - restore xray*/
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 85) { // EXTEND 'DISCO_M4'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 366) { // EXTEND 'ROCK_mirror_m2a'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 542) { // EXTEND 'SIRIUS_def_mirror'
  if (!SCATTERED) ABSORB; 
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef zdepth
  #undef xwidth
  #undef yheight
  #undef coating
  #undef R0
  #undef geometry
  #undef re
  #undef offdata
  #undef shape
  return;
} /* class_Mirror_trace */

#pragma acc routine
void class_Mirror_elliptic_trace(_class_Mirror_elliptic *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define x_a (_comp->_parameters.x_a)
  #define y_b (_comp->_parameters.y_b)
  #define z_c (_comp->_parameters.z_c)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define radius (_comp->_parameters.radius)
  #define a2inv (_comp->_parameters.a2inv)
  #define b2inv (_comp->_parameters.b2inv)
  #define c2inv (_comp->_parameters.c2inv)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_DISCO_M51_trace] component DISCO_M51=Mirror_elliptic() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_elliptic.comp:100]");

  double E;             // (keV) x-ray energy
  double K;             // length of k-vector
  double kxu, kyu, kzu; // unit vector in the direction of k-vector.
  double x_int, y_int, z_int;
  double R;

  /* get the photon's kvector and energy */
  K = sqrt (kx * kx + ky * ky + kz * kz);
  E = K2E * K; /* use built-in constants for consistency */
  /* make unit vector in the direction of k :*/
  kxu = kx;
  kyu = ky;
  kzu = kz;
  NORM (kxu, kyu, kzu);

  double A, B, C, xt, yt, zt;
  double t0, t1;
  /*an offset to the mirror parameters perhaps*/

  xt = x;
  zt = z;
  yt = y - y_b;

  C = xt * xt * a2inv + yt * yt * b2inv + zt * zt * c2inv - 1;
  B = 2 * (kxu * xt * a2inv + kyu * yt * b2inv + kzu * zt * c2inv);
  A = kxu * kxu * a2inv + kyu * kyu * b2inv + kzu * kzu * c2inv;

  if (solve_2nd_order (&t0, &t1, A, B, C)) {
    double xx0, xx1, yy0, yy1, zz0, zz1; /* we will have to tentatively propagate twice to see which surface we hit */
    xx0 = x + kxu * t0;
    yy0 = y + kyu * t0;
    zz0 = z + kzu * t0;
    xx1 = x + kxu * t1;
    yy1 = y + kyu * t1;
    zz1 = z + kzu * t1;

    /*Check if we hit the mirror and whether the hit it is in front of the ray.
     * This does not account for mirror curvature */

    int hit0 = (fabs (xx0) < width / 2.0) && (fabs (zz0) < length / 2.0) && t0 > 0;
    int hit1 = (fabs (xx1) < width / 2.0) && (fabs (zz1) < length / 2.0) && t1 > 0;
    int doit = hit0 || hit1;

    if (hit0 && !hit1)
      PROP_DL (t0); /* only one intersection actually on mirror */
    else if (hit1 && !hit0)
      PROP_DL (t1);          /* other intersection */
    else if (hit0 && hit1) { /* both, take first strike (which may be back of mirror) */
      PROP_DL (t0 < t1 ? t0 : t1);
    } else {
      RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
    }

    if (doit) {
      SCATTER;
      xt = x;
      yt = y - y_b;
      zt = z; /* update shifted coordinates to intersection point */
      double nx, ny, nz;
      /* grad is the inner normal to the surface at this point */
      nx = -xt * a2inv;
      ny = -yt * b2inv;
      nz = -zt * c2inv;
      NORM (nx, ny, nz);

      double kdotn;
      kdotn = -scalar_prod (kx, ky, kz, nx, ny, nz);
      double kfx, kfy, kfz;
      kfx = kx + 2 * kdotn * nx;
      kfy = ky + 2 * kdotn * ny;
      kfz = kz + 2 * kdotn * nz;

      kx = kfx;
      ky = kfy;
      kz = kfz;

      /*adjust weight of ray*/

      double q = 2.0 * kdotn;
      double R = reflecq (re, q, 0, K, fabs (90 - acos (kdotn / K) * RAD2DEG));
      p *= R;
      /*update phase - as an approximation turn by 180 deg.*/;
      phi += M_PI;

      /*catch dead rays*/

      // if (p==0) ABSORB;
    } else {
      RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
    }
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 92) { // EXTEND 'DISCO_M51'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 113) { // EXTEND 'DISCO_mirror_m1'
	if (!SCATTERED) ABSORB;
}
if (_comp->_index == 127) { // EXTEND 'DISCO_mirror_m2'
	if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef x_a
  #undef y_b
  #undef z_c
  #undef zdepth
  #undef xwidth
  #undef R0
  #undef coating
  #undef length
  #undef width
  #undef radius
  #undef a2inv
  #undef b2inv
  #undef c2inv
  #undef re
  return;
} /* class_Mirror_elliptic_trace */

#pragma acc routine
void class_Grating_reflect_trace(_class_Grating_reflect *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define d_phi (_comp->_parameters.d_phi)
  #define R0 (_comp->_parameters.R0)
  #define rho_l (_comp->_parameters.rho_l)
  #define order (_comp->_parameters.order)
  #define phi0 (_comp->_parameters.phi0)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define verbose (_comp->_parameters.verbose)
  #define pdir (_comp->_parameters.pdir)
  #define d (_comp->_parameters.d)
  #define b (_comp->_parameters.b)
  #define nslits (_comp->_parameters.nslits)
  SIG_MESSAGE("[_DISCO_reflective_grating_trace] component DISCO_reflective_grating=Grating_reflect() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Grating_reflect.comp:103]");

  /********************************************************************************************
    Initializing by simulating a perfectly reflecting mirror:
   ********************************************************************************************/

  /*Placing the grating along the Y-axis. */
  PROP_Y0;
  /*If the photon is passing the grating, it shouldn't be reflected. Instead, for book-keeping, it is restored to previoulsy state before the component using
   * RESTORE_XRAY */
  if (x < -xwidth / 2.0 || x > xwidth / 2.0 || z < -zdepth / 2.0 || z > zdepth / 2.0) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  } else {
    double nx, ny, nz;
    double Gamma, gamma, psi_i, psi_o, spsi_i, spsi_o;
    double kx_notouch, ky_notouch, kz_notouch;
    double delta_theta, pdiff;
    /* Normal vector for the grating*/
    nx = 0;
    ny = 1;
    nz = 0;
    /* scalar-product, s and length of k.*/
    double s = scalar_prod (kx, ky, kz, nx, ny, nz);
    double k = sqrt (scalar_prod (kx, ky, kz, kx, ky, kz));
    /* Outgoing grazing angle for a perfectly reflecting mirror using angle between two vectors.*/
    psi_i = acos (s / k) - M_PI_2;

    /* outgoing vector for a perfectly reflecting mirror. Order 0.*/
    kx = kx - 2 * s * nx;
    ky = ky - 2 * s * ny;
    kz = kz - 2 * s * nz;
    // MC picked angle going from +- d_phi
    delta_theta = DEG2RAD * (rand01 () * d_phi - (d_phi * 0.5));
    double alpha, beta;
    alpha = M_PI_2 - psi_i;

    /********************************************************************************************
      The grating is lamellar:
     ********************************************************************************************/
    /* Lamellar grating is used.
         Thus finding outgoing angle only from ingoing angle.
         using old k and n and rotation matrix.*/
    beta = asin (-order * (2 * M_PI / k) / d + sin (alpha));
    // Could have also used an angle convention where the angle between the grating's norm and the ray of order m is positive if it is on the samer side as the
    // incident angle, negative otherwise.
    if (phi0) {
      /*a target angle is specified*/
      psi_o = phi0 * DEG2RAD;
    } else {
      psi_o = M_PI_2 - fabs (beta); /*the fabs is necessary due to the sign convention of beta*/
    }

    kx_notouch = kx;
    ky_notouch = ky;
    kz_notouch = kz;

    kx = kx_notouch;

    if (!isnan (psi_o) && !isnan (psi_i)) {
      // Still need to take into account the case where the incident ray does not hit perpendicular to the grating
      if (beta >= 0) {
        if (kz >= 0) {
          ky = (ky_notouch * cos (-(psi_o - psi_i) + delta_theta) - kz_notouch * sin (-(psi_o - psi_i) + delta_theta));
          kz = (ky_notouch * sin (-(psi_o - psi_i) + delta_theta) + kz_notouch * cos (-(psi_o - psi_i) + delta_theta));
        } else {
          ky = (ky_notouch * cos ((psi_o - psi_i) + delta_theta) - kz_notouch * sin ((psi_o - psi_i) + delta_theta));
          kz = (ky_notouch * sin ((psi_o - psi_i) + delta_theta) + kz_notouch * cos ((psi_o - psi_i) + delta_theta));
        }
      } else {
        if (kz >= 0) {
          ky = (ky_notouch * cos ((-2 * alpha + (psi_o - psi_i)) + delta_theta) - kz_notouch * sin ((-2 * alpha + (psi_o - psi_i)) + delta_theta));
          kz = (ky_notouch * sin ((-2 * alpha + (psi_o - psi_i)) + delta_theta) + kz_notouch * cos ((-2 * alpha + (psi_o - psi_i)) + delta_theta));
        } else {
          ky = (ky_notouch * cos ((2 * alpha - (psi_o - psi_i)) + delta_theta) - kz_notouch * sin ((2 * alpha - (psi_o - psi_i)) + delta_theta));
          kz = (ky_notouch * sin ((2 * alpha - (psi_o - psi_i)) + delta_theta) + kz_notouch * cos ((2 * alpha - (psi_o - psi_i)) + delta_theta));
        }
      }

      /*Finding the weight using diffraction theory.*/
      s = scalar_prod (kx, ky, kz, nx, ny, nz);
      psi_o = acos (s / k) - M_PI_2;

      /*pay attention to sign conventions here. We might cross to the "incoming" side of the normal.*/
      spsi_i = sin (M_PI_2 - psi_i);
      spsi_o = sin (M_PI_2 - psi_o); //+delta_theta)); // asin angle out

      /* Phase for interference pattern:  k = wave vector, d = lines/Angstrom, b=width in Angstrom */
      gamma = k * d * (spsi_o - spsi_i);
      /* Phase for diffraction pattern */
      Gamma = k * b * (spsi_o - spsi_i);
      pdiff = ((sin (Gamma / 2) / (Gamma / 2)) * (sin (Gamma / 2) / (Gamma / 2)))
              * ((sin (nslits * gamma / 2) / sin (gamma / 2)) * (sin (nslits * gamma / 2) / sin (gamma / 2)));
      p = p * pdir * (pdiff / (pow (nslits, 2)));

    } else {
      p = 0;
    }
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef d_phi
  #undef R0
  #undef rho_l
  #undef order
  #undef phi0
  #undef zdepth
  #undef xwidth
  #undef verbose
  #undef pdir
  #undef d
  #undef b
  #undef nslits
  return;
} /* class_Grating_reflect_trace */

void class_Undulator_trace(_class_Undulator *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define dEe (_comp->_parameters.dEe)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define lu (_comp->_parameters.lu)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define sigepx (_comp->_parameters.sigepx)
  #define sigepy (_comp->_parameters.sigepy)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define quick_integ (_comp->_parameters.quick_integ)
  #define E1st (_comp->_parameters.E1st)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define length (_comp->_parameters.length)
  #define kc (_comp->_parameters.kc)
  #define pmul (_comp->_parameters.pmul)
  #define gap (_comp->_parameters.gap)
  #define Bsig (_comp->_parameters.Bsig)
  #define Bpi (_comp->_parameters.Bpi)
  #define gsl_int_ws (_comp->_parameters.gsl_int_ws)
  #define alpha (_comp->_parameters.alpha)
  #define MELE (_comp->_parameters.MELE)
  SIG_MESSAGE("[_CRISTAL_Source_trace] component CRISTAL_Source=Undulator() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:223]");


  double k, e, l, w_u, r, w;
  double xo, yo, zo, xi, psi, theta2, Omega;
  double bsigma_integral, bpi_integral, s_n2;
  double bsigma_error, bpi_error;

  /* pick an energy in the given interval */
  e = E0 + randpm1 () * dE;

  /* add electron beam energy spread to gamma parameters (if necessary).*/
  if (dEe) {
    double deltaEe = (randnorm () * dEe * Ee) + Ee;
    gamma = (deltaEe * 1e9) / (MELE / CELE * M_C * M_C); /*the extra CELE is to convert to eV*/
    gamma2 = gamma * gamma;
    igamma = 1.0 / gamma;
  }

  /* the undulator's fundamental angular frequency*/
  w_u = 2 * M_PI * M_C / lu;

  /* now pick angles (\xi and \psi => \theta) within the focus_window
   * (point on window + point in electron beam)
   * ... we can now weight properly according to ang. flux density*/
  if (focus_xw && focus_yh) {
    randvec_target_rect (&xo, &yo, &zo, &Omega, 0, 0, dist, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
  } else if (focus_yh != 0) {
    xi = 0;
    xo = 0;
    yo = 0;
    yo = randpm1 () * 0.5 * focus_yh;
    Omega = 1;
  } else if (focus_xw != 0) {
    psi = 0;
    xo = 0;
    yo = 0;
    xo = randpm1 () * 0.5 * focus_xw;
    Omega = 1;
  } else {
    xi = 0;
    psi = 0;
    xo = 0;
    yo = 0;
    Omega = 1;
  }
  p = pmul * Omega / (4 * M_PI);

  /*add emittance effects - note that doing it this way will shoot some rays outside the focus-window*/
  x = y = z = 0;
  if (sigex) {
    x = randnorm () * sigex;
  }
  if (sigey) {
    y = randnorm () * sigey;
  }

  xi = fabs (atan2 (xo, dist));
  psi = fabs (atan2 (yo, dist));
  /* This has to be after (xi,psi), else it will be convoluted into the weight calculation.*/
  if (sigepx) {
    xo += randnorm () * sigepx * dist;
  }
  if (sigepy) {
    yo += randnorm () * sigepy * dist;
  }

  theta2 = xi * xi + psi * psi;

  k = E2K * e;
  /*angular frequency w:*/
  w = M_C * k * 1e10;

  kx = xo;
  ky = yo;
  kz = dist;
  NORM (kx, ky, kz);
  kx *= k;
  ky *= k;
  kz *= k;

  double w1theta = 2 * gamma2 / (1 + K * K / 2.0 + gamma2 * theta2) * w_u;
  double w10 = 2 * gamma2 / (1 + K * K / 2.0) * w_u;
  double w_w1 = w / w1theta;
  double w_w10 = w / w10;

  double Bsig_integ_prms[4], Bpi_integ_prms[4];
  Bsig_integ_prms[0] = Bpi_integ_prms[0] = w_w1;                                           /*relative frequency*/
  Bsig_integ_prms[1] = Bpi_integ_prms[1] = 2 * w_w10 * xi * gamma * K / (1 + K * K / 2.0); /*p*/
  Bsig_integ_prms[2] = Bpi_integ_prms[2] = 0.25 * w_w10 * K * K / (1 + K * K / 2.0);       /*q*/
  Bsig_integ_prms[3] = xi * gamma / K;                                                     /*angle terms*/
  Bpi_integ_prms[3] = psi * gamma / K;

  /*pass the parameters to the integrand*/
  Bsig.params = Bsig_integ_prms;
  Bpi.params = Bpi_integ_prms;
  if (!quick_integ) {
    gsl_integration_qags (&(Bsig), 0, M_PI, 0, 1e-6, 1000, gsl_int_ws, &bsigma_integral, &bsigma_error);
    gsl_integration_qags (&(Bpi), 0, M_PI, 0, 1e-6, 1000, gsl_int_ws, &bpi_integral, &bpi_error);
  } else {
    size_t neval;
    gsl_integration_qng (&(Bsig), 0, M_PI, 0, 1e-6, &bsigma_integral, &bsigma_error, &neval);
    gsl_integration_qng (&(Bpi), 0, M_PI, 0, 1e-6, &bpi_integral, &bpi_error, &neval);
  }
  bsigma_integral *= M_2_PI; /*correct for only integrating half interval and normalize by pi.*/
  bpi_integral *= M_2_PI;

  s_n2 = mxundulator_S_N (w_w1, Nper);

  double prefactor = alpha * Ie / CELE * pow (K * gamma / (1 + K * K / 2.0), 2.0) * Nper * Nper * w_w10 * w_w10;

  p *= prefactor * (pow (bsigma_integral, 2.0) + pow (bpi_integral, 2.0)) * s_n2;

  /*randomly pick phase*/
  if (randomphase) {
    phi = rand01 () * 2 * M_PI;
  } else {
    phi = phase;
  }

  /*Set polarization vector. TODO: Do this right.*/
  Ex = 0;
  Ey = 0;
  Ez = 0;
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef E0
  #undef dE
  #undef phase
  #undef randomphase
  #undef Ee
  #undef dEe
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef lu
  #undef sigey
  #undef sigex
  #undef sigepx
  #undef sigepy
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef quick_integ
  #undef E1st
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef s1x
  #undef s1y
  #undef length
  #undef kc
  #undef pmul
  #undef gap
  #undef Bsig
  #undef Bpi
  #undef gsl_int_ws
  #undef alpha
  #undef MELE
  return;
} /* class_Undulator_trace */

#pragma acc routine
void class_Mirror_toroid_trace(_class_Mirror_toroid *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define coating (_comp->_parameters.coating)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define radius (_comp->_parameters.radius)
  #define radius_o (_comp->_parameters.radius_o)
  #define R0 (_comp->_parameters.R0)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_GALAXIES_M2A_trace] component GALAXIES_M2A=Mirror_toroid() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_toroid.comp:74]");

  int status;
  double k, l0, l1, l2, l3, tx, ty, tz;

  do {
    k = sqrt (scalar_prod (kx, ky, kz, kx, ky, kz));

    /*TODO check the permutation of coordinates and the actual position of the cylinder.*/
    status = cylinder_intersect (&l0, &l1, x, z, y + radius, kx, kz, ky, radius, zdepth);
    if (!status)
      break; /* no interaction with the cylinder*/
    if (status & (02 | 04))
      break; /*we exit the top/bottom of the cylinder*/
    /*if the first intersection is behind the particle - this means the ray is on the wrong side of the mirror*/
    if (l0 < 0)
      break;

    tx = x + l0 * kx / k;
    ty = y + l0 * ky / k;
    tz = z + l0 * kz / k;

    /*check mirror limits of intersection point.*/
    if (tz < -zdepth / 2.0 || tz > zdepth / 2.0)
      break;
    /*check if the width is OK*/
    double xmax = sin(xwidth / (2.0 * radius)) * radius;
    if (tx < -xmax || tx > xmax)
      break;

    status = ellipsoid_intersect(&l2, &l3, x, y+radius, z, kx, ky, kz, radius, radius, sqrt(radius*(radius_o+radius)), NULL);    
    if (!status)
      break;
    if (l2 < 0)
      break; /*This shouldn't be possible*/
    /*the mirror is indeed hit*/
    PROP_DL (l2);
    SCATTER;

    double nx, ny, nz;
    nx = 2 * x / (radius * radius);
    ny = 2 * (y + radius) / (radius * radius); /*ellipsoid is displaced to put Origin on the surface*/
    nz = 2 * z / (radius*(radius+radius_o));
    NORM (nx, ny, nz);

    /*By definition the normal vector points out from the ellipsoid*/
    double s = scalar_prod (kx, ky, kz, nx, ny, nz);

    kx = kx - 2 * s * nx;
    ky = ky - 2 * s * ny;
    kz = kz - 2 * s * nz;

    /*the get ref. by call to reflectivity lib*/
    double R, q;
    q = 2.0 * s;
    R = reflecq (re, q, 0, k * K2E, fabs (90 - acos (s / k) * RAD2DEG));
    p *= R;
    phi += M_PI;
  } while (0);
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 227) { // EXTEND 'GALAXIES_M2A'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 233) { // EXTEND 'GALAXIES_M2B'
  if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef coating
  #undef zdepth
  #undef xwidth
  #undef radius
  #undef radius_o
  #undef R0
  #undef re
  return;
} /* class_Mirror_toroid_trace */

void class_FluoCrystal_trace(_class_FluoCrystal *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define sx_refl (_comp->_parameters.sx_refl)
  #define flag_sx (_comp->_parameters.flag_sx)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define barns (_comp->_parameters.barns)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define order (_comp->_parameters.order)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_coh_refl (_comp->_parameters.reuse_coh_refl)
  #define reuse_coh_xsect (_comp->_parameters.reuse_coh_xsect)
  #define reuse_tau_count (_comp->_parameters.reuse_tau_count)
  SIG_MESSAGE("[_GALAXIES_sample_trace] component GALAXIES_sample=FluoCrystal() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoCrystal.comp:449]");


int    intersect=0;       /* flag to continue/stop */
int    reuse    =0;       /* flag raised when reusing (SPLIT) */
int    type     =-1;      /* type of interaction */
double l0,  l1,  l2,  l3; /* distances for intersections */
double dl0, dl1, dl2, dl; /* distance intervals */
int    flag_concentric = 0;
int    flag_ishollow   = 0;
int    event_counter   = 0;         /* scattering event counter (multiple fluorescence) */
int    force_transmit  = 0;         /* Flag to handle cross-section weighting in case of finite order */
double sigma_barn=0, xs[5];         /* cross sections [barn/atom] fluo/Compton/Rayleigh/diff/transmit */
double aim_x=0, aim_y=0, aim_z=1;   /* Position of target relative to scattering point */


// SX stuff
double coh_xsect = 0, coh_refl = 0; // diffraction stuff

#ifdef OPENACC
#ifdef USE_OFF
off_struct thread_offdata = offdata;
#endif
#else
#define thread_offdata offdata
#endif

double k, E;
double ki,pi;

/* Store Initial photon state */
k  = ki = sqrt(kx*kx+ky*ky+kz*kz); //  Angs-1
E  = K2E*k; // keV
pi = p;      // used to test for multiple fluo weighting and order cutoff

// SX init
struct tau_data *T=tau_list;           /* List of reflections close to Ewald sphere */
struct hkl_data *L=hkl_list;           /* Structure factor list */
int tau_count;                /* Number of reflections close to Ewald sphere*/

do { /* while (intersect) Loop over multiple scattering events */

  // test for a SPLIT event (same particle comes in)
  l0=l1=l2=l3=dl0=dl1=dl2=0;
  if (!event_counter && fabs(reuse_ki - ki) < 1e-15) {
    reuse     = 1;
    reuse_nb++;
    // use cached values and skip actual computation
    intersect = reuse_intersect;
    l0        = reuse_l0;
    l1        = reuse_l1;
    l2        = reuse_l2;
    l3        = reuse_l3;

  } else {
    // we have a different event: compute intersection lengths

    /* ========================================================================== */
    /*                                   GEOMETRY                                 */
    /* ========================================================================== */

    /* Intersection photon trajectory / sample (sample surface) */
    if (thickness >= 0) {
      if (shape==0)
        intersect=cylinder_intersect(&l0,&l3, x,y,z,kx,ky,kz, radius,yheight);
      else if (shape==1)
        intersect=box_intersect     (&l0,&l3, x,y,z,kx,ky,kz, xwidth,yheight,zdepth);
      else if (shape==2)
        intersect=sphere_intersect  (&l0,&l3, x,y,z,kx,ky,kz, radius);
      #ifdef USE_OFF
      else if (shape == 3)
        intersect=off_x_intersect(&l0, &l3, NULL, NULL, x, y, z, kx,ky,kz, thread_offdata );
      #endif
    } else {
      if (shape==0)
        intersect=cylinder_intersect(&l0,&l3, x,y,z,kx,ky,kz, radius-thickness,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight);
      else if (shape==1)
        intersect=box_intersect     (&l0,&l3, x,y,z,kx,ky,kz,
          xwidth-2*thickness > 0 ?  xwidth-2*thickness : xwidth,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight,
          zdepth-2*thickness > 0 ?  zdepth-2*thickness : zdepth);
      else if (shape==2)
        intersect=sphere_intersect  (&l0,&l3, x,y,z,kx,ky,kz, radius-thickness);
      #ifdef USE_OFF
      else if (shape == 3)
        intersect=off_x_intersect   (&l0, &l3, NULL, NULL, x, y, z, kx,ky,kz, thread_offdata );
      #endif
    }


    /* Computing the intermediate lengths */
    if (intersect && p_interact >= 0) {
      flag_ishollow = 0;
      if (thickness > 0) {
        if (shape==0 && cylinder_intersect(&l1,&l2, x,y,z,kx,ky,kz, radius-thickness,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight))
          flag_ishollow=1;
        else if (shape==2 && sphere_intersect   (&l1,&l2, x,y,z,kx,ky,kz, radius-thickness))
          flag_ishollow=1;
        else if (shape==1 && box_intersect(&l1,&l2, x,y,z,kx,ky,kz,
          xwidth-2*thickness > 0 ? xwidth-2*thickness : xwidth,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight,
          zdepth-2*thickness > 0 ? zdepth-2*thickness : zdepth))
          flag_ishollow=1;
      } else if (thickness<0) {
        if (shape==0 && cylinder_intersect(&l1,&l2, x,y,z,kx,ky,kz, radius,yheight))
          flag_ishollow=1;
        else if (shape==2 && sphere_intersect   (&l1,&l2, x,y,z,kx,ky,kz, radius))
          flag_ishollow=1;
        else if (shape==1 && box_intersect(&l1,&l2, x,y,z,kx,ky,kz, xwidth, yheight, zdepth))
          flag_ishollow=1;
      }
      if (l3 > 1000) l3=0;              // we passed the sample, far away
      if (!flag_ishollow) l1 = l2 = l3; /* no empty space inside */
    } /* if intersect */


    // store values for potential next SPLIT
    if (!event_counter) {
      reuse_intersect = intersect;
      reuse_l0        = l0;
      reuse_l1        = l1;
      reuse_l2        = l2;
      reuse_l3        = l3;
      reuse_ki        = ki;
    }
    reuse           = 0;
  } // if !reuse (SPLIT)

  if (intersect) { /* the photon hits the sample */

    if (l0 > 0) {  /* we are before the sample */
      PROP_DL(l0); /* propagates photon to the entry of the sample */
    } else if (l1 > 0 && l1 > l0) { /* we are inside first part of the sample */
      /* no propagation, stay inside */
    } else if (l2 > 0 && l2 > l1) { /* we are in the hole */
      PROP_DL(l2); /* propagate to inner surface of 2nd part of sample */
    } else if (l3 > 0 && l3 > l2) { /* we are in the 2nd part of sample */
      /* no propagation, stay inside */
    }

    dl0=l1-(l0 > 0 ? l0 : 0); /* Distance in first part of hollow/cylinder/box */
    dl1=l2-(l1 > 0 ? l1 : 0); /* Distance in hole */
    dl2=l3-(l2 > 0 ? l2 : 0); /* Distance in 2nd part of hollow cylinder */

    if (dl0 < 0) dl0 = 0;
    if (dl1 < 0) dl1 = 0;
    if (dl2 < 0) dl2 = 0;

    /* initialize concentric mode */
    if (concentric && !flag_concentric && l0 >= 0
     && shape==0 && thickness) {
      flag_concentric=1;
    }

    if (flag_concentric == 1) {
      dl1=dl2=0; /* force exit when reaching hole/2nd part */
    }

    if (!dl0 && !dl2) {
      intersect = 0; /* the sample was passed entirely */
    }
  } // if intersect (geometry)

  /* ========================================================================== */
  /*                             INTERACTION PROCESS                            */
  /* ========================================================================== */
  xs[FLUORESCENCE]=xs[COMPTON]=xs[RAYLEIGH]=xs[TRANSMISSION]=xs[DIFFRACTION]=sigma_barn=0;
  cum_xs_fluo[0] = cum_xs_Compton[0] = cum_xs_Rayleigh[0] = 0;
  
  if (intersect) {
    double my_s;
    int    i_Z,i;
    int    flag=0;
    double d_path, p_trans, p_scatt, mc_trans, mc_scatt;

    /* compute total scattering cross section ------------------------------ */
    /* compute each contribution XS */
    if (!reuse) {
      for (i_Z=0; i_Z< compound->nElements; i_Z++) {
        int    Z   = compound->Elements[i_Z];
        double frac= compound->massFractions[i_Z];
        double xs_Z[3];

        // get Fluorescence xs
        XRMC_CrossSections(Z, E, xs_Z, flag_kissel); // [barn/atom]
        cum_xs_fluo[i_Z+1]     = cum_xs_fluo[i_Z]    +frac*xs_Z[FLUORESCENCE];
        cum_xs_Rayleigh[i_Z+1] = cum_xs_Rayleigh[i_Z]+frac*xs_Z[RAYLEIGH];
        cum_xs_Compton[i_Z+1]  = cum_xs_Compton[i_Z] +frac*xs_Z[COMPTON];
        for (i=0; i<COMPTON+1; i++) { xs[i] += frac*xs_Z[i]; }
      } // for Z in compound
      for (i=0; i<3; i++) sigma_barn += xs[i]; // total XS

      if (flag_sx) {
        // we add the diffraction XS
        double tau_max   = 2*k/(1 - 5*hkl_info.m_delta_d_d);
        /* call hkl_search */
        tau_count = hkl_search(L, T, hkl_info.count, hkl_info.V0,
                               kx, ky, kz, tau_max,
                               &coh_refl, &coh_xsect);
        xs[DIFFRACTION] = coh_xsect;
        sigma_barn     += xs[DIFFRACTION];
      } else {
        xs[DIFFRACTION] = coh_refl = coh_xsect = 0;
        tau_count       = 0;
      }

      // store values into cache for SPLIT
      if (!event_counter) {
        for (i_Z=0; i_Z< compound->nElements+1; i_Z++) {
          reuse_cum_xs_fluo[i_Z]     = cum_xs_fluo[i_Z];
          reuse_cum_xs_Compton[i_Z]  = cum_xs_Compton[i_Z];
          reuse_cum_xs_Rayleigh[i_Z] = cum_xs_Rayleigh[i_Z];
        }
        reuse_sigma_barn          = sigma_barn;
        if (flag_sx) {
          reuse_cum_xs_diffraction  = xs[DIFFRACTION];
          reuse_coh_refl            = coh_refl;
          reuse_coh_xsect           = coh_xsect;
          reuse_tau_count           = tau_count;
        }
      }

    } else {
      // reuse cached values (SPLIT), event_counter=0
      for (i_Z=0; i_Z< compound->nElements+1; i_Z++) {
        cum_xs_fluo[i_Z]     = reuse_cum_xs_fluo[i_Z];
        cum_xs_Compton[i_Z]  = reuse_cum_xs_Compton[i_Z];
        cum_xs_Rayleigh[i_Z] = reuse_cum_xs_Rayleigh[i_Z];
        xs[FLUORESCENCE]      += reuse_cum_xs_fluo[i_Z];
        xs[COMPTON]           += reuse_cum_xs_Compton[i_Z];
        xs[RAYLEIGH]          += reuse_cum_xs_Rayleigh[i_Z];
      }
      sigma_barn               = reuse_sigma_barn;
      if (flag_sx) {
        xs[DIFFRACTION]        = reuse_cum_xs_diffraction;
        coh_refl  = hkl_info.coh_refl  = reuse_coh_refl;
        coh_xsect = hkl_info.coh_xsect = reuse_coh_xsect;
        tau_count = reuse_tau_count;
      }
    }

    /* probability to absorb/scatter --------------------------------------- */
    /* determine scattering location in sample */
    my_s   = fluo_rho*100*sigma_barn; /* mu 100: convert from barns to fm^2. my_s in [1/m] */
    d_path = ( dl0 +dl2 );            /* total path lenght in sample */

    /* Proba of transmission/interaction along length d_path */
    p_trans = exp(-my_s*d_path); /* probability to not-interact (transmit) */
    //printf("sigma_barn=%g p_trans=%g\n", sigma_barn, p_trans);
    p_scatt = 1 - p_trans;       /* portion of beam which scatters */

    /* force a given fraction of the beam to scatter */
    if (!event_counter && p_interact>0 && p_interact<=1) {
      /* we force a portion of the beam to interact */
      /* This is used to improve statistics */
      mc_trans = 1-p_interact;
    } else {
      mc_trans = p_trans; /* 1 - p_scatt */
    }
    mc_scatt = 1 - mc_trans; /* portion of beam to scatter (or force to) */
    if (mc_scatt <= 0) ABSORB;

    if (!force_transmit && mc_scatt > 0 && (mc_scatt >= 1 || rand01() < mc_scatt)) {
      /* we "scatter" with one of the interaction processes */
      dl = -log(1 - rand0max((1 - exp(-my_s*d_path)))) / my_s; /* length */
      /* If t0 is in hole, propagate to next part of the hollow cylinder */
      if (dl1 > 0 && dl0 > 0 && dl > dl0) dl += dl1;
      /* photon propagation to the scattering point */
      PROP_DL(dl);
      p *= fabs(p_scatt/mc_scatt); /* account for p_interact, lower than 1 */

    } else { // force_transmit
      /* we go through the material without interaction, and exit */
      if (type <0) type = TRANSMISSION; // transmission
      intersect = 0;
      PROP_DL(d_path);
      /* attenuate beam by portion which is scattered (and left along) */
      p *= p_trans;
      if (!event_counter && p_interact>0 && p_interact<=1) p /= mc_trans;
      break; // end while (intersect)
    }

  } /* if intersect (propagate) */

  /* select scattering line ------------------------------------------------ */
  if (intersect) { /* scattering event */
    int    i_Z=-1, Z, j=-1;
    double solid_angle=0;
    double theta, dsigma, alpha;
    double Ef, dE, sum;
    double kf=k, kf_x, kf_y, kf_z;  // next particle direction

    /* MC choose process from cross sections 'xs': fluo, Rayleigh, Compton, diff */
    type = XRMC_SelectInteraction(xs, DIFFRACTION+1, rand01()); // up to DIFFRACTION

    /* choose Z (element) on associated XS, taking into account mass-fractions */
    switch (type) {
      case FLUORESCENCE:
        i_Z = XRMC_SelectFromDistribution(cum_xs_fluo,     compound->nElements+1, rand01());
        break;
      case RAYLEIGH:
        if (!flag_rayleigh) ABSORB;
        i_Z = XRMC_SelectFromDistribution(cum_xs_Rayleigh, compound->nElements+1, rand01());
        break;
      case COMPTON:
        if (!flag_compton)  ABSORB;
        i_Z = XRMC_SelectFromDistribution(cum_xs_Compton,  compound->nElements+1, rand01());
        break;
      case DIFFRACTION:
        if (!flag_sx)       ABSORB;
        if (tau_count > 1) {
          sum=0;
          // choose a line among those possible, using F2 as relative probability/intensity
          j = hkl_select(T, tau_count, coh_refl, &sum,_particle);
          if(j >= tau_count) j = tau_count - 1;
        } else j = 0; /* Select between tau_count Bragg spots */
          break;
      default: // should never happen
        // printf("WARNING: %s: process %i unknown. Absorb.\n", NAME_CURRENT_COMP, type);
        ABSORB;
    }

    // select scattering direction --------------------------------------------
    if (i_Z >= 0) {
      // fluorescence/Rayleigh/Compton: 4PI scattering
      Z   = compound->Elements[i_Z];

      /* select outgoing vector */
      if ((target_x || target_y || target_z)) {
        aim_x = target_x-x;       /* Vector pointing at target (anal./det.) */
        aim_y = target_y-y;
        aim_z = target_z-z;
      }
      if(focus_aw && focus_ah) {
        randvec_target_rect_angular(&kf_x, &kf_y, &kf_z, &solid_angle,
          aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP);
      } else if(focus_xw && focus_yh) {
        randvec_target_rect(&kf_x, &kf_y, &kf_z, &solid_angle,
          aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
      } else {
        randvec_target_circle(&kf_x, &kf_y, &kf_z, &solid_angle, aim_x, aim_y, aim_z, focus_r);
      }
      p *= solid_angle/(4*PI); // correct for selected solid-angle

    } else if (j >= 0) {
      // SX diffraction
      int i = T[j].index; // index in L
      /* Pick scattered wavevector kf from 2D Gauss distribution. */
      double z1  = randnorm();
      double z2  = randnorm();
      double y1  = T[j].l11*z1 + T[j].y0x;
      double y2  = T[j].l12*z1 + T[j].l22*z2 + T[j].y0y;
      double kfx = T[j].rho_x  + T[j].ox     + T[j].b1x*y1 + T[j].b2x*y2;
      double kfy = T[j].rho_y  + T[j].oy     + T[j].b1y*y1 + T[j].b2y*y2;
      double kfz = T[j].rho_z  + T[j].oz     + T[j].b1z*y1 + T[j].b2z*y2;

      /* Normalize kf to length of ki, to account for planer
         approximation of the Ewald sphere. */
      double adjust = ki/sqrt(kfx*kfx + kfy*kfy + kfz*kfz);
      kfx *= adjust;
      kfy *= adjust;
      kfz *= adjust;

      /* Adjust photon weight (see manual for explanation). */
      double pmul = T[j].xsect*coh_refl/(coh_xsect*T[j].refl);
      if (!isnan(pmul)) p *= pmul;
      kf_x = L[i].u1x*kfx + L[i].u2x*kfy + L[i].u3x*kfz;
      kf_y = L[i].u1y*kfx + L[i].u2y*kfy + L[i].u3y*kfz;
      kf_z = L[i].u1z*kfx + L[i].u2z*kfy + L[i].u3z*kfz;
    } else ABSORB; // should never happen

    NORM(kf_x, kf_y, kf_z);  // normalize the outout direction |kf|=1

    // determine final energy
    switch (type) {
      case FLUORESCENCE: /* 0 Fluo: choose line */
        Ef      = XRMC_SelectFluorescenceEnergy(Z, E, &dE, flag_kissel, rand01()); // dE full-width in keV
        if (dE) {
          dE /= 2;  // half-width
          if (flag_lorentzian) dE  *= tan(PI/2*randpm1()); // Lorentzian distribution
          else                 dE  *= randnorm();          // Gaussian distribution
          Ef = Ef + dE;
        }
        kf      = Ef*E2K;
        theta   = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k);
        /* add polarisation factor */
        if (Ex!=0 || Ey!=0 || Ez!=0){
          double EE=sqrt(Ex*Ex+Ey*Ey+Ez*Ez);
          double s=scalar_prod(kf_x,kf_y,kf_z,Ex,Ey,Ez)/EE;
          p *= (1-s)*(1-s);
        } else {
          /*unpolarized light in - means an effective reduction according to only theta*/
          p *= (1+cos(theta)*cos(theta))*0.5;
        }
        n_fluo++;
        p_fluo += p;
        break;

      case RAYLEIGH:     /* 1 Rayleigh: Coherent, elastic    */
        theta      = acos(scalar_prod(kf_x,kf_y,kf_z, kx, ky,kz)/k); // kf is the previous |k|
        dsigma     = DCSb_Rayl(Z,  E, theta, NULL); // [barn/at/st]
        p         *= 4*PI*dsigma/xs[RAYLEIGH];
        n_Rayleigh++;
        p_Rayleigh+= p;
        break;

      case COMPTON:      /* 2 Compton: Incoherent: choose final energy */
        theta      = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k); // kf is the previous |k|
        dsigma     = DCS_Compt(Z,  Ef, theta, NULL); // [barn/at/st] Ef is the previous particle energy
        kf         = ComptonEnergy(Ef, theta, NULL)*E2K; /* XRayLib, fraction of emc2=511 keV */
        p         *= 4*PI*dsigma/xs[COMPTON];
        n_Compton++;
        p_Compton += p;
        break;

      case DIFFRACTION:  /* 3 diffraction: line chosen before */
        n_diff++;
        p_diff += p;
        theta   = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k);
        /* add polarisation factor */
        if (Ex!=0 || Ey!=0 || Ez!=0){
          double EE=sqrt(Ex*Ex+Ey*Ey+Ez*Ez);
          double s=scalar_prod(kf_x,kf_y,kf_z,Ex,Ey,Ez)/EE;
          p *= (1-s)*(1-s);
        } else {
          /*unpolarized light in - means an effective reduction according to only theta*/
          p *= (1+cos(theta)*cos(theta))*0.5;
        }
        break;

      default:  // should never happen
        ABSORB;
    }

    kx = kf*kf_x;
    ky = kf*kf_y;
    kz = kf*kf_z;
    k  = kf;
    E  = K2E*kf;
    SCATTER;
    event_counter++;

    /* exit if multiple scattering order has been reached */
    if (!order) break; // skip final absorption
    // stop when order has been reached, or weighting is very low
    if (order && (event_counter >= order || p/pi < 1e-15)) { force_transmit=1; }

  } // if intersect (scatter)
} while(intersect); /* end do (intersect) (multiple scattering loop) */

#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 245) { // EXTEND 'GALAXIES_sample'
  if (SCATTERED) flag_scatt++;
  else ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef sx_refl
  #undef flag_sx
  #undef delta_d_d
  #undef barns
  #undef recip_cell
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef aa
  #undef bb
  #undef cc
  #undef mosaic_AB
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef order
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef n_diff
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef p_diff
  #undef fluo_rho
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_cum_xs_diffraction
  #undef reuse_coh_refl
  #undef reuse_coh_xsect
  #undef reuse_tau_count
  return;
} /* class_FluoCrystal_trace */

#pragma acc routine
void class_Single_crystal_trace(_class_Single_crystal *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define reflections (_comp->_parameters.reflections)
  #define geometry (_comp->_parameters.geometry)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define barns (_comp->_parameters.barns)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define p_transmit (_comp->_parameters.p_transmit)
  #define sigma_inc (_comp->_parameters.sigma_inc)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define order (_comp->_parameters.order)
  #define extra_order (_comp->_parameters.extra_order)
  #define RX (_comp->_parameters.RX)
  #define RY (_comp->_parameters.RY)
  #define powder (_comp->_parameters.powder)
  #define deltak (_comp->_parameters.deltak)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define surf_size (_comp->_parameters.surf_size)
  #define surf_k (_comp->_parameters.surf_k)
  #define surf_FT2 (_comp->_parameters.surf_FT2)
  #define surf_dir (_comp->_parameters.surf_dir)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  SIG_MESSAGE("[_PX1_sample_trace] component PX1_sample=Single_crystal() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1461]");

  double l1, l2 = -1;  /* Entry and exit lengths in sample */
  struct hkl_data* L; /* Structure factor list */
  int i;              /* Index into structure factor list */
                      #ifndef OPENACC
  struct tau_data* T; /* List of reflections close to Ewald sphere */
                      #else
  struct tau_data T[MCSX_REFL_SLIST_SIZE];
  #endif
  int tau_count;              /* Number of reflections close to Ewald sphere*/
  int j;                      /* Index into reflection list */
  int event_counter;          /* scattering event counter */
  double kix, kiy, kiz, ki;   /* Initial wave vector [1/AA] */
  double kfx, kfy, kfz;       /* Final wave vector */
  double k;                   /* photon wave vector */
  double rho_x, rho_y, rho_z; /* the vector ki - tau */
  double rho;
  double diff;                      /* Deviation from Bragg condition */
  double ox, oy, oz;                /* Origin of Ewald sphere tangent plane */
  double b1x, b1y, b1z;             /* First vector spanning tangent plane */
  double b2x, b2y, b2z;             /* Second vector spanning tangent plane */
  double n11, n12, n22;             /* 2D Gauss description matrix N */
  double det_N;                     /* Determinant of N */
  double inv_n11, inv_n12, inv_n22; /* Inverse of N */
  double l11, l12, l22;             /* Cholesky decomposition L of 1/2*inv(N) */
  double det_L;                     /* Determinant of L */
  double Bt_D_O_x, Bt_D_O_y;        /* Temporaries */
  double y0x, y0y;                  /* Center of 2D Gauss in plane coordinates */
  double alpha;                     /* Offset of 2D Gauss center from 3D center */
  double V0;                        /* Volume of unit cell */
  double l_full;                    /* photon path length for transmission */
  double l;                         /* Path length to scattering event */
  double abs_xsect, abs_xlen;       /* Absorption cross section and length */
  double inc_xsect, inc_xlen;       /* Incoherent scattering cross section and length */
  double coh_xsect, coh_xlen;       /* Coherent cross section and length */
  double tot_xsect, tot_xlen;       /* Total cross section and length */
  double z1, z2, y1, y2;            /* Temporaries to choose kf from 2D Gauss */
  double adjust, sum;               /* Temporaries */

  double p_trans;               /* Transmission probability */
  double mc_trans, mc_interact; /* Transmission, interaction MC choices */
  int intersect = 0;

  double curv_xangle;
  double curv_yangle;

  double _kx;
  double _ky;
  double _kz;

  char type; /* type of last event: t=transmit,c=coherent or i=incoherent */
  int itype; /* type of last event: t=1,c=2 or i=3 */

  #ifdef OPENACC
  #ifdef USE_OFF
  off_struct thread_offdata = offdata;
  #endif
  #else
  #define thread_offdata offdata
  #endif

  /* Intersection photon trajectory / sample (sample surface) */
  if (hkl_info.shape == 0)
    intersect = cylinder_intersect (&l1, &l2, x, y, z, kx, ky, kz, radius, yheight);
  else if (hkl_info.shape == 1)
    intersect = box_intersect (&l1, &l2, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);
  else if (hkl_info.shape == 2)
    intersect = sphere_intersect (&l1, &l2, x, y, z, kx, ky, kz, radius);
  #ifdef USE_OFF
  else if (hkl_info.shape == 3)
    intersect = off_x_intersect (&l1, &l2, NULL, NULL, x, y, z, kx, ky, kz, thread_offdata);
  #endif
  if (l2 < 0)
    intersect = 0; /* we passed sample volume already */

  if (intersect) { /* photon intersects crystal */
    if (l1 > 0)
      PROP_DL (l1); /* Move to crystal surface if not inside */
    ki = sqrt (kx * kx + ky * ky + kz * kz);
    event_counter = 0;

    /*absorption cross-section */
    abs_xsect = 0;
    if (abs_info.muc) {
      double mu = Table_Value (abs_info.table, ki * K2E, abs_info.muc);
      abs_xsect = (abs_info.atomic_weight / (6.02214076 * 10E23)) * mu; // this is in cm^2
      // atomic weight = [g . mol^-1]
      // Avogadro number = [mol^-1]
      // mu = [cm squared . g⁻1]
      // therefore convert to barns if barns set to 1, otherwise to fm^2
      if (hkl_info.flag_barns) { // convert cm^2 into barns
        abs_xsect *= 10E26;
      } else { // convert cm^2 into fm^2, else we assume fm^2
        abs_xsect *= 10E24;
      }
    }
    V0 = hkl_info.V0;
    abs_xlen = abs_xsect / V0;

    /*look into Compton scattering*/
    inc_xsect = hkl_info.sigma_i;
    inc_xlen = inc_xsect / V0;

    if (hkl_info.flag_barns) {
      /*If cross sections are given in barns, we need a scaling factor of 100
        to get scattering lengths in m, since V0 is assumed to be in AA*/
      abs_xlen *= 100;
      inc_xlen *= 100;
    } /* else assume fm^2 */
    L = hkl_list;

    type = '\0';
    itype = 0;

    #ifndef OPENACC
    T = tau_list;
    hkl_info.type = type;
    #endif
    do { /* Loop over multiple scattering events */
      /* Angles for powder randomization */
      double Alpha, Beta, Gamma;

      if (hkl_info.shape == 0)
        intersect = cylinder_intersect (&l1, &l2, x, y, z, kx, ky, kz, radius, yheight);
      else if (hkl_info.shape == 1)
        intersect = box_intersect (&l1, &l2, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);
      else if (hkl_info.shape == 2)
        intersect = sphere_intersect (&l1, &l2, x, y, z, kx, ky, kz, radius);
      #ifdef USE_OFF
      else if (hkl_info.shape == 3)
        intersect = off_x_intersect (&l1, &l2, NULL, NULL, x, y, z, kx, ky, kz, thread_offdata);
      #endif
      if (!intersect || l2 < -1e-7 || l1 > 1e-7) {
        /* photon is leaving the sample */
        hkl_info.flag_warning++;
        if (hkl_info.flag_warning < 10)
          #ifndef OPENACC
          MPI_MASTER (fprintf (stderr,
                               "Single_crystal: %s: WARNING: photon has unexpectedly left the crystal!\n"
                               "                l1=%g l2=%g x=%g y=%g z=%g kx=%g ky=%g kz=%g order=%i\n",
                               NAME_CURRENT_COMP, l1, l2, x, y, z, kx, ky, kz, event_counter););
        #endif
        break;
      }

      l_full = l2;

      if ((order && !(extra_order) && event_counter >= order) || (order && extra_order && event_counter >= order + extra_order)) {
        // Exit due to truncated order, weight with relevant cross-sections to distance l_full
        p *= exp (-abs_xlen * l_full);
        intersect = 0;
        break;
      }

      /* (1). Compute incoming wave vector ki */
      if (powder) { /* orientation of crystallite is random */
        Alpha = randpm1 () * PI * powder;
        Beta = randpm1 () * PI / 2;
        Gamma = randpm1 () * PI;
        randrotate (&kx, &ky, &kz, Alpha, Beta, Gamma);
      }

      /* ------------------------------------------------------------------------- */
      /* lattice curvature option: rotate photon velocity */
      curv_xangle = 0;
      curv_yangle = 0;

      _kx = kx;
      _ky = ky;
      _kz = kz;

      if (RY) { /* rotate v around x axis based on y pos, for vertical focus */
        curv_yangle = atan2 (y, RY);
        vec_rotate_2d (&ky, &kz, curv_yangle);
        vec_rotate_2d (&Ey, &Ez, curv_yangle);

        /*changing y,z actually curves the crystal, not only the planes*/
        /*comment out if only curvature of the lattice planes is needed*/
        vec_rotate_2d (&y, &z, curv_yangle);
      }
      if (RX) { /* rotate v around y axis based on x pos, for horizontal focus */
        curv_xangle = atan2 (x, RX);
        vec_rotate_2d (&kx, &kz, curv_xangle);
        vec_rotate_2d (&Ex, &Ez, curv_xangle);

        /*changing x,z actually curves the crystal, not only the planes*/
        /*comment out if only curvature of the lattice planes is needed*/
        vec_rotate_2d (&x, &z, curv_xangle);
      }

      kix = kx;
      kiy = ky;
      kiz = kz;
      kx = _kx;
      ky = _ky;
      kz = _kz;
      /* ------------------------------------------------------------------------- */

      /* (2). Intersection of Ewald sphere with reciprocal lattice points */

      double coh_xsect = 0, coh_refl = 0;

      // Condition to skip calculation of coherent cross section when, needed for extra_order feature
      if (order == 0 || extra_order == 0 || event_counter < order) {
        /* in case we use 'SPLIT' then consecutive photons can be identical when entering here
           and we may skip the hkl_search call */
        #ifndef OPENACC
        if (order == 1 && fabs (kix - hkl_info.kix) < deltak && fabs (kiy - hkl_info.kiy) < deltak && fabs (kiz - hkl_info.kiz) < deltak) {
          hkl_info.nb_reuses++;

          /* Restore in case of matching event (e.g. SPLIT) */
          coh_refl = hkl_info.coh_refl;
          coh_xsect = hkl_info.coh_xsect;
          tau_count = hkl_info.tau_count;

        } else {
          #endif
          /* Max possible tau for this ki with 5*sigma delta-d/d cutoff. */
          double tau_max = 2 * ki / (1 - 5 * hkl_info.m_delta_d_d);

          /* call hkl_search */

          tau_count = hkl_search (L, T, hkl_info.count, hkl_info.V0, kix, kiy, kiz, tau_max, &coh_refl, &coh_xsect);

          /* store ki so that we can check for further SPLIT iterations */
          #ifndef OPENACC
          if (tau_count > hkl_info.max_tau_count) {
            hkl_info.max_tau_count = tau_count;
          }
          if (event_counter == 0) { /* only for incoming photon */
            hkl_info.kix = kix;
            hkl_info.kiy = kiy;
            hkl_info.kiz = kiz;

            /* Store for potential re-use (e.g. SPLIT) */
            hkl_info.coh_refl = coh_refl;
            hkl_info.coh_xsect = coh_xsect;
            hkl_info.tau_count = tau_count;
            hkl_info.nb_refl += tau_count;
            hkl_info.nb_refl_count++;
          }
        }
        #endif
      } else {
        // When extra_order used, disable coherent scattering after order reached, but continue
        // Set coherent cross section to zero to ignore coherent part
        coh_refl = 0;
        coh_xsect = 0;
        tau_count = 0;
      }

      /* (3). Probabilities of the different possible interactions. */
      /* Cross-sections are in barns = 10**-28 m**2, and unit cell volumes are
         in AA**3 = 10**-30 m**2. Hence a factor of 100 is used to convert
         scattering lengths to m**-1 */
      coh_xlen = coh_xsect / V0;
      if (hkl_info.flag_barns) {
        coh_xlen *= 100;
      } /* else assume fm^2 */
      tot_xlen = abs_xlen + inc_xlen + coh_xlen;

      if (tot_xlen <= 0) {
        ABSORB; // Should we really absorb here? If "nothing" can happen we perhaps ought to "pass" instead?
      }

      /* (5). Transmission */
      p_trans = exp (-tot_xlen * l_full);
      if (!event_counter && p_transmit >= 0 && p_transmit <= 1) {
        mc_trans = p_transmit; /* first event */
      } else {
        mc_trans = p_trans;
      }
      mc_interact = 1 - mc_trans;
      if (mc_trans > 0 && (mc_trans >= 1 || rand01 () < mc_trans)) /* Transmit */
      {
        p *= p_trans / mc_trans;
        intersect = 0;
        if (powder) { /* orientation of crystallite is no longer random */
          randderotate (&kx, &ky, &kz, Alpha, Beta, Gamma);
        }

        type = 't';
        if (!itype)
          itype = 1;
        #ifndef OPENACC
        hkl_info.type = type;
        #endif

        break;
        /* This break means that we are leaving the while-loop, exiting the
           crystal by "tunneling". */
      }

      /* Scattering "proper", i.e. coh or incoh */
      if (mc_interact <= 0) /* Protect against rounding errors */
      {
        intersect = 0;
        if (powder) { /* orientation of crystallite is no longer random */
          randderotate (&kx, &ky, &kz, Alpha, Beta, Gamma);
        }
        break;
      }

      /* First-pass considerations: */
      if (!event_counter)
        p *= fabs (1 - p_trans) / mc_interact;
      /* Select a point at which to scatter the photon, taking
         secondary extinction into account. */
      /* dP(l) = exp(-tot_xlen*l)dl
         P(l<l_0) = [-1/tot_xlen*exp(-tot_xlen*l)]_0^l_0
                  = (1 - exp(-tot_xlen*l0))/tot_xlen
         l = -log(1 - tot_xlen*rand0max(P(l<l_full)))/tot_xlen
       */
      if (tot_xlen * l_full < 1e-6)
        /* For very weak scattering, use simple uniform sampling of scattering
           point to avoid rounding errors. */
        l = rand0max (l_full);
      else
        l = -log (1 - rand0max ((1 - exp (-tot_xlen * l_full)))) / tot_xlen;

      /* Propagate to scattering point */
      PROP_DL (l);
      event_counter++;

      /* (4). Account for the probability of sigma_abs */
      p *= (coh_xlen + inc_xlen) / tot_xlen;
      /* Choose between coherent and incoherent scattering */
      if (coh_xlen == 0 || rand0max (coh_xlen + inc_xlen) <= inc_xlen) {
        /* (6). Incoherent scattering */
        randvec_target_circle (&kix, &kiy, &kiz, NULL, kx, ky, kz, 0);
        kx = kix; /* ki vector is used as tmp var with norm v */
        ky = kiy;
        kz = kiz; /* Go for next scattering event */

        type = 'i';
        if (!itype)
          itype = 2;
        #ifndef OPENACC
        hkl_info.type = type;
        #endif
      } else {
        /* 7. Coherent scattering. Select reciprocal lattice point. */
        if (coh_refl <= 0) {
          ABSORB;
        }
        sum = 0;
        j = hkl_select (T, tau_count, coh_refl, &sum, _particle);
        if (j >= tau_count) {
          #ifndef OPENACC
          if (hkl_info.flag_warning < 10)
            MPI_MASTER (fprintf (stderr,
                                 "Single_crystal: %s: WARNING: failed tau search "
                                 "(sum=%g, coh_refl=%g, j=%i, tau_count=%i). Using last reflection.\n",
                                 NAME_CURRENT_COMP, sum, coh_refl, j, tau_count););
          #endif
          hkl_info.flag_warning++;
          j = tau_count - 1;
        }
        i = T[j].index;
        /* (8). Pick scattered wavevector kf from 2D Gauss distribution. */
        z1 = randnorm ();
        z2 = randnorm ();
        y1 = T[j].l11 * z1 + T[j].y0x;
        y2 = T[j].l12 * z1 + T[j].l22 * z2 + T[j].y0y;
        kfx = T[j].rho_x + T[j].ox + T[j].b1x * y1 + T[j].b2x * y2;
        kfy = T[j].rho_y + T[j].oy + T[j].b1y * y1 + T[j].b2y * y2;
        kfz = T[j].rho_z + T[j].oz + T[j].b1z * y1 + T[j].b2z * y2;

        /* Normalize kf to length of ki, to account for planer
           approximation of the Ewald sphere. */
        adjust = ki / sqrt (kfx * kfx + kfy * kfy + kfz * kfz);
        kfx *= adjust;
        kfy *= adjust;
        kfz *= adjust;
        /* Adjust photon weight (see manual for explanation). */
        double pmul = T[j].xsect * coh_refl / (coh_xsect * T[j].refl);
        if (!isnan (pmul))
          p *= pmul;
        kx = L[i].u1x * kfx + L[i].u2x * kfy + L[i].u3x * kfz;
        ky = L[i].u1y * kfx + L[i].u2y * kfy + L[i].u3y * kfz;
        kz = L[i].u1z * kfx + L[i].u2z * kfy + L[i].u3z * kfz;

        /* add thin layer k-broadening, only with box/cylinder shape */
        if (hkl_info.shape == 1) {                                /* box */
          double thickness_threshold = 1000 * 2 * PI / ki / 1e10; // 1000*lambda in Angs, /1e10 -> m
          if (xwidth < thickness_threshold)
            kx += 2 * PI / xwidth / 1e10 * randnorm ();
          if (yheight < thickness_threshold)
            ky += 2 * PI / yheight / 1e10 * randnorm ();
          if (zdepth < thickness_threshold)
            kz += 2 * PI / zdepth / 1e10 * randnorm ();
        } else if (hkl_info.shape == 0) { /* cylinder */
          double thickness_threshold = 1000 * 2 * PI / ki / 1e10;
          if (yheight < thickness_threshold)
            ky += 2 * PI / yheight / 1e10 * randnorm ();
        }

        type = 'c';
        if (!itype)
          itype = 3;
        #ifndef OPENACC
        hkl_info.type = type;
        hkl_info.h = L[i].h;
        hkl_info.k = L[i].k;
        hkl_info.l = L[i].l;
        #endif
      }
      /* ------------------------------------------------------------------------- */
      /* lattice curvature option: rotate back photon velocity */
      if (RX) {
        vec_rotate_2d (&kx, &kz, -curv_xangle);
        vec_rotate_2d (&Ex, &Ez, -curv_xangle);

        /*changing x,z actually curves the crystal, not only the planes*/
        /*comment out if only curvature of the lattice planes is needed*/
        vec_rotate_2d (&x, &z, -curv_xangle);
      }
      if (RY) {
        vec_rotate_2d (&ky, &kz, -curv_yangle);
        vec_rotate_2d (&Ey, &Ez, -curv_yangle);

        /*changing y,z actually curves the crystal, not only the planes*/
        /*comment out if only curvature of the lattice planes is needed*/
        vec_rotate_2d (&y, &z, -curv_yangle);
      }
      /* ------------------------------------------------------------------------- */
      SCATTER;
      if (powder) { /* orientation of crystallite is no longer random */
        randderotate (&kx, &ky, &kz, Alpha, Beta, Gamma);
      }
      /* Repeat loop for next scattering event. */
    } while (intersect); /* end do (intersect) (multiple scattering loop) */
  } /* if intersect */
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 297) { // EXTEND 'PX1_sample'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 323) { // EXTEND 'PX2a_sample'
  if (!SCATTERED) ABSORB;
}
if (_comp->_index == 498) { // EXTEND 'SIXS_sx_layer'
  if (SCATTERED) SIXS_flag_scatt++;
}
if (_comp->_index == 499) { // EXTEND 'SIXS_sx_bulk'
  if (SCATTERED) SIXS_flag_scatt += 2;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef reflections
  #undef geometry
  #undef mosaic_AB
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef delta_d_d
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef recip_cell
  #undef barns
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef p_transmit
  #undef sigma_inc
  #undef aa
  #undef bb
  #undef cc
  #undef order
  #undef extra_order
  #undef RX
  #undef RY
  #undef powder
  #undef deltak
  #undef material_datafile
  #undef surf_size
  #undef surf_k
  #undef surf_FT2
  #undef surf_dir
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  return;
} /* class_Single_crystal_trace */

#pragma acc routine
void class_PSD_monitor_4PI_trace(_class_PSD_monitor_4PI *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  SIG_MESSAGE("[_PX1_psd4pi_trace] component PX1_psd4pi=PSD_monitor_4PI() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:66]");

  double l0, l1, theta, psi;
  int i, j;

  if (sphere_intersect (&l0, &l1, x, y, z, kx, ky, kz, radius) && l1 > 0) {
    if (l0 < 0)
      l0 = l1;
    /* l0 is the intersection length with the sphere. */
    PROP_DL (l0);

    /* Measure longitude via atan2. Returned values will be in [-PI PI] */
    theta = atan2 (x, z);
    
    /* Map to nx * [0 1] interval */
    i = floor (nx * 0.5*(theta / PI+1));

    /* Measure latitude via asin(elevation/radius). Returned values will be in [-PI/2 PI/2] */
    psi = asin (y / radius);

    /* Map to ny * [0 1] interval */
    j = floor (ny * (psi + PI / 2) / PI);

    double p2 = p * p;
    #pragma acc atomic
    PSD_N[i][j] = PSD_N[i][j] + 1;

    #pragma acc atomic
    PSD_p[i][j] = PSD_p[i][j] + p;

    #pragma acc atomic
    PSD_p2[i][j] = PSD_p2[i][j] + p2;

    SCATTER;
  }
  if (restore_xray) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef radius
  #undef restore_xray
  #undef nx
  #undef ny
  #undef filename
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  return;
} /* class_PSD_monitor_4PI_trace */

#pragma acc routine
void class_Saxs_spheres_trace(_class_Saxs_spheres *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define sphere_mtrl (_comp->_parameters.sphere_mtrl)
  #define R (_comp->_parameters.R)
  #define Phi (_comp->_parameters.Phi)
  #define Delta_rho (_comp->_parameters.Delta_rho)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define target_index (_comp->_parameters.target_index)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define focus_r (_comp->_parameters.focus_r)
  #define mu_c (_comp->_parameters.mu_c)
  #define my_s_pre (_comp->_parameters.my_s_pre)
  #define shape (_comp->_parameters.shape)
  #define Z (_comp->_parameters.Z)
  #define At (_comp->_parameters.At)
  #define rho (_comp->_parameters.rho)
  #define T (_comp->_parameters.T)
  #define mu_ci (_comp->_parameters.mu_ci)
  #define abs_data (_comp->_parameters.abs_data)
  SIG_MESSAGE("[_SWING_sample_test_trace] component SWING_sample_test=Saxs_spheres() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Saxs_spheres.comp:137]");

  double l0, l1, v, l_full, l, l_1, dt, dl, d_phi, theta, my_a_v;
  double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z;
  double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z;
  double f, solid_angle, kx_i, ky_i, kz_i, k, q, qx, qy, qz;
  char intersect = 0;

  /* Intersection particle trajectory / sample (sample surface) */
  if (shape == 0)
    intersect = cylinder_intersect (&l0, &l1, x, y, z, kx, ky, kz, radius, yheight);
  else if (shape == 1)
    intersect = box_intersect (&l0, &l1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);
  else if (shape == 2)
    intersect = sphere_intersect (&l0, &l1, x, y, z, kx, ky, kz, radius);
  if (intersect) {
    if (l0 < 0) {
      fprintf (stderr, "photon already inside sample %s - absorbing\n", NAME_CURRENT_COMP);
      ABSORB;
    }
    /* Xray enters at l=l0. */
    k = sqrt (kx * kx + ky * ky + kz * kz);
    l_full = (l1 - l0);              /* Length of full path through sample */
    dl = rand01 () * (l1 - l0) + l0; /* Time of scattering */
    PROP_DL (dl);                    /* Point of scattering */
    l = (dl - l0);                   /* Penetration in sample */

    kx_i = kx;
    ky_i = ky;
    kz_i = kz;
    if ((target_x || target_y || target_z)) {
      aim_x = target_x - x; /* Vector pointing at target (anal./det.) */
      aim_y = target_y - y;
      aim_z = target_z - z;
    }
    if (focus_aw && focus_ah) {
      randvec_target_rect_angular (&kx, &ky, &kz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP);
    } else if (focus_xw && focus_yh) {
      randvec_target_rect (&kx, &ky, &kz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
    } else {
      randvec_target_circle (&kx, &ky, &kz, &solid_angle, aim_x, aim_y, aim_z, focus_r);
    }
    NORM (kx, ky, kz);
    kx *= k;
    ky *= k;
    kz *= k;
    qx = (kx_i - kx);
    qy = (ky_i - ky);
    qz = (kz_i - kz);
    q = sqrt (qx * qx + qy * qy + qz * qz);

    f = 3 * (sin (q * R) - q * R * cos (q * R)) / (q * R * q * R * q * R);

    /*calculate absorption*/
    if (abs_data) {
      my_a_v = Table_Value (T, k * K2E, mu_ci);
    } else {
      my_a_v = 0;
    }
    p *= l_full * solid_angle / (4 * PI) * my_s_pre * f * f * exp (-my_a_v * (l + l1));
    SCATTER;
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 349) { // EXTEND 'SWING_sample_test'
  if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef sphere_mtrl
  #undef R
  #undef Phi
  #undef Delta_rho
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef target_x
  #undef target_y
  #undef target_z
  #undef target_index
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef focus_r
  #undef mu_c
  #undef my_s_pre
  #undef shape
  #undef Z
  #undef At
  #undef rho
  #undef T
  #undef mu_ci
  #undef abs_data
  return;
} /* class_Saxs_spheres_trace */

void class_SAXSPDBFast_trace(_class_SAXSPDBFast *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define RhoSolvent (_comp->_parameters.RhoSolvent)
  #define Concentration (_comp->_parameters.Concentration)
  #define AbsorptionCrosssection (_comp->_parameters.AbsorptionCrosssection)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define SampleToDetectorDistance (_comp->_parameters.SampleToDetectorDistance)
  #define DetectorRadius (_comp->_parameters.DetectorRadius)
  #define qMin (_comp->_parameters.qMin)
  #define qMax (_comp->_parameters.qMax)
  #define NumberOfQBins (_comp->_parameters.NumberOfQBins)
  #define PDBFilepath (_comp->_parameters.PDBFilepath)
  #define Absorption (_comp->_parameters.Absorption)
  #define NumberDensity (_comp->_parameters.NumberDensity)
  #define qArray (_comp->_parameters.qArray)
  #define IArray (_comp->_parameters.IArray)
  SIG_MESSAGE("[_SWING_sample_trace] component SWING_sample=SAXSPDBFast() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSPDBFast.comp:450]");

  // Declarations
  double l0;
  double l1;
  double l_full;
  double l;
  double l_1;
  double q;
  double Intensity;
  double Weight;
  double IntensityPart;
  double SolidAngle;
  double qx;
  double qy;
  double qz;
  double k;
  double dl;
  double kx_i;
  double ky_i;
  double kz_i;
  char Intersect = 0;
  double Slope;
  double Offset;
  int i;

  // Computation
  Intersect = box_intersect (&l0, &l1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);

  if (Intersect) {

    if (l0 < 0.0) {
      fprintf (stderr, "SAXSPDBFast: %s: Photon already inside sample - absorbing...\n", NAME_CURRENT_COMP);
      ABSORB;
    }

    // Compute properties of photon
    k = sqrt (pow (kx, 2) + pow (ky, 2) + pow (kz, 2));
    l_full = l1 - l0;
    dl = rand01 () * (l1 - l0) + l0;
    PROP_DL (dl);
    l = dl - l0;

    // Store properties of incoming photon
    kx_i = kx;
    ky_i = ky;
    kz_i = kz;

    // Generate new direction of photon
    randvec_target_circle (&kx, &ky, &kz, &SolidAngle, 0, 0, SampleToDetectorDistance, DetectorRadius);

    NORM (kx, ky, kz);

    kx *= k;
    ky *= k;
    kz *= k;

    // Compute q
    qx = kx_i - kx;
    qy = ky_i - ky;
    qz = kz_i - kz;

    q = sqrt (pow (qx, 2) + pow (qy, 2) + pow (qz, 2));

    // Discard photon, if q is out of range
    if ((q < qArray[0]) || (q > qArray[NumberOfQBins - 1])) {
      ABSORB;
    }

    // Find the first value of q in the curve larger than that of the photon
    i = 1;

    while (q > qArray[i]) {
      ++i;
    }

    // Do a linear interpolation
    Slope = (IArray[i] - IArray[i - 1]) / (qArray[i] - qArray[i - 1]);
    Offset = IArray[i] - Slope * qArray[i];

    Intensity = (Slope * q + Offset);

    p *= l_full * SolidAngle / (4.0 * PI) * NumberDensity * Intensity * exp (-Absorption * (l + l1));

    SCATTER;
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif

  #define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
  #define flag_scatt (_particle->flag_scatt)
  #define flag_hfm (_particle->flag_hfm)
  #define flag_vfm (_particle->flag_vfm)
  #define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
  #define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
  #define SWING_flag_hfm (_particle->SWING_flag_hfm)
  #define SWING_flag_vfm (_particle->SWING_flag_vfm)
  #define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
  #define beamline (_particle->beamline)
if (_comp->_index == 350) { // EXTEND 'SWING_sample'
  if (!SCATTERED) ABSORB;
}
  #undef PUMA_scat_before_VFM
  #undef flag_scatt
  #undef flag_hfm
  #undef flag_vfm
  #undef PX2a_flag_hfm
  #undef PX2a_flag_vfm
  #undef SWING_flag_hfm
  #undef SWING_flag_vfm
  #undef SIXS_flag_scatt
  #undef beamline

  #undef RhoSolvent
  #undef Concentration
  #undef AbsorptionCrosssection
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef SampleToDetectorDistance
  #undef DetectorRadius
  #undef qMin
  #undef qMax
  #undef NumberOfQBins
  #undef PDBFilepath
  #undef Absorption
  #undef NumberDensity
  #undef qArray
  #undef IArray
  return;
} /* class_SAXSPDBFast_trace */

#pragma acc routine
void class_SAXSQMonitor_trace(_class_SAXSQMonitor *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define RFilename (_comp->_parameters.RFilename)
  #define qFilename (_comp->_parameters.qFilename)
  #define NumberOfBins (_comp->_parameters.NumberOfBins)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define RadiusDetector (_comp->_parameters.RadiusDetector)
  #define DistanceFromSample (_comp->_parameters.DistanceFromSample)
  #define LambdaMin (_comp->_parameters.LambdaMin)
  #define Lambda0 (_comp->_parameters.Lambda0)
  #define qMax (_comp->_parameters.qMax)
  #define Nofq (_comp->_parameters.Nofq)
  #define Iofq (_comp->_parameters.Iofq)
  #define IofqSquared (_comp->_parameters.IofqSquared)
  #define NofR (_comp->_parameters.NofR)
  #define IofR (_comp->_parameters.IofR)
  #define IofRSquared (_comp->_parameters.IofRSquared)
  SIG_MESSAGE("[_SWING_QMonitor_trace] component SWING_QMonitor=SAXSQMonitor() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSQMonitor.comp:87]");

  int i;
  double TwoTheta;
  double Lambda;

  double R;
  double RLow;
  double RHigh;

  double q;
  double qLow;
  double qHigh;

  double TwoThetaLow;
  double TwoThetaHigh;
  double AreaOfSlice;

  PROP_Z0;

  R = sqrt (x * x + y * y);

  // Computation of q
  if (Lambda0 <= 0.0) {
    Lambda = 2.0 * PI / sqrt (kx * kx + ky * ky + kz * kz);
  } else {
    Lambda = Lambda0;
  }

  TwoTheta = atan (R / DistanceFromSample);
  q = 4.0 * PI * sin (TwoTheta / 2.0) / Lambda;

  // Put photon in the correct r-bin
  if (R < RadiusDetector) {
    i = floor (NumberOfBins * R / RadiusDetector);

    RLow = RadiusDetector / NumberOfBins * i;
    RHigh = RadiusDetector / NumberOfBins * (i + 1);

    TwoThetaLow = atan (RLow / DistanceFromSample);
    TwoThetaHigh = atan (RHigh / DistanceFromSample);

    AreaOfSlice = fabs ((cos (2.0 * TwoThetaLow) - cos (2.0 * TwoThetaHigh)) * 2.0 * PI);

    #pragma acc atomic
    NofR[i] = NofR[i] + 1;
    double p_A = p / AreaOfSlice;
    #pragma acc atomic
    IofR[i] += p_A;
    double p2_A2 = p * p / (AreaOfSlice * AreaOfSlice);
    #pragma acc atomic
    IofRSquared[i] += p2_A2;
  }

  // Put photon in the correct q-bin
  if (q < qMax) {
    i = floor (NumberOfBins * q / qMax);

    qLow = qMax / NumberOfBins * i;
    qHigh = qMax / NumberOfBins * (i + 1);

    TwoThetaLow = asin (qLow * Lambda / (4.0 * PI));
    TwoThetaHigh = asin (qHigh * Lambda / (4.0 * PI));

    AreaOfSlice = fabs ((cos (2.0 * TwoThetaLow) - cos (2.0 * TwoThetaHigh)) * 2.0 * PI);

    #pragma acc atomic
    Nofq[i] = Nofq[i] + 1;
    double p_A = p / AreaOfSlice;
    #pragma acc atomic
    Iofq[i] += p_A;
    double p2_A2 = p * p / (AreaOfSlice * AreaOfSlice);
    #pragma acc atomic
    IofqSquared[i] += p2_A2;

    SCATTER;
  }

  // Restore xray if requested
  if (restore_xray) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef RFilename
  #undef qFilename
  #undef NumberOfBins
  #undef restore_xray
  #undef RadiusDetector
  #undef DistanceFromSample
  #undef LambdaMin
  #undef Lambda0
  #undef qMax
  #undef Nofq
  #undef Iofq
  #undef IofqSquared
  #undef NofR
  #undef IofR
  #undef IofRSquared
  return;
} /* class_SAXSQMonitor_trace */

#pragma acc routine
void class_Divergence_monitor_trace(_class_Divergence_monitor *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define nh (_comp->_parameters.nh)
  #define nv (_comp->_parameters.nv)
  #define rad (_comp->_parameters.rad)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define maxdiv_h (_comp->_parameters.maxdiv_h)
  #define maxdiv_v (_comp->_parameters.maxdiv_v)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define Div_N (_comp->_parameters.Div_N)
  #define Div_p (_comp->_parameters.Div_p)
  #define Div_p2 (_comp->_parameters.Div_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_ROCK_slit3_div_trace] component ROCK_slit3_div=Divergence_monitor() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Divergence_monitor.comp:93]");

  int i, j;
  double h_div, v_div;
  double k, kn;

  int backprop = allow_backprop; /* set by caller: also count backward hits */
  double t0 = t;
  ALLOW_BACKPROP;
  PROP_Z0;
  if ((backprop || t >= t0) && x > xmin && x < xmax && y > ymin && y < ymax) {
    /* Find length of projection onto the [nx ny nz] axis */
    kn = scalar_prod (kx, ky, kz, nx, ny, nz);
    if (rad) {
      h_div = atan2 (kx, kn);
      v_div = atan2 (ky, kn);
    } else {
      h_div = RAD2DEG * atan2 (kx, kn);
      v_div = RAD2DEG * atan2 (ky, kn);
    }
    if (h_div < maxdiv_h && h_div > -maxdiv_h && v_div < maxdiv_v && v_div > -maxdiv_v) {
      i = floor ((h_div + maxdiv_h) * nh / (2.0 * maxdiv_h));
      j = floor ((v_div + maxdiv_v) * nv / (2.0 * maxdiv_v));
      double p2 = p * p;
      #pragma acc atomic
      Div_N[i][j] = Div_N[i][j] + 1;
      #pragma acc atomic
      Div_p[i][j] = Div_p[i][j] + p;
      #pragma acc atomic
      Div_p2[i][j] = Div_p2[i][j] + p2;
      SCATTER;
    }
  }
  if (restore_xray || !SCATTERED) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef nh
  #undef nv
  #undef rad
  #undef filename
  #undef xwidth
  #undef yheight
  #undef maxdiv_h
  #undef maxdiv_v
  #undef restore_xray
  #undef nx
  #undef ny
  #undef nz
  #undef nowritefile
  #undef Div_N
  #undef Div_p
  #undef Div_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return;
} /* class_Divergence_monitor_trace */

void class_Fluorescence_trace(_class_Fluorescence *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define rho (_comp->_parameters.rho)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define flag_low_z (_comp->_parameters.flag_low_z)
  #define order (_comp->_parameters.order)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define xs_fluo (_comp->_parameters.xs_fluo)
  #define xs_Compton (_comp->_parameters.xs_Compton)
  #define xs_Rayleigh (_comp->_parameters.xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_xs_fluo (_comp->_parameters.reuse_xs_fluo)
  #define reuse_xs_Compton (_comp->_parameters.reuse_xs_Compton)
  #define reuse_xs_Rayleigh (_comp->_parameters.reuse_xs_Rayleigh)
  SIG_MESSAGE("[_ROCK_absorption_sample_trace] component ROCK_absorption_sample=Fluorescence() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:587]");


int    intersect=0;       /* flag to continue/stop */
int    reuse    =0;       /* flag raised when reusing (SPLIT) */
int    type     =-1;      /* type of interaction */
double l0,  l1,  l2,  l3; /* distances for intersections */
double dl0, dl1, dl2, dl; /* distance intervals */
int    flag_concentric = 0;
int    flag_ishollow   = 0;
int    event_counter   = 0;         /* scattering event counter (multiple fluorescence) */
int    force_transmit  = 0;         /* Flag to handle cross-section weighting in case of finite order */
double sigma_barn=0, xs[5];         /* cross sections [barn/atom] fluo/Compton/Rayleigh/diff/transmit */
double aim_x=0, aim_y=0, aim_z=1;   /* Position of target relative to scattering point */


#ifdef OPENACC
#ifdef USE_OFF
off_struct thread_offdata = offdata;
#endif
#else
#define thread_offdata offdata
#endif

double k, E;
double ki,pi;

/* Store Initial photon state */
k  = ki = sqrt(kx*kx+ky*ky+kz*kz); //  Angs-1
E  = K2E*k; // keV
pi = p;     // used to test for multiple fluo weighting and order cutoff

do { /* while (intersect) Loop over multiple scattering events */

  // test for a SPLIT event (same particle comes in)
  l0=l1=l2=l3=dl0=dl1=dl2=0;
  if (!event_counter && fabs(reuse_ki - ki) < 1e-15) {
    reuse     = 1;
    reuse_nb++;
    // use cached values and skip actual computation
    intersect = reuse_intersect;
    l0        = reuse_l0;
    l1        = reuse_l1;
    l2        = reuse_l2;
    l3        = reuse_l3;

  } else {
    // we have a different event: compute intersection lengths
    
    /* ========================================================================== */
    /*                                   GEOMETRY                                 */
    /* ========================================================================== */

    /* Intersection photon trajectory / sample (sample surface) */
    if (thickness >= 0) {
      if (shape==0)
        intersect=cylinder_intersect(&l0,&l3, x,y,z,kx,ky,kz, radius,yheight);
      else if (shape==1)
        intersect=box_intersect     (&l0,&l3, x,y,z,kx,ky,kz, xwidth,yheight,zdepth);
      else if (shape==2)
        intersect=sphere_intersect  (&l0,&l3, x,y,z,kx,ky,kz, radius);
      #ifdef USE_OFF
      else if (shape == 3)
        intersect=off_x_intersect(&l0, &l3, NULL, NULL, x, y, z, kx,ky,kz, thread_offdata );
      #endif
    } else {
      if (shape==0)
        intersect=cylinder_intersect(&l0,&l3, x,y,z,kx,ky,kz, radius-thickness,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight);
      else if (shape==1)
        intersect=box_intersect     (&l0,&l3, x,y,z,kx,ky,kz,
          xwidth-2*thickness > 0 ?  xwidth-2*thickness : xwidth,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight,
          zdepth-2*thickness > 0 ?  zdepth-2*thickness : zdepth);
      else if (shape==2)
        intersect=sphere_intersect  (&l0,&l3, x,y,z,kx,ky,kz, radius-thickness);
      #ifdef USE_OFF
      else if (shape == 3)
        intersect=off_x_intersect(&l0, &l3, NULL, NULL, x, y, z, kx,ky,kz, thread_offdata );
      #endif
    }


    /* Computing the intermediate lengths */
    if (intersect && p_interact >= 0) {
      flag_ishollow = 0;
      if (thickness > 0) {
        if (shape==0 && cylinder_intersect(&l1,&l2, x,y,z,kx,ky,kz, radius-thickness,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight))
          flag_ishollow=1;
        else if (shape==2 && sphere_intersect   (&l1,&l2, x,y,z,kx,ky,kz, radius-thickness))
          flag_ishollow=1;
        else if (shape==1 && box_intersect(&l1,&l2, x,y,z,kx,ky,kz,
          xwidth-2*thickness > 0 ? xwidth-2*thickness : xwidth,
          yheight-2*thickness > 0 ? yheight-2*thickness : yheight,
          zdepth-2*thickness > 0 ? zdepth-2*thickness : zdepth))
          flag_ishollow=1;
      } else if (thickness<0) {
        if (shape==0 && cylinder_intersect(&l1,&l2, x,y,z,kx,ky,kz, radius,yheight))
          flag_ishollow=1;
        else if (shape==2 && sphere_intersect   (&l1,&l2, x,y,z,kx,ky,kz, radius))
          flag_ishollow=1;
        else if (shape==1 && box_intersect(&l1,&l2, x,y,z,kx,ky,kz, xwidth, yheight, zdepth))
          flag_ishollow=1;
      }
      if (l3 > 1000) l3=0;              // we passed the sample, far away
      if (!flag_ishollow) l1 = l2 = l3; /* no empty space inside */
    } /* if intersect */


    // store values for potential next SPLIT
    if (!event_counter) {
      reuse_intersect = intersect;
      reuse_l0        = l0;
      reuse_l1        = l1;
      reuse_l2        = l2;
      reuse_l3        = l3;
      reuse_ki        = ki;
    }
    reuse           = 0;
  } // if !reuse (SPLIT)

  if (intersect) { /* the photon hits the sample */

    if (l0 > 0) {  /* we are before the sample */
      PROP_DL(l0); /* propagates photon to the entry of the sample */
    } else if (l1 > 0 && l1 > l0) { /* we are inside first part of the sample */
      /* no propagation, stay inside */
    } else if (l2 > 0 && l2 > l1) { /* we are in the hole */
      PROP_DL(l2); /* propagate to inner surface of 2nd part of sample */
    } else if (l3 > 0 && l3 > l2) { /* we are in the 2nd part of sample */
      /* no propagation, stay inside */
    }

    dl0=l1-(l0 > 0 ? l0 : 0); /* Distance in first part of hollow/cylinder/box */
    dl1=l2-(l1 > 0 ? l1 : 0); /* Distance in hole */
    dl2=l3-(l2 > 0 ? l2 : 0); /* Distance in 2nd part of hollow cylinder */

    if (dl0 < 0) dl0 = 0;
    if (dl1 < 0) dl1 = 0;
    if (dl2 < 0) dl2 = 0;

    /* initialize concentric mode */
    if (concentric && !flag_concentric && l0 >= 0
     && shape==0 && thickness) {
      flag_concentric=1;
    }

    if (flag_concentric == 1) {
      dl1=dl2=0; /* force exit when reaching hole/2nd part */
    }

    if (!dl0 && !dl2) {
      intersect = 0; /* the sample was passed entirely */
    }
  } // if intersect (geometry)

    
  /* ========================================================================== */
  /*                             INTERACTION PROCESS                            */
  /* ========================================================================== */
  xs[FLUORESCENCE]=xs[COMPTON]=xs[RAYLEIGH]=xs[TRANSMISSION]=xs[DIFFRACTION]=sigma_barn=0;
  cum_xs_fluo[0] = cum_xs_Compton[0] = cum_xs_Rayleigh[0] = 0;
  
  if (intersect) {
    double my_s;
    int    i_Z,i;
    int    flag=0;
    double d_path, p_trans, p_scatt, mc_trans, mc_scatt;
    
    /* actual fluorescence calculation */
    
    /* compute total scattering cross section for incoming photon energy Ei */
    /* compute each contribution XS */
    if (!reuse) {
      for (i_Z=0; i_Z< compound->nElements; i_Z++) {
        int    Z   = compound->Elements[i_Z];
        double frac= compound->massFractions[i_Z];
        double xs_Z[3];

        // get Fluorescence xs
        XRMC_CrossSections(Z, E, xs_Z, flag_kissel); // [barn/atom]

        // local XS for atom (Z)
        xs_fluo[i_Z+1]     = frac*xs_Z[FLUORESCENCE];
        xs_Compton[i_Z+1]  = frac*xs_Z[COMPTON];
        xs_Rayleigh[i_Z+1] = frac*xs_Z[RAYLEIGH];
        // selection on cumulated distribution xs*frac
        cum_xs_fluo[i_Z+1]     = cum_xs_fluo[i_Z]    +xs_fluo[i_Z+1];
        cum_xs_Compton[i_Z+1]  = cum_xs_Compton[i_Z] +xs_Compton[i_Z+1];
        cum_xs_Rayleigh[i_Z+1] = cum_xs_Rayleigh[i_Z]+xs_Rayleigh[i_Z+1];
        for (i=0; i<3; i++) { xs[i] += frac*xs_Z[i]; }
      } // for Z in compound
      for (i=0; i<3; i++) sigma_barn += xs[i]; // total XS
      
      // store values into cache for SPLIT
      if (!event_counter) {
        for (i_Z=0; i_Z< compound->nElements+1; i_Z++) {
          reuse_cum_xs_fluo[i_Z]     = cum_xs_fluo[i_Z];
          reuse_cum_xs_Compton[i_Z]  = cum_xs_Compton[i_Z];
          reuse_cum_xs_Rayleigh[i_Z] = cum_xs_Rayleigh[i_Z];
          reuse_xs_fluo[i_Z]         = xs_fluo[i_Z];
          reuse_xs_Compton[i_Z]      = xs_Compton[i_Z];
          reuse_xs_Rayleigh[i_Z]     = xs_Rayleigh[i_Z];
        }
        reuse_sigma_barn = sigma_barn;
      }

    } else {
      // reuse cached values (SPLIT), event_counter=0
      for (i_Z=0; i_Z< compound->nElements+1; i_Z++) {
        cum_xs_fluo[i_Z]      = reuse_cum_xs_fluo[i_Z];
        cum_xs_Compton[i_Z]   = reuse_cum_xs_Compton[i_Z];
        cum_xs_Rayleigh[i_Z]  = reuse_cum_xs_Rayleigh[i_Z];
        xs[FLUORESCENCE]     += reuse_cum_xs_fluo[i_Z];
        xs[COMPTON]          += reuse_cum_xs_Compton[i_Z];
        xs[RAYLEIGH]         += reuse_cum_xs_Rayleigh[i_Z];
        xs_fluo[i_Z]          = reuse_xs_fluo[i_Z];
        xs_Compton[i_Z]       = reuse_xs_Compton[i_Z];
        xs_Rayleigh[i_Z]      = reuse_xs_Rayleigh[i_Z];
      }
      sigma_barn = reuse_sigma_barn;
    }
//    printf("DEBUG: pi=%g p=%g ; ki=%g k=%g ; xs=[%g %g %g] type=FOLLOW sigma_barn=%g\n",
//        pi, p, ki, k, xs[0], xs[1], xs[2], sigma_barn);
    
    /* probability to absorb/scatter */
    my_s   = rho*100*sigma_barn; /* mu, 100: convert from barns to fm^2. my_s in [1/m] */
    d_path = ( dl0 +dl2 );  /* total path lenght in sample */
    
    /* Proba of transmission/interaction along length d_path */    
    p_trans = exp(-my_s*d_path); /* probability to not-interact (transmit) */
    p_scatt = 1 - p_trans;       /* portion of beam which scatters */
    
    /* force a given fraction of the beam to scatter */
    if (!event_counter && p_interact>0 && p_interact<=1) {
      /* we force a portion of the beam to interact */
      /* This is used to improve statistics */
      mc_trans = 1-p_interact;
    } else {
      mc_trans = p_trans; /* 1 - p_scatt */
    }
    mc_scatt = 1 - mc_trans; /* portion of beam to scatter (or force to) */
    if (mc_scatt <= 0) ABSORB;
    
    if (!force_transmit && mc_scatt > 0 && (mc_scatt >= 1 || rand01() < mc_scatt)) {
      /* we "scatter" with one of the interaction processes */
        
      dl = -log(1 - rand0max((1 - exp(-my_s*d_path)))) / my_s; /* length */

      /* If t0 is in hole, propagate to next part of the hollow cylinder */
      if (dl1 > 0 && dl0 > 0 && dl > dl0) dl += dl1;

      /* photon propagation to the scattering point */
      PROP_DL(dl);
      p *= fabs(p_scatt/mc_scatt); /* account for p_interact, lower than 1 */
      
    } else { // force_transmit
      /* we go through the material without interaction, and exit */
      if (type <0) type = TRANSMISSION; // transmission
      intersect = 0;
      PROP_DL(d_path);
      /* attenuate beam by portion which is scattered (and left along) */
      p *= p_trans;
      if (!event_counter && p_interact>0 && p_interact<=1) p /= mc_trans;
//      printf("DEBUG: pi=%g p=%g ; ki=%g k=%g ; xs=[%g %g %g] type=TRANSMIT\n",
//        pi, p, ki, k, xs[0], xs[1], xs[2]);
      break; // end while (intersect)
    }
    
  } /* if intersect (propagate) */

  if (intersect) { /* scattering event */
    int    i_Z, Z;
    double solid_angle=0;
    double theta, dsigma;
    double Ef, dE;
    double kf=k, kf_x, kf_y, kf_z;  // next particle direction

    /* MC choose process from cross sections 'xs': fluo, Rayleigh, Compton  */
    type = XRMC_SelectInteraction(xs, COMPTON+1, rand01()); // up to COMPTON
    
    /* choose Z (element) on associated XS, taking into account mass-fractions */
    if (flag_low_z) {
      i_Z = (int)floor(compound->nElements * rand01());
      switch (type) {
        case FLUORESCENCE:
          p *= xs_fluo[i_Z+1]/xs[type];
          break;
        case RAYLEIGH:
          p *= xs_Rayleigh[i_Z+1]/xs[type];
          break;
        case COMPTON:
          p *= xs_Compton[i_Z+1]/xs[type];
          break;
        default:
          // printf("%s: WARNING: process %i unknown. Absorb.\n", NAME_CURRENT_COMP, type);
          ABSORB;
      }
    } else {
      switch (type) {
        case FLUORESCENCE:
          i_Z = XRMC_SelectFromDistribution(cum_xs_fluo,     compound->nElements+1, rand01());
          break;
        case RAYLEIGH:
          if (!flag_rayleigh) ABSORB;
          i_Z = XRMC_SelectFromDistribution(cum_xs_Rayleigh, compound->nElements+1, rand01());
          break;
        case COMPTON:
          if (!flag_compton) ABSORB;
          i_Z = XRMC_SelectFromDistribution(cum_xs_Compton,  compound->nElements+1, rand01());
          break;
        default:
          // printf("%s: WARNING: process %i unknown. Absorb.\n", NAME_CURRENT_COMP, type);
          ABSORB;
      }
    }
    Z   = compound->Elements[i_Z];
    
    /* select outgoing vector (kf_x, kf_y, kf_z) and |kf| */
    if ((target_x || target_y || target_z)) {
      aim_x = target_x-x;       /* Vector pointing at target (anal./det.) */
      aim_y = target_y-y;
      aim_z = target_z-z;
    }
    if(focus_aw && focus_ah) {
      randvec_target_rect_angular(&kf_x, &kf_y, &kf_z, &solid_angle,
        aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP);
    } else if(focus_xw && focus_yh) {
      randvec_target_rect(&kf_x, &kf_y, &kf_z, &solid_angle,
        aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
    } else {
      randvec_target_circle(&kf_x, &kf_y, &kf_z, &solid_angle, aim_x, aim_y, aim_z, focus_r);
    }
    p *= solid_angle/(4*PI); // correct for selected solid-angle

    NORM(kf_x, kf_y, kf_z);  // normalize the outout direction |kf|=1
    
    // determine final energy (kf)
    switch (type) {
      case FLUORESCENCE: /* 0 Fluo: choose line */
        Ef      = XRMC_SelectFluorescenceEnergy(Z, E, &dE, flag_kissel, rand01()); // dE full-width in keV
        if (dE) {
          dE /= 2;  // half-width
          if (flag_lorentzian) dE  *= tan(PI/2*randpm1()); // Lorentzian distribution
          else                 dE  *= randnorm();          // Gaussian distribution
          Ef = Ef + dE;
        }
        kf      = Ef*E2K;
        theta   = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k);
        /* add polarisation factor */
        if (Ex!=0 || Ey!=0 || Ez!=0){
          double EE=sqrt(Ex*Ex+Ey*Ey+Ez*Ez);
          double s=scalar_prod(kf_x,kf_y,kf_z,Ex,Ey,Ez)/EE;
          p *= (1-s)*(1-s);
        } else {
          /*unpolarized light in - means an effective reduction according to only theta*/
          p *= (1+cos(theta)*cos(theta))*0.5;
        }
        n_fluo++;
        p_fluo += p;
        break;
        
      case RAYLEIGH:     /* 1 Rayleigh: Coherent, elastic */
        theta      = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k);
        dsigma     = DCSb_Rayl(Z,  E, theta, NULL); // [barn/at/st]
        p         *= 4*PI*dsigma/xs[RAYLEIGH];
        n_Rayleigh++;
        p_Rayleigh += p;
        break;
      
      case COMPTON:      /* 2 Compton: Incoherent: choose final energy */
        theta      = acos(scalar_prod(kf_x,kf_y, kf_z, kx,ky,kz)/k);
        dsigma     = DCS_Compt(Z,  E, theta, NULL); // [barn/at/st]
        kf         = ComptonEnergy(E, theta, NULL)*E2K; /* XRayLib, fraction of emc2=511 keV */
        p         *= 4*PI*dsigma/xs[COMPTON];
        n_Compton++;
        p_Compton += p;
        break;
    }
    
    kx = kf*kf_x;
    ky = kf*kf_y;
    kz = kf*kf_z;
    k  = kf;
    E  = k*K2E;
    SCATTER;
    event_counter++;
    
    /* exit if multiple scattering order has been reached */
    if (!order) break; // skip final absorption
    // stop when order has been reached, or weighting is very low
    if (order && (event_counter >= order || p/pi < 1e-15)) { force_transmit=1; }
 
  } // if intersect (scatter)
  
//  if (type>=0)
//  printf("DEBUG: pi=%g p=%g ; ki=%g k=%g ; xs=[%g %g %g] type=%i sigma_barn=%g %s\n",
//    pi, p, ki, k, xs[0], xs[1], xs[2], type, sigma_barn, reuse ? "SPLIT" : "");

} while(intersect); /* end do (intersect) (multiple scattering loop) */



#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef rho
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef flag_low_z
  #undef order
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef xs_fluo
  #undef xs_Compton
  #undef xs_Rayleigh
  #undef shape
  #undef offdata
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_xs_fluo
  #undef reuse_xs_Compton
  #undef reuse_xs_Rayleigh
  return;
} /* class_Fluorescence_trace */

#pragma acc routine
void class_Filter_trace(_class_Filter *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define refraction (_comp->_parameters.refraction)
  #define fixed_delta (_comp->_parameters.fixed_delta)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define geometry (_comp->_parameters.geometry)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define mu_col (_comp->_parameters.mu_col)
  #define Z (_comp->_parameters.Z)
  #define mu_c (_comp->_parameters.mu_c)
  #define Ar (_comp->_parameters.Ar)
  #define rho (_comp->_parameters.rho)
  #define delta_prefactor (_comp->_parameters.delta_prefactor)
  #define betafact (_comp->_parameters.betafact)
  #define table (_comp->_parameters.table)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define filter_row (_comp->_parameters.filter_row)
  SIG_MESSAGE("[_ANATOMIX_sample_trace] component ANATOMIX_sample=Filter() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Filter.comp:201]");

  double alpha, e, k, mu, mu0, delta, beta, f;
  double l0, l1, nx, ny, nz;
  int i, status = 0;
  if (shape == CYLINDER) {
    status = cylinder_intersect (&l0, &l1, x, y, z, kx, ky, kz, radius, yheight);
  } else if (shape == SPHERE) {
    status = sphere_intersect (&l0, &l1, x, y, z, kx, ky, kz, radius);
  } else if (shape == CUBE) {
    status = box_intersect (&l0, &l1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);
  } else if (shape == ANY) {
    status = off_x_intersect (&l0, &l1, NULL, NULL, x, y, z, kx, ky, kz, offdata);
  }

  if (status) {
    PROP_DL (l0);
    l1 -= l0;

    k = sqrt (kx * kx + ky * ky + kz * kz);
    e = k * K2E;
    /*Material's Number Density of Electrons [e/A^3] incl f' scattering length correction*/
    f = Table_Value (table, e, 1);
    delta = (fixed_delta ? fixed_delta : f / (k * k) * delta_prefactor);
    mu0 = Table_Value (table, e, mu_c) * rho * 1e2;
    beta = mu0 / (2 * k);

    /*change direction of ray due to refraction*/
    if (refraction) {
      switch (shape) {
      case CUBE:
        if (fabs (x - xwidth * 0.5) < FLT_EPSILON || fabs (x + xwidth * 0.5) < FLT_EPSILON) {
          nx = 1.0;
          ny = 0.0;
          nz = 0.0;
        } else if (fabs (y - yheight * 0.5) < FLT_EPSILON || fabs (y + yheight * 0.5) < FLT_EPSILON) {
          nx = 0.0;
          ny = 1.0;
          nz = 0.0;
        } else if (fabs (z - zdepth * 0.5) < FLT_EPSILON || fabs (z + zdepth * 0.5) < FLT_EPSILON) {
          nx = 0.0;
          ny = 0.0;
          nz = 1.0;
        };
        break;
      case SPHERE:
        nx = x;
        ny = y;
        nz = z;
        NORM (nx, ny, nz);
        break;
      case CYLINDER:
        if (fabs (y - yheight * 0.5) < FLT_EPSILON || fabs (y + yheight * 0.5) < FLT_EPSILON) {
          x = 0.0;
          y = 1.0;
          z = 0.0;
        } else {
          nx = x;
          nz = z;
          ny = 0.0;
          NORM (nx, ny, nz);
        }
        break;
      default:
        1;
      }
      status = filter_refract (&kx, &ky, &kz, nx, ny, nz, 0.0, delta);
      SCATTER;

      /*change of direction - we must now intersect again*/
      if (shape == CUBE) {
        status = box_intersect (&l0, &l1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);
      } else if (shape == ANY) {
        status = off_x_intersect (&l0, &l1, NULL, NULL, x, y, z, kx, ky, kz, offdata);
      }
    }

    /*change k ' we're now inside some material*/
    kx *= 1 - delta;
    ky *= 1 - delta;
    kz *= 1 - delta;

    /*propagate to next intersection with filter (assumed to be exit)*/
    p *= exp (-mu0 * l1);
    SCATTER;
    PROP_DL (l1);

    /*change direction of ray due to refraction*/
    if (refraction) {
      switch (shape) {
      case CUBE:
        if (fabs (x - xwidth * 0.5) < FLT_EPSILON || fabs (x + xwidth * 0.5) < FLT_EPSILON) {
          nx = 1.0;
          ny = 0.0;
          nz = 0.0;
        } else if (fabs (y - yheight * 0.5) < FLT_EPSILON || fabs (y + yheight * 0.5) < FLT_EPSILON) {
          nx = 0.0;
          ny = 1.0;
          nz = 0.0;
        } else if (fabs (z - zdepth * 0.5) < FLT_EPSILON || fabs (z + zdepth * 0.5) < FLT_EPSILON) {
          nx = 0.0;
          ny = 0.0;
          nz = 1.0;
        };
        break;
      case SPHERE:
        nx = x;
        ny = y;
        nz = z;
        NORM (nx, ny, nz);
        break;
      case CYLINDER:
        if (fabs (y - yheight * 0.5) < FLT_EPSILON || fabs (y + yheight * 0.5) < FLT_EPSILON) {
          x = 0.0;
          y = 1.0;
          z = 0.0;
        } else {
          nx = x;
          nz = z;
          ny = 0.0;
          NORM (nx, ny, nz);
        }
        break;
      default:
        1;
      }
      SCATTER;
      status = filter_refract (&kx, &ky, &kz, nx, ny, nz, delta, 0.0);
    }

    /*correct for optical path length through the material*/
    /*change k back*/
    kx /= 1 - delta;
    ky /= 1 - delta;
    kz /= 1 - delta;
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef refraction
  #undef fixed_delta
  #undef material_datafile
  #undef geometry
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef mu_col
  #undef Z
  #undef mu_c
  #undef Ar
  #undef rho
  #undef delta_prefactor
  #undef betafact
  #undef table
  #undef shape
  #undef offdata
  #undef filter_row
  return;
} /* class_Filter_trace */

#pragma acc routine
void class_PSD_monitor_coh_trace(_class_PSD_monitor_coh *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define ratio (_comp->_parameters.ratio)
  #define centering (_comp->_parameters.centering)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define PSD_phi_real (_comp->_parameters.PSD_phi_real)
  #define PSD_phi_imag (_comp->_parameters.PSD_phi_imag)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_NANO_psd_source_trace] component NANO_psd_source=PSD_monitor_coh() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_coh.comp:101]");

  int i, j;
  double k, x_o, y_o, z_o;
  double p2;
  cdouble dphi;
  double dphi_r, dphi_i;

  x_o = x;
  y_o = y;
  z_o = z;
  k = sqrt (kx * kx + ky * ky + kz * kz);
  int backprop = allow_backprop; /* set by caller: also count backward hits */
  double t0 = t;
  ALLOW_BACKPROP;
  PROP_Z0;
  if ((backprop || t >= t0) && x > xmin && x < xmax && y > ymin && y < ymax) {

    double dl, dlc, dnu, cx, cy;

    i = floor ((x - xmin) * nx / (xmax - xmin));
    j = floor ((y - ymin) * ny / (ymax - ymin));

    /*center coordinates of the pixel*/
    if (centering) {
      dl = sqrt ((x - x_o) * (x - x_o) + (y - y_o) * (y - y_o) + z_o * z_o);

      cx = xwidth / nx * (i + 0.5) - xwidth / 2.0;
      cy = yheight / ny * (j + 0.5) - yheight / 2.0;
      /*what would the phase be if we transported it to the center of the pixel?*/
      dlc = sqrt ((cx - x_o) * (cx - x_o) + (cy - y_o) * (cy - y_o) + z_o * z_o);
      dnu = (dl - dlc) * k * 1e10;
    } else {
      dnu = 0;
    }

    /*check if within the ratio of the pixel*/
    if (fabs (xwidth / nx * (i + 0.5) - xwidth / 2.0 - x) < xwidth / nx * ratio && fabs (yheight / ny * (j + 0.5) - yheight / 2.0 - y) < yheight / ny * ratio) {
      dphi = rmul(p,cexp (rmul(phi - dnu,cplx(0,1))));
      dphi_r = creal (dphi);
      dphi_i = cimag (dphi);
      p2 = p * p;
      #pragma acc atomic
      PSD_N[i][j] += 1;
      #pragma acc atomic
      PSD_phi_real[i][j] += dphi_r;
      #pragma acc atomic
      PSD_phi_imag[i][j] += dphi_i;
      #pragma acc atomic
      PSD_p2[i][j] += p2;
      SCATTER;
    }
  }
  if (restore_xray || !SCATTERED) {
    RESTORE_XRAY (INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef nx
  #undef ny
  #undef filename
  #undef restore_xray
  #undef xwidth
  #undef yheight
  #undef ratio
  #undef centering
  #undef nowritefile
  #undef PSD_N
  #undef PSD_p2
  #undef PSD_phi_real
  #undef PSD_phi_imag
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return;
} /* class_PSD_monitor_coh_trace */

#pragma acc routine
void class_Fluo_detector_trace(_class_Fluo_detector *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define escape_ratio (_comp->_parameters.escape_ratio)
  #define escape_energy (_comp->_parameters.escape_energy)
  #define pileup_ratio (_comp->_parameters.pileup_ratio)
  #define electronic_noise (_comp->_parameters.electronic_noise)
  #define resolution_energy (_comp->_parameters.resolution_energy)
  #define resolution (_comp->_parameters.resolution)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define E_N_pileup (_comp->_parameters.E_N_pileup)
  #define E_p_pileup (_comp->_parameters.E_p_pileup)
  #define E_p2_pileup (_comp->_parameters.E_p2_pileup)
  #define E_N_escape (_comp->_parameters.E_N_escape)
  #define E_p_escape (_comp->_parameters.E_p_escape)
  #define E_p2_escape (_comp->_parameters.E_p2_escape)
  #define shape (_comp->_parameters.shape)
  #define K (_comp->_parameters.K)
  #define p_sum (_comp->_parameters.p_sum)
  #define N_sum (_comp->_parameters.N_sum)
  SIG_MESSAGE("[_LUCIA_mon_spl_SDD_trace] component LUCIA_mon_spl_SDD=Fluo_detector() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Fluo_detector.comp:143]");

  int    intersect=0;       /* flag to continue/stop */
  double l0,  l1;           /* times for intersections */
  int    type=-1;
  int backprop = allow_backprop; /* set by caller: also count backward hits */
  double t0 = t;

  if (shape==0)       // disk
    {
      ALLOW_BACKPROP;
      PROP_Z0;
      intersect=((backprop || t >= t0) && x*x + y*y < radius*radius);
    }
  else if (shape==1)  // rectangle
    { ALLOW_BACKPROP;
      PROP_Z0;
      intersect=((backprop || t >= t0) && -xwidth/2  < x && x < xwidth/2
              && -yheight/2 < y && y < yheight/2);
    }
  else if (shape==2)  // sphere
    intersect=sphere_intersect  (&l0,&l1, x,y,z,kx,ky,kz, radius);

  if (intersect) {  /* we propagate to the detector surface */
    int i;
    double k, E, dE;

    if (shape==2) {
      if (l0 > 0 && (l0 < l1 || l1 < 0))
        PROP_DL(l0);
      else
        PROP_DL(l1);
    }

    k     = sqrt(kx*kx + ky*ky + kz*kz);
    E     = k*K2E;
    type  = 0;

    // handle detector escape peak: just shift energy down by detector K-alpha
    if (escape_ratio > 0 && escape_energy > 0 && E > escape_energy && rand01() < escape_ratio) {
        E   -= escape_energy; // escape
        type = SDD_ESCAPE;

    }
    if (pileup_ratio > 0 && N_sum > 1000 && rand01() < pileup_ratio) {
        // handle detector pile-up peak: get an other fluo line and sum it
        // require some statistics in the spectrum in order to select a line
        int i_E = XRMC_SelectInteraction(E_p, nE, rand01());
        E  += Emin+i_E*(Emax-Emin)/nE;             // pile-up
        type= SDD_PILEUP;
    }

    // we add the detector resolution (broadening)
    if (K)
      dE = sqrt(K*E+electronic_noise*electronic_noise);
    else if (resolution > 0)
      dE = resolution;
    else if (electronic_noise > 0)
      dE = electronic_noise;
    else dE=0;
    if (dE) {
      dE /= 2;  // half-width
      if (flag_lorentzian) dE  *= tan(PI/2*randpm1()); // Lorentzian distribution
      else                 dE  *= randnorm();          // Gaussian distribution
      E += dE;
    }

    i = floor((E-Emin)*nE/(Emax-Emin));
    if(i >= 0 && i < nE)
    {
        #pragma acc atomic
        E_N[i] = E_N[i] + 1;
        #pragma acc atomic
        E_p[i] = E_p[i] + p;
        #pragma acc atomic
        E_p2[i] = E_p2[i] + p*p;

        // special storage
        if (type == SDD_PILEUP) {
          #pragma acc atomic
          E_N_pileup[i] = E_N_pileup[i] + 1;
          #pragma acc atomic
          E_p_pileup[i] = E_p_pileup[i] + p;
          #pragma acc atomic
          E_p2_pileup[i] = E_p2_pileup[i] + p*p;

        } else if (type == SDD_ESCAPE) {
          #pragma acc atomic
          E_N_escape[i] = E_N_escape[i] + 1;
          #pragma acc atomic
          E_p_escape[i] = E_p_escape[i] + p;
          #pragma acc atomic
          E_p2_escape[i] = E_p2_escape[i] + p*p;
        }

        #pragma acc atomic
        N_sum = N_sum +1;
        #pragma acc atomic
        p_sum = p_sum +1;
        SCATTER;
    }

    if (restore_xray) {
        RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
    }
  } else {
    RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
  }

#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef radius
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef nE
  #undef filename
  #undef restore_xray
  #undef escape_ratio
  #undef escape_energy
  #undef pileup_ratio
  #undef electronic_noise
  #undef resolution_energy
  #undef resolution
  #undef flag_lorentzian
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef E_N_pileup
  #undef E_p_pileup
  #undef E_p2_pileup
  #undef E_N_escape
  #undef E_p_escape
  #undef E_p2_escape
  #undef shape
  #undef K
  #undef p_sum
  #undef N_sum
  return;
} /* class_Fluo_detector_trace */

#pragma acc routine
void class_Shape_trace(_class_Shape *_comp
  , _class_particle *_particle) {
  ABSORBED=SCATTERED=RESTORE=0;
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define thickness (_comp->_parameters.thickness)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define center (_comp->_parameters.center)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_storage_trace] component storage=Shape() TRACE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:88]");

  /* component Shape does nothing */
#ifndef NOABSORB_INF_NAN
  /* Check for nan or inf particle parms */ 
  if(isnan(p + t + kx + ky + kz + x + y + z + phi)) ABSORB;
  if(isinf(fabs(p) + fabs(t) + fabs(kx) + fabs(ky) + fabs(kz) + fabs(x) + fabs(y) + fabs(z) + fabs(phi))) ABSORB;
#else
  if(isnan(p)  ||  isinf(p)) printf("NAN or INF found in p,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(t)  ||  isinf(t)) printf("NAN or INF found in t,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(phi)  ||  isinf(phi)) printf("NAN or INF found in phi, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kx) || isinf(kx)) printf("NAN or INF found in kx, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(ky) || isinf(ky)) printf("NAN or INF found in ky, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(kz) || isinf(kz)) printf("NAN or INF found in kz, %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(x)  ||  isinf(x)) printf("NAN or INF found in x,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(y)  ||  isinf(y)) printf("NAN or INF found in y,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
  if(isnan(z)  ||  isinf(z)) printf("NAN or INF found in z,  %s (particle %lld)\n",_comp->_name,_particle->_uid);
#endif
  #undef geometry
  #undef radius
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef thickness
  #undef nx
  #undef ny
  #undef nz
  #undef center
  #undef offdata
  return;
} /* class_Shape_trace */

#define PUMA_scat_before_VFM (_particle->PUMA_scat_before_VFM)
#define flag_scatt (_particle->flag_scatt)
#define flag_hfm (_particle->flag_hfm)
#define flag_vfm (_particle->flag_vfm)
#define PX2a_flag_hfm (_particle->PX2a_flag_hfm)
#define PX2a_flag_vfm (_particle->PX2a_flag_vfm)
#define SWING_flag_hfm (_particle->SWING_flag_hfm)
#define SWING_flag_vfm (_particle->SWING_flag_vfm)
#define SIXS_flag_scatt (_particle->SIXS_flag_scatt)
#define beamline (_particle->beamline)
/* *****************************************************************************
* instrument 'SOLEIL' TRACE
***************************************************************************** */

#ifndef FUNNEL
#pragma acc routine
int raytrace(_class_particle* _particle) { /* single event propagation, called by mccode_main for SOLEIL:TRACE */

  /* init variables and counters for TRACE */
  #undef ABSORB0
  #undef ABSORB
  #define ABSORB0 do { DEBUG_ABSORB(); MAGNET_OFF; ABSORBED++;} while(0)
  #define ABSORB ABSORB0
  DEBUG_ENTER();
  DEBUG_STATE();
  _particle->flag_nocoordschange=0; /* Init */
  _class_particle _particle_save=*_particle;
  /* the main iteration loop for one incoming event */
  while (!ABSORBED) { /* iterate event until absorbed */
    /* send particle event to component instance, one after the other */
    /* begin component origin=Arm() [1] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_origin_var._rotation_is_identity) {
        if(!_origin_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _origin_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_origin_var._position_relative, _origin_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 1) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_origin_var._name);
      DEBUG_STATE();
      class_Arm_trace(&_origin_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component origin [1] */
    /* begin component jumper=Arm() [2] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_jumper_var._rotation_is_identity) {
        if(!_jumper_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _jumper_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_jumper_var._position_relative, _jumper_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 2) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_jumper_var._name);
      DEBUG_STATE();
      if (beamline == 0) {/* conditional JUMP to MARS */
        _particle->_index=7;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 1) {/* conditional JUMP to PSICHE */
        _particle->_index=40;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 2) {/* conditional JUMP to DISCO */
        _particle->_index=61;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 3) {/* conditional JUMP to PUMA */
        _particle->_index=140;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 4) {/* conditional JUMP to CRISTAL */
        _particle->_index=178;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 5) {/* conditional JUMP to GALAXIES */
        _particle->_index=204;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 6) {/* conditional JUMP to SAMBA */
        _particle->_index=253;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 7) {/* conditional JUMP to PX1 */
        _particle->_index=278;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 8) {/* conditional JUMP to PX2a */
        _particle->_index=301;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 9) {/* conditional JUMP to SWING */
        _particle->_index=327;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 10) {/* conditional JUMP to ROCK */
        _particle->_index=356;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 11) {/* conditional JUMP to ANATOMIX */
        _particle->_index=388;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 12) {/* conditional JUMP to NANOSCOPIUM */
        _particle->_index=405;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 13) {/* conditional JUMP to SIXS */
        _particle->_index=475;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 14) {/* conditional JUMP to DIFFABS */
        _particle->_index=444;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 15) {/* conditional JUMP to CASSIOPEE */
        _particle->_index=505;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 16) {/* conditional JUMP to SIRIUS */
        _particle->_index=525;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      if (beamline == 17) {/* conditional JUMP to LUCIA */
        _particle->_index=549;
        _particle->flag_nocoordschange=1; /* pass corrdinate transformations when jumping */
      }
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component jumper [2] */
    /* begin component beamdump=Beamstop() [3] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_var._rotation_is_identity) {
        if(!_beamdump_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_var._position_relative, _beamdump_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 3) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump [3] */
    /* begin component ODE_pos=Text() [4] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ODE_pos_var._rotation_is_identity) {
        if(!_ODE_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ODE_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ODE_pos_var._position_relative, _ODE_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 4) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ODE_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_ODE_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ODE_pos [4] */
    /* begin component SMIS_pos=Text() [5] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SMIS_pos_var._rotation_is_identity) {
        if(!_SMIS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SMIS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SMIS_pos_var._position_relative, _SMIS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 5) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SMIS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_SMIS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SMIS_pos [5] */
    /* begin component AILES_pos=Text() [6] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_AILES_pos_var._rotation_is_identity) {
        if(!_AILES_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _AILES_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_AILES_pos_var._position_relative, _AILES_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 6) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_AILES_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_AILES_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component AILES_pos [6] */
    /* begin component MARS_pos=Text() [7] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_pos_var._rotation_is_identity) {
        if(!_MARS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_pos_var._position_relative, _MARS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 7) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_MARS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_pos [7] */
    /* begin component MARS=Arm() [8] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_var._rotation_is_identity) {
        if(!_MARS_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_var._position_relative, _MARS_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 8) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS [8] */
    /* begin component MARS_Source=Bending_magnet() [9] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_Source_var._rotation_is_identity) {
        if(!_MARS_Source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_Source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_Source_var._position_relative, _MARS_Source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 9) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_Source_var._name);
      DEBUG_STATE();
      class_Bending_magnet_trace(&_MARS_Source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_Source [9] */
    /* begin component MARS_displaySourceLength=Monitor_nD() [10] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_displaySourceLength_var._rotation_is_identity) {
        if(!_MARS_displaySourceLength_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_displaySourceLength_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_displaySourceLength_var._position_relative, _MARS_displaySourceLength_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 10) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_displaySourceLength_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_MARS_displaySourceLength_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_displaySourceLength [10] */
    /* begin component MARS_displaySource=PSD_monitor() [11] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_displaySource_var._rotation_is_identity) {
        if(!_MARS_displaySource_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_displaySource_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_displaySource_var._position_relative, _MARS_displaySource_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 11) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_displaySource_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_MARS_displaySource_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_displaySource [11] */
    /* begin component MARS_slit1=Slit() [12] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_slit1_var._rotation_is_identity) {
        if(!_MARS_slit1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_slit1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_slit1_var._position_relative, _MARS_slit1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 12) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_slit1_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_MARS_slit1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_slit1 [12] */
    /* begin component MARS_slit2=Slit() [13] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_slit2_var._rotation_is_identity) {
        if(!_MARS_slit2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_slit2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_slit2_var._position_relative, _MARS_slit2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 13) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_slit2_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_MARS_slit2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_slit2 [13] */
    /* begin component MARS_M1_arm_translation=Arm() [14] */
    if (!ABSORBED && _particle->_index == 14) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M1_arm_translation [14] */
    /* begin component MARS_M1_arm_rotation_1=Arm() [15] */
    if (!ABSORBED && _particle->_index == 15) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M1_arm_rotation_1 [15] */
    /* begin component MARS_mirror_M1=Mirror_curved() [16] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_mirror_M1_var._rotation_is_identity) {
        if(!_MARS_mirror_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_mirror_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_mirror_M1_var._position_relative, _MARS_mirror_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 16) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_mirror_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_MARS_mirror_M1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_mirror_M1 [16] */
    /* begin component MARS_M1_arm_rotation_2=Arm() [17] */
    if (!ABSORBED && _particle->_index == 17) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M1_arm_rotation_2 [17] */
    /* begin component MARS_M1_arm_rotation_2_undo=Arm() [18] */
    if (!ABSORBED && _particle->_index == 18) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M1_arm_rotation_2_undo [18] */
    /* begin component MARS_beam_arm_before_crystal=Arm() [19] */
    if (!ABSORBED && _particle->_index == 19) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_beam_arm_before_crystal [19] */
    /* begin component MARS_dcm_xtal0=Bragg_crystal() [20] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_dcm_xtal0_var._rotation_is_identity) {
        if(!_MARS_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_dcm_xtal0_var._position_relative, _MARS_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 20) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_dcm_xtal0_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_MARS_dcm_xtal0_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_dcm_xtal0 [20] */
    /* begin component MARS_dcm0=Arm() [21] */
    if (!ABSORBED && _particle->_index == 21) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_dcm0 [21] */
    /* begin component MARS_dcm_xtal1=Bragg_crystal() [22] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_dcm_xtal1_var._rotation_is_identity) {
        if(!_MARS_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_dcm_xtal1_var._position_relative, _MARS_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 22) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_dcm_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_MARS_dcm_xtal1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_dcm_xtal1 [22] */
    /* begin component MARS_dcm1=Arm() [23] */
    if (!ABSORBED && _particle->_index == 23) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_dcm1 [23] */
    /* begin component MARS_emon_dcm0=E_monitor() [24] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_emon_dcm0_var._rotation_is_identity) {
        if(!_MARS_emon_dcm0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_emon_dcm0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_emon_dcm0_var._position_relative, _MARS_emon_dcm0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 24) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_emon_dcm0_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_MARS_emon_dcm0_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_emon_dcm0 [24] */
    /* begin component MARS_displayMono=PSD_monitor() [25] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_displayMono_var._rotation_is_identity) {
        if(!_MARS_displayMono_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_displayMono_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_displayMono_var._position_relative, _MARS_displayMono_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 25) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_displayMono_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_MARS_displayMono_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_displayMono [25] */
    /* begin component MARS_displayMonoLength=E_monitor() [26] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_displayMonoLength_var._rotation_is_identity) {
        if(!_MARS_displayMonoLength_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_displayMonoLength_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_displayMonoLength_var._position_relative, _MARS_displayMonoLength_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 26) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_displayMonoLength_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_MARS_displayMonoLength_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_displayMonoLength [26] */
    /* begin component MARS_M2_arm_translation=Arm() [27] */
    if (!ABSORBED && _particle->_index == 27) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M2_arm_translation [27] */
    /* begin component MARS_M2_arm_rotation_1=Arm() [28] */
    if (!ABSORBED && _particle->_index == 28) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M2_arm_rotation_1 [28] */
    /* begin component MARS_mirror_M2=Mirror_curved() [29] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_mirror_M2_var._rotation_is_identity) {
        if(!_MARS_mirror_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_mirror_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_mirror_M2_var._position_relative, _MARS_mirror_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 29) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_mirror_M2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_MARS_mirror_M2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_mirror_M2 [29] */
    /* begin component MARS_M2_arm_rotation_2=Arm() [30] */
    if (!ABSORBED && _particle->_index == 30) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M2_arm_rotation_2 [30] */
    /* begin component MARS_M2_arm_rotation_2_undo=Arm() [31] */
    if (!ABSORBED && _particle->_index == 31) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component MARS_M2_arm_rotation_2_undo [31] */
    /* begin component MARS_slitSecon1=Slit() [32] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_slitSecon1_var._rotation_is_identity) {
        if(!_MARS_slitSecon1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_slitSecon1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_slitSecon1_var._position_relative, _MARS_slitSecon1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 32) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_slitSecon1_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_MARS_slitSecon1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_slitSecon1 [32] */
    /* begin component MARS_slitSecon2=Slit() [33] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_slitSecon2_var._rotation_is_identity) {
        if(!_MARS_slitSecon2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_slitSecon2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_slitSecon2_var._position_relative, _MARS_slitSecon2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 33) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_slitSecon2_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_MARS_slitSecon2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_slitSecon2 [33] */
    /* begin component MARS_emon_dcm1=E_monitor() [34] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_emon_dcm1_var._rotation_is_identity) {
        if(!_MARS_emon_dcm1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_emon_dcm1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_emon_dcm1_var._position_relative, _MARS_emon_dcm1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 34) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_emon_dcm1_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_MARS_emon_dcm1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_emon_dcm1 [34] */
    /* begin component MARS_displaySlit2=PSD_monitor() [35] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_displaySlit2_var._rotation_is_identity) {
        if(!_MARS_displaySlit2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_displaySlit2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_displaySlit2_var._position_relative, _MARS_displaySlit2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 35) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_displaySlit2_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_MARS_displaySlit2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_displaySlit2 [35] */
#ifndef NOSPLIT
    /* start SPLIT at MARS_Sample */
    if (!ABSORBED) {
    _class_particle Split_MARS_Sample_particle=*_particle;
    int Split_MARS_Sample_counter;
    int SplitS_MARS_Sample = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_MARS_Sample_counter = 0; Split_MARS_Sample_counter< SplitS_MARS_Sample; Split_MARS_Sample_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_MARS_Sample_randstate_idx = 0; Split_MARS_Sample_randstate_idx < RANDSTATE_LEN; Split_MARS_Sample_randstate_idx++) {
        randbackup[Split_MARS_Sample_randstate_idx] = _particle->randstate[Split_MARS_Sample_randstate_idx];
      }
      *_particle=Split_MARS_Sample_particle;
      for (int Split_MARS_Sample_randstate_idx = 0; Split_MARS_Sample_randstate_idx < RANDSTATE_LEN; Split_MARS_Sample_randstate_idx++) {
        _particle->randstate[Split_MARS_Sample_randstate_idx] = randbackup[Split_MARS_Sample_randstate_idx];
      }
      p /= SplitS_MARS_Sample > 0 ? SplitS_MARS_Sample : 1;
#endif
    /* begin component MARS_Sample=FluoPowder() [36] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_Sample_var._rotation_is_identity) {
        if(!_MARS_Sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_Sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_Sample_var._position_relative, _MARS_Sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 36) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_Sample_var._name);
      DEBUG_STATE();
      class_FluoPowder_trace(&_MARS_Sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_Sample [36] */
    /* begin component MARS_detector_diffraction=Monitor_nD() [37] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_detector_diffraction_var._rotation_is_identity) {
        if(!_MARS_detector_diffraction_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_detector_diffraction_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_detector_diffraction_var._position_relative, _MARS_detector_diffraction_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 37) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_detector_diffraction_var._name);
      DEBUG_STATE();
      if ((( 0.75 * _instrument_var._parameters.MARS_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_MARS_detector_diffraction_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_detector_diffraction [37] */
    /* begin component MARS_detector_fluo=Monitor_nD() [38] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_MARS_detector_fluo_var._rotation_is_identity) {
        if(!_MARS_detector_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _MARS_detector_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_MARS_detector_fluo_var._position_relative, _MARS_detector_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 38) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_MARS_detector_fluo_var._name);
      DEBUG_STATE();
      if ((( K2E * sqrt ( kx * kx + ky * ky + kz * kz ) < 0.95 * _instrument_var._parameters.MARS_E0 ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_MARS_detector_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component MARS_detector_fluo [38] */
    /* begin component beamdump_40=Beamstop() [39] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_40_var._rotation_is_identity) {
        if(!_beamdump_40_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_40_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_40_var._position_relative, _beamdump_40_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 39) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_40_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_40_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_40 [39] */
    /* begin component PSICHE_pos=Text() [40] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_pos_var._rotation_is_identity) {
        if(!_PSICHE_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_pos_var._position_relative, _PSICHE_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 40) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_PSICHE_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_pos [40] */
    /* begin component PSICHE=Arm() [41] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_var._rotation_is_identity) {
        if(!_PSICHE_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_var._position_relative, _PSICHE_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 41) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE [41] */
    /* begin component PSICHE_source=Wiggler() [42] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_source_var._rotation_is_identity) {
        if(!_PSICHE_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_source_var._position_relative, _PSICHE_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 42) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_source_var._name);
      DEBUG_STATE();
      class_Wiggler_trace(&_PSICHE_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_source [42] */
    /* begin component PSICHE_mon_src_e=Monitor_nD() [43] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_src_e_var._rotation_is_identity) {
        if(!_PSICHE_mon_src_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_src_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_src_e_var._position_relative, _PSICHE_mon_src_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 43) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_src_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_src_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_src_e [43] */
    /* begin component PSICHE_mon_src_xy=Monitor_nD() [44] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_src_xy_var._rotation_is_identity) {
        if(!_PSICHE_mon_src_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_src_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_src_xy_var._position_relative, _PSICHE_mon_src_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 44) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_src_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_src_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_src_xy [44] */
    /* begin component PSICHE_DCM_location=Arm() [45] */
    if (!ABSORBED && _particle->_index == 45) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PSICHE_DCM_location [45] */
    /* begin component PSICHE_dcm_xtal0=Bragg_crystal() [46] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_dcm_xtal0_var._rotation_is_identity) {
        if(!_PSICHE_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_dcm_xtal0_var._position_relative, _PSICHE_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 46) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_dcm_xtal0_var._name);
      DEBUG_STATE();
      if ((( _instrument_var._parameters.PSICHE_DCM_present ))) // conditional WHEN execution
      class_Bragg_crystal_trace(&_PSICHE_dcm_xtal0_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_dcm_xtal0 [46] */
    /* begin component PSICHE_dcm0=Arm() [47] */
    if (!ABSORBED && _particle->_index == 47) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PSICHE_dcm0 [47] */
    /* begin component PSICHE_dcm_xtal1=Bragg_crystal() [48] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_dcm_xtal1_var._rotation_is_identity) {
        if(!_PSICHE_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_dcm_xtal1_var._position_relative, _PSICHE_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 48) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_dcm_xtal1_var._name);
      DEBUG_STATE();
      if ((( _instrument_var._parameters.PSICHE_DCM_present ))) // conditional WHEN execution
      class_Bragg_crystal_trace(&_PSICHE_dcm_xtal1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_dcm_xtal1 [48] */
    /* begin component PSICHE_dcm1=Arm() [49] */
    if (!ABSORBED && _particle->_index == 49) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PSICHE_dcm1 [49] */
    /* begin component PSICHE_mon_dcm_e=Monitor_nD() [50] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_dcm_e_var._rotation_is_identity) {
        if(!_PSICHE_mon_dcm_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_dcm_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_dcm_e_var._position_relative, _PSICHE_mon_dcm_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 50) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_dcm_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_dcm_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_dcm_e [50] */
    /* begin component PSICHE_mon_dcm_xy=Monitor_nD() [51] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_dcm_xy_var._rotation_is_identity) {
        if(!_PSICHE_mon_dcm_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_dcm_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_dcm_xy_var._position_relative, _PSICHE_mon_dcm_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 51) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_dcm_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_dcm_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_dcm_xy [51] */
    /* begin component PSICHE_slit=Slit() [52] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_slit_var._rotation_is_identity) {
        if(!_PSICHE_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_slit_var._position_relative, _PSICHE_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 52) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PSICHE_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_slit [52] */
    /* begin component PSICHE_sample_stage=Arm() [53] */
    if (!ABSORBED && _particle->_index == 53) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PSICHE_sample_stage [53] */
    /* begin component PSICHE_sample=FluoPowder() [54] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_sample_var._rotation_is_identity) {
        if(!_PSICHE_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_sample_var._position_relative, _PSICHE_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 54) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_sample_var._name);
      DEBUG_STATE();
      class_FluoPowder_trace(&_PSICHE_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_sample [54] */
    /* begin component PSICHE_fluo_holder=Arm() [55] */
    if (!ABSORBED && _particle->_index == 55) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PSICHE_fluo_holder [55] */
    /* begin component PSICHE_mon_spl_fluo=Monitor_nD() [56] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_spl_fluo_var._rotation_is_identity) {
        if(!_PSICHE_mon_spl_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_spl_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_spl_fluo_var._position_relative, _PSICHE_mon_spl_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 56) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_spl_fluo_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_spl_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_spl_fluo [56] */
    /* begin component PSICHE_mon_spl_e=Monitor_nD() [57] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_spl_e_var._rotation_is_identity) {
        if(!_PSICHE_mon_spl_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_spl_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_spl_e_var._position_relative, _PSICHE_mon_spl_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 57) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_spl_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_spl_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_spl_e [57] */
    /* begin component PSICHE_mon_spl_xy=Monitor_nD() [58] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PSICHE_mon_spl_xy_var._rotation_is_identity) {
        if(!_PSICHE_mon_spl_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_spl_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PSICHE_mon_spl_xy_var._position_relative, _PSICHE_mon_spl_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 58) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PSICHE_mon_spl_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PSICHE_mon_spl_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PSICHE_mon_spl_xy [58] */
    /* begin component beamdump_61=Beamstop() [59] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_61_var._rotation_is_identity) {
        if(!_beamdump_61_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_61_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_61_var._position_relative, _beamdump_61_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 59) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_61_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_61_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_61 [59] */
    /* begin component PLEIADES_pos=Text() [60] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PLEIADES_pos_var._rotation_is_identity) {
        if(!_PLEIADES_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PLEIADES_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PLEIADES_pos_var._position_relative, _PLEIADES_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 60) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PLEIADES_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_PLEIADES_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PLEIADES_pos [60] */
    /* begin component DISCO_pos=Text() [61] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_pos_var._rotation_is_identity) {
        if(!_DISCO_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_pos_var._position_relative, _DISCO_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 61) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_DISCO_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_pos [61] */
    /* begin component DISCO=Arm() [62] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_var._rotation_is_identity) {
        if(!_DISCO_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_var._position_relative, _DISCO_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 62) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO [62] */
    /* begin component DISCO_Source=Bending_magnet() [63] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_Source_var._rotation_is_identity) {
        if(!_DISCO_Source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_Source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_Source_var._position_relative, _DISCO_Source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 63) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_Source_var._name);
      DEBUG_STATE();
      class_Bending_magnet_trace(&_DISCO_Source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_Source [63] */
    /* begin component DISCO_ColdFinger=Mask() [64] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_ColdFinger_var._rotation_is_identity) {
        if(!_DISCO_ColdFinger_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_ColdFinger_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_ColdFinger_var._position_relative, _DISCO_ColdFinger_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 64) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_ColdFinger_var._name);
      DEBUG_STATE();
      class_Mask_trace(&_DISCO_ColdFinger_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_ColdFinger [64] */
    /* begin component DISCO_M1_location=Arm() [65] */
    if (!ABSORBED && _particle->_index == 65) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_location [65] */
    /* begin component DISCO_M1_rotated=Arm() [66] */
    if (!ABSORBED && _particle->_index == 66) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_rotated [66] */
    /* begin component DISCO_M1_x=Arm() [67] */
    if (!ABSORBED && _particle->_index == 67) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_x [67] */
    /* begin component DISCO_M1=Mirror_curved() [68] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M1_var._rotation_is_identity) {
        if(!_DISCO_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M1_var._position_relative, _DISCO_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 68) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_DISCO_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M1 [68] */
    /* begin component DISCO_M1_takeoff=Arm() [69] */
    if (!ABSORBED && _particle->_index == 69) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_takeoff [69] */
    /* begin component DISCO_M1_x_takeoff=Arm() [70] */
    if (!ABSORBED && _particle->_index == 70) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_x_takeoff [70] */
    /* begin component DISCO_M2_location=Arm() [71] */
    if (!ABSORBED && _particle->_index == 71) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M2_location [71] */
    /* begin component DISCO_M2_rotated_x=Arm() [72] */
    if (!ABSORBED && _particle->_index == 72) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M2_rotated_x [72] */
    /* begin component DISCO_M2_rotated=Arm() [73] */
    if (!ABSORBED && _particle->_index == 73) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M2_rotated [73] */
    /* begin component DISCO_M2_other_side=Arm() [74] */
    if (!ABSORBED && _particle->_index == 74) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M2_other_side [74] */
    /* begin component DISCO_M2=Mirror_toroid_pothole() [75] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M2_var._rotation_is_identity) {
        if(!_DISCO_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M2_var._position_relative, _DISCO_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 75) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M2_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_pothole_trace(&_DISCO_M2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M2 [75] */
    /* begin component DISCO_M2_other_side_back=Arm() [76] */
    if (!ABSORBED && _particle->_index == 76) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M2_other_side_back [76] */
    /* begin component DISCO_M2_takeoff=Arm() [77] */
    if (!ABSORBED && _particle->_index == 77) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M2_takeoff [77] */
    /* begin component DISCO_HFP_location=Arm() [78] */
    if (!ABSORBED && _particle->_index == 78) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_HFP_location [78] */
    /* begin component DISCO_HFP=PSD_monitor() [79] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_HFP_var._rotation_is_identity) {
        if(!_DISCO_HFP_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_HFP_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_HFP_var._position_relative, _DISCO_HFP_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 79) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_HFP_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_DISCO_HFP_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_HFP [79] */
    /* begin component DISCO_M3_arm=Arm() [80] */
    if (!ABSORBED && _particle->_index == 80) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M3_arm [80] */
    /* begin component DISCO_M3=Mirror_curved() [81] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M3_var._rotation_is_identity) {
        if(!_DISCO_M3_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M3_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M3_var._position_relative, _DISCO_M3_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 81) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M3_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_DISCO_M3_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M3 [81] */
    /* begin component DISCO_M3_takeoff=Arm() [82] */
    if (!ABSORBED && _particle->_index == 82) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M3_takeoff [82] */
    /* begin component DISCO_M3_yz=Arm() [83] */
    if (!ABSORBED && _particle->_index == 83) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M3_yz [83] */
    /* begin component DISCO_M4_yz=Arm() [84] */
    if (!ABSORBED && _particle->_index == 84) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M4_yz [84] */
    /* begin component DISCO_M4=Mirror() [85] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M4_var._rotation_is_identity) {
        if(!_DISCO_M4_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M4_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M4_var._position_relative, _DISCO_M4_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 85) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M4_var._name);
      DEBUG_STATE();
      class_Mirror_trace(&_DISCO_M4_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M4 [85] */
    /* begin component DISCO_M4_takeoff=Arm() [86] */
    if (!ABSORBED && _particle->_index == 86) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M4_takeoff [86] */
    /* begin component DISCO_M4_arm_back=Arm() [87] */
    if (!ABSORBED && _particle->_index == 87) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M4_arm_back [87] */
    /* begin component DISCO_VFP_location=Arm() [88] */
    if (!ABSORBED && _particle->_index == 88) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_VFP_location [88] */
    /* begin component DISCO_VFP=PSD_monitor() [89] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_VFP_var._rotation_is_identity) {
        if(!_DISCO_VFP_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_VFP_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_VFP_var._position_relative, _DISCO_VFP_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 89) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_VFP_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_DISCO_VFP_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_VFP [89] */
    /* begin component DISCO_M51_position=Arm() [90] */
    if (!ABSORBED && _particle->_index == 90) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M51_position [90] */
    /* begin component DISCO_M51_rotation=Arm() [91] */
    if (!ABSORBED && _particle->_index == 91) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M51_rotation [91] */
    /* begin component DISCO_M51=Mirror_elliptic() [92] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M51_var._rotation_is_identity) {
        if(!_DISCO_M51_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M51_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M51_var._position_relative, _DISCO_M51_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 92) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M51_var._name);
      DEBUG_STATE();
      class_Mirror_elliptic_trace(&_DISCO_M51_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M51 [92] */
    /* begin component DISCO_arm=Arm() [93] */
    if (!ABSORBED && _particle->_index == 93) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_arm [93] */
    /* begin component DISCO_M51_arm_back=Arm() [94] */
    if (!ABSORBED && _particle->_index == 94) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M51_arm_back [94] */
    /* begin component DISCO_M52_position=Arm() [95] */
    if (!ABSORBED && _particle->_index == 95) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M52_position [95] */
    /* begin component DISCO_M52_x=Arm() [96] */
    if (!ABSORBED && _particle->_index == 96) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M52_x [96] */
    /* begin component DISCO_M52=Mirror_curved() [97] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M52_var._rotation_is_identity) {
        if(!_DISCO_M52_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M52_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M52_var._position_relative, _DISCO_M52_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 97) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M52_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_DISCO_M52_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M52 [97] */
    /* begin component DISCO_M52_takeoff=Arm() [98] */
    if (!ABSORBED && _particle->_index == 98) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M52_takeoff [98] */
    /* begin component DISCO_M52_x_takeoff=Arm() [99] */
    if (!ABSORBED && _particle->_index == 99) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M52_x_takeoff [99] */
    /* begin component DISCO_second_HFP_location=Arm() [100] */
    if (!ABSORBED && _particle->_index == 100) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_second_HFP_location [100] */
    /* begin component DISCO_second_HFP=PSD_monitor() [101] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_second_HFP_var._rotation_is_identity) {
        if(!_DISCO_second_HFP_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_second_HFP_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_second_HFP_var._position_relative, _DISCO_second_HFP_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 101) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_second_HFP_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_DISCO_second_HFP_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_second_HFP [101] */
    /* begin component DISCO_M53_location=Arm() [102] */
    if (!ABSORBED && _particle->_index == 102) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M53_location [102] */
    /* begin component DISCO_M53_rotated=Arm() [103] */
    if (!ABSORBED && _particle->_index == 103) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M53_rotated [103] */
    /* begin component DISCO_M53=Mirror_toroid_pothole() [104] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M53_var._rotation_is_identity) {
        if(!_DISCO_M53_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M53_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M53_var._position_relative, _DISCO_M53_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 104) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M53_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_pothole_trace(&_DISCO_M53_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M53 [104] */
    /* begin component DISCO_M53_takeoff=Arm() [105] */
    if (!ABSORBED && _particle->_index == 105) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M53_takeoff [105] */
    /* begin component DISCO_M54_location=Arm() [106] */
    if (!ABSORBED && _particle->_index == 106) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M54_location [106] */
    /* begin component DISCO_M54_rotated=Arm() [107] */
    if (!ABSORBED && _particle->_index == 107) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M54_rotated [107] */
    /* begin component DISCO_M54=Mirror_toroid_pothole() [108] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_M54_var._rotation_is_identity) {
        if(!_DISCO_M54_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M54_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_M54_var._position_relative, _DISCO_M54_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 108) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_M54_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_pothole_trace(&_DISCO_M54_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_M54 [108] */
    /* begin component DISCO_M54_takeoff=Arm() [109] */
    if (!ABSORBED && _particle->_index == 109) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M54_takeoff [109] */
    /* begin component DISCO_Mtoroids_arm_back=Arm() [110] */
    if (!ABSORBED && _particle->_index == 110) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Mtoroids_arm_back [110] */
    /* begin component DISCO_M1_position=Arm() [111] */
    if (!ABSORBED && _particle->_index == 111) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_position [111] */
    /* begin component DISCO_M1_rotation=Arm() [112] */
    if (!ABSORBED && _particle->_index == 112) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_rotation [112] */
    /* begin component DISCO_mirror_m1=Mirror_elliptic() [113] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_mirror_m1_var._rotation_is_identity) {
        if(!_DISCO_mirror_m1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_mirror_m1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_mirror_m1_var._position_relative, _DISCO_mirror_m1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 113) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_mirror_m1_var._name);
      DEBUG_STATE();
      class_Mirror_elliptic_trace(&_DISCO_mirror_m1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_mirror_m1 [113] */
    /* begin component DISCO_armm=Arm() [114] */
    if (!ABSORBED && _particle->_index == 114) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_armm [114] */
    /* begin component DISCO_M1_arm_back=Arm() [115] */
    if (!ABSORBED && _particle->_index == 115) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M1_arm_back [115] */
    /* begin component DISCO_Grating_position=Arm() [116] */
    if (!ABSORBED && _particle->_index == 116) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_position [116] */
    /* begin component DISCO_Grating_rotation=Arm() [117] */
    if (!ABSORBED && _particle->_index == 117) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_rotation [117] */
    /* begin component DISCO_Grating_rotation_lines_grating=Arm() [118] */
    if (!ABSORBED && _particle->_index == 118) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_rotation_lines_grating [118] */
    /* begin component DISCO_Grating_rotation_nine_degrees=Arm() [119] */
    if (!ABSORBED && _particle->_index == 119) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_rotation_nine_degrees [119] */
#ifndef NOSPLIT
    /* start SPLIT at DISCO_reflective_grating */
    if (!ABSORBED) {
    _class_particle Split_DISCO_reflective_grating_particle=*_particle;
    int Split_DISCO_reflective_grating_counter;
    int SplitS_DISCO_reflective_grating = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_DISCO_reflective_grating_counter = 0; Split_DISCO_reflective_grating_counter< SplitS_DISCO_reflective_grating; Split_DISCO_reflective_grating_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_DISCO_reflective_grating_randstate_idx = 0; Split_DISCO_reflective_grating_randstate_idx < RANDSTATE_LEN; Split_DISCO_reflective_grating_randstate_idx++) {
        randbackup[Split_DISCO_reflective_grating_randstate_idx] = _particle->randstate[Split_DISCO_reflective_grating_randstate_idx];
      }
      *_particle=Split_DISCO_reflective_grating_particle;
      for (int Split_DISCO_reflective_grating_randstate_idx = 0; Split_DISCO_reflective_grating_randstate_idx < RANDSTATE_LEN; Split_DISCO_reflective_grating_randstate_idx++) {
        _particle->randstate[Split_DISCO_reflective_grating_randstate_idx] = randbackup[Split_DISCO_reflective_grating_randstate_idx];
      }
      p /= SplitS_DISCO_reflective_grating > 0 ? SplitS_DISCO_reflective_grating : 1;
#endif
    /* begin component DISCO_reflective_grating=Grating_reflect() [120] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_reflective_grating_var._rotation_is_identity) {
        if(!_DISCO_reflective_grating_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_reflective_grating_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_reflective_grating_var._position_relative, _DISCO_reflective_grating_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 120) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_reflective_grating_var._name);
      DEBUG_STATE();
      class_Grating_reflect_trace(&_DISCO_reflective_grating_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_reflective_grating [120] */
    /* begin component DISCO_Grating_rotation_lines_grating_back=Arm() [121] */
    if (!ABSORBED && _particle->_index == 121) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_rotation_lines_grating_back [121] */
    /* begin component DISCO_Grating_arm_back=Arm() [122] */
    if (!ABSORBED && _particle->_index == 122) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_arm_back [122] */
    /* begin component DISCO_Grating_arm_back_2=Arm() [123] */
    if (!ABSORBED && _particle->_index == 123) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_arm_back_2 [123] */
    /* begin component DISCO_Grating_arm_back_3=Arm() [124] */
    if (!ABSORBED && _particle->_index == 124) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_Grating_arm_back_3 [124] */
    /* begin component DISCO_M22_location=Arm() [125] */
    if (!ABSORBED && _particle->_index == 125) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M22_location [125] */
    /* begin component DISCO_M22_rotated=Arm() [126] */
    if (!ABSORBED && _particle->_index == 126) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M22_rotated [126] */
    /* begin component DISCO_mirror_m2=Mirror_elliptic() [127] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_mirror_m2_var._rotation_is_identity) {
        if(!_DISCO_mirror_m2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_mirror_m2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_mirror_m2_var._position_relative, _DISCO_mirror_m2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 127) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_mirror_m2_var._name);
      DEBUG_STATE();
      class_Mirror_elliptic_trace(&_DISCO_mirror_m2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_mirror_m2 [127] */
    /* begin component DISCO_arm2=Arm() [128] */
    if (!ABSORBED && _particle->_index == 128) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_arm2 [128] */
    /* begin component DISCO_M44_arm_back=Arm() [129] */
    if (!ABSORBED && _particle->_index == 129) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_M44_arm_back [129] */
    /* begin component DISCO_arm3=Arm() [130] */
    if (!ABSORBED && _particle->_index == 130) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DISCO_arm3 [130] */
    /* begin component DISCO_psd_before_slit=PSD_monitor() [131] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_psd_before_slit_var._rotation_is_identity) {
        if(!_DISCO_psd_before_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_psd_before_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_psd_before_slit_var._position_relative, _DISCO_psd_before_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 131) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_psd_before_slit_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_DISCO_psd_before_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_psd_before_slit [131] */
    /* begin component DISCO_slit=Slit() [132] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_slit_var._rotation_is_identity) {
        if(!_DISCO_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_slit_var._position_relative, _DISCO_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 132) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_DISCO_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_slit [132] */
    /* begin component DISCO_psd_monitor=PSD_monitor() [133] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_psd_monitor_var._rotation_is_identity) {
        if(!_DISCO_psd_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_psd_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_psd_monitor_var._position_relative, _DISCO_psd_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 133) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_psd_monitor_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_DISCO_psd_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_psd_monitor [133] */
    /* begin component DISCO_psd_giant_after_grating=PSD_monitor() [134] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_psd_giant_after_grating_var._rotation_is_identity) {
        if(!_DISCO_psd_giant_after_grating_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_psd_giant_after_grating_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_psd_giant_after_grating_var._position_relative, _DISCO_psd_giant_after_grating_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 134) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_psd_giant_after_grating_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_DISCO_psd_giant_after_grating_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_psd_giant_after_grating [134] */
    /* begin component DISCO_e_monitor=Monitor_nD() [135] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_e_monitor_var._rotation_is_identity) {
        if(!_DISCO_e_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_e_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_e_monitor_var._position_relative, _DISCO_e_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 135) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_e_monitor_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DISCO_e_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_e_monitor [135] */
    /* begin component DISCO_w_monitor=Monitor_nD() [136] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DISCO_w_monitor_var._rotation_is_identity) {
        if(!_DISCO_w_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DISCO_w_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DISCO_w_monitor_var._position_relative, _DISCO_w_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 136) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DISCO_w_monitor_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DISCO_w_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DISCO_w_monitor [136] */
    /* begin component beamdump_140=Beamstop() [137] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_140_var._rotation_is_identity) {
        if(!_beamdump_140_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_140_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_140_var._position_relative, _beamdump_140_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 137) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_140_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_140_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_140 [137] */
    /* begin component DESIRS_pos=Text() [138] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DESIRS_pos_var._rotation_is_identity) {
        if(!_DESIRS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DESIRS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DESIRS_pos_var._position_relative, _DESIRS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 138) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DESIRS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_DESIRS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DESIRS_pos [138] */
    /* begin component METRO_pos=Text() [139] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_METRO_pos_var._rotation_is_identity) {
        if(!_METRO_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _METRO_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_METRO_pos_var._position_relative, _METRO_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 139) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_METRO_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_METRO_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component METRO_pos [139] */
    /* begin component PUMA_pos=Text() [140] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_pos_var._rotation_is_identity) {
        if(!_PUMA_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_pos_var._position_relative, _PUMA_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 140) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_PUMA_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_pos [140] */
    /* begin component PUMA=Arm() [141] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_var._rotation_is_identity) {
        if(!_PUMA_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_var._position_relative, _PUMA_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 141) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA [141] */
    /* begin component PUMA_Source=Wiggler() [142] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_Source_var._rotation_is_identity) {
        if(!_PUMA_Source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_Source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_Source_var._position_relative, _PUMA_Source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 142) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_Source_var._name);
      DEBUG_STATE();
      class_Wiggler_trace(&_PUMA_Source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_Source [142] */
    /* begin component PUMA_slit1=Slit() [143] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_slit1_var._rotation_is_identity) {
        if(!_PUMA_slit1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_slit1_var._position_relative, _PUMA_slit1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 143) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_slit1_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PUMA_slit1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_slit1 [143] */
    /* begin component PUMA_slit2=Slit() [144] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_slit2_var._rotation_is_identity) {
        if(!_PUMA_slit2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_slit2_var._position_relative, _PUMA_slit2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 144) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_slit2_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PUMA_slit2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_slit2 [144] */
    /* begin component PUMA_mon_src_e=E_monitor() [145] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_src_e_var._rotation_is_identity) {
        if(!_PUMA_mon_src_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_src_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_src_e_var._position_relative, _PUMA_mon_src_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 145) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_src_e_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_PUMA_mon_src_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_src_e [145] */
    /* begin component PUMA_mon_src_xy=PSD_monitor() [146] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_src_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_src_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_src_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_src_xy_var._position_relative, _PUMA_mon_src_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 146) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_src_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_src_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_src_xy [146] */
    /* begin component PUMA_HFM_location=Arm() [147] */
    if (!ABSORBED && _particle->_index == 147) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_HFM_location [147] */
    /* begin component PUMA_HFM_rotated=Arm() [148] */
    if (!ABSORBED && _particle->_index == 148) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_HFM_rotated [148] */
    /* begin component PUMA_mirror_HFM=Mirror_curved() [149] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mirror_HFM_var._rotation_is_identity) {
        if(!_PUMA_mirror_HFM_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mirror_HFM_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mirror_HFM_var._position_relative, _PUMA_mirror_HFM_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 149) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mirror_HFM_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PUMA_mirror_HFM_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mirror_HFM [149] */
    /* begin component PUMA_HFM_out=Arm() [150] */
    if (!ABSORBED && _particle->_index == 150) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_HFM_out [150] */
    /* begin component PUMA_mon_HFM_out_xy=PSD_monitor() [151] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_HFM_out_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_HFM_out_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_HFM_out_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_HFM_out_xy_var._position_relative, _PUMA_mon_HFM_out_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 151) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_HFM_out_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_HFM_out_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_HFM_out_xy [151] */
    /* begin component PUMA_DCM_location=Arm() [152] */
    if (!ABSORBED && _particle->_index == 152) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_DCM_location [152] */
    /* begin component PUMA_DCM_xtal1=Bragg_crystal() [153] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_DCM_xtal1_var._rotation_is_identity) {
        if(!_PUMA_DCM_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_DCM_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_DCM_xtal1_var._position_relative, _PUMA_DCM_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 153) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_DCM_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_PUMA_DCM_xtal1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_DCM_xtal1 [153] */
    /* begin component PUMA_DCM_xtal1_out=Arm() [154] */
    if (!ABSORBED && _particle->_index == 154) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_DCM_xtal1_out [154] */
    /* begin component PUMA_mon_DCM_xtal1_only_xy=PSD_monitor() [155] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_DCM_xtal1_only_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_DCM_xtal1_only_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_DCM_xtal1_only_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_DCM_xtal1_only_xy_var._position_relative, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 155) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_DCM_xtal1_only_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_DCM_xtal1_only_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_DCM_xtal1_only_xy [155] */
    /* begin component PUMA_DCM_xtal2=Bragg_crystal() [156] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_DCM_xtal2_var._rotation_is_identity) {
        if(!_PUMA_DCM_xtal2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_DCM_xtal2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_DCM_xtal2_var._position_relative, _PUMA_DCM_xtal2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 156) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_DCM_xtal2_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_PUMA_DCM_xtal2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_DCM_xtal2 [156] */
    /* begin component PUMA_DCM_xtal2_out=Arm() [157] */
    if (!ABSORBED && _particle->_index == 157) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_DCM_xtal2_out [157] */
    /* begin component PUMA_mon_DCM_out_e=E_monitor() [158] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_DCM_out_e_var._rotation_is_identity) {
        if(!_PUMA_mon_DCM_out_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_DCM_out_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_DCM_out_e_var._position_relative, _PUMA_mon_DCM_out_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 158) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_DCM_out_e_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_PUMA_mon_DCM_out_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_DCM_out_e [158] */
    /* begin component PUMA_mon_DCM_out_xy=PSD_monitor() [159] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_DCM_out_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_DCM_out_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_DCM_out_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_DCM_out_xy_var._position_relative, _PUMA_mon_DCM_out_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 159) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_DCM_out_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_DCM_out_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_DCM_out_xy [159] */
    /* begin component PUMA_slit3=Slit() [160] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_slit3_var._rotation_is_identity) {
        if(!_PUMA_slit3_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit3_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_slit3_var._position_relative, _PUMA_slit3_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 160) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_slit3_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PUMA_slit3_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_slit3 [160] */
    /* begin component PUMA_slit4=Slit() [161] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_slit4_var._rotation_is_identity) {
        if(!_PUMA_slit4_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit4_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_slit4_var._position_relative, _PUMA_slit4_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 161) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_slit4_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PUMA_slit4_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_slit4 [161] */
    /* begin component PUMA_slit5=Slit() [162] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_slit5_var._rotation_is_identity) {
        if(!_PUMA_slit5_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit5_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_slit5_var._position_relative, _PUMA_slit5_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 162) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_slit5_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PUMA_slit5_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_slit5 [162] */
    /* begin component PUMA_KB_VFM_location=Arm() [163] */
    if (!ABSORBED && _particle->_index == 163) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_KB_VFM_location [163] */
    /* begin component PUMA_mon_KB_in_xy=PSD_monitor() [164] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_KB_in_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_KB_in_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_KB_in_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_KB_in_xy_var._position_relative, _PUMA_mon_KB_in_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 164) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_KB_in_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_KB_in_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_KB_in_xy [164] */
    /* begin component PUMA_KB_VFM_rotated=Arm() [165] */
    if (!ABSORBED && _particle->_index == 165) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_KB_VFM_rotated [165] */
    /* begin component PUMA_mirror_KB_VFM=Mirror_curved() [166] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mirror_KB_VFM_var._rotation_is_identity) {
        if(!_PUMA_mirror_KB_VFM_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mirror_KB_VFM_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mirror_KB_VFM_var._position_relative, _PUMA_mirror_KB_VFM_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 166) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mirror_KB_VFM_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PUMA_mirror_KB_VFM_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mirror_KB_VFM [166] */
    /* begin component PUMA_KB_VFM_out=Arm() [167] */
    if (!ABSORBED && _particle->_index == 167) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_KB_VFM_out [167] */
    /* begin component PUMA_mon_KB_VFM_out_xy=PSD_monitor() [168] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_KB_VFM_out_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_KB_VFM_out_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_KB_VFM_out_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_KB_VFM_out_xy_var._position_relative, _PUMA_mon_KB_VFM_out_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 168) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_KB_VFM_out_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_KB_VFM_out_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_KB_VFM_out_xy [168] */
    /* begin component PUMA_KB_HFM_location=Arm() [169] */
    if (!ABSORBED && _particle->_index == 169) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_KB_HFM_location [169] */
    /* begin component PUMA_KB_HFM_rotated=Arm() [170] */
    if (!ABSORBED && _particle->_index == 170) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_KB_HFM_rotated [170] */
    /* begin component PUMA_mirror_KB_HFM=Mirror_curved() [171] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mirror_KB_HFM_var._rotation_is_identity) {
        if(!_PUMA_mirror_KB_HFM_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mirror_KB_HFM_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mirror_KB_HFM_var._position_relative, _PUMA_mirror_KB_HFM_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 171) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mirror_KB_HFM_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PUMA_mirror_KB_HFM_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mirror_KB_HFM [171] */
    /* begin component PUMA_KB_HFM_out=Arm() [172] */
    if (!ABSORBED && _particle->_index == 172) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_KB_HFM_out [172] */
    /* begin component PUMA_mon_KB_HFM_out_xy=PSD_monitor() [173] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_KB_HFM_out_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_KB_HFM_out_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_KB_HFM_out_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_KB_HFM_out_xy_var._position_relative, _PUMA_mon_KB_HFM_out_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 173) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_KB_HFM_out_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_KB_HFM_out_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_KB_HFM_out_xy [173] */
    /* begin component PUMA_sample_location=Arm() [174] */
    if (!ABSORBED && _particle->_index == 174) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PUMA_sample_location [174] */
    /* begin component PUMA_mon_sample_xy=PSD_monitor() [175] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_sample_xy_var._rotation_is_identity) {
        if(!_PUMA_mon_sample_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_sample_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_sample_xy_var._position_relative, _PUMA_mon_sample_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 175) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_sample_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PUMA_mon_sample_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_sample_xy [175] */
    /* begin component PUMA_mon_sample_e=E_monitor() [176] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PUMA_mon_sample_e_var._rotation_is_identity) {
        if(!_PUMA_mon_sample_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_sample_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PUMA_mon_sample_e_var._position_relative, _PUMA_mon_sample_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 176) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PUMA_mon_sample_e_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_PUMA_mon_sample_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PUMA_mon_sample_e [176] */
    /* begin component beamdump_181=Beamstop() [177] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_181_var._rotation_is_identity) {
        if(!_beamdump_181_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_181_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_181_var._position_relative, _beamdump_181_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 177) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_181_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_181_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_181 [177] */
    /* begin component CRISTAL_pos=Text() [178] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_pos_var._rotation_is_identity) {
        if(!_CRISTAL_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_pos_var._position_relative, _CRISTAL_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 178) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_CRISTAL_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_pos [178] */
    /* begin component CRISTAL=Arm() [179] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_var._rotation_is_identity) {
        if(!_CRISTAL_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_var._position_relative, _CRISTAL_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 179) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL [179] */
    /* begin component CRISTAL_Source=Undulator() [180] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_Source_var._rotation_is_identity) {
        if(!_CRISTAL_Source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_Source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_Source_var._position_relative, _CRISTAL_Source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 180) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_Source_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_CRISTAL_Source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_Source [180] */
    /* begin component CRISTAL_slit1=Slit() [181] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_slit1_var._rotation_is_identity) {
        if(!_CRISTAL_slit1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_slit1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_slit1_var._position_relative, _CRISTAL_slit1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 181) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_slit1_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_CRISTAL_slit1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_slit1 [181] */
    /* begin component CRISTAL_dcm_location=Arm() [182] */
    if (!ABSORBED && _particle->_index == 182) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_dcm_location [182] */
    /* begin component CRISTAL_dcm_xtal0=Bragg_crystal() [183] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_dcm_xtal0_var._rotation_is_identity) {
        if(!_CRISTAL_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_dcm_xtal0_var._position_relative, _CRISTAL_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 183) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_dcm_xtal0_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_CRISTAL_dcm_xtal0_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_dcm_xtal0 [183] */
    /* begin component CRISTAL_arm_xtal0=Arm() [184] */
    if (!ABSORBED && _particle->_index == 184) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_arm_xtal0 [184] */
    /* begin component CRISTAL_dcm_xtal1=Bragg_crystal() [185] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_dcm_xtal1_var._rotation_is_identity) {
        if(!_CRISTAL_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_dcm_xtal1_var._position_relative, _CRISTAL_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 185) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_dcm_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_CRISTAL_dcm_xtal1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_dcm_xtal1 [185] */
    /* begin component CRISTAL_arm_xtal1=Arm() [186] */
    if (!ABSORBED && _particle->_index == 186) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_arm_xtal1 [186] */
    /* begin component CRISTAL_emon_dcm=E_monitor() [187] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_emon_dcm_var._rotation_is_identity) {
        if(!_CRISTAL_emon_dcm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_emon_dcm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_emon_dcm_var._position_relative, _CRISTAL_emon_dcm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 187) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_emon_dcm_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_CRISTAL_emon_dcm_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_emon_dcm [187] */
    /* begin component CRISTAL_M1_location=Arm() [188] */
    if (!ABSORBED && _particle->_index == 188) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_M1_location [188] */
    /* begin component CRISTAL_M1_rotated=Arm() [189] */
    if (!ABSORBED && _particle->_index == 189) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_M1_rotated [189] */
    /* begin component CRISTAL_M1=Mirror_curved() [190] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_M1_var._rotation_is_identity) {
        if(!_CRISTAL_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_M1_var._position_relative, _CRISTAL_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 190) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_CRISTAL_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_M1 [190] */
    /* begin component CRISTAL_M1_out=Arm() [191] */
    if (!ABSORBED && _particle->_index == 191) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_M1_out [191] */
    /* begin component CRISTAL_M2_location=Arm() [192] */
    if (!ABSORBED && _particle->_index == 192) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_M2_location [192] */
    /* begin component CRISTAL_M2_rotated=Arm() [193] */
    if (!ABSORBED && _particle->_index == 193) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_M2_rotated [193] */
    /* begin component CRISTAL_M2=Mirror_curved() [194] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_M2_var._rotation_is_identity) {
        if(!_CRISTAL_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_M2_var._position_relative, _CRISTAL_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 194) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_M2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_CRISTAL_M2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_M2 [194] */
    /* begin component CRISTAL_M2_out=Arm() [195] */
    if (!ABSORBED && _particle->_index == 195) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_M2_out [195] */
    /* begin component CRISTAL_slit2=Slit() [196] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_slit2_var._rotation_is_identity) {
        if(!_CRISTAL_slit2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_slit2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_slit2_var._position_relative, _CRISTAL_slit2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 196) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_slit2_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_CRISTAL_slit2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_slit2 [196] */
    /* begin component CRISTAL_psd_slit2=PSD_monitor() [197] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_psd_slit2_var._rotation_is_identity) {
        if(!_CRISTAL_psd_slit2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_psd_slit2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_psd_slit2_var._position_relative, _CRISTAL_psd_slit2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 197) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_psd_slit2_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_CRISTAL_psd_slit2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_psd_slit2 [197] */
    /* begin component CRISTAL_sample_stage=Arm() [198] */
    if (!ABSORBED && _particle->_index == 198) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CRISTAL_sample_stage [198] */
#ifndef NOSPLIT
    /* start SPLIT at CRISTAL_fluo */
    if (!ABSORBED) {
    _class_particle Split_CRISTAL_fluo_particle=*_particle;
    int Split_CRISTAL_fluo_counter;
    int SplitS_CRISTAL_fluo = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_CRISTAL_fluo_counter = 0; Split_CRISTAL_fluo_counter< SplitS_CRISTAL_fluo; Split_CRISTAL_fluo_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_CRISTAL_fluo_randstate_idx = 0; Split_CRISTAL_fluo_randstate_idx < RANDSTATE_LEN; Split_CRISTAL_fluo_randstate_idx++) {
        randbackup[Split_CRISTAL_fluo_randstate_idx] = _particle->randstate[Split_CRISTAL_fluo_randstate_idx];
      }
      *_particle=Split_CRISTAL_fluo_particle;
      for (int Split_CRISTAL_fluo_randstate_idx = 0; Split_CRISTAL_fluo_randstate_idx < RANDSTATE_LEN; Split_CRISTAL_fluo_randstate_idx++) {
        _particle->randstate[Split_CRISTAL_fluo_randstate_idx] = randbackup[Split_CRISTAL_fluo_randstate_idx];
      }
      p /= SplitS_CRISTAL_fluo > 0 ? SplitS_CRISTAL_fluo : 1;
#endif
    /* begin component CRISTAL_fluo=FluoPowder() [199] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_fluo_var._rotation_is_identity) {
        if(!_CRISTAL_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_fluo_var._position_relative, _CRISTAL_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 199) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_fluo_var._name);
      DEBUG_STATE();
      class_FluoPowder_trace(&_CRISTAL_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_fluo [199] */
    /* begin component CRISTAL_detector_diffraction=Monitor_nD() [200] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_detector_diffraction_var._rotation_is_identity) {
        if(!_CRISTAL_detector_diffraction_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_detector_diffraction_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_detector_diffraction_var._position_relative, _CRISTAL_detector_diffraction_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 200) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_detector_diffraction_var._name);
      DEBUG_STATE();
      if ((( 0.75 * _instrument_var._parameters.CRISTAL_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_CRISTAL_detector_diffraction_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_detector_diffraction [200] */
    /* begin component CRISTAL_detector_fluo=Monitor_nD() [201] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CRISTAL_detector_fluo_var._rotation_is_identity) {
        if(!_CRISTAL_detector_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_detector_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CRISTAL_detector_fluo_var._position_relative, _CRISTAL_detector_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 201) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CRISTAL_detector_fluo_var._name);
      DEBUG_STATE();
      if ((( K2E * sqrt ( kx * kx + ky * ky + kz * kz ) < 0.95 * _instrument_var._parameters.CRISTAL_E0 ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_CRISTAL_detector_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CRISTAL_detector_fluo [201] */
    /* begin component beamdump_207=Beamstop() [202] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_207_var._rotation_is_identity) {
        if(!_beamdump_207_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_207_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_207_var._position_relative, _beamdump_207_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 202) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_207_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_207_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_207 [202] */
    /* begin component DEIMOS_pos=Text() [203] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DEIMOS_pos_var._rotation_is_identity) {
        if(!_DEIMOS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DEIMOS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DEIMOS_pos_var._position_relative, _DEIMOS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 203) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DEIMOS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_DEIMOS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DEIMOS_pos [203] */
    /* begin component GALAXIES_pos=Text() [204] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_pos_var._rotation_is_identity) {
        if(!_GALAXIES_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_pos_var._position_relative, _GALAXIES_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 204) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_GALAXIES_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_pos [204] */
    /* begin component GALAXIES=Arm() [205] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_var._rotation_is_identity) {
        if(!_GALAXIES_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_var._position_relative, _GALAXIES_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 205) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES [205] */
    /* begin component GALAXIES_Source_U20=Undulator() [206] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_Source_U20_var._rotation_is_identity) {
        if(!_GALAXIES_Source_U20_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_Source_U20_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_Source_U20_var._position_relative, _GALAXIES_Source_U20_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 206) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_Source_U20_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_GALAXIES_Source_U20_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_Source_U20 [206] */
    /* begin component GALAXIES_mon_src_xy=Monitor_nD() [207] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_src_xy_var._rotation_is_identity) {
        if(!_GALAXIES_mon_src_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_src_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_src_xy_var._position_relative, _GALAXIES_mon_src_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 207) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_src_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_src_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_src_xy [207] */
    /* begin component GALAXIES_mon_src_e=Monitor_nD() [208] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_src_e_var._rotation_is_identity) {
        if(!_GALAXIES_mon_src_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_src_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_src_e_var._position_relative, _GALAXIES_mon_src_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 208) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_src_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_src_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_src_e [208] */
    /* begin component GALAXIES_absorber=Slit() [209] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_absorber_var._rotation_is_identity) {
        if(!_GALAXIES_absorber_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_absorber_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_absorber_var._position_relative, _GALAXIES_absorber_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 209) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_absorber_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_GALAXIES_absorber_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_absorber [209] */
    /* begin component GALAXIES_diaphragme=Slit() [210] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_diaphragme_var._rotation_is_identity) {
        if(!_GALAXIES_diaphragme_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_diaphragme_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_diaphragme_var._position_relative, _GALAXIES_diaphragme_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 210) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_diaphragme_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_GALAXIES_diaphragme_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_diaphragme [210] */
    /* begin component GALAXIES_fentes_primaires=Slit() [211] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_fentes_primaires_var._rotation_is_identity) {
        if(!_GALAXIES_fentes_primaires_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_fentes_primaires_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_fentes_primaires_var._position_relative, _GALAXIES_fentes_primaires_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 211) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_fentes_primaires_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_GALAXIES_fentes_primaires_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_fentes_primaires [211] */
    /* begin component GALAXIES_mon_prim_xy=Monitor_nD() [212] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_prim_xy_var._rotation_is_identity) {
        if(!_GALAXIES_mon_prim_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_prim_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_prim_xy_var._position_relative, _GALAXIES_mon_prim_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 212) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_prim_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_prim_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_prim_xy [212] */
    /* begin component GALAXIES_DCM_location=Arm() [213] */
    if (!ABSORBED && _particle->_index == 213) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_DCM_location [213] */
    /* begin component GALAXIES_dcm_xtal0=Bragg_crystal() [214] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_dcm_xtal0_var._rotation_is_identity) {
        if(!_GALAXIES_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_dcm_xtal0_var._position_relative, _GALAXIES_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 214) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_dcm_xtal0_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_GALAXIES_dcm_xtal0_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_dcm_xtal0 [214] */
    /* begin component GALAXIES_dcm0=Arm() [215] */
    if (!ABSORBED && _particle->_index == 215) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_dcm0 [215] */
    /* begin component GALAXIES_dcm_xtal1=Bragg_crystal() [216] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_dcm_xtal1_var._rotation_is_identity) {
        if(!_GALAXIES_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_dcm_xtal1_var._position_relative, _GALAXIES_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 216) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_dcm_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_GALAXIES_dcm_xtal1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_dcm_xtal1 [216] */
    /* begin component GALAXIES_dcm1=Arm() [217] */
    if (!ABSORBED && _particle->_index == 217) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_dcm1 [217] */
    /* begin component GALAXIES_mon_dcm_e=Monitor_nD() [218] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_dcm_e_var._rotation_is_identity) {
        if(!_GALAXIES_mon_dcm_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_dcm_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_dcm_e_var._position_relative, _GALAXIES_mon_dcm_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 218) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_dcm_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_dcm_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_dcm_e [218] */
    /* begin component GALAXIES_mon_dcm_xy=Monitor_nD() [219] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_dcm_xy_var._rotation_is_identity) {
        if(!_GALAXIES_mon_dcm_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_dcm_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_dcm_xy_var._position_relative, _GALAXIES_mon_dcm_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 219) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_dcm_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_dcm_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_dcm_xy [219] */
    /* begin component GALAXIES_M1_location=Arm() [220] */
    if (!ABSORBED && _particle->_index == 220) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M1_location [220] */
    /* begin component GALAXIES_M1_rotated=Arm() [221] */
    if (!ABSORBED && _particle->_index == 221) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M1_rotated [221] */
    /* begin component GALAXIES_M1=Mirror_curved() [222] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_M1_var._rotation_is_identity) {
        if(!_GALAXIES_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_M1_var._position_relative, _GALAXIES_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 222) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_GALAXIES_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_M1 [222] */
    /* begin component GALAXIES_M1_out=Arm() [223] */
    if (!ABSORBED && _particle->_index == 223) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M1_out [223] */
    /* begin component GALAXIES_HRM_gate_in=Slit() [224] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_HRM_gate_in_var._rotation_is_identity) {
        if(!_GALAXIES_HRM_gate_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_HRM_gate_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_HRM_gate_in_var._position_relative, _GALAXIES_HRM_gate_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 224) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_HRM_gate_in_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_GALAXIES_HRM_gate_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_HRM_gate_in [224] */
    /* begin component GALAXIES_M2A_location=Arm() [225] */
    if (!ABSORBED && _particle->_index == 225) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M2A_location [225] */
    /* begin component GALAXIES_M2A_rotated=Arm() [226] */
    if (!ABSORBED && _particle->_index == 226) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M2A_rotated [226] */
    /* begin component GALAXIES_M2A=Mirror_toroid() [227] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_M2A_var._rotation_is_identity) {
        if(!_GALAXIES_M2A_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_M2A_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_M2A_var._position_relative, _GALAXIES_M2A_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 227) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_M2A_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_trace(&_GALAXIES_M2A_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_M2A [227] */
    /* begin component GALAXIES_M2A_out=Arm() [228] */
    if (!ABSORBED && _particle->_index == 228) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M2A_out [228] */
    /* begin component GALAXIES_secondary_slits=Slit() [229] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_secondary_slits_var._rotation_is_identity) {
        if(!_GALAXIES_secondary_slits_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_secondary_slits_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_secondary_slits_var._position_relative, _GALAXIES_secondary_slits_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 229) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_secondary_slits_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_GALAXIES_secondary_slits_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_secondary_slits [229] */
    /* begin component GALAXIES_mon_sec_xy=Monitor_nD() [230] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_sec_xy_var._rotation_is_identity) {
        if(!_GALAXIES_mon_sec_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_sec_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_sec_xy_var._position_relative, _GALAXIES_mon_sec_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 230) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_sec_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_sec_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_sec_xy [230] */
    /* begin component GALAXIES_M2B_location=Arm() [231] */
    if (!ABSORBED && _particle->_index == 231) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M2B_location [231] */
    /* begin component GALAXIES_M2B_rotated=Arm() [232] */
    if (!ABSORBED && _particle->_index == 232) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M2B_rotated [232] */
    /* begin component GALAXIES_M2B=Mirror_toroid() [233] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_M2B_var._rotation_is_identity) {
        if(!_GALAXIES_M2B_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_M2B_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_M2B_var._position_relative, _GALAXIES_M2B_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 233) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_M2B_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_trace(&_GALAXIES_M2B_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_M2B [233] */
    /* begin component GALAXIES_M2B_out=Arm() [234] */
    if (!ABSORBED && _particle->_index == 234) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_M2B_out [234] */
    /* begin component GALAXIES_VFM_location=Arm() [235] */
    if (!ABSORBED && _particle->_index == 235) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_VFM_location [235] */
    /* begin component GALAXIES_VFM_rotated=Arm() [236] */
    if (!ABSORBED && _particle->_index == 236) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_VFM_rotated [236] */
    /* begin component GALAXIES_VFM=Mirror_curved() [237] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_VFM_var._rotation_is_identity) {
        if(!_GALAXIES_VFM_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_VFM_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_VFM_var._position_relative, _GALAXIES_VFM_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 237) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_VFM_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_GALAXIES_VFM_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_VFM [237] */
    /* begin component GALAXIES_VFM_out=Arm() [238] */
    if (!ABSORBED && _particle->_index == 238) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_VFM_out [238] */
    /* begin component GALAXIES_HFM_rotated=Arm() [239] */
    if (!ABSORBED && _particle->_index == 239) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_HFM_rotated [239] */
    /* begin component GALAXIES_HFM=Mirror_curved() [240] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_HFM_var._rotation_is_identity) {
        if(!_GALAXIES_HFM_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_HFM_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_HFM_var._position_relative, _GALAXIES_HFM_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 240) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_HFM_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_GALAXIES_HFM_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_HFM [240] */
    /* begin component GALAXIES_HFM_out=Arm() [241] */
    if (!ABSORBED && _particle->_index == 241) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_HFM_out [241] */
    /* begin component GALAXIES_mon_sample_xy_kb=Monitor_nD() [242] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_sample_xy_kb_var._rotation_is_identity) {
        if(!_GALAXIES_mon_sample_xy_kb_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_sample_xy_kb_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_sample_xy_kb_var._position_relative, _GALAXIES_mon_sample_xy_kb_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 242) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_sample_xy_kb_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_sample_xy_kb_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_sample_xy_kb [242] */
    /* begin component GALAXIES_mon_sample_e=Monitor_nD() [243] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_mon_sample_e_var._rotation_is_identity) {
        if(!_GALAXIES_mon_sample_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_sample_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_mon_sample_e_var._position_relative, _GALAXIES_mon_sample_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 243) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_mon_sample_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_mon_sample_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_mon_sample_e [243] */
    /* begin component GALAXIES_sample_stage=Arm() [244] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_sample_stage_var._rotation_is_identity) {
        if(!_GALAXIES_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_sample_stage_var._position_relative, _GALAXIES_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 244) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_sample_stage_var._name);
      DEBUG_STATE();
      class_Arm_trace(&_GALAXIES_sample_stage_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_sample_stage [244] */
#ifndef NOSPLIT
    /* start SPLIT at GALAXIES_sample */
    if (!ABSORBED) {
    _class_particle Split_GALAXIES_sample_particle=*_particle;
    int Split_GALAXIES_sample_counter;
    int SplitS_GALAXIES_sample = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_GALAXIES_sample_counter = 0; Split_GALAXIES_sample_counter< SplitS_GALAXIES_sample; Split_GALAXIES_sample_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_GALAXIES_sample_randstate_idx = 0; Split_GALAXIES_sample_randstate_idx < RANDSTATE_LEN; Split_GALAXIES_sample_randstate_idx++) {
        randbackup[Split_GALAXIES_sample_randstate_idx] = _particle->randstate[Split_GALAXIES_sample_randstate_idx];
      }
      *_particle=Split_GALAXIES_sample_particle;
      for (int Split_GALAXIES_sample_randstate_idx = 0; Split_GALAXIES_sample_randstate_idx < RANDSTATE_LEN; Split_GALAXIES_sample_randstate_idx++) {
        _particle->randstate[Split_GALAXIES_sample_randstate_idx] = randbackup[Split_GALAXIES_sample_randstate_idx];
      }
      p /= SplitS_GALAXIES_sample > 0 ? SplitS_GALAXIES_sample : 1;
#endif
    /* begin component GALAXIES_sample=FluoCrystal() [245] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_sample_var._rotation_is_identity) {
        if(!_GALAXIES_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_sample_var._position_relative, _GALAXIES_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 245) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_sample_var._name);
      DEBUG_STATE();
      class_FluoCrystal_trace(&_GALAXIES_sample_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_sample [245] */
    /* begin component GALAXIES_sample_out=Arm() [246] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_sample_out_var._rotation_is_identity) {
        if(!_GALAXIES_sample_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_sample_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_sample_out_var._position_relative, _GALAXIES_sample_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 246) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_sample_out_var._name);
      DEBUG_STATE();
      class_Arm_trace(&_GALAXIES_sample_out_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_sample_out [246] */
    /* begin component GALAXIES_ana_arm=Arm() [247] */
    if (!ABSORBED && _particle->_index == 247) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_ana_arm [247] */
    /* begin component GALAXIES_analyzer=Bragg_crystal() [248] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_analyzer_var._rotation_is_identity) {
        if(!_GALAXIES_analyzer_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_analyzer_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_analyzer_var._position_relative, _GALAXIES_analyzer_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 248) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_analyzer_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_GALAXIES_analyzer_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_analyzer [248] */
    /* begin component GALAXIES_ana_out=Arm() [249] */
    if (!ABSORBED && _particle->_index == 249) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component GALAXIES_ana_out [249] */
    /* begin component GALAXIES_IXS_det=Monitor_nD() [250] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_GALAXIES_IXS_det_var._rotation_is_identity) {
        if(!_GALAXIES_IXS_det_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_IXS_det_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_GALAXIES_IXS_det_var._position_relative, _GALAXIES_IXS_det_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 250) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_GALAXIES_IXS_det_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_GALAXIES_IXS_det_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component GALAXIES_IXS_det [250] */
    /* begin component beamdump_257=Beamstop() [251] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_257_var._rotation_is_identity) {
        if(!_beamdump_257_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_257_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_257_var._position_relative, _beamdump_257_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 251) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_257_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_257_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_257 [251] */
    /* begin component TEMPO_pos=Text() [252] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_TEMPO_pos_var._rotation_is_identity) {
        if(!_TEMPO_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _TEMPO_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_TEMPO_pos_var._position_relative, _TEMPO_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 252) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_TEMPO_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_TEMPO_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component TEMPO_pos [252] */
    /* begin component SAMBA_pos=Text() [253] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_pos_var._rotation_is_identity) {
        if(!_SAMBA_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_pos_var._position_relative, _SAMBA_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 253) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_SAMBA_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_pos [253] */
    /* begin component SAMBA=Arm() [254] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_var._rotation_is_identity) {
        if(!_SAMBA_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_var._position_relative, _SAMBA_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 254) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA [254] */
    /* begin component SAMBA_BM_source=Bending_magnet() [255] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_BM_source_var._rotation_is_identity) {
        if(!_SAMBA_BM_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_BM_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_BM_source_var._position_relative, _SAMBA_BM_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 255) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_BM_source_var._name);
      DEBUG_STATE();
      class_Bending_magnet_trace(&_SAMBA_BM_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_BM_source [255] */
    /* begin component SAMBA_M1_location=Arm() [256] */
    if (!ABSORBED && _particle->_index == 256) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_M1_location [256] */
    /* begin component SAMBA_M1_rotated=Arm() [257] */
    if (!ABSORBED && _particle->_index == 257) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_M1_rotated [257] */
    /* begin component SAMBA_M1=Mirror_curved() [258] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_M1_var._rotation_is_identity) {
        if(!_SAMBA_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_M1_var._position_relative, _SAMBA_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 258) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SAMBA_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_M1 [258] */
    /* begin component SAMBA_M1_out=Monitor_nD() [259] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_M1_out_var._rotation_is_identity) {
        if(!_SAMBA_M1_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M1_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_M1_out_var._position_relative, _SAMBA_M1_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 259) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_M1_out_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_M1_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_M1_out [259] */
    /* begin component SAMBA_DCM_location=Arm() [260] */
    if (!ABSORBED && _particle->_index == 260) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_DCM_location [260] */
    /* begin component SAMBA_bragg_crystal=Bragg_crystal() [261] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_bragg_crystal_var._rotation_is_identity) {
        if(!_SAMBA_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_bragg_crystal_var._position_relative, _SAMBA_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 261) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SAMBA_bragg_crystal_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_bragg_crystal [261] */
    /* begin component SAMBA_arm_crystal1=Arm() [262] */
    if (!ABSORBED && _particle->_index == 262) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_arm_crystal1 [262] */
    /* begin component SAMBA_bragg_crystal_two=Bragg_crystal() [263] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_bragg_crystal_two_var._rotation_is_identity) {
        if(!_SAMBA_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_bragg_crystal_two_var._position_relative, _SAMBA_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 263) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SAMBA_bragg_crystal_two_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_bragg_crystal_two [263] */
    /* begin component SAMBA_arm_crystal2=Arm() [264] */
    if (!ABSORBED && _particle->_index == 264) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_arm_crystal2 [264] */
    /* begin component SAMBA_DCM_out=Monitor_nD() [265] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_DCM_out_var._rotation_is_identity) {
        if(!_SAMBA_DCM_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_DCM_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_DCM_out_var._position_relative, _SAMBA_DCM_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 265) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_DCM_out_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_DCM_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_DCM_out [265] */
    /* begin component SAMBA_DCM_out_div=Monitor_nD() [266] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_DCM_out_div_var._rotation_is_identity) {
        if(!_SAMBA_DCM_out_div_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_DCM_out_div_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_DCM_out_div_var._position_relative, _SAMBA_DCM_out_div_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 266) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_DCM_out_div_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_DCM_out_div_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_DCM_out_div [266] */
    /* begin component SAMBA_DCM_out_e=Monitor_nD() [267] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_DCM_out_e_var._rotation_is_identity) {
        if(!_SAMBA_DCM_out_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_DCM_out_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_DCM_out_e_var._position_relative, _SAMBA_DCM_out_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 267) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_DCM_out_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_DCM_out_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_DCM_out_e [267] */
    /* begin component SAMBA_M2_loc=Arm() [268] */
    if (!ABSORBED && _particle->_index == 268) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_M2_loc [268] */
    /* begin component SAMBA_M2_rotated=Arm() [269] */
    if (!ABSORBED && _particle->_index == 269) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SAMBA_M2_rotated [269] */
    /* begin component SAMBA_M2=Mirror_curved() [270] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_M2_var._rotation_is_identity) {
        if(!_SAMBA_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_M2_var._position_relative, _SAMBA_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 270) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_M2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SAMBA_M2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_M2 [270] */
    /* begin component SAMBA_M2_out=Monitor_nD() [271] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_M2_out_var._rotation_is_identity) {
        if(!_SAMBA_M2_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M2_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_M2_out_var._position_relative, _SAMBA_M2_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 271) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_M2_out_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_M2_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_M2_out [271] */
    /* begin component SAMBA_sample_stage=Monitor_nD() [272] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_sample_stage_var._rotation_is_identity) {
        if(!_SAMBA_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_sample_stage_var._position_relative, _SAMBA_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 272) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_sample_stage_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_sample_stage_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_sample_stage [272] */
#ifndef NOSPLIT
    /* start SPLIT at SAMBA_fluo */
    if (!ABSORBED) {
    _class_particle Split_SAMBA_fluo_particle=*_particle;
    int Split_SAMBA_fluo_counter;
    int SplitS_SAMBA_fluo = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_SAMBA_fluo_counter = 0; Split_SAMBA_fluo_counter< SplitS_SAMBA_fluo; Split_SAMBA_fluo_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_SAMBA_fluo_randstate_idx = 0; Split_SAMBA_fluo_randstate_idx < RANDSTATE_LEN; Split_SAMBA_fluo_randstate_idx++) {
        randbackup[Split_SAMBA_fluo_randstate_idx] = _particle->randstate[Split_SAMBA_fluo_randstate_idx];
      }
      *_particle=Split_SAMBA_fluo_particle;
      for (int Split_SAMBA_fluo_randstate_idx = 0; Split_SAMBA_fluo_randstate_idx < RANDSTATE_LEN; Split_SAMBA_fluo_randstate_idx++) {
        _particle->randstate[Split_SAMBA_fluo_randstate_idx] = randbackup[Split_SAMBA_fluo_randstate_idx];
      }
      p /= SplitS_SAMBA_fluo > 0 ? SplitS_SAMBA_fluo : 1;
#endif
    /* begin component SAMBA_fluo=FluoPowder() [273] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_fluo_var._rotation_is_identity) {
        if(!_SAMBA_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_fluo_var._position_relative, _SAMBA_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 273) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_fluo_var._name);
      DEBUG_STATE();
      class_FluoPowder_trace(&_SAMBA_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_fluo [273] */
    /* begin component SAMBA_det_trans=Monitor_nD() [274] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_det_trans_var._rotation_is_identity) {
        if(!_SAMBA_det_trans_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_det_trans_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_det_trans_var._position_relative, _SAMBA_det_trans_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 274) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_det_trans_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_det_trans_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_det_trans [274] */
    /* begin component SAMBA_det_fluo=Monitor_nD() [275] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SAMBA_det_fluo_var._rotation_is_identity) {
        if(!_SAMBA_det_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_det_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SAMBA_det_fluo_var._position_relative, _SAMBA_det_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 275) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SAMBA_det_fluo_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SAMBA_det_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SAMBA_det_fluo [275] */
    /* begin component beamdump_283=Beamstop() [276] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_283_var._rotation_is_identity) {
        if(!_beamdump_283_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_283_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_283_var._position_relative, _beamdump_283_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 276) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_283_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_283_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_283 [276] */
    /* begin component HERMES_pos=Text() [277] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_HERMES_pos_var._rotation_is_identity) {
        if(!_HERMES_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _HERMES_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_HERMES_pos_var._position_relative, _HERMES_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 277) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_HERMES_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_HERMES_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component HERMES_pos [277] */
    /* begin component PX1_pos=Text() [278] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_pos_var._rotation_is_identity) {
        if(!_PX1_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_pos_var._position_relative, _PX1_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 278) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_PX1_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_pos [278] */
    /* begin component PX1=Arm() [279] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_var._rotation_is_identity) {
        if(!_PX1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_var._position_relative, _PX1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 279) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1 [279] */
    /* begin component PX1_undulator=Undulator() [280] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_undulator_var._rotation_is_identity) {
        if(!_PX1_undulator_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_undulator_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_undulator_var._position_relative, _PX1_undulator_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 280) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_undulator_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_PX1_undulator_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_undulator [280] */
    /* begin component PX1_bragg_crystal_location=Arm() [281] */
    if (!ABSORBED && _particle->_index == 281) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX1_bragg_crystal_location [281] */
    /* begin component PX1_bragg_crystal=Bragg_crystal() [282] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_bragg_crystal_var._rotation_is_identity) {
        if(!_PX1_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_bragg_crystal_var._position_relative, _PX1_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 282) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_PX1_bragg_crystal_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_bragg_crystal [282] */
    /* begin component PX1_arm=Arm() [283] */
    if (!ABSORBED && _particle->_index == 283) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX1_arm [283] */
    /* begin component PX1_bragg_crystal_two=Bragg_crystal() [284] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_bragg_crystal_two_var._rotation_is_identity) {
        if(!_PX1_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_bragg_crystal_two_var._position_relative, _PX1_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 284) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_PX1_bragg_crystal_two_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_bragg_crystal_two [284] */
    /* begin component PX1_arm_two=Arm() [285] */
    if (!ABSORBED && _particle->_index == 285) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX1_arm_two [285] */
    /* begin component PX1_bragg_crystal_out=E_monitor() [286] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_bragg_crystal_out_var._rotation_is_identity) {
        if(!_PX1_bragg_crystal_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_bragg_crystal_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_bragg_crystal_out_var._position_relative, _PX1_bragg_crystal_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 286) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_bragg_crystal_out_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_PX1_bragg_crystal_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_bragg_crystal_out [286] */
    /* begin component PX1_secondary_slits=Slit() [287] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_secondary_slits_var._rotation_is_identity) {
        if(!_PX1_secondary_slits_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_secondary_slits_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_secondary_slits_var._position_relative, _PX1_secondary_slits_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 287) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_secondary_slits_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_PX1_secondary_slits_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_secondary_slits [287] */
    /* begin component PX1_vfm_location=Monitor_nD() [288] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_vfm_location_var._rotation_is_identity) {
        if(!_PX1_vfm_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_vfm_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_vfm_location_var._position_relative, _PX1_vfm_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 288) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_vfm_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX1_vfm_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_vfm_location [288] */
    /* begin component PX1_vfm_in_xz_plane=Arm() [289] */
    if (!ABSORBED && _particle->_index == 289) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX1_vfm_in_xz_plane [289] */
    /* begin component PX1_vfm=Mirror_curved() [290] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_vfm_var._rotation_is_identity) {
        if(!_PX1_vfm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_vfm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_vfm_var._position_relative, _PX1_vfm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 290) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_vfm_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PX1_vfm_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_vfm [290] */
    /* begin component PX1_vfm_takeoff=Monitor_nD() [291] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_vfm_takeoff_var._rotation_is_identity) {
        if(!_PX1_vfm_takeoff_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_vfm_takeoff_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_vfm_takeoff_var._position_relative, _PX1_vfm_takeoff_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 291) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_vfm_takeoff_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX1_vfm_takeoff_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_vfm_takeoff [291] */
    /* begin component PX1_hfm_location=Monitor_nD() [292] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_hfm_location_var._rotation_is_identity) {
        if(!_PX1_hfm_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_hfm_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_hfm_location_var._position_relative, _PX1_hfm_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 292) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_hfm_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX1_hfm_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_hfm_location [292] */
    /* begin component PX1_hfm=Mirror_curved() [293] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_hfm_var._rotation_is_identity) {
        if(!_PX1_hfm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_hfm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_hfm_var._position_relative, _PX1_hfm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 293) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_hfm_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PX1_hfm_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_hfm [293] */
    /* begin component PX1_hfm_takeoff=Monitor_nD() [294] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_hfm_takeoff_var._rotation_is_identity) {
        if(!_PX1_hfm_takeoff_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_hfm_takeoff_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_hfm_takeoff_var._position_relative, _PX1_hfm_takeoff_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 294) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_hfm_takeoff_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX1_hfm_takeoff_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_hfm_takeoff [294] */
    /* begin component PX1_sample_stage=Arm() [295] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_sample_stage_var._rotation_is_identity) {
        if(!_PX1_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_sample_stage_var._position_relative, _PX1_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 295) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_sample_stage_var._name);
      DEBUG_STATE();
      class_Arm_trace(&_PX1_sample_stage_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_sample_stage [295] */
    /* begin component PX1_sample_monitor=Monitor_nD() [296] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_sample_monitor_var._rotation_is_identity) {
        if(!_PX1_sample_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_sample_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_sample_monitor_var._position_relative, _PX1_sample_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 296) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_sample_monitor_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX1_sample_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_sample_monitor [296] */
#ifndef NOSPLIT
    /* start SPLIT at PX1_sample */
    if (!ABSORBED) {
    _class_particle Split_PX1_sample_particle=*_particle;
    int Split_PX1_sample_counter;
    int SplitS_PX1_sample = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_PX1_sample_counter = 0; Split_PX1_sample_counter< SplitS_PX1_sample; Split_PX1_sample_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_PX1_sample_randstate_idx = 0; Split_PX1_sample_randstate_idx < RANDSTATE_LEN; Split_PX1_sample_randstate_idx++) {
        randbackup[Split_PX1_sample_randstate_idx] = _particle->randstate[Split_PX1_sample_randstate_idx];
      }
      *_particle=Split_PX1_sample_particle;
      for (int Split_PX1_sample_randstate_idx = 0; Split_PX1_sample_randstate_idx < RANDSTATE_LEN; Split_PX1_sample_randstate_idx++) {
        _particle->randstate[Split_PX1_sample_randstate_idx] = randbackup[Split_PX1_sample_randstate_idx];
      }
      p /= SplitS_PX1_sample > 0 ? SplitS_PX1_sample : 1;
#endif
    /* begin component PX1_sample=Single_crystal() [297] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_sample_var._rotation_is_identity) {
        if(!_PX1_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_sample_var._position_relative, _PX1_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 297) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_sample_var._name);
      DEBUG_STATE();
      class_Single_crystal_trace(&_PX1_sample_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_sample [297] */
    /* begin component PX1_psd4pi=PSD_monitor_4PI() [298] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_psd4pi_var._rotation_is_identity) {
        if(!_PX1_psd4pi_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_psd4pi_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_psd4pi_var._position_relative, _PX1_psd4pi_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 298) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_psd4pi_var._name);
      DEBUG_STATE();
      class_PSD_monitor_4PI_trace(&_PX1_psd4pi_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_psd4pi [298] */
    /* begin component PX1_EigerX16M=PSD_monitor() [299] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX1_EigerX16M_var._rotation_is_identity) {
        if(!_PX1_EigerX16M_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX1_EigerX16M_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX1_EigerX16M_var._position_relative, _PX1_EigerX16M_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 299) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX1_EigerX16M_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PX1_EigerX16M_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX1_EigerX16M [299] */
    /* begin component beamdump_308=Beamstop() [300] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_308_var._rotation_is_identity) {
        if(!_beamdump_308_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_308_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_308_var._position_relative, _beamdump_308_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 300) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_308_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_308_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_308 [300] */
    /* begin component PX2a_pos=Text() [301] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_pos_var._rotation_is_identity) {
        if(!_PX2a_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_pos_var._position_relative, _PX2a_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 301) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_PX2a_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_pos [301] */
    /* begin component PX2a=Arm() [302] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_var._rotation_is_identity) {
        if(!_PX2a_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_var._position_relative, _PX2a_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 302) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a [302] */
    /* begin component PX2a_undulator=Undulator() [303] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_undulator_var._rotation_is_identity) {
        if(!_PX2a_undulator_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_undulator_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_undulator_var._position_relative, _PX2a_undulator_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 303) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_undulator_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_PX2a_undulator_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_undulator [303] */
    /* begin component PX2a_bragg_crystal_location=Arm() [304] */
    if (!ABSORBED && _particle->_index == 304) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_bragg_crystal_location [304] */
    /* begin component PX2a_bragg_crystal=Bragg_crystal() [305] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_bragg_crystal_var._rotation_is_identity) {
        if(!_PX2a_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_bragg_crystal_var._position_relative, _PX2a_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 305) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_PX2a_bragg_crystal_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_bragg_crystal [305] */
    /* begin component PX2a_arm=Arm() [306] */
    if (!ABSORBED && _particle->_index == 306) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_arm [306] */
    /* begin component PX2a_bragg_crystal_two=Bragg_crystal() [307] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_bragg_crystal_two_var._rotation_is_identity) {
        if(!_PX2a_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_bragg_crystal_two_var._position_relative, _PX2a_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 307) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_PX2a_bragg_crystal_two_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_bragg_crystal_two [307] */
    /* begin component PX2a_arm_two=Arm() [308] */
    if (!ABSORBED && _particle->_index == 308) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_arm_two [308] */
    /* begin component PX2a_bragg_crystal_out=E_monitor() [309] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_bragg_crystal_out_var._rotation_is_identity) {
        if(!_PX2a_bragg_crystal_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_bragg_crystal_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_bragg_crystal_out_var._position_relative, _PX2a_bragg_crystal_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 309) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_bragg_crystal_out_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_PX2a_bragg_crystal_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_bragg_crystal_out [309] */
    /* begin component PX2a_hpm_location=Arm() [310] */
    if (!ABSORBED && _particle->_index == 310) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_hpm_location [310] */
    /* begin component PX2a_hpm_in_yz_plane=Arm() [311] */
    if (!ABSORBED && _particle->_index == 311) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_hpm_in_yz_plane [311] */
    /* begin component PX2a_hpm=Mirror_toroid() [312] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_hpm_var._rotation_is_identity) {
        if(!_PX2a_hpm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hpm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_hpm_var._position_relative, _PX2a_hpm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 312) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_hpm_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_trace(&_PX2a_hpm_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_hpm [312] */
    /* begin component PX2a_hpm_takeoff=Arm() [313] */
    if (!ABSORBED && _particle->_index == 313) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_hpm_takeoff [313] */
    /* begin component PX2a_vfm_location=Monitor_nD() [314] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_vfm_location_var._rotation_is_identity) {
        if(!_PX2a_vfm_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_vfm_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_vfm_location_var._position_relative, _PX2a_vfm_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 314) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_vfm_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX2a_vfm_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_vfm_location [314] */
    /* begin component PX2a_vfm_in_xz_plane=Arm() [315] */
    if (!ABSORBED && _particle->_index == 315) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component PX2a_vfm_in_xz_plane [315] */
    /* begin component PX2a_vfm=Mirror_curved() [316] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_vfm_var._rotation_is_identity) {
        if(!_PX2a_vfm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_vfm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_vfm_var._position_relative, _PX2a_vfm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 316) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_vfm_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PX2a_vfm_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_vfm [316] */
    /* begin component PX2a_vfm_takeoff=Monitor_nD() [317] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_vfm_takeoff_var._rotation_is_identity) {
        if(!_PX2a_vfm_takeoff_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_vfm_takeoff_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_vfm_takeoff_var._position_relative, _PX2a_vfm_takeoff_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 317) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_vfm_takeoff_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX2a_vfm_takeoff_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_vfm_takeoff [317] */
    /* begin component PX2a_hfm_location=Monitor_nD() [318] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_hfm_location_var._rotation_is_identity) {
        if(!_PX2a_hfm_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hfm_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_hfm_location_var._position_relative, _PX2a_hfm_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 318) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_hfm_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX2a_hfm_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_hfm_location [318] */
    /* begin component PX2a_hfm=Mirror_curved() [319] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_hfm_var._rotation_is_identity) {
        if(!_PX2a_hfm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hfm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_hfm_var._position_relative, _PX2a_hfm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 319) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_hfm_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_PX2a_hfm_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_hfm [319] */
    /* begin component PX2a_hfm_takeoff=Monitor_nD() [320] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_hfm_takeoff_var._rotation_is_identity) {
        if(!_PX2a_hfm_takeoff_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hfm_takeoff_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_hfm_takeoff_var._position_relative, _PX2a_hfm_takeoff_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 320) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_hfm_takeoff_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX2a_hfm_takeoff_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_hfm_takeoff [320] */
    /* begin component PX2a_sample_stage=Arm() [321] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_sample_stage_var._rotation_is_identity) {
        if(!_PX2a_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_sample_stage_var._position_relative, _PX2a_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 321) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_sample_stage_var._name);
      DEBUG_STATE();
      class_Arm_trace(&_PX2a_sample_stage_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_sample_stage [321] */
    /* begin component PX2a_sample_monitor=Monitor_nD() [322] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_sample_monitor_var._rotation_is_identity) {
        if(!_PX2a_sample_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_sample_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_sample_monitor_var._position_relative, _PX2a_sample_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 322) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_sample_monitor_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_PX2a_sample_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_sample_monitor [322] */
#ifndef NOSPLIT
    /* start SPLIT at PX2a_sample */
    if (!ABSORBED) {
    _class_particle Split_PX2a_sample_particle=*_particle;
    int Split_PX2a_sample_counter;
    int SplitS_PX2a_sample = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_PX2a_sample_counter = 0; Split_PX2a_sample_counter< SplitS_PX2a_sample; Split_PX2a_sample_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_PX2a_sample_randstate_idx = 0; Split_PX2a_sample_randstate_idx < RANDSTATE_LEN; Split_PX2a_sample_randstate_idx++) {
        randbackup[Split_PX2a_sample_randstate_idx] = _particle->randstate[Split_PX2a_sample_randstate_idx];
      }
      *_particle=Split_PX2a_sample_particle;
      for (int Split_PX2a_sample_randstate_idx = 0; Split_PX2a_sample_randstate_idx < RANDSTATE_LEN; Split_PX2a_sample_randstate_idx++) {
        _particle->randstate[Split_PX2a_sample_randstate_idx] = randbackup[Split_PX2a_sample_randstate_idx];
      }
      p /= SplitS_PX2a_sample > 0 ? SplitS_PX2a_sample : 1;
#endif
    /* begin component PX2a_sample=Single_crystal() [323] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_sample_var._rotation_is_identity) {
        if(!_PX2a_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_sample_var._position_relative, _PX2a_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 323) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_sample_var._name);
      DEBUG_STATE();
      class_Single_crystal_trace(&_PX2a_sample_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_sample [323] */
    /* begin component PX2a_psd4pi=PSD_monitor_4PI() [324] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_psd4pi_var._rotation_is_identity) {
        if(!_PX2a_psd4pi_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_psd4pi_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_psd4pi_var._position_relative, _PX2a_psd4pi_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 324) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_psd4pi_var._name);
      DEBUG_STATE();
      class_PSD_monitor_4PI_trace(&_PX2a_psd4pi_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_psd4pi [324] */
    /* begin component PX2a_Eiger9M=PSD_monitor() [325] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_PX2a_Eiger9M_var._rotation_is_identity) {
        if(!_PX2a_Eiger9M_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _PX2a_Eiger9M_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_PX2a_Eiger9M_var._position_relative, _PX2a_Eiger9M_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 325) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_PX2a_Eiger9M_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_PX2a_Eiger9M_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component PX2a_Eiger9M [325] */
    /* begin component beamdump_335=Beamstop() [326] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_335_var._rotation_is_identity) {
        if(!_beamdump_335_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_335_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_335_var._position_relative, _beamdump_335_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 326) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_335_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_335_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_335 [326] */
    /* begin component SWING_pos=Text() [327] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_pos_var._rotation_is_identity) {
        if(!_SWING_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_pos_var._position_relative, _SWING_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 327) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_SWING_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_pos [327] */
    /* begin component SWING=Arm() [328] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_var._rotation_is_identity) {
        if(!_SWING_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_var._position_relative, _SWING_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 328) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING [328] */
    /* begin component SWING_Source_U20=Undulator() [329] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_Source_U20_var._rotation_is_identity) {
        if(!_SWING_Source_U20_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_Source_U20_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_Source_U20_var._position_relative, _SWING_Source_U20_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 329) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_Source_U20_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_SWING_Source_U20_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_Source_U20 [329] */
    /* begin component SWING_mon_src_xy=Monitor_nD() [330] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_mon_src_xy_var._rotation_is_identity) {
        if(!_SWING_mon_src_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_src_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_mon_src_xy_var._position_relative, _SWING_mon_src_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 330) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_mon_src_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_mon_src_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_mon_src_xy [330] */
    /* begin component SWING_mon_src_e=Monitor_nD() [331] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_mon_src_e_var._rotation_is_identity) {
        if(!_SWING_mon_src_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_src_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_mon_src_e_var._position_relative, _SWING_mon_src_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 331) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_mon_src_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_mon_src_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_mon_src_e [331] */
    /* begin component SWING_slit=Slit() [332] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_slit_var._rotation_is_identity) {
        if(!_SWING_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_slit_var._position_relative, _SWING_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 332) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_SWING_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_slit [332] */
    /* begin component SWING_slit_mon_xy=Monitor_nD() [333] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_slit_mon_xy_var._rotation_is_identity) {
        if(!_SWING_slit_mon_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_slit_mon_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_slit_mon_xy_var._position_relative, _SWING_slit_mon_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 333) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_slit_mon_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_slit_mon_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_slit_mon_xy [333] */
    /* begin component SWING_DCM_location=Arm() [334] */
    if (!ABSORBED && _particle->_index == 334) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SWING_DCM_location [334] */
    /* begin component SWING_dcm_xtal0=Bragg_crystal() [335] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_dcm_xtal0_var._rotation_is_identity) {
        if(!_SWING_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_dcm_xtal0_var._position_relative, _SWING_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 335) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_dcm_xtal0_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SWING_dcm_xtal0_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_dcm_xtal0 [335] */
    /* begin component SWING_dcm0=Arm() [336] */
    if (!ABSORBED && _particle->_index == 336) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SWING_dcm0 [336] */
    /* begin component SWING_dcm_xtal1=Bragg_crystal() [337] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_dcm_xtal1_var._rotation_is_identity) {
        if(!_SWING_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_dcm_xtal1_var._position_relative, _SWING_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 337) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_dcm_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SWING_dcm_xtal1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_dcm_xtal1 [337] */
    /* begin component SWING_dcm1=Arm() [338] */
    if (!ABSORBED && _particle->_index == 338) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SWING_dcm1 [338] */
    /* begin component SWING_mon_dcm_e=Monitor_nD() [339] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_mon_dcm_e_var._rotation_is_identity) {
        if(!_SWING_mon_dcm_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_dcm_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_mon_dcm_e_var._position_relative, _SWING_mon_dcm_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 339) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_mon_dcm_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_mon_dcm_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_mon_dcm_e [339] */
    /* begin component SWING_mon_dcm_xy=Monitor_nD() [340] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_mon_dcm_xy_var._rotation_is_identity) {
        if(!_SWING_mon_dcm_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_dcm_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_mon_dcm_xy_var._position_relative, _SWING_mon_dcm_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 340) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_mon_dcm_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_mon_dcm_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_mon_dcm_xy [340] */
    /* begin component SWING_vfm_location=Monitor_nD() [341] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_vfm_location_var._rotation_is_identity) {
        if(!_SWING_vfm_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_vfm_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_vfm_location_var._position_relative, _SWING_vfm_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 341) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_vfm_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_vfm_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_vfm_location [341] */
    /* begin component SWING_vfm_in_xz_plane=Arm() [342] */
    if (!ABSORBED && _particle->_index == 342) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SWING_vfm_in_xz_plane [342] */
    /* begin component SWING_vfm=Mirror_curved() [343] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_vfm_var._rotation_is_identity) {
        if(!_SWING_vfm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_vfm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_vfm_var._position_relative, _SWING_vfm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 343) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_vfm_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SWING_vfm_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_vfm [343] */
    /* begin component SWING_vfm_takeoff=Monitor_nD() [344] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_vfm_takeoff_var._rotation_is_identity) {
        if(!_SWING_vfm_takeoff_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_vfm_takeoff_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_vfm_takeoff_var._position_relative, _SWING_vfm_takeoff_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 344) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_vfm_takeoff_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_vfm_takeoff_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_vfm_takeoff [344] */
    /* begin component SWING_hfm_location=Monitor_nD() [345] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_hfm_location_var._rotation_is_identity) {
        if(!_SWING_hfm_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_hfm_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_hfm_location_var._position_relative, _SWING_hfm_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 345) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_hfm_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_hfm_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_hfm_location [345] */
    /* begin component SWING_hfm=Mirror_curved() [346] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_hfm_var._rotation_is_identity) {
        if(!_SWING_hfm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_hfm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_hfm_var._position_relative, _SWING_hfm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 346) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_hfm_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SWING_hfm_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_hfm [346] */
    /* begin component SWING_hfm_takeoff=Monitor_nD() [347] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_hfm_takeoff_var._rotation_is_identity) {
        if(!_SWING_hfm_takeoff_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_hfm_takeoff_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_hfm_takeoff_var._position_relative, _SWING_hfm_takeoff_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 347) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_hfm_takeoff_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_hfm_takeoff_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_hfm_takeoff [347] */
#ifndef NOSPLIT
    /* start SPLIT at SWING_sample_stage */
    if (!ABSORBED) {
    _class_particle Split_SWING_sample_stage_particle=*_particle;
    int Split_SWING_sample_stage_counter;
    int SplitS_SWING_sample_stage = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_SWING_sample_stage_counter = 0; Split_SWING_sample_stage_counter< SplitS_SWING_sample_stage; Split_SWING_sample_stage_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_SWING_sample_stage_randstate_idx = 0; Split_SWING_sample_stage_randstate_idx < RANDSTATE_LEN; Split_SWING_sample_stage_randstate_idx++) {
        randbackup[Split_SWING_sample_stage_randstate_idx] = _particle->randstate[Split_SWING_sample_stage_randstate_idx];
      }
      *_particle=Split_SWING_sample_stage_particle;
      for (int Split_SWING_sample_stage_randstate_idx = 0; Split_SWING_sample_stage_randstate_idx < RANDSTATE_LEN; Split_SWING_sample_stage_randstate_idx++) {
        _particle->randstate[Split_SWING_sample_stage_randstate_idx] = randbackup[Split_SWING_sample_stage_randstate_idx];
      }
      p /= SplitS_SWING_sample_stage > 0 ? SplitS_SWING_sample_stage : 1;
#endif
    /* begin component SWING_sample_stage=Monitor_nD() [348] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_sample_stage_var._rotation_is_identity) {
        if(!_SWING_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_sample_stage_var._position_relative, _SWING_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 348) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_sample_stage_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_sample_stage_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_sample_stage [348] */
    /* begin component SWING_sample_test=Saxs_spheres() [349] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_sample_test_var._rotation_is_identity) {
        if(!_SWING_sample_test_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_sample_test_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_sample_test_var._position_relative, _SWING_sample_test_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 349) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_sample_test_var._name);
      DEBUG_STATE();
      if ((( SWING_flag_sample_sphere ))) // conditional WHEN execution
      class_Saxs_spheres_trace(&_SWING_sample_test_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_sample_test [349] */
    /* begin component SWING_sample=SAXSPDBFast() [350] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_sample_var._rotation_is_identity) {
        if(!_SWING_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_sample_var._position_relative, _SWING_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 350) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_sample_var._name);
      DEBUG_STATE();
      if ((( ! SWING_flag_sample_sphere ))) // conditional WHEN execution
      class_SAXSPDBFast_trace(&_SWING_sample_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_sample [350] */
    /* begin component SWING_sample_out=Arm() [351] */
    if (!ABSORBED && _particle->_index == 351) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SWING_sample_out [351] */
    /* begin component SWING_Eiger4M=Monitor_nD() [352] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_Eiger4M_var._rotation_is_identity) {
        if(!_SWING_Eiger4M_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_Eiger4M_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_Eiger4M_var._position_relative, _SWING_Eiger4M_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 352) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_Eiger4M_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SWING_Eiger4M_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_Eiger4M [352] */
    /* begin component SWING_QMonitor=SAXSQMonitor() [353] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SWING_QMonitor_var._rotation_is_identity) {
        if(!_SWING_QMonitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SWING_QMonitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SWING_QMonitor_var._position_relative, _SWING_QMonitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 353) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SWING_QMonitor_var._name);
      DEBUG_STATE();
      class_SAXSQMonitor_trace(&_SWING_QMonitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SWING_QMonitor [353] */
    /* begin component beamdump_364=Beamstop() [354] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_364_var._rotation_is_identity) {
        if(!_beamdump_364_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_364_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_364_var._position_relative, _beamdump_364_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 354) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_364_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_364_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_364 [354] */
    /* begin component ANTARES_pos=Text() [355] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANTARES_pos_var._rotation_is_identity) {
        if(!_ANTARES_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANTARES_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANTARES_pos_var._position_relative, _ANTARES_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 355) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANTARES_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_ANTARES_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANTARES_pos [355] */
    /* begin component ROCK_pos=Text() [356] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_pos_var._rotation_is_identity) {
        if(!_ROCK_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_pos_var._position_relative, _ROCK_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 356) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_ROCK_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_pos [356] */
    /* begin component ROCK=Arm() [357] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_var._rotation_is_identity) {
        if(!_ROCK_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_var._position_relative, _ROCK_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 357) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK [357] */
    /* begin component ROCK_Source=Bending_magnet() [358] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_Source_var._rotation_is_identity) {
        if(!_ROCK_Source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_Source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_Source_var._position_relative, _ROCK_Source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 358) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_Source_var._name);
      DEBUG_STATE();
      class_Bending_magnet_trace(&_ROCK_Source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_Source [358] */
    /* begin component ROCK_slit1=Slit() [359] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit1_var._rotation_is_identity) {
        if(!_ROCK_slit1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit1_var._position_relative, _ROCK_slit1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 359) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit1_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_ROCK_slit1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit1 [359] */
    /* begin component ROCK_slit2=Slit() [360] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit2_var._rotation_is_identity) {
        if(!_ROCK_slit2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit2_var._position_relative, _ROCK_slit2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 360) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit2_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_ROCK_slit2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit2 [360] */
    /* begin component ROCK_mirror_m1=Mirror_toroid_pothole() [361] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_mirror_m1_var._rotation_is_identity) {
        if(!_ROCK_mirror_m1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_mirror_m1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_mirror_m1_var._position_relative, _ROCK_mirror_m1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 361) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_mirror_m1_var._name);
      DEBUG_STATE();
      class_Mirror_toroid_pothole_trace(&_ROCK_mirror_m1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_mirror_m1 [361] */
    /* begin component ROCK_mirror_m1_out=Arm() [362] */
    if (!ABSORBED && _particle->_index == 362) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ROCK_mirror_m1_out [362] */
    /* begin component ROCK_slit3_xy=PSD_monitor() [363] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit3_xy_var._rotation_is_identity) {
        if(!_ROCK_slit3_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit3_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit3_xy_var._position_relative, _ROCK_slit3_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 363) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit3_xy_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ROCK_slit3_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit3_xy [363] */
    /* begin component ROCK_slit3_div=Divergence_monitor() [364] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit3_div_var._rotation_is_identity) {
        if(!_ROCK_slit3_div_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit3_div_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit3_div_var._position_relative, _ROCK_slit3_div_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 364) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit3_div_var._name);
      DEBUG_STATE();
      class_Divergence_monitor_trace(&_ROCK_slit3_div_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit3_div [364] */
    /* begin component ROCK_slit3=Slit() [365] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit3_var._rotation_is_identity) {
        if(!_ROCK_slit3_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit3_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit3_var._position_relative, _ROCK_slit3_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 365) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit3_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_ROCK_slit3_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit3 [365] */
    /* begin component ROCK_mirror_m2a=Mirror() [366] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_mirror_m2a_var._rotation_is_identity) {
        if(!_ROCK_mirror_m2a_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_mirror_m2a_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_mirror_m2a_var._position_relative, _ROCK_mirror_m2a_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 366) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_mirror_m2a_var._name);
      DEBUG_STATE();
      class_Mirror_trace(&_ROCK_mirror_m2a_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_mirror_m2a [366] */
    /* begin component ROCK_mirror_m2a_out=Arm() [367] */
    if (!ABSORBED && _particle->_index == 367) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ROCK_mirror_m2a_out [367] */
    /* begin component ROCK_slit4_in=PSD_monitor() [368] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit4_in_var._rotation_is_identity) {
        if(!_ROCK_slit4_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit4_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit4_in_var._position_relative, _ROCK_slit4_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 368) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit4_in_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ROCK_slit4_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit4_in [368] */
    /* begin component ROCK_slit4=Slit() [369] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit4_var._rotation_is_identity) {
        if(!_ROCK_slit4_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit4_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit4_var._position_relative, _ROCK_slit4_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 369) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit4_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_ROCK_slit4_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit4 [369] */
    /* begin component ROCK_arm_crystal0=Arm() [370] */
    if (!ABSORBED && _particle->_index == 370) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ROCK_arm_crystal0 [370] */
    /* begin component ROCK_bragg_crystal=Bragg_crystal() [371] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_bragg_crystal_var._rotation_is_identity) {
        if(!_ROCK_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_bragg_crystal_var._position_relative, _ROCK_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 371) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_ROCK_bragg_crystal_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_bragg_crystal [371] */
    /* begin component ROCK_arm_crystal1=Arm() [372] */
    if (!ABSORBED && _particle->_index == 372) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ROCK_arm_crystal1 [372] */
    /* begin component ROCK_bragg_crystal_two=Bragg_crystal() [373] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_bragg_crystal_two_var._rotation_is_identity) {
        if(!_ROCK_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_bragg_crystal_two_var._position_relative, _ROCK_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 373) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_ROCK_bragg_crystal_two_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_bragg_crystal_two [373] */
    /* begin component ROCK_arm_crystal2=Arm() [374] */
    if (!ABSORBED && _particle->_index == 374) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ROCK_arm_crystal2 [374] */
    /* begin component ROCK_bragg_crystal_out=PSD_monitor() [375] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_bragg_crystal_out_var._rotation_is_identity) {
        if(!_ROCK_bragg_crystal_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_bragg_crystal_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_bragg_crystal_out_var._position_relative, _ROCK_bragg_crystal_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 375) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_bragg_crystal_out_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ROCK_bragg_crystal_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_bragg_crystal_out [375] */
    /* begin component ROCK_slit5=Slit() [376] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit5_var._rotation_is_identity) {
        if(!_ROCK_slit5_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit5_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit5_var._position_relative, _ROCK_slit5_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 376) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit5_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_ROCK_slit5_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit5 [376] */
    /* begin component ROCK_slit6=Slit() [377] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_slit6_var._rotation_is_identity) {
        if(!_ROCK_slit6_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit6_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_slit6_var._position_relative, _ROCK_slit6_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 377) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_slit6_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_ROCK_slit6_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_slit6 [377] */
    /* begin component ROCK_mirror_m2b=Mirror_curved() [378] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_mirror_m2b_var._rotation_is_identity) {
        if(!_ROCK_mirror_m2b_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_mirror_m2b_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_mirror_m2b_var._position_relative, _ROCK_mirror_m2b_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 378) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_mirror_m2b_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_ROCK_mirror_m2b_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_mirror_m2b [378] */
    /* begin component ROCK_mirror_m2b_out=Arm() [379] */
    if (!ABSORBED && _particle->_index == 379) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ROCK_mirror_m2b_out [379] */
    /* begin component ROCK_EnergyMonitor_before_sample=Monitor_nD() [380] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_EnergyMonitor_before_sample_var._rotation_is_identity) {
        if(!_ROCK_EnergyMonitor_before_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_EnergyMonitor_before_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_EnergyMonitor_before_sample_var._position_relative, _ROCK_EnergyMonitor_before_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 380) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_EnergyMonitor_before_sample_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_ROCK_EnergyMonitor_before_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_EnergyMonitor_before_sample [380] */
    /* begin component ROCK_e_repartition_after_m2b=Monitor_nD() [381] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_e_repartition_after_m2b_var._rotation_is_identity) {
        if(!_ROCK_e_repartition_after_m2b_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_e_repartition_after_m2b_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_e_repartition_after_m2b_var._position_relative, _ROCK_e_repartition_after_m2b_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 381) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_e_repartition_after_m2b_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_ROCK_e_repartition_after_m2b_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_e_repartition_after_m2b [381] */
    /* begin component ROCK_sample_in=PSD_monitor() [382] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_sample_in_var._rotation_is_identity) {
        if(!_ROCK_sample_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_sample_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_sample_in_var._position_relative, _ROCK_sample_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 382) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_sample_in_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ROCK_sample_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_sample_in [382] */
#ifndef NOSPLIT
    /* start SPLIT at ROCK_absorption_sample */
    if (!ABSORBED) {
    _class_particle Split_ROCK_absorption_sample_particle=*_particle;
    int Split_ROCK_absorption_sample_counter;
    int SplitS_ROCK_absorption_sample = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_ROCK_absorption_sample_counter = 0; Split_ROCK_absorption_sample_counter< SplitS_ROCK_absorption_sample; Split_ROCK_absorption_sample_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_ROCK_absorption_sample_randstate_idx = 0; Split_ROCK_absorption_sample_randstate_idx < RANDSTATE_LEN; Split_ROCK_absorption_sample_randstate_idx++) {
        randbackup[Split_ROCK_absorption_sample_randstate_idx] = _particle->randstate[Split_ROCK_absorption_sample_randstate_idx];
      }
      *_particle=Split_ROCK_absorption_sample_particle;
      for (int Split_ROCK_absorption_sample_randstate_idx = 0; Split_ROCK_absorption_sample_randstate_idx < RANDSTATE_LEN; Split_ROCK_absorption_sample_randstate_idx++) {
        _particle->randstate[Split_ROCK_absorption_sample_randstate_idx] = randbackup[Split_ROCK_absorption_sample_randstate_idx];
      }
      p /= SplitS_ROCK_absorption_sample > 0 ? SplitS_ROCK_absorption_sample : 1;
#endif
    /* begin component ROCK_absorption_sample=Fluorescence() [383] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_absorption_sample_var._rotation_is_identity) {
        if(!_ROCK_absorption_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_absorption_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_absorption_sample_var._position_relative, _ROCK_absorption_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 383) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_absorption_sample_var._name);
      DEBUG_STATE();
      class_Fluorescence_trace(&_ROCK_absorption_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_absorption_sample [383] */
    /* begin component ROCK_fluo_monitor=Monitor_nD() [384] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_fluo_monitor_var._rotation_is_identity) {
        if(!_ROCK_fluo_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_fluo_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_fluo_monitor_var._position_relative, _ROCK_fluo_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 384) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_fluo_monitor_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_ROCK_fluo_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_fluo_monitor [384] */
    /* begin component ROCK_EnergyMonitor_after_sample=Monitor_nD() [385] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_EnergyMonitor_after_sample_var._rotation_is_identity) {
        if(!_ROCK_EnergyMonitor_after_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_EnergyMonitor_after_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_EnergyMonitor_after_sample_var._position_relative, _ROCK_EnergyMonitor_after_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 385) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_EnergyMonitor_after_sample_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_ROCK_EnergyMonitor_after_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_EnergyMonitor_after_sample [385] */
    /* begin component ROCK_psd_monitor=PSD_monitor() [386] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ROCK_psd_monitor_var._rotation_is_identity) {
        if(!_ROCK_psd_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ROCK_psd_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ROCK_psd_monitor_var._position_relative, _ROCK_psd_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 386) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ROCK_psd_monitor_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ROCK_psd_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ROCK_psd_monitor [386] */
    /* begin component beamdump_398=Beamstop() [387] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_398_var._rotation_is_identity) {
        if(!_beamdump_398_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_398_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_398_var._position_relative, _beamdump_398_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 387) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_398_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_398_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_398 [387] */
    /* begin component ANATOMIX_pos=Text() [388] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_pos_var._rotation_is_identity) {
        if(!_ANATOMIX_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_pos_var._position_relative, _ANATOMIX_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 388) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_ANATOMIX_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_pos [388] */
    /* begin component ANATOMIX=Arm() [389] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_var._rotation_is_identity) {
        if(!_ANATOMIX_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_var._position_relative, _ANATOMIX_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 389) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX [389] */
    /* begin component ANATOMIX_source=Undulator() [390] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_source_var._rotation_is_identity) {
        if(!_ANATOMIX_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_source_var._position_relative, _ANATOMIX_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 390) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_source_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_ANATOMIX_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_source [390] */
    /* begin component ANATOMIX_e_repartition_before_cc=Monitor_nD() [391] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_e_repartition_before_cc_var._rotation_is_identity) {
        if(!_ANATOMIX_e_repartition_before_cc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_e_repartition_before_cc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_e_repartition_before_cc_var._position_relative, _ANATOMIX_e_repartition_before_cc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 391) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_e_repartition_before_cc_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_ANATOMIX_e_repartition_before_cc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_e_repartition_before_cc [391] */
    /* begin component ANATOMIX_psd_monitor_before_cc=PSD_monitor() [392] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_psd_monitor_before_cc_var._rotation_is_identity) {
        if(!_ANATOMIX_psd_monitor_before_cc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_monitor_before_cc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_psd_monitor_before_cc_var._position_relative, _ANATOMIX_psd_monitor_before_cc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 392) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_psd_monitor_before_cc_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ANATOMIX_psd_monitor_before_cc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_psd_monitor_before_cc [392] */
    /* begin component ANATOMIX_bragg_crystal=Bragg_crystal() [393] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_bragg_crystal_var._rotation_is_identity) {
        if(!_ANATOMIX_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_bragg_crystal_var._position_relative, _ANATOMIX_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 393) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_ANATOMIX_bragg_crystal_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_bragg_crystal [393] */
    /* begin component ANATOMIX_arm=Arm() [394] */
    if (!ABSORBED && _particle->_index == 394) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ANATOMIX_arm [394] */
    /* begin component ANATOMIX_bragg_crystal_two=Bragg_crystal() [395] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_bragg_crystal_two_var._rotation_is_identity) {
        if(!_ANATOMIX_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_bragg_crystal_two_var._position_relative, _ANATOMIX_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 395) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_ANATOMIX_bragg_crystal_two_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_bragg_crystal_two [395] */
    /* begin component ANATOMIX_arm_two=Arm() [396] */
    if (!ABSORBED && _particle->_index == 396) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ANATOMIX_arm_two [396] */
    /* begin component ANATOMIX_psd_after_cc=PSD_monitor() [397] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_psd_after_cc_var._rotation_is_identity) {
        if(!_ANATOMIX_psd_after_cc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_after_cc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_psd_after_cc_var._position_relative, _ANATOMIX_psd_after_cc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 397) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_psd_after_cc_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ANATOMIX_psd_after_cc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_psd_after_cc [397] */
    /* begin component ANATOMIX_e_monitor_before_sample=E_monitor() [398] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_e_monitor_before_sample_var._rotation_is_identity) {
        if(!_ANATOMIX_e_monitor_before_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_e_monitor_before_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_e_monitor_before_sample_var._position_relative, _ANATOMIX_e_monitor_before_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 398) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_e_monitor_before_sample_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_ANATOMIX_e_monitor_before_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_e_monitor_before_sample [398] */
    /* begin component ANATOMIX_psd_repartition_after_cc=PSD_monitor() [399] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_psd_repartition_after_cc_var._rotation_is_identity) {
        if(!_ANATOMIX_psd_repartition_after_cc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_repartition_after_cc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_psd_repartition_after_cc_var._position_relative, _ANATOMIX_psd_repartition_after_cc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 399) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_psd_repartition_after_cc_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ANATOMIX_psd_repartition_after_cc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_psd_repartition_after_cc [399] */
    /* begin component ANATOMIX_sample_rotation_stage=Arm() [400] */
    if (!ABSORBED && _particle->_index == 400) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component ANATOMIX_sample_rotation_stage [400] */
    /* begin component ANATOMIX_sample=Filter() [401] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_sample_var._rotation_is_identity) {
        if(!_ANATOMIX_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_sample_var._position_relative, _ANATOMIX_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 401) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_sample_var._name);
      DEBUG_STATE();
      class_Filter_trace(&_ANATOMIX_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_sample [401] */
    /* begin component ANATOMIX_e_monitor_after_sample=E_monitor() [402] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_e_monitor_after_sample_var._rotation_is_identity) {
        if(!_ANATOMIX_e_monitor_after_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_e_monitor_after_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_e_monitor_after_sample_var._position_relative, _ANATOMIX_e_monitor_after_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 402) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_e_monitor_after_sample_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_ANATOMIX_e_monitor_after_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_e_monitor_after_sample [402] */
    /* begin component ANATOMIX_psd_monitor_after_cc=PSD_monitor() [403] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_psd_monitor_after_cc_var._rotation_is_identity) {
        if(!_ANATOMIX_psd_monitor_after_cc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_monitor_after_cc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_psd_monitor_after_cc_var._position_relative, _ANATOMIX_psd_monitor_after_cc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 403) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_psd_monitor_after_cc_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_ANATOMIX_psd_monitor_after_cc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_psd_monitor_after_cc [403] */
    /* begin component beamdump_416=Beamstop() [404] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_416_var._rotation_is_identity) {
        if(!_beamdump_416_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_416_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_416_var._position_relative, _beamdump_416_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 404) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_416_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_416_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_416 [404] */
    /* begin component NANOSCOPIUM_pos=Text() [405] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANOSCOPIUM_pos_var._rotation_is_identity) {
        if(!_NANOSCOPIUM_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANOSCOPIUM_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANOSCOPIUM_pos_var._position_relative, _NANOSCOPIUM_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 405) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANOSCOPIUM_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_NANOSCOPIUM_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANOSCOPIUM_pos [405] */
    /* begin component NANOSCOPIUM=Arm() [406] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANOSCOPIUM_var._rotation_is_identity) {
        if(!_NANOSCOPIUM_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANOSCOPIUM_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANOSCOPIUM_var._position_relative, _NANOSCOPIUM_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 406) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANOSCOPIUM_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANOSCOPIUM [406] */
    /* begin component NANO_source=Undulator() [407] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_source_var._rotation_is_identity) {
        if(!_NANO_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_source_var._position_relative, _NANO_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 407) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_source_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_NANO_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_source [407] */
    /* begin component NANO_e_monitor_source=E_monitor() [408] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_e_monitor_source_var._rotation_is_identity) {
        if(!_NANO_e_monitor_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_e_monitor_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_e_monitor_source_var._position_relative, _NANO_e_monitor_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 408) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_e_monitor_source_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_NANO_e_monitor_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_e_monitor_source [408] */
    /* begin component NANO_psd_source=PSD_monitor_coh() [409] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_psd_source_var._rotation_is_identity) {
        if(!_NANO_psd_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_psd_source_var._position_relative, _NANO_psd_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 409) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_psd_source_var._name);
      DEBUG_STATE();
      class_PSD_monitor_coh_trace(&_NANO_psd_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_psd_source [409] */
    /* begin component NANO_slit_1=Slit() [410] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_slit_1_var._rotation_is_identity) {
        if(!_NANO_slit_1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_slit_1_var._position_relative, _NANO_slit_1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 410) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_slit_1_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_NANO_slit_1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_slit_1 [410] */
    /* begin component NANO_m1_in=Arm() [411] */
    if (!ABSORBED && _particle->_index == 411) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_m1_in [411] */
    /* begin component NANO_m1_roll=Arm() [412] */
    if (!ABSORBED && _particle->_index == 412) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_m1_roll [412] */
    /* begin component NANO_mirror_m1=Mirror_curved() [413] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_mirror_m1_var._rotation_is_identity) {
        if(!_NANO_mirror_m1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_mirror_m1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_mirror_m1_var._position_relative, _NANO_mirror_m1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 413) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_mirror_m1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_NANO_mirror_m1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_mirror_m1 [413] */
    /* begin component NANO_beam_deviation=Arm() [414] */
    if (!ABSORBED && _particle->_index == 414) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_beam_deviation [414] */
    /* begin component NANO_m2_in=Arm() [415] */
    if (!ABSORBED && _particle->_index == 415) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_m2_in [415] */
    /* begin component NANO_mirror_m2=Mirror_curved() [416] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_mirror_m2_var._rotation_is_identity) {
        if(!_NANO_mirror_m2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_mirror_m2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_mirror_m2_var._position_relative, _NANO_mirror_m2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 416) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_mirror_m2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_NANO_mirror_m2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_mirror_m2 [416] */
    /* begin component NANO_mirror_m2_out=Arm() [417] */
    if (!ABSORBED && _particle->_index == 417) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_mirror_m2_out [417] */
    /* begin component NANO_slit_2=Slit() [418] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_slit_2_var._rotation_is_identity) {
        if(!_NANO_slit_2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_slit_2_var._position_relative, _NANO_slit_2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 418) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_slit_2_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_NANO_slit_2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_slit_2 [418] */
    /* begin component NANO_dcm_in=Arm() [419] */
    if (!ABSORBED && _particle->_index == 419) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_dcm_in [419] */
    /* begin component NANO_PSD_dcm_in=PSD_monitor() [420] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_PSD_dcm_in_var._rotation_is_identity) {
        if(!_NANO_PSD_dcm_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_PSD_dcm_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_PSD_dcm_in_var._position_relative, _NANO_PSD_dcm_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 420) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_PSD_dcm_in_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_NANO_PSD_dcm_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_PSD_dcm_in [420] */
    /* begin component NANO_bragg_roll=Arm() [421] */
    if (!ABSORBED && _particle->_index == 421) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_bragg_roll [421] */
    /* begin component NANO_bragg_crystal_1=Bragg_crystal() [422] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_bragg_crystal_1_var._rotation_is_identity) {
        if(!_NANO_bragg_crystal_1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_bragg_crystal_1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_bragg_crystal_1_var._position_relative, _NANO_bragg_crystal_1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 422) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_bragg_crystal_1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_NANO_bragg_crystal_1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_bragg_crystal_1 [422] */
    /* begin component NANO_dcm2_rot=Arm() [423] */
    if (!ABSORBED && _particle->_index == 423) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_dcm2_rot [423] */
    /* begin component NANO_dcm_transl=Arm() [424] */
    if (!ABSORBED && _particle->_index == 424) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_dcm_transl [424] */
    /* begin component NANO_bragg_crystal_2=Bragg_crystal() [425] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_bragg_crystal_2_var._rotation_is_identity) {
        if(!_NANO_bragg_crystal_2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_bragg_crystal_2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_bragg_crystal_2_var._position_relative, _NANO_bragg_crystal_2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 425) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_bragg_crystal_2_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_NANO_bragg_crystal_2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_bragg_crystal_2 [425] */
    /* begin component NANO_bragg2_out=Arm() [426] */
    if (!ABSORBED && _particle->_index == 426) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_bragg2_out [426] */
    /* begin component NANO_dcm_out=Arm() [427] */
    if (!ABSORBED && _particle->_index == 427) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_dcm_out [427] */
    /* begin component NANO_e_dcm_out=E_monitor() [428] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_e_dcm_out_var._rotation_is_identity) {
        if(!_NANO_e_dcm_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_e_dcm_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_e_dcm_out_var._position_relative, _NANO_e_dcm_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 428) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_e_dcm_out_var._name);
      DEBUG_STATE();
      class_E_monitor_trace(&_NANO_e_dcm_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_e_dcm_out [428] */
    /* begin component NANO_secondary_source_slits=Arm() [429] */
    if (!ABSORBED && _particle->_index == 429) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_secondary_source_slits [429] */
    /* begin component NANO_psd_ss_in=PSD_monitor() [430] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_psd_ss_in_var._rotation_is_identity) {
        if(!_NANO_psd_ss_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_ss_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_psd_ss_in_var._position_relative, _NANO_psd_ss_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 430) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_psd_ss_in_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_NANO_psd_ss_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_psd_ss_in [430] */
    /* begin component NANO_slit_3=Slit() [431] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_slit_3_var._rotation_is_identity) {
        if(!_NANO_slit_3_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_3_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_slit_3_var._position_relative, _NANO_slit_3_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 431) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_slit_3_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_NANO_slit_3_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_slit_3 [431] */
    /* begin component NANO_psd_ss_out=PSD_monitor() [432] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_psd_ss_out_var._rotation_is_identity) {
        if(!_NANO_psd_ss_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_ss_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_psd_ss_out_var._position_relative, _NANO_psd_ss_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 432) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_psd_ss_out_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_NANO_psd_ss_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_psd_ss_out [432] */
    /* begin component NANO_jjxray2_slits=Arm() [433] */
    if (!ABSORBED && _particle->_index == 433) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_jjxray2_slits [433] */
    /* begin component NANO_slit_5=Slit() [434] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_slit_5_var._rotation_is_identity) {
        if(!_NANO_slit_5_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_5_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_slit_5_var._position_relative, _NANO_slit_5_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 434) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_slit_5_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_NANO_slit_5_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_slit_5 [434] */
    /* begin component NANO_kb_in=Arm() [435] */
    if (!ABSORBED && _particle->_index == 435) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_kb_in [435] */
    /* begin component NANO_kb_1=Mirror_curved() [436] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_kb_1_var._rotation_is_identity) {
        if(!_NANO_kb_1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_kb_1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_kb_1_var._position_relative, _NANO_kb_1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 436) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_kb_1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_NANO_kb_1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_kb_1 [436] */
    /* begin component NANO_kb_beam_deviation=Arm() [437] */
    if (!ABSORBED && _particle->_index == 437) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_kb_beam_deviation [437] */
    /* begin component NANO_kb1_out=Arm() [438] */
    if (!ABSORBED && _particle->_index == 438) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_kb1_out [438] */
    /* begin component NANO_kb2=Mirror_curved() [439] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_kb2_var._rotation_is_identity) {
        if(!_NANO_kb2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_kb2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_kb2_var._position_relative, _NANO_kb2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 439) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_kb2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_NANO_kb2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_kb2 [439] */
    /* begin component NANO_kb_out=Arm() [440] */
    if (!ABSORBED && _particle->_index == 440) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component NANO_kb_out [440] */
    /* begin component NANO_slit=Slit() [441] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_slit_var._rotation_is_identity) {
        if(!_NANO_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_slit_var._position_relative, _NANO_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 441) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_NANO_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_slit [441] */
    /* begin component NANO_psd_sample_stage=PSD_monitor() [442] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_NANO_psd_sample_stage_var._rotation_is_identity) {
        if(!_NANO_psd_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_NANO_psd_sample_stage_var._position_relative, _NANO_psd_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 442) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_NANO_psd_sample_stage_var._name);
      DEBUG_STATE();
      class_PSD_monitor_trace(&_NANO_psd_sample_stage_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component NANO_psd_sample_stage [442] */
    /* begin component beamdump_456=Beamstop() [443] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_456_var._rotation_is_identity) {
        if(!_beamdump_456_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_456_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_456_var._position_relative, _beamdump_456_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 443) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_456_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_456_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_456 [443] */
    /* begin component DIFFABS_pos=Text() [444] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_pos_var._rotation_is_identity) {
        if(!_DIFFABS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_pos_var._position_relative, _DIFFABS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 444) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_DIFFABS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_pos [444] */
    /* begin component DIFFABS=Arm() [445] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_var._rotation_is_identity) {
        if(!_DIFFABS_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_var._position_relative, _DIFFABS_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 445) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS [445] */
    /* begin component DIFFABS_BM_D13_1=Bending_magnet() [446] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_BM_D13_1_var._rotation_is_identity) {
        if(!_DIFFABS_BM_D13_1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_BM_D13_1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_BM_D13_1_var._position_relative, _DIFFABS_BM_D13_1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 446) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_BM_D13_1_var._name);
      DEBUG_STATE();
      class_Bending_magnet_trace(&_DIFFABS_BM_D13_1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_BM_D13_1 [446] */
    /* begin component DIFFABS_primary_slit=Slit() [447] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_primary_slit_var._rotation_is_identity) {
        if(!_DIFFABS_primary_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_primary_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_primary_slit_var._position_relative, _DIFFABS_primary_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 447) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_primary_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_DIFFABS_primary_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_primary_slit [447] */
    /* begin component DIFFABS_M1_location=Arm() [448] */
    if (!ABSORBED && _particle->_index == 448) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_M1_location [448] */
    /* begin component DIFFABS_M1_rotated=Arm() [449] */
    if (!ABSORBED && _particle->_index == 449) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_M1_rotated [449] */
    /* begin component DIFFABS_M1=Mirror_curved() [450] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_M1_var._rotation_is_identity) {
        if(!_DIFFABS_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_M1_var._position_relative, _DIFFABS_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 450) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_DIFFABS_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_M1 [450] */
    /* begin component DIFFABS_M1_out=Arm() [451] */
    if (!ABSORBED && _particle->_index == 451) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_M1_out [451] */
    /* begin component DIFFABS_DCM_slit_in=Slit() [452] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_slit_in_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_slit_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_slit_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_slit_in_var._position_relative, _DIFFABS_DCM_slit_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 452) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_slit_in_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_DIFFABS_DCM_slit_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_slit_in [452] */
    /* begin component DIFFABS_DCM_in=Monitor_nD() [453] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_in_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_in_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_in_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_in_var._position_relative, _DIFFABS_DCM_in_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 453) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_in_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_DCM_in_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_in [453] */
    /* begin component DIFFABS_DCM_in_div=Monitor_nD() [454] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_in_div_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_in_div_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_in_div_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_in_div_var._position_relative, _DIFFABS_DCM_in_div_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 454) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_in_div_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_DCM_in_div_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_in_div [454] */
    /* begin component DIFFABS_DCM_location=Arm() [455] */
    if (!ABSORBED && _particle->_index == 455) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_DCM_location [455] */
    /* begin component DIFFABS_bragg_crystal=Bragg_crystal() [456] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_bragg_crystal_var._rotation_is_identity) {
        if(!_DIFFABS_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_bragg_crystal_var._position_relative, _DIFFABS_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 456) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_DIFFABS_bragg_crystal_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_bragg_crystal [456] */
    /* begin component DIFFABS_arm_crystal1=Arm() [457] */
    if (!ABSORBED && _particle->_index == 457) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_arm_crystal1 [457] */
    /* begin component DIFFABS_bragg_crystal_two=Bragg_crystal() [458] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_bragg_crystal_two_var._rotation_is_identity) {
        if(!_DIFFABS_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_bragg_crystal_two_var._position_relative, _DIFFABS_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 458) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_DIFFABS_bragg_crystal_two_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_bragg_crystal_two [458] */
    /* begin component DIFFABS_arm_crystal2=Arm() [459] */
    if (!ABSORBED && _particle->_index == 459) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_arm_crystal2 [459] */
    /* begin component DIFFABS_DCM_out=Monitor_nD() [460] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_out_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_out_var._position_relative, _DIFFABS_DCM_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 460) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_out_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_DCM_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_out [460] */
    /* begin component DIFFABS_DCM_out_div=Monitor_nD() [461] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_out_div_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_out_div_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_out_div_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_out_div_var._position_relative, _DIFFABS_DCM_out_div_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 461) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_out_div_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_DCM_out_div_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_out_div [461] */
    /* begin component DIFFABS_DCM_out_e=Monitor_nD() [462] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_out_e_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_out_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_out_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_out_e_var._position_relative, _DIFFABS_DCM_out_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 462) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_out_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_DCM_out_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_out_e [462] */
    /* begin component DIFFABS_DCM_slit_out=Slit() [463] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_DCM_slit_out_var._rotation_is_identity) {
        if(!_DIFFABS_DCM_slit_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_slit_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_DCM_slit_out_var._position_relative, _DIFFABS_DCM_slit_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 463) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_DCM_slit_out_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_DIFFABS_DCM_slit_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_DCM_slit_out [463] */
    /* begin component DIFFABS_M2_location=Arm() [464] */
    if (!ABSORBED && _particle->_index == 464) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_M2_location [464] */
    /* begin component DIFFABS_M2_rotated=Arm() [465] */
    if (!ABSORBED && _particle->_index == 465) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_M2_rotated [465] */
    /* begin component DIFFABS_M2=Mirror_curved() [466] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_M2_var._rotation_is_identity) {
        if(!_DIFFABS_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_M2_var._position_relative, _DIFFABS_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 466) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_M2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_DIFFABS_M2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_M2 [466] */
    /* begin component DIFFABS_M2_out=Arm() [467] */
    if (!ABSORBED && _particle->_index == 467) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component DIFFABS_M2_out [467] */
    /* begin component DIFFABS_sample_stage=Monitor_nD() [468] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_sample_stage_var._rotation_is_identity) {
        if(!_DIFFABS_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_sample_stage_var._position_relative, _DIFFABS_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 468) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_sample_stage_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_sample_stage_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_sample_stage [468] */
#ifndef NOSPLIT
    /* start SPLIT at DIFFABS_fluo */
    if (!ABSORBED) {
    _class_particle Split_DIFFABS_fluo_particle=*_particle;
    int Split_DIFFABS_fluo_counter;
    int SplitS_DIFFABS_fluo = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_DIFFABS_fluo_counter = 0; Split_DIFFABS_fluo_counter< SplitS_DIFFABS_fluo; Split_DIFFABS_fluo_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_DIFFABS_fluo_randstate_idx = 0; Split_DIFFABS_fluo_randstate_idx < RANDSTATE_LEN; Split_DIFFABS_fluo_randstate_idx++) {
        randbackup[Split_DIFFABS_fluo_randstate_idx] = _particle->randstate[Split_DIFFABS_fluo_randstate_idx];
      }
      *_particle=Split_DIFFABS_fluo_particle;
      for (int Split_DIFFABS_fluo_randstate_idx = 0; Split_DIFFABS_fluo_randstate_idx < RANDSTATE_LEN; Split_DIFFABS_fluo_randstate_idx++) {
        _particle->randstate[Split_DIFFABS_fluo_randstate_idx] = randbackup[Split_DIFFABS_fluo_randstate_idx];
      }
      p /= SplitS_DIFFABS_fluo > 0 ? SplitS_DIFFABS_fluo : 1;
#endif
    /* begin component DIFFABS_fluo=FluoPowder() [469] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_fluo_var._rotation_is_identity) {
        if(!_DIFFABS_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_fluo_var._position_relative, _DIFFABS_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 469) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_fluo_var._name);
      DEBUG_STATE();
      class_FluoPowder_trace(&_DIFFABS_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_fluo [469] */
    /* begin component DIFFABS_fluo_monitor=Monitor_nD() [470] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_fluo_monitor_var._rotation_is_identity) {
        if(!_DIFFABS_fluo_monitor_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_fluo_monitor_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_fluo_monitor_var._position_relative, _DIFFABS_fluo_monitor_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 470) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_fluo_monitor_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_DIFFABS_fluo_monitor_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_fluo_monitor [470] */
    /* begin component DIFFABS_det_angle=Monitor_nD() [471] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_det_angle_var._rotation_is_identity) {
        if(!_DIFFABS_det_angle_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_det_angle_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_det_angle_var._position_relative, _DIFFABS_det_angle_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 471) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_det_angle_var._name);
      DEBUG_STATE();
      if ((( 0.75 * _instrument_var._parameters.DIFFABS_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_DIFFABS_det_angle_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_det_angle [471] */
    /* begin component DIFFABS_xpad=Monitor_nD() [472] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_DIFFABS_xpad_var._rotation_is_identity) {
        if(!_DIFFABS_xpad_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_xpad_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_DIFFABS_xpad_var._position_relative, _DIFFABS_xpad_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 472) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_DIFFABS_xpad_var._name);
      DEBUG_STATE();
      if ((( 0.75 * _instrument_var._parameters.DIFFABS_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_DIFFABS_xpad_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component DIFFABS_xpad [472] */
    /* begin component beamdump_487=Beamstop() [473] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_487_var._rotation_is_identity) {
        if(!_beamdump_487_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_487_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_487_var._position_relative, _beamdump_487_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 473) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_487_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_487_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_487 [473] */
    /* begin component SEXTANTS=Text() [474] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SEXTANTS_var._rotation_is_identity) {
        if(!_SEXTANTS_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SEXTANTS_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SEXTANTS_var._position_relative, _SEXTANTS_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 474) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SEXTANTS_var._name);
      DEBUG_STATE();
      class_Text_trace(&_SEXTANTS_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SEXTANTS [474] */
    /* begin component SIXS_pos=Text() [475] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_pos_var._rotation_is_identity) {
        if(!_SIXS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_pos_var._position_relative, _SIXS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 475) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_SIXS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_pos [475] */
    /* begin component SIXS=Arm() [476] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_var._rotation_is_identity) {
        if(!_SIXS_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_var._position_relative, _SIXS_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 476) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS [476] */
    /* begin component SIXS_Source_U20=Undulator() [477] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_Source_U20_var._rotation_is_identity) {
        if(!_SIXS_Source_U20_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_Source_U20_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_Source_U20_var._position_relative, _SIXS_Source_U20_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 477) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_Source_U20_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_SIXS_Source_U20_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_Source_U20 [477] */
    /* begin component SIXS_mon_src_xy=Monitor_nD() [478] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_mon_src_xy_var._rotation_is_identity) {
        if(!_SIXS_mon_src_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_src_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_mon_src_xy_var._position_relative, _SIXS_mon_src_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 478) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_mon_src_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_mon_src_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_mon_src_xy [478] */
    /* begin component SIXS_mon_src_e=Monitor_nD() [479] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_mon_src_e_var._rotation_is_identity) {
        if(!_SIXS_mon_src_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_src_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_mon_src_e_var._position_relative, _SIXS_mon_src_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 479) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_mon_src_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_mon_src_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_mon_src_e [479] */
    /* begin component SIXS_slit=Slit() [480] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_slit_var._rotation_is_identity) {
        if(!_SIXS_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_slit_var._position_relative, _SIXS_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 480) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_SIXS_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_slit [480] */
    /* begin component SIXS_slit_mon_xy=Monitor_nD() [481] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_slit_mon_xy_var._rotation_is_identity) {
        if(!_SIXS_slit_mon_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_slit_mon_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_slit_mon_xy_var._position_relative, _SIXS_slit_mon_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 481) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_slit_mon_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_slit_mon_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_slit_mon_xy [481] */
    /* begin component SIXS_DCM_location=Arm() [482] */
    if (!ABSORBED && _particle->_index == 482) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_DCM_location [482] */
    /* begin component SIXS_dcm_xtal0=Bragg_crystal() [483] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_dcm_xtal0_var._rotation_is_identity) {
        if(!_SIXS_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_dcm_xtal0_var._position_relative, _SIXS_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 483) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_dcm_xtal0_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SIXS_dcm_xtal0_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_dcm_xtal0 [483] */
    /* begin component SIXS_dcm0=Arm() [484] */
    if (!ABSORBED && _particle->_index == 484) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_dcm0 [484] */
    /* begin component SIXS_dcm_xtal1=Bragg_crystal() [485] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_dcm_xtal1_var._rotation_is_identity) {
        if(!_SIXS_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_dcm_xtal1_var._position_relative, _SIXS_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 485) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_dcm_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SIXS_dcm_xtal1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_dcm_xtal1 [485] */
    /* begin component SIXS_dcm1=Arm() [486] */
    if (!ABSORBED && _particle->_index == 486) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_dcm1 [486] */
    /* begin component SIXS_mon_dcm_e=Monitor_nD() [487] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_mon_dcm_e_var._rotation_is_identity) {
        if(!_SIXS_mon_dcm_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_dcm_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_mon_dcm_e_var._position_relative, _SIXS_mon_dcm_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 487) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_mon_dcm_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_mon_dcm_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_mon_dcm_e [487] */
    /* begin component SIXS_mon_dcm_xy=Monitor_nD() [488] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_mon_dcm_xy_var._rotation_is_identity) {
        if(!_SIXS_mon_dcm_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_dcm_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_mon_dcm_xy_var._position_relative, _SIXS_mon_dcm_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 488) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_mon_dcm_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_mon_dcm_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_mon_dcm_xy [488] */
    /* begin component SIXS_M1_location=Arm() [489] */
    if (!ABSORBED && _particle->_index == 489) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_M1_location [489] */
    /* begin component SIXS_M1_rotated=Arm() [490] */
    if (!ABSORBED && _particle->_index == 490) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_M1_rotated [490] */
    /* begin component SIXS_M1=Mirror_curved() [491] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_M1_var._rotation_is_identity) {
        if(!_SIXS_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_M1_var._position_relative, _SIXS_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 491) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SIXS_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_M1 [491] */
    /* begin component SIXS_M1_out=Arm() [492] */
    if (!ABSORBED && _particle->_index == 492) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_M1_out [492] */
    /* begin component SIXS_M2_location=Arm() [493] */
    if (!ABSORBED && _particle->_index == 493) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_M2_location [493] */
    /* begin component SIXS_M2_rotated=Arm() [494] */
    if (!ABSORBED && _particle->_index == 494) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_M2_rotated [494] */
    /* begin component SIXS_M2=Mirror_curved() [495] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_M2_var._rotation_is_identity) {
        if(!_SIXS_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_M2_var._position_relative, _SIXS_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 495) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_M2_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SIXS_M2_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_M2 [495] */
    /* begin component SIXS_M2_out=Arm() [496] */
    if (!ABSORBED && _particle->_index == 496) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIXS_M2_out [496] */
#ifndef NOSPLIT
    /* start SPLIT at SIXS_sample_stage */
    if (!ABSORBED) {
    _class_particle Split_SIXS_sample_stage_particle=*_particle;
    int Split_SIXS_sample_stage_counter;
    int SplitS_SIXS_sample_stage = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_SIXS_sample_stage_counter = 0; Split_SIXS_sample_stage_counter< SplitS_SIXS_sample_stage; Split_SIXS_sample_stage_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_SIXS_sample_stage_randstate_idx = 0; Split_SIXS_sample_stage_randstate_idx < RANDSTATE_LEN; Split_SIXS_sample_stage_randstate_idx++) {
        randbackup[Split_SIXS_sample_stage_randstate_idx] = _particle->randstate[Split_SIXS_sample_stage_randstate_idx];
      }
      *_particle=Split_SIXS_sample_stage_particle;
      for (int Split_SIXS_sample_stage_randstate_idx = 0; Split_SIXS_sample_stage_randstate_idx < RANDSTATE_LEN; Split_SIXS_sample_stage_randstate_idx++) {
        _particle->randstate[Split_SIXS_sample_stage_randstate_idx] = randbackup[Split_SIXS_sample_stage_randstate_idx];
      }
      p /= SplitS_SIXS_sample_stage > 0 ? SplitS_SIXS_sample_stage : 1;
#endif
    /* begin component SIXS_sample_stage=Monitor_nD() [497] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_sample_stage_var._rotation_is_identity) {
        if(!_SIXS_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_sample_stage_var._position_relative, _SIXS_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 497) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_sample_stage_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_sample_stage_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_sample_stage [497] */
    /* begin component SIXS_sx_layer=Single_crystal() [498] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_sx_layer_var._rotation_is_identity) {
        if(!_SIXS_sx_layer_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sx_layer_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_sx_layer_var._position_relative, _SIXS_sx_layer_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 498) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_sx_layer_var._name);
      DEBUG_STATE();
      if ((_instrument_var._parameters.SIXS_sample_thickness > 0)) // conditional WHEN execution
      class_Single_crystal_trace(&_SIXS_sx_layer_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_sx_layer [498] */
    /* begin component SIXS_sx_bulk=Single_crystal() [499] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_sx_bulk_var._rotation_is_identity) {
        if(!_SIXS_sx_bulk_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sx_bulk_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_sx_bulk_var._position_relative, _SIXS_sx_bulk_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 499) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_sx_bulk_var._name);
      DEBUG_STATE();
      class_Single_crystal_trace(&_SIXS_sx_bulk_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_sx_bulk [499] */
    /* begin component SIXS_sample_out=Arm() [500] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_sample_out_var._rotation_is_identity) {
        if(!_SIXS_sample_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sample_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_sample_out_var._position_relative, _SIXS_sample_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 500) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_sample_out_var._name);
      DEBUG_STATE();
      class_Arm_trace(&_SIXS_sample_out_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_sample_out [500] */
    /* begin component SIXS_det4pi=Monitor_nD() [501] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_det4pi_var._rotation_is_identity) {
        if(!_SIXS_det4pi_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_det4pi_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_det4pi_var._position_relative, _SIXS_det4pi_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 501) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_det4pi_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIXS_det4pi_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_det4pi [501] */
    /* begin component SIXS_detector_layer=Monitor_nD() [502] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_detector_layer_var._rotation_is_identity) {
        if(!_SIXS_detector_layer_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_detector_layer_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_detector_layer_var._position_relative, _SIXS_detector_layer_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 502) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_detector_layer_var._name);
      DEBUG_STATE();
      if ((( SIXS_flag_scatt == 1 || SIXS_flag_scatt == 3 ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_SIXS_detector_layer_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_detector_layer [502] */
    /* begin component SIXS_detector_bulk=Monitor_nD() [503] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIXS_detector_bulk_var._rotation_is_identity) {
        if(!_SIXS_detector_bulk_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIXS_detector_bulk_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIXS_detector_bulk_var._position_relative, _SIXS_detector_bulk_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 503) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIXS_detector_bulk_var._name);
      DEBUG_STATE();
      if ((( SIXS_flag_scatt > 1 ))) // conditional WHEN execution
      class_Monitor_nD_trace(&_SIXS_detector_bulk_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIXS_detector_bulk [503] */
    /* begin component beamdump_519=Beamstop() [504] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_519_var._rotation_is_identity) {
        if(!_beamdump_519_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_519_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_519_var._position_relative, _beamdump_519_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 504) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_519_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_519_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_519 [504] */
    /* begin component CASSIOPEE_pos=Text() [505] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_pos_var._rotation_is_identity) {
        if(!_CASSIOPEE_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_pos_var._position_relative, _CASSIOPEE_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 505) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_CASSIOPEE_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_pos [505] */
    /* begin component CASSIOPEE=Arm() [506] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_var._rotation_is_identity) {
        if(!_CASSIOPEE_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_var._position_relative, _CASSIOPEE_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 506) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE [506] */
    /* begin component CASSIOPEE_Source_HU60=Undulator() [507] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_Source_HU60_var._rotation_is_identity) {
        if(!_CASSIOPEE_Source_HU60_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_Source_HU60_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_Source_HU60_var._position_relative, _CASSIOPEE_Source_HU60_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 507) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_Source_HU60_var._name);
      DEBUG_STATE();
      if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 1)) // conditional WHEN execution
      class_Undulator_trace(&_CASSIOPEE_Source_HU60_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_Source_HU60 [507] */
    /* begin component CASSIOPEE_Source_HU256=Undulator() [508] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_Source_HU256_var._rotation_is_identity) {
        if(!_CASSIOPEE_Source_HU256_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_Source_HU256_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_Source_HU256_var._position_relative, _CASSIOPEE_Source_HU256_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 508) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_Source_HU256_var._name);
      DEBUG_STATE();
      if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 2)) // conditional WHEN execution
      class_Undulator_trace(&_CASSIOPEE_Source_HU256_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_Source_HU256 [508] */
    /* begin component CASSIOPEE_M1a_location=Arm() [509] */
    if (!ABSORBED && _particle->_index == 509) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CASSIOPEE_M1a_location [509] */
    /* begin component CASSIOPEE_M1a=Mirror_curved() [510] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_M1a_var._rotation_is_identity) {
        if(!_CASSIOPEE_M1a_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M1a_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_M1a_var._position_relative, _CASSIOPEE_M1a_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 510) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_M1a_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_CASSIOPEE_M1a_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_M1a [510] */
    /* begin component CASSIOPEE_M1a_out=Arm() [511] */
    if (!ABSORBED && _particle->_index == 511) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CASSIOPEE_M1a_out [511] */
    /* begin component CASSIOPEE_M1b=Mirror_curved() [512] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_M1b_var._rotation_is_identity) {
        if(!_CASSIOPEE_M1b_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M1b_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_M1b_var._position_relative, _CASSIOPEE_M1b_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 512) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_M1b_var._name);
      DEBUG_STATE();
      if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 2)) // conditional WHEN execution
      class_Mirror_curved_trace(&_CASSIOPEE_M1b_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_M1b [512] */
    /* begin component CASSIOPEE_M1c=Mirror_curved() [513] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_M1c_var._rotation_is_identity) {
        if(!_CASSIOPEE_M1c_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M1c_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_M1c_var._position_relative, _CASSIOPEE_M1c_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 513) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_M1c_var._name);
      DEBUG_STATE();
      if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 1)) // conditional WHEN execution
      class_Mirror_curved_trace(&_CASSIOPEE_M1c_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_M1c [513] */
    /* begin component CASSIOPEE_M1bc_out=Arm() [514] */
    if (!ABSORBED && _particle->_index == 514) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CASSIOPEE_M1bc_out [514] */
    /* begin component CASSIOPEE_PSD_M1out=Monitor_nD() [515] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_PSD_M1out_var._rotation_is_identity) {
        if(!_CASSIOPEE_PSD_M1out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_PSD_M1out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_PSD_M1out_var._position_relative, _CASSIOPEE_PSD_M1out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 515) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_PSD_M1out_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_CASSIOPEE_PSD_M1out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_PSD_M1out [515] */
    /* begin component CASSIOPEE_PG_location=Arm() [516] */
    if (!ABSORBED && _particle->_index == 516) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CASSIOPEE_PG_location [516] */
    /* begin component CASSIOPEE_PG=Grating_reflect() [517] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_PG_var._rotation_is_identity) {
        if(!_CASSIOPEE_PG_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_PG_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_PG_var._position_relative, _CASSIOPEE_PG_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 517) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_PG_var._name);
      DEBUG_STATE();
      class_Grating_reflect_trace(&_CASSIOPEE_PG_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_PG [517] */
    /* begin component CASSIOPEE_M2_rotation_axis=Monitor_nD() [518] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_M2_rotation_axis_var._rotation_is_identity) {
        if(!_CASSIOPEE_M2_rotation_axis_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M2_rotation_axis_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_M2_rotation_axis_var._position_relative, _CASSIOPEE_M2_rotation_axis_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 518) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_M2_rotation_axis_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_CASSIOPEE_M2_rotation_axis_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_M2_rotation_axis [518] */
    /* begin component CASSIOPEE_M2=Mirror() [519] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_M2_var._rotation_is_identity) {
        if(!_CASSIOPEE_M2_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M2_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_M2_var._position_relative, _CASSIOPEE_M2_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 519) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_M2_var._name);
      DEBUG_STATE();
      class_Mirror_trace(&_CASSIOPEE_M2_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_M2 [519] */
    /* begin component CASSIOPEE_PM_takeoff=Arm() [520] */
    if (!ABSORBED && _particle->_index == 520) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component CASSIOPEE_PM_takeoff [520] */
    /* begin component CASSIOPEE_slit=Slit() [521] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_slit_var._rotation_is_identity) {
        if(!_CASSIOPEE_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_slit_var._position_relative, _CASSIOPEE_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 521) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_CASSIOPEE_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_slit [521] */
    /* begin component CASSIOPEE_M4=Mirror_curved() [522] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_M4_var._rotation_is_identity) {
        if(!_CASSIOPEE_M4_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M4_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_M4_var._position_relative, _CASSIOPEE_M4_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 522) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_M4_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_CASSIOPEE_M4_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_M4 [522] */
    /* begin component CASSIOPEE_PSD=Monitor_nD() [523] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_CASSIOPEE_PSD_var._rotation_is_identity) {
        if(!_CASSIOPEE_PSD_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_PSD_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_CASSIOPEE_PSD_var._position_relative, _CASSIOPEE_PSD_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 523) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_CASSIOPEE_PSD_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_CASSIOPEE_PSD_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component CASSIOPEE_PSD [523] */
    /* begin component beamdump_540=Beamstop() [524] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_540_var._rotation_is_identity) {
        if(!_beamdump_540_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_540_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_540_var._position_relative, _beamdump_540_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 524) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_540_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_540_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_540 [524] */
    /* begin component SIRIUS_pos=Text() [525] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_pos_var._rotation_is_identity) {
        if(!_SIRIUS_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_pos_var._position_relative, _SIRIUS_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 525) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_SIRIUS_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_pos [525] */
    /* begin component SIRIUS=Arm() [526] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_var._rotation_is_identity) {
        if(!_SIRIUS_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_var._position_relative, _SIRIUS_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 526) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS [526] */
    /* begin component SIRIUS_source=Bending_magnet() [527] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_source_var._rotation_is_identity) {
        if(!_SIRIUS_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_source_var._position_relative, _SIRIUS_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 527) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_source_var._name);
      DEBUG_STATE();
      class_Bending_magnet_trace(&_SIRIUS_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_source [527] */
    /* begin component SIRIUS_M1_loc=Monitor_nD() [528] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_M1_loc_var._rotation_is_identity) {
        if(!_SIRIUS_M1_loc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_M1_loc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_M1_loc_var._position_relative, _SIRIUS_M1_loc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 528) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_M1_loc_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_M1_loc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_M1_loc [528] */
    /* begin component SIRIUS_M1_rot=Arm() [529] */
    if (!ABSORBED && _particle->_index == 529) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIRIUS_M1_rot [529] */
    /* begin component SIRIUS_M1=Mirror_curved() [530] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_M1_var._rotation_is_identity) {
        if(!_SIRIUS_M1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_M1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_M1_var._position_relative, _SIRIUS_M1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 530) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_M1_var._name);
      DEBUG_STATE();
      class_Mirror_curved_trace(&_SIRIUS_M1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_M1 [530] */
    /* begin component SIRIUS_M1_out=Arm() [531] */
    if (!ABSORBED && _particle->_index == 531) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIRIUS_M1_out [531] */
    /* begin component SIRIUS_DCM_location=Monitor_nD() [532] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_DCM_location_var._rotation_is_identity) {
        if(!_SIRIUS_DCM_location_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_location_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_DCM_location_var._position_relative, _SIRIUS_DCM_location_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 532) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_DCM_location_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_DCM_location_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_DCM_location [532] */
    /* begin component SIRIUS_bragg_crystal=Bragg_crystal() [533] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_bragg_crystal_var._rotation_is_identity) {
        if(!_SIRIUS_bragg_crystal_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_bragg_crystal_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_bragg_crystal_var._position_relative, _SIRIUS_bragg_crystal_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 533) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_bragg_crystal_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SIRIUS_bragg_crystal_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_bragg_crystal [533] */
    /* begin component SIRIUS_arm_crystal1=Arm() [534] */
    if (!ABSORBED && _particle->_index == 534) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIRIUS_arm_crystal1 [534] */
    /* begin component SIRIUS_bragg_crystal_two=Bragg_crystal() [535] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_bragg_crystal_two_var._rotation_is_identity) {
        if(!_SIRIUS_bragg_crystal_two_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_bragg_crystal_two_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_bragg_crystal_two_var._position_relative, _SIRIUS_bragg_crystal_two_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 535) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_bragg_crystal_two_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_SIRIUS_bragg_crystal_two_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_bragg_crystal_two [535] */
    /* begin component SIRIUS_arm_crystal2=Arm() [536] */
    if (!ABSORBED && _particle->_index == 536) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIRIUS_arm_crystal2 [536] */
    /* begin component SIRIUS_DCM_out=Monitor_nD() [537] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_DCM_out_var._rotation_is_identity) {
        if(!_SIRIUS_DCM_out_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_out_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_DCM_out_var._position_relative, _SIRIUS_DCM_out_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 537) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_DCM_out_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_DCM_out_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_DCM_out [537] */
    /* begin component SIRIUS_DCM_out_div=Monitor_nD() [538] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_DCM_out_div_var._rotation_is_identity) {
        if(!_SIRIUS_DCM_out_div_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_out_div_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_DCM_out_div_var._position_relative, _SIRIUS_DCM_out_div_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 538) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_DCM_out_div_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_DCM_out_div_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_DCM_out_div [538] */
    /* begin component SIRIUS_DCM_out_e=Monitor_nD() [539] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_DCM_out_e_var._rotation_is_identity) {
        if(!_SIRIUS_DCM_out_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_out_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_DCM_out_e_var._position_relative, _SIRIUS_DCM_out_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 539) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_DCM_out_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_DCM_out_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_DCM_out_e [539] */
    /* begin component SIRIUS_def_loc=Monitor_nD() [540] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_def_loc_var._rotation_is_identity) {
        if(!_SIRIUS_def_loc_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_def_loc_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_def_loc_var._position_relative, _SIRIUS_def_loc_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 540) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_def_loc_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_def_loc_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_def_loc [540] */
    /* begin component SIRIUS_def_rot=Arm() [541] */
    if (!ABSORBED && _particle->_index == 541) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIRIUS_def_rot [541] */
    /* begin component SIRIUS_def_mirror=Mirror() [542] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_def_mirror_var._rotation_is_identity) {
        if(!_SIRIUS_def_mirror_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_def_mirror_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_def_mirror_var._position_relative, _SIRIUS_def_mirror_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 542) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_def_mirror_var._name);
      DEBUG_STATE();
      class_Mirror_trace(&_SIRIUS_def_mirror_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_def_mirror [542] */
    /* begin component SIRIUS_def_out=Arm() [543] */
    if (!ABSORBED && _particle->_index == 543) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component SIRIUS_def_out [543] */
    /* begin component SIRIUS_sample_stage=Monitor_nD() [544] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_sample_stage_var._rotation_is_identity) {
        if(!_SIRIUS_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_sample_stage_var._position_relative, _SIRIUS_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 544) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_sample_stage_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_sample_stage_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_sample_stage [544] */
#ifndef NOSPLIT
    /* start SPLIT at SIRIUS_fluo */
    if (!ABSORBED) {
    _class_particle Split_SIRIUS_fluo_particle=*_particle;
    int Split_SIRIUS_fluo_counter;
    int SplitS_SIRIUS_fluo = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_SIRIUS_fluo_counter = 0; Split_SIRIUS_fluo_counter< SplitS_SIRIUS_fluo; Split_SIRIUS_fluo_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_SIRIUS_fluo_randstate_idx = 0; Split_SIRIUS_fluo_randstate_idx < RANDSTATE_LEN; Split_SIRIUS_fluo_randstate_idx++) {
        randbackup[Split_SIRIUS_fluo_randstate_idx] = _particle->randstate[Split_SIRIUS_fluo_randstate_idx];
      }
      *_particle=Split_SIRIUS_fluo_particle;
      for (int Split_SIRIUS_fluo_randstate_idx = 0; Split_SIRIUS_fluo_randstate_idx < RANDSTATE_LEN; Split_SIRIUS_fluo_randstate_idx++) {
        _particle->randstate[Split_SIRIUS_fluo_randstate_idx] = randbackup[Split_SIRIUS_fluo_randstate_idx];
      }
      p /= SplitS_SIRIUS_fluo > 0 ? SplitS_SIRIUS_fluo : 1;
#endif
    /* begin component SIRIUS_fluo=FluoPowder() [545] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_fluo_var._rotation_is_identity) {
        if(!_SIRIUS_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_fluo_var._position_relative, _SIRIUS_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 545) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_fluo_var._name);
      DEBUG_STATE();
      class_FluoPowder_trace(&_SIRIUS_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_fluo [545] */
    /* begin component SIRIUS_det_2d=Monitor_nD() [546] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_det_2d_var._rotation_is_identity) {
        if(!_SIRIUS_det_2d_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_det_2d_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_det_2d_var._position_relative, _SIRIUS_det_2d_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 546) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_det_2d_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_det_2d_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_det_2d [546] */
    /* begin component SIRIUS_det_fluo=Monitor_nD() [547] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_SIRIUS_det_fluo_var._rotation_is_identity) {
        if(!_SIRIUS_det_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_det_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_SIRIUS_det_fluo_var._position_relative, _SIRIUS_det_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 547) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_SIRIUS_det_fluo_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_SIRIUS_det_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component SIRIUS_det_fluo [547] */
    /* begin component beamdump_565=Beamstop() [548] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_565_var._rotation_is_identity) {
        if(!_beamdump_565_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_565_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_565_var._position_relative, _beamdump_565_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 548) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_565_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_565_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_565 [548] */
    /* begin component LUCIA_pos=Text() [549] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_pos_var._rotation_is_identity) {
        if(!_LUCIA_pos_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_pos_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_pos_var._position_relative, _LUCIA_pos_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 549) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_pos_var._name);
      DEBUG_STATE();
      class_Text_trace(&_LUCIA_pos_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_pos [549] */
    /* begin component LUCIA=Arm() [550] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_var._rotation_is_identity) {
        if(!_LUCIA_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_var._position_relative, _LUCIA_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 550) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_var._name);
      DEBUG_STATE();
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA [550] */
    /* begin component LUCIA_source=Undulator() [551] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_source_var._rotation_is_identity) {
        if(!_LUCIA_source_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_source_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_source_var._position_relative, _LUCIA_source_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 551) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_source_var._name);
      DEBUG_STATE();
      class_Undulator_trace(&_LUCIA_source_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_source [551] */
    /* begin component LUCIA_mon_src_xy=Monitor_nD() [552] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_mon_src_xy_var._rotation_is_identity) {
        if(!_LUCIA_mon_src_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_src_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_mon_src_xy_var._position_relative, _LUCIA_mon_src_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 552) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_mon_src_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_mon_src_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_mon_src_xy [552] */
    /* begin component LUCIA_mon_src_e=Monitor_nD() [553] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_mon_src_e_var._rotation_is_identity) {
        if(!_LUCIA_mon_src_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_src_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_mon_src_e_var._position_relative, _LUCIA_mon_src_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 553) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_mon_src_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_mon_src_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_mon_src_e [553] */
    /* begin component LUCIA_slit=Slit() [554] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_slit_var._rotation_is_identity) {
        if(!_LUCIA_slit_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_slit_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_slit_var._position_relative, _LUCIA_slit_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 554) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_slit_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_LUCIA_slit_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_slit [554] */
    /* begin component LUCIA_slit_mon_xy=Monitor_nD() [555] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_slit_mon_xy_var._rotation_is_identity) {
        if(!_LUCIA_slit_mon_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_slit_mon_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_slit_mon_xy_var._position_relative, _LUCIA_slit_mon_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 555) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_slit_mon_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_slit_mon_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_slit_mon_xy [555] */
    /* begin component LUCIA_DCM_location=Arm() [556] */
    if (!ABSORBED && _particle->_index == 556) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component LUCIA_DCM_location [556] */
    /* begin component LUCIA_dcm_xtal0=Bragg_crystal() [557] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_dcm_xtal0_var._rotation_is_identity) {
        if(!_LUCIA_dcm_xtal0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_dcm_xtal0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_dcm_xtal0_var._position_relative, _LUCIA_dcm_xtal0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 557) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_dcm_xtal0_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_LUCIA_dcm_xtal0_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_dcm_xtal0 [557] */
    /* begin component LUCIA_dcm0=Arm() [558] */
    if (!ABSORBED && _particle->_index == 558) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component LUCIA_dcm0 [558] */
    /* begin component LUCIA_dcm_xtal1=Bragg_crystal() [559] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_dcm_xtal1_var._rotation_is_identity) {
        if(!_LUCIA_dcm_xtal1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_dcm_xtal1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_dcm_xtal1_var._position_relative, _LUCIA_dcm_xtal1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 559) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_dcm_xtal1_var._name);
      DEBUG_STATE();
      class_Bragg_crystal_trace(&_LUCIA_dcm_xtal1_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_dcm_xtal1 [559] */
    /* begin component LUCIA_dcm1=Arm() [560] */
    if (!ABSORBED && _particle->_index == 560) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component LUCIA_dcm1 [560] */
    /* begin component LUCIA_mon_dcm_e=Monitor_nD() [561] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_mon_dcm_e_var._rotation_is_identity) {
        if(!_LUCIA_mon_dcm_e_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_dcm_e_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_mon_dcm_e_var._position_relative, _LUCIA_mon_dcm_e_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 561) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_mon_dcm_e_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_mon_dcm_e_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_mon_dcm_e [561] */
    /* begin component LUCIA_mon_dcm_xy=Monitor_nD() [562] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_mon_dcm_xy_var._rotation_is_identity) {
        if(!_LUCIA_mon_dcm_xy_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_dcm_xy_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_mon_dcm_xy_var._position_relative, _LUCIA_mon_dcm_xy_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 562) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_mon_dcm_xy_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_mon_dcm_xy_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_mon_dcm_xy [562] */
    /* begin component LUCIA_diaphragm=Slit() [563] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_diaphragm_var._rotation_is_identity) {
        if(!_LUCIA_diaphragm_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_diaphragm_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_diaphragm_var._position_relative, _LUCIA_diaphragm_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 563) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_diaphragm_var._name);
      DEBUG_STATE();
      class_Slit_trace(&_LUCIA_diaphragm_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_diaphragm [563] */
    /* begin component LUCIA_sample_stage=Monitor_nD() [564] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_sample_stage_var._rotation_is_identity) {
        if(!_LUCIA_sample_stage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_sample_stage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_sample_stage_var._position_relative, _LUCIA_sample_stage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 564) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_sample_stage_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_sample_stage_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_sample_stage [564] */
    /* begin component LUCIA_fluo_rotated=Arm() [565] */
    if (!ABSORBED && _particle->_index == 565) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component LUCIA_fluo_rotated [565] */
#ifndef NOSPLIT
    /* start SPLIT at LUCIA_sample */
    if (!ABSORBED) {
    _class_particle Split_LUCIA_sample_particle=*_particle;
    int Split_LUCIA_sample_counter;
    int SplitS_LUCIA_sample = _instrument_var._parameters.splits;
    #pragma acc loop independent
    for (Split_LUCIA_sample_counter = 0; Split_LUCIA_sample_counter< SplitS_LUCIA_sample; Split_LUCIA_sample_counter++) {
      randstate_t randbackup[RANDSTATE_LEN];
      for (int Split_LUCIA_sample_randstate_idx = 0; Split_LUCIA_sample_randstate_idx < RANDSTATE_LEN; Split_LUCIA_sample_randstate_idx++) {
        randbackup[Split_LUCIA_sample_randstate_idx] = _particle->randstate[Split_LUCIA_sample_randstate_idx];
      }
      *_particle=Split_LUCIA_sample_particle;
      for (int Split_LUCIA_sample_randstate_idx = 0; Split_LUCIA_sample_randstate_idx < RANDSTATE_LEN; Split_LUCIA_sample_randstate_idx++) {
        _particle->randstate[Split_LUCIA_sample_randstate_idx] = randbackup[Split_LUCIA_sample_randstate_idx];
      }
      p /= SplitS_LUCIA_sample > 0 ? SplitS_LUCIA_sample : 1;
#endif
    /* begin component LUCIA_sample=Fluorescence() [566] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_sample_var._rotation_is_identity) {
        if(!_LUCIA_sample_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_sample_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_sample_var._position_relative, _LUCIA_sample_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 566) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_sample_var._name);
      DEBUG_STATE();
      class_Fluorescence_trace(&_LUCIA_sample_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_sample [566] */
    /* begin component LUCIA_transmission=Monitor_nD() [567] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_transmission_var._rotation_is_identity) {
        if(!_LUCIA_transmission_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_transmission_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_transmission_var._position_relative, _LUCIA_transmission_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 567) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_transmission_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_transmission_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_transmission [567] */
    /* begin component LUCIA_mon_spl_SDD=Fluo_detector() [568] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_mon_spl_SDD_var._rotation_is_identity) {
        if(!_LUCIA_mon_spl_SDD_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_spl_SDD_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_mon_spl_SDD_var._position_relative, _LUCIA_mon_spl_SDD_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 568) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_mon_spl_SDD_var._name);
      DEBUG_STATE();
      class_Fluo_detector_trace(&_LUCIA_mon_spl_SDD_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_mon_spl_SDD [568] */
    /* begin component LUCIA_mon_spl_fluo=Monitor_nD() [569] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_LUCIA_mon_spl_fluo_var._rotation_is_identity) {
        if(!_LUCIA_mon_spl_fluo_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_spl_fluo_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_LUCIA_mon_spl_fluo_var._position_relative, _LUCIA_mon_spl_fluo_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 569) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_LUCIA_mon_spl_fluo_var._name);
      DEBUG_STATE();
      class_Monitor_nD_trace(&_LUCIA_mon_spl_fluo_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component LUCIA_mon_spl_fluo [569] */
    /* begin component beamdump_588=Beamstop() [570] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_beamdump_588_var._rotation_is_identity) {
        if(!_beamdump_588_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _beamdump_588_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_beamdump_588_var._position_relative, _beamdump_588_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 570) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_beamdump_588_var._name);
      DEBUG_STATE();
      class_Beamstop_trace(&_beamdump_588_var, _particle); /* contains EXTEND code */
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component beamdump_588 [570] */
    /* begin component storage=Shape() [571] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_storage_var._rotation_is_identity) {
        if(!_storage_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _storage_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_storage_var._position_relative, _storage_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 571) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_storage_var._name);
      DEBUG_STATE();
      class_Shape_trace(&_storage_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component storage [571] */
    /* begin component hall0=Shape() [572] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_hall0_var._rotation_is_identity) {
        if(!_hall0_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _hall0_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_hall0_var._position_relative, _hall0_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 572) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_hall0_var._name);
      DEBUG_STATE();
      class_Shape_trace(&_hall0_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component hall0 [572] */
    /* begin component hall1=Shape() [573] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_hall1_var._rotation_is_identity) {
        if(!_hall1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _hall1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_hall1_var._position_relative, _hall1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 573) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_hall1_var._name);
      DEBUG_STATE();
      class_Shape_trace(&_hall1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component hall1 [573] */
    /* begin component entrance_0=Arm() [574] */
    if (!ABSORBED && _particle->_index == 574) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle->_index++;
    } /* end component entrance_0 [574] */
    /* begin component entrance_1=Shape() [575] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_entrance_1_var._rotation_is_identity) {
        if(!_entrance_1_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _entrance_1_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_entrance_1_var._position_relative, _entrance_1_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 575) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_entrance_1_var._name);
      DEBUG_STATE();
      class_Shape_trace(&_entrance_1_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component entrance_1 [575] */
    /* begin component ANATOMIX_building=Shape() [576] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_ANATOMIX_building_var._rotation_is_identity) {
        if(!_ANATOMIX_building_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_building_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_ANATOMIX_building_var._position_relative, _ANATOMIX_building_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 576) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_ANATOMIX_building_var._name);
      DEBUG_STATE();
      class_Shape_trace(&_ANATOMIX_building_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component ANATOMIX_building [576] */
    /* begin component soleil_label=Text() [577] */
    if (!_particle->flag_nocoordschange) { // flag activated by JUMP to pass coords change
      if (_soleil_label_var._rotation_is_identity) {
        if(!_soleil_label_var._position_relative_is_zero) {
          coords_get(coords_add(coords_set(x,y,z), _soleil_label_var._position_relative),&x, &y, &z);
        }
      } else {
          mccoordschange(_soleil_label_var._position_relative, _soleil_label_var._rotation_relative, _particle);
      }
    }
    if (!ABSORBED && _particle->_index == 577) {
      _particle->flag_nocoordschange=0; /* Reset if we came here from a JUMP */
      _particle_save = *_particle;
      DEBUG_COMP(_soleil_label_var._name);
      DEBUG_STATE();
      class_Text_trace(&_soleil_label_var, _particle);
      if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
      _particle->_index++;
      if (!ABSORBED) { DEBUG_STATE(); }
    } /* end component soleil_label [577] */
#ifndef NOSPLIT
    } /* end SPLIT at LUCIA_sample */
    } /* if (!ABSORBED) relating to SPLIT at LUCIA_sample */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at SIRIUS_fluo */
    } /* if (!ABSORBED) relating to SPLIT at SIRIUS_fluo */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at SIXS_sample_stage */
    } /* if (!ABSORBED) relating to SPLIT at SIXS_sample_stage */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at DIFFABS_fluo */
    } /* if (!ABSORBED) relating to SPLIT at DIFFABS_fluo */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at ROCK_absorption_sample */
    } /* if (!ABSORBED) relating to SPLIT at ROCK_absorption_sample */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at SWING_sample_stage */
    } /* if (!ABSORBED) relating to SPLIT at SWING_sample_stage */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at PX2a_sample */
    } /* if (!ABSORBED) relating to SPLIT at PX2a_sample */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at PX1_sample */
    } /* if (!ABSORBED) relating to SPLIT at PX1_sample */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at SAMBA_fluo */
    } /* if (!ABSORBED) relating to SPLIT at SAMBA_fluo */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at GALAXIES_sample */
    } /* if (!ABSORBED) relating to SPLIT at GALAXIES_sample */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at CRISTAL_fluo */
    } /* if (!ABSORBED) relating to SPLIT at CRISTAL_fluo */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at DISCO_reflective_grating */
    } /* if (!ABSORBED) relating to SPLIT at DISCO_reflective_grating */
#endif
#ifndef NOSPLIT
    } /* end SPLIT at MARS_Sample */
    } /* if (!ABSORBED) relating to SPLIT at MARS_Sample */
#endif
    if (_particle->_index > 577)
      ABSORBED++; /* absorbed when passed all components */
  } /* while !ABSORBED */

  DEBUG_LEAVE()
  particle_restore(_particle, &_particle_save);
  DEBUG_STATE()

  return(_particle->_index);
} /* raytrace */

/* loop to generate events and call raytrace() propagate them */
void raytrace_all(unsigned long long ncount, unsigned long seed) {

  // if on GPU and mcdotrace just exit
  #ifdef OPENACC
  if (!mcdotrace) {
  #endif

  /* CPU-loop */
  unsigned long long loops;
  loops = ceil((double)ncount/gpu_innerloop);
  /* if on GPU, printf has been globally nullified, re-enable here */
  #ifdef OPENACC
  #undef strlen
  #undef strcmp
  #undef exit
  #undef printf
  #undef sprintf
  #undef fprintf
  #endif

  #ifdef OPENACC
  if (ncount>gpu_innerloop) {
    printf("Defining %llu CPU loops around GPU kernel and adjusting ncount\n",loops);
    mcset_ncount(loops*gpu_innerloop);
  } else {
    #endif
    loops=1;
    gpu_innerloop = ncount;
    #ifdef OPENACC
  }
    #endif

  for (unsigned long long cloop=0; cloop<loops; cloop++) {
    #ifdef OPENACC
    if (loops>1) fprintf(stdout, "%d..", (int)cloop); fflush(stdout);
    #endif

    /* if on GPU, re-nullify printf */
     #ifdef OPENACC
     #undef strlen
     #undef strcmp
     #undef exit
     #undef printf
     #undef sprintf
     #undef fprintf
     #endif

    #pragma acc parallel loop num_gangs(numgangs) vector_length(vecsize)
    for (unsigned long pidx=0 ; pidx < gpu_innerloop ; pidx++) {
      _class_particle particleN = mcgenstate(); // initial particle
      _class_particle* _particle = &particleN;
      particleN._uid = cloop*gpu_innerloop + pidx;
      #ifdef USE_MPI
      particleN._uid += mpi_node_rank * loops*gpu_innerloop;
      #endif

      srandom(_hash(_hash(seed) + cloop*gpu_innerloop + pidx));

      raytrace(_particle);
    } /* inner for */
  } /* CPU for */
  /* if on GPU, printf has been globally nullified, re-enable here */
     #ifdef OPENACC
     #undef strlen
     #undef strcmp
     #undef exit
     #undef printf
     #undef sprintf
     #undef fprintf
     #endif
  MPI_MASTER(
  printf("*** TRACE end *** \n");
  );

  // if on GPU and mcdotrace just exit
  #ifdef OPENACC
  }
  #endif

} /* raytrace_all */

#endif //no-FUNNEL

#ifdef FUNNEL
// Alternative raytrace algorithm which iterates all particles through
// one component at the time, can remove absorbs from the next loop and
// switch between cpu/gpu.
void raytrace_all_funnel(unsigned long long ncount, unsigned long seed) {

  // if on GPU and mcdotrace just exit
  #ifdef OPENACC
  if (!mcdotrace) {
  #endif
  // set up outer (CPU) loop / particle batches
  unsigned long long loops;

  /* if on GPU, printf has been globally nullified, re-enable here */
   #ifdef OPENACC
   #undef strlen
   #undef strcmp
   #undef exit
   #undef printf
   #undef sprintf
   #undef fprintf
   #endif
printf("\nWARNING:\n --> JUMP found at COMPONENT 2, jumper\n");
printf(" --> JUMPS are not supported in FUNNEL mode and are ignored\n");
printf(" --> Your instrument may give different output with FUNNEL\n");
  #ifdef OPENACC
  loops = ceil((double)ncount/gpu_innerloop);
  if (ncount>gpu_innerloop) {
    printf("Defining %llu CPU loops around kernel and adjusting ncount\n",loops);
    mcset_ncount(loops*gpu_innerloop);
  } else {
  #endif
    loops=1;
    gpu_innerloop = ncount;
  #ifdef OPENACC
  }
  #endif

  // create particles struct and pointer arrays (same memory used by all batches)
  _class_particle* particles = malloc(gpu_innerloop*sizeof(_class_particle));
  _class_particle* pbuffer = malloc(gpu_innerloop*sizeof(_class_particle));
  if (!particles || !pbuffer) {
    fprintf(stderr, "Error: cannot allocate %ld particles (raytrace_all_funnel). Use a smaller --gpu_innerloop.\n", gpu_innerloop);
    exit(1);
  }
  long livebatchsize = gpu_innerloop;

  #undef ABSORB0
  #undef ABSORB
  #define ABSORB0 do { DEBUG_ABSORB(); MAGNET_OFF; ABSORBED++; } while(0)
  #define ABSORB ABSORB0
  // outer loop / particle batches
  for (unsigned long long cloop=0; cloop<loops; cloop++) {
    if (loops>1) fprintf(stdout, "%d..", (int)cloop); fflush(stdout);

    livebatchsize = gpu_innerloop; // a SPLIT in the previous batch may have changed it
    // init particles
    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      // generate particle state, set loop index and seed
      particles[pidx] = mcgenstate();
      _class_particle* _particle = particles + pidx;
      _particle->_uid = cloop*gpu_innerloop + pidx;
      #ifdef USE_MPI
      _particle->_uid += mpi_node_rank * loops*gpu_innerloop;
      #endif
      srandom(_hash(_hash(seed) + cloop*gpu_innerloop + pidx)); // _particle->state usage built into srandom macro
    }

    // iterate components

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // origin
    if (!ABSORBED && _particle->_index == 1) {
#ifndef MULTICORE
        if (_origin_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _origin_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_origin_var._position_relative, _origin_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Arm_trace(&_origin_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // jumper
    if (!ABSORBED && _particle->_index == 2) {
#ifndef MULTICORE
        if (_jumper_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _jumper_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_jumper_var._position_relative, _jumper_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // beamdump
    if (!ABSORBED && _particle->_index == 3) {
#ifndef MULTICORE
        if (_beamdump_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_var._position_relative, _beamdump_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ODE_pos
    if (!ABSORBED && _particle->_index == 4) {
#ifndef MULTICORE
        if (_ODE_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ODE_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ODE_pos_var._position_relative, _ODE_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_ODE_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SMIS_pos
    if (!ABSORBED && _particle->_index == 5) {
#ifndef MULTICORE
        if (_SMIS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SMIS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SMIS_pos_var._position_relative, _SMIS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_SMIS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // AILES_pos
    if (!ABSORBED && _particle->_index == 6) {
#ifndef MULTICORE
        if (_AILES_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _AILES_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_AILES_pos_var._position_relative, _AILES_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_AILES_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_pos
    if (!ABSORBED && _particle->_index == 7) {
#ifndef MULTICORE
        if (_MARS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_pos_var._position_relative, _MARS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_MARS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS
    if (!ABSORBED && _particle->_index == 8) {
#ifndef MULTICORE
        if (_MARS_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_var._position_relative, _MARS_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // MARS_Source
    if (!ABSORBED && _particle->_index == 9) {
#ifndef MULTICORE
        if (_MARS_Source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_Source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_Source_var._position_relative, _MARS_Source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bending_magnet_trace(&_MARS_Source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_displaySourceLength
    if (!ABSORBED && _particle->_index == 10) {
#ifndef MULTICORE
        if (_MARS_displaySourceLength_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_displaySourceLength_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_displaySourceLength_var._position_relative, _MARS_displaySourceLength_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_MARS_displaySourceLength_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_displaySource
    if (!ABSORBED && _particle->_index == 11) {
#ifndef MULTICORE
        if (_MARS_displaySource_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_displaySource_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_displaySource_var._position_relative, _MARS_displaySource_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_MARS_displaySource_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_slit1
    if (!ABSORBED && _particle->_index == 12) {
#ifndef MULTICORE
        if (_MARS_slit1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_slit1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_slit1_var._position_relative, _MARS_slit1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_MARS_slit1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_slit2
    if (!ABSORBED && _particle->_index == 13) {
#ifndef MULTICORE
        if (_MARS_slit2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_slit2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_slit2_var._position_relative, _MARS_slit2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_MARS_slit2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_M1_arm_translation
    if (!ABSORBED && _particle->_index == 14) {
        _particle->_index++;
      }

      // MARS_M1_arm_rotation_1
    if (!ABSORBED && _particle->_index == 15) {
        _particle->_index++;
      }

      // MARS_mirror_M1
    if (!ABSORBED && _particle->_index == 16) {
#ifndef MULTICORE
        if (_MARS_mirror_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_mirror_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_mirror_M1_var._position_relative, _MARS_mirror_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_MARS_mirror_M1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_M1_arm_rotation_2
    if (!ABSORBED && _particle->_index == 17) {
        _particle->_index++;
      }

      // MARS_M1_arm_rotation_2_undo
    if (!ABSORBED && _particle->_index == 18) {
        _particle->_index++;
      }

      // MARS_beam_arm_before_crystal
    if (!ABSORBED && _particle->_index == 19) {
        _particle->_index++;
      }

      // MARS_dcm_xtal0
    if (!ABSORBED && _particle->_index == 20) {
#ifndef MULTICORE
        if (_MARS_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_dcm_xtal0_var._position_relative, _MARS_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_MARS_dcm_xtal0_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_dcm0
    if (!ABSORBED && _particle->_index == 21) {
        _particle->_index++;
      }

      // MARS_dcm_xtal1
    if (!ABSORBED && _particle->_index == 22) {
#ifndef MULTICORE
        if (_MARS_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_dcm_xtal1_var._position_relative, _MARS_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_MARS_dcm_xtal1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_dcm1
    if (!ABSORBED && _particle->_index == 23) {
        _particle->_index++;
      }

      // MARS_emon_dcm0
    if (!ABSORBED && _particle->_index == 24) {
#ifndef MULTICORE
        if (_MARS_emon_dcm0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_emon_dcm0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_emon_dcm0_var._position_relative, _MARS_emon_dcm0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_MARS_emon_dcm0_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_displayMono
    if (!ABSORBED && _particle->_index == 25) {
#ifndef MULTICORE
        if (_MARS_displayMono_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_displayMono_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_displayMono_var._position_relative, _MARS_displayMono_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_MARS_displayMono_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_displayMonoLength
    if (!ABSORBED && _particle->_index == 26) {
#ifndef MULTICORE
        if (_MARS_displayMonoLength_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_displayMonoLength_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_displayMonoLength_var._position_relative, _MARS_displayMonoLength_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_MARS_displayMonoLength_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_M2_arm_translation
    if (!ABSORBED && _particle->_index == 27) {
        _particle->_index++;
      }

      // MARS_M2_arm_rotation_1
    if (!ABSORBED && _particle->_index == 28) {
        _particle->_index++;
      }

      // MARS_mirror_M2
    if (!ABSORBED && _particle->_index == 29) {
#ifndef MULTICORE
        if (_MARS_mirror_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_mirror_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_mirror_M2_var._position_relative, _MARS_mirror_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_MARS_mirror_M2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_M2_arm_rotation_2
    if (!ABSORBED && _particle->_index == 30) {
        _particle->_index++;
      }

      // MARS_M2_arm_rotation_2_undo
    if (!ABSORBED && _particle->_index == 31) {
        _particle->_index++;
      }

      // MARS_slitSecon1
    if (!ABSORBED && _particle->_index == 32) {
#ifndef MULTICORE
        if (_MARS_slitSecon1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_slitSecon1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_slitSecon1_var._position_relative, _MARS_slitSecon1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_MARS_slitSecon1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_slitSecon2
    if (!ABSORBED && _particle->_index == 33) {
#ifndef MULTICORE
        if (_MARS_slitSecon2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_slitSecon2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_slitSecon2_var._position_relative, _MARS_slitSecon2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_MARS_slitSecon2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_emon_dcm1
    if (!ABSORBED && _particle->_index == 34) {
#ifndef MULTICORE
        if (_MARS_emon_dcm1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_emon_dcm1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_emon_dcm1_var._position_relative, _MARS_emon_dcm1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_MARS_emon_dcm1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_displaySlit2
    if (!ABSORBED && _particle->_index == 35) {
#ifndef MULTICORE
        if (_MARS_displaySlit2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_displaySlit2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_displaySlit2_var._position_relative, _MARS_displaySlit2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_MARS_displaySlit2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_MARS_Sample;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_MARS_Sample);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // MARS_Sample
    if (!ABSORBED && _particle->_index == 36) {
#ifndef MULTICORE
        if (_MARS_Sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_Sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_Sample_var._position_relative, _MARS_Sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoPowder_trace(&_MARS_Sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // MARS_detector_diffraction
    if (!ABSORBED && _particle->_index == 37) {
#ifndef MULTICORE
        if (_MARS_detector_diffraction_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_detector_diffraction_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_detector_diffraction_var._position_relative, _MARS_detector_diffraction_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( 0.75 * _instrument_var._parameters.MARS_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN
        class_Monitor_nD_trace(&_MARS_detector_diffraction_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // MARS_detector_fluo
    if (!ABSORBED && _particle->_index == 38) {
#ifndef MULTICORE
        if (_MARS_detector_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _MARS_detector_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_MARS_detector_fluo_var._position_relative, _MARS_detector_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( K2E * sqrt ( kx * kx + ky * ky + kz * kz ) < 0.95 * _instrument_var._parameters.MARS_E0 ))) // conditional WHEN
        class_Monitor_nD_trace(&_MARS_detector_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_40
    if (!ABSORBED && _particle->_index == 39) {
#ifndef MULTICORE
        if (_beamdump_40_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_40_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_40_var._position_relative, _beamdump_40_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_40_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_pos
    if (!ABSORBED && _particle->_index == 40) {
#ifndef MULTICORE
        if (_PSICHE_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_pos_var._position_relative, _PSICHE_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_PSICHE_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE
    if (!ABSORBED && _particle->_index == 41) {
#ifndef MULTICORE
        if (_PSICHE_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_var._position_relative, _PSICHE_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // PSICHE_source
    if (!ABSORBED && _particle->_index == 42) {
#ifndef MULTICORE
        if (_PSICHE_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_source_var._position_relative, _PSICHE_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Wiggler_trace(&_PSICHE_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_mon_src_e
    if (!ABSORBED && _particle->_index == 43) {
#ifndef MULTICORE
        if (_PSICHE_mon_src_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_src_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_src_e_var._position_relative, _PSICHE_mon_src_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_src_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_mon_src_xy
    if (!ABSORBED && _particle->_index == 44) {
#ifndef MULTICORE
        if (_PSICHE_mon_src_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_src_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_src_xy_var._position_relative, _PSICHE_mon_src_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_src_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_DCM_location
    if (!ABSORBED && _particle->_index == 45) {
        _particle->_index++;
      }

      // PSICHE_dcm_xtal0
    if (!ABSORBED && _particle->_index == 46) {
#ifndef MULTICORE
        if (_PSICHE_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_dcm_xtal0_var._position_relative, _PSICHE_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( _instrument_var._parameters.PSICHE_DCM_present ))) // conditional WHEN
        class_Bragg_crystal_trace(&_PSICHE_dcm_xtal0_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_dcm0
    if (!ABSORBED && _particle->_index == 47) {
        _particle->_index++;
      }

      // PSICHE_dcm_xtal1
    if (!ABSORBED && _particle->_index == 48) {
#ifndef MULTICORE
        if (_PSICHE_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_dcm_xtal1_var._position_relative, _PSICHE_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( _instrument_var._parameters.PSICHE_DCM_present ))) // conditional WHEN
        class_Bragg_crystal_trace(&_PSICHE_dcm_xtal1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_dcm1
    if (!ABSORBED && _particle->_index == 49) {
        _particle->_index++;
      }

      // PSICHE_mon_dcm_e
    if (!ABSORBED && _particle->_index == 50) {
#ifndef MULTICORE
        if (_PSICHE_mon_dcm_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_dcm_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_dcm_e_var._position_relative, _PSICHE_mon_dcm_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_dcm_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_mon_dcm_xy
    if (!ABSORBED && _particle->_index == 51) {
#ifndef MULTICORE
        if (_PSICHE_mon_dcm_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_dcm_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_dcm_xy_var._position_relative, _PSICHE_mon_dcm_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_dcm_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_slit
    if (!ABSORBED && _particle->_index == 52) {
#ifndef MULTICORE
        if (_PSICHE_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_slit_var._position_relative, _PSICHE_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PSICHE_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_sample_stage
    if (!ABSORBED && _particle->_index == 53) {
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PSICHE_sample
    if (!ABSORBED && _particle->_index == 54) {
#ifndef MULTICORE
        if (_PSICHE_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_sample_var._position_relative, _PSICHE_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoPowder_trace(&_PSICHE_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PSICHE_fluo_holder
    if (!ABSORBED && _particle->_index == 55) {
        _particle->_index++;
      }

      // PSICHE_mon_spl_fluo
    if (!ABSORBED && _particle->_index == 56) {
#ifndef MULTICORE
        if (_PSICHE_mon_spl_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_spl_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_spl_fluo_var._position_relative, _PSICHE_mon_spl_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_spl_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_mon_spl_e
    if (!ABSORBED && _particle->_index == 57) {
#ifndef MULTICORE
        if (_PSICHE_mon_spl_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_spl_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_spl_e_var._position_relative, _PSICHE_mon_spl_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_spl_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PSICHE_mon_spl_xy
    if (!ABSORBED && _particle->_index == 58) {
#ifndef MULTICORE
        if (_PSICHE_mon_spl_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PSICHE_mon_spl_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PSICHE_mon_spl_xy_var._position_relative, _PSICHE_mon_spl_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PSICHE_mon_spl_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_61
    if (!ABSORBED && _particle->_index == 59) {
#ifndef MULTICORE
        if (_beamdump_61_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_61_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_61_var._position_relative, _beamdump_61_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_61_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PLEIADES_pos
    if (!ABSORBED && _particle->_index == 60) {
#ifndef MULTICORE
        if (_PLEIADES_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PLEIADES_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PLEIADES_pos_var._position_relative, _PLEIADES_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_PLEIADES_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_pos
    if (!ABSORBED && _particle->_index == 61) {
#ifndef MULTICORE
        if (_DISCO_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_pos_var._position_relative, _DISCO_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_DISCO_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO
    if (!ABSORBED && _particle->_index == 62) {
#ifndef MULTICORE
        if (_DISCO_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_var._position_relative, _DISCO_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // DISCO_Source
    if (!ABSORBED && _particle->_index == 63) {
#ifndef MULTICORE
        if (_DISCO_Source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_Source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_Source_var._position_relative, _DISCO_Source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bending_magnet_trace(&_DISCO_Source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_ColdFinger
    if (!ABSORBED && _particle->_index == 64) {
#ifndef MULTICORE
        if (_DISCO_ColdFinger_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_ColdFinger_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_ColdFinger_var._position_relative, _DISCO_ColdFinger_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mask_trace(&_DISCO_ColdFinger_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M1_location
    if (!ABSORBED && _particle->_index == 65) {
        _particle->_index++;
      }

      // DISCO_M1_rotated
    if (!ABSORBED && _particle->_index == 66) {
        _particle->_index++;
      }

      // DISCO_M1_x
    if (!ABSORBED && _particle->_index == 67) {
        _particle->_index++;
      }

      // DISCO_M1
    if (!ABSORBED && _particle->_index == 68) {
#ifndef MULTICORE
        if (_DISCO_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M1_var._position_relative, _DISCO_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_DISCO_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M1_takeoff
    if (!ABSORBED && _particle->_index == 69) {
        _particle->_index++;
      }

      // DISCO_M1_x_takeoff
    if (!ABSORBED && _particle->_index == 70) {
        _particle->_index++;
      }

      // DISCO_M2_location
    if (!ABSORBED && _particle->_index == 71) {
        _particle->_index++;
      }

      // DISCO_M2_rotated_x
    if (!ABSORBED && _particle->_index == 72) {
        _particle->_index++;
      }

      // DISCO_M2_rotated
    if (!ABSORBED && _particle->_index == 73) {
        _particle->_index++;
      }

      // DISCO_M2_other_side
    if (!ABSORBED && _particle->_index == 74) {
        _particle->_index++;
      }

      // DISCO_M2
    if (!ABSORBED && _particle->_index == 75) {
#ifndef MULTICORE
        if (_DISCO_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M2_var._position_relative, _DISCO_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_pothole_trace(&_DISCO_M2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M2_other_side_back
    if (!ABSORBED && _particle->_index == 76) {
        _particle->_index++;
      }

      // DISCO_M2_takeoff
    if (!ABSORBED && _particle->_index == 77) {
        _particle->_index++;
      }

      // DISCO_HFP_location
    if (!ABSORBED && _particle->_index == 78) {
        _particle->_index++;
      }

      // DISCO_HFP
    if (!ABSORBED && _particle->_index == 79) {
#ifndef MULTICORE
        if (_DISCO_HFP_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_HFP_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_HFP_var._position_relative, _DISCO_HFP_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_DISCO_HFP_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M3_arm
    if (!ABSORBED && _particle->_index == 80) {
        _particle->_index++;
      }

      // DISCO_M3
    if (!ABSORBED && _particle->_index == 81) {
#ifndef MULTICORE
        if (_DISCO_M3_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M3_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M3_var._position_relative, _DISCO_M3_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_DISCO_M3_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M3_takeoff
    if (!ABSORBED && _particle->_index == 82) {
        _particle->_index++;
      }

      // DISCO_M3_yz
    if (!ABSORBED && _particle->_index == 83) {
        _particle->_index++;
      }

      // DISCO_M4_yz
    if (!ABSORBED && _particle->_index == 84) {
        _particle->_index++;
      }

      // DISCO_M4
    if (!ABSORBED && _particle->_index == 85) {
#ifndef MULTICORE
        if (_DISCO_M4_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M4_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M4_var._position_relative, _DISCO_M4_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_trace(&_DISCO_M4_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M4_takeoff
    if (!ABSORBED && _particle->_index == 86) {
        _particle->_index++;
      }

      // DISCO_M4_arm_back
    if (!ABSORBED && _particle->_index == 87) {
        _particle->_index++;
      }

      // DISCO_VFP_location
    if (!ABSORBED && _particle->_index == 88) {
        _particle->_index++;
      }

      // DISCO_VFP
    if (!ABSORBED && _particle->_index == 89) {
#ifndef MULTICORE
        if (_DISCO_VFP_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_VFP_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_VFP_var._position_relative, _DISCO_VFP_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_DISCO_VFP_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M51_position
    if (!ABSORBED && _particle->_index == 90) {
        _particle->_index++;
      }

      // DISCO_M51_rotation
    if (!ABSORBED && _particle->_index == 91) {
        _particle->_index++;
      }

      // DISCO_M51
    if (!ABSORBED && _particle->_index == 92) {
#ifndef MULTICORE
        if (_DISCO_M51_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M51_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M51_var._position_relative, _DISCO_M51_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_elliptic_trace(&_DISCO_M51_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_arm
    if (!ABSORBED && _particle->_index == 93) {
        _particle->_index++;
      }

      // DISCO_M51_arm_back
    if (!ABSORBED && _particle->_index == 94) {
        _particle->_index++;
      }

      // DISCO_M52_position
    if (!ABSORBED && _particle->_index == 95) {
        _particle->_index++;
      }

      // DISCO_M52_x
    if (!ABSORBED && _particle->_index == 96) {
        _particle->_index++;
      }

      // DISCO_M52
    if (!ABSORBED && _particle->_index == 97) {
#ifndef MULTICORE
        if (_DISCO_M52_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M52_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M52_var._position_relative, _DISCO_M52_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_DISCO_M52_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M52_takeoff
    if (!ABSORBED && _particle->_index == 98) {
        _particle->_index++;
      }

      // DISCO_M52_x_takeoff
    if (!ABSORBED && _particle->_index == 99) {
        _particle->_index++;
      }

      // DISCO_second_HFP_location
    if (!ABSORBED && _particle->_index == 100) {
        _particle->_index++;
      }

      // DISCO_second_HFP
    if (!ABSORBED && _particle->_index == 101) {
#ifndef MULTICORE
        if (_DISCO_second_HFP_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_second_HFP_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_second_HFP_var._position_relative, _DISCO_second_HFP_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_DISCO_second_HFP_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M53_location
    if (!ABSORBED && _particle->_index == 102) {
        _particle->_index++;
      }

      // DISCO_M53_rotated
    if (!ABSORBED && _particle->_index == 103) {
        _particle->_index++;
      }

      // DISCO_M53
    if (!ABSORBED && _particle->_index == 104) {
#ifndef MULTICORE
        if (_DISCO_M53_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M53_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M53_var._position_relative, _DISCO_M53_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_pothole_trace(&_DISCO_M53_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M53_takeoff
    if (!ABSORBED && _particle->_index == 105) {
        _particle->_index++;
      }

      // DISCO_M54_location
    if (!ABSORBED && _particle->_index == 106) {
        _particle->_index++;
      }

      // DISCO_M54_rotated
    if (!ABSORBED && _particle->_index == 107) {
        _particle->_index++;
      }

      // DISCO_M54
    if (!ABSORBED && _particle->_index == 108) {
#ifndef MULTICORE
        if (_DISCO_M54_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_M54_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_M54_var._position_relative, _DISCO_M54_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_pothole_trace(&_DISCO_M54_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_M54_takeoff
    if (!ABSORBED && _particle->_index == 109) {
        _particle->_index++;
      }

      // DISCO_Mtoroids_arm_back
    if (!ABSORBED && _particle->_index == 110) {
        _particle->_index++;
      }

      // DISCO_M1_position
    if (!ABSORBED && _particle->_index == 111) {
        _particle->_index++;
      }

      // DISCO_M1_rotation
    if (!ABSORBED && _particle->_index == 112) {
        _particle->_index++;
      }

      // DISCO_mirror_m1
    if (!ABSORBED && _particle->_index == 113) {
#ifndef MULTICORE
        if (_DISCO_mirror_m1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_mirror_m1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_mirror_m1_var._position_relative, _DISCO_mirror_m1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_elliptic_trace(&_DISCO_mirror_m1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_armm
    if (!ABSORBED && _particle->_index == 114) {
        _particle->_index++;
      }

      // DISCO_M1_arm_back
    if (!ABSORBED && _particle->_index == 115) {
        _particle->_index++;
      }

      // DISCO_Grating_position
    if (!ABSORBED && _particle->_index == 116) {
        _particle->_index++;
      }

      // DISCO_Grating_rotation
    if (!ABSORBED && _particle->_index == 117) {
        _particle->_index++;
      }

      // DISCO_Grating_rotation_lines_grating
    if (!ABSORBED && _particle->_index == 118) {
        _particle->_index++;
      }

      // DISCO_Grating_rotation_nine_degrees
    if (!ABSORBED && _particle->_index == 119) {
        _particle->_index++;
      }
    }

    // SPLIT with available livebatchsize 
    long mult_DISCO_reflective_grating;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_DISCO_reflective_grating);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // DISCO_reflective_grating
    if (!ABSORBED && _particle->_index == 120) {
#ifndef MULTICORE
        if (_DISCO_reflective_grating_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_reflective_grating_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_reflective_grating_var._position_relative, _DISCO_reflective_grating_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Grating_reflect_trace(&_DISCO_reflective_grating_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_Grating_rotation_lines_grating_back
    if (!ABSORBED && _particle->_index == 121) {
        _particle->_index++;
      }

      // DISCO_Grating_arm_back
    if (!ABSORBED && _particle->_index == 122) {
        _particle->_index++;
      }

      // DISCO_Grating_arm_back_2
    if (!ABSORBED && _particle->_index == 123) {
        _particle->_index++;
      }

      // DISCO_Grating_arm_back_3
    if (!ABSORBED && _particle->_index == 124) {
        _particle->_index++;
      }

      // DISCO_M22_location
    if (!ABSORBED && _particle->_index == 125) {
        _particle->_index++;
      }

      // DISCO_M22_rotated
    if (!ABSORBED && _particle->_index == 126) {
        _particle->_index++;
      }

      // DISCO_mirror_m2
    if (!ABSORBED && _particle->_index == 127) {
#ifndef MULTICORE
        if (_DISCO_mirror_m2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_mirror_m2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_mirror_m2_var._position_relative, _DISCO_mirror_m2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_elliptic_trace(&_DISCO_mirror_m2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_arm2
    if (!ABSORBED && _particle->_index == 128) {
        _particle->_index++;
      }

      // DISCO_M44_arm_back
    if (!ABSORBED && _particle->_index == 129) {
        _particle->_index++;
      }

      // DISCO_arm3
    if (!ABSORBED && _particle->_index == 130) {
        _particle->_index++;
      }

      // DISCO_psd_before_slit
    if (!ABSORBED && _particle->_index == 131) {
#ifndef MULTICORE
        if (_DISCO_psd_before_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_psd_before_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_psd_before_slit_var._position_relative, _DISCO_psd_before_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_DISCO_psd_before_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_slit
    if (!ABSORBED && _particle->_index == 132) {
#ifndef MULTICORE
        if (_DISCO_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_slit_var._position_relative, _DISCO_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_DISCO_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_psd_monitor
    if (!ABSORBED && _particle->_index == 133) {
#ifndef MULTICORE
        if (_DISCO_psd_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_psd_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_psd_monitor_var._position_relative, _DISCO_psd_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_DISCO_psd_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_psd_giant_after_grating
    if (!ABSORBED && _particle->_index == 134) {
#ifndef MULTICORE
        if (_DISCO_psd_giant_after_grating_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_psd_giant_after_grating_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_psd_giant_after_grating_var._position_relative, _DISCO_psd_giant_after_grating_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_DISCO_psd_giant_after_grating_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_e_monitor
    if (!ABSORBED && _particle->_index == 135) {
#ifndef MULTICORE
        if (_DISCO_e_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_e_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_e_monitor_var._position_relative, _DISCO_e_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DISCO_e_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DISCO_w_monitor
    if (!ABSORBED && _particle->_index == 136) {
#ifndef MULTICORE
        if (_DISCO_w_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DISCO_w_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DISCO_w_monitor_var._position_relative, _DISCO_w_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DISCO_w_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_140
    if (!ABSORBED && _particle->_index == 137) {
#ifndef MULTICORE
        if (_beamdump_140_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_140_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_140_var._position_relative, _beamdump_140_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_140_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DESIRS_pos
    if (!ABSORBED && _particle->_index == 138) {
#ifndef MULTICORE
        if (_DESIRS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DESIRS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DESIRS_pos_var._position_relative, _DESIRS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_DESIRS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // METRO_pos
    if (!ABSORBED && _particle->_index == 139) {
#ifndef MULTICORE
        if (_METRO_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _METRO_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_METRO_pos_var._position_relative, _METRO_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_METRO_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_pos
    if (!ABSORBED && _particle->_index == 140) {
#ifndef MULTICORE
        if (_PUMA_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_pos_var._position_relative, _PUMA_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_PUMA_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA
    if (!ABSORBED && _particle->_index == 141) {
#ifndef MULTICORE
        if (_PUMA_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_var._position_relative, _PUMA_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // PUMA_Source
    if (!ABSORBED && _particle->_index == 142) {
#ifndef MULTICORE
        if (_PUMA_Source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_Source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_Source_var._position_relative, _PUMA_Source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Wiggler_trace(&_PUMA_Source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_slit1
    if (!ABSORBED && _particle->_index == 143) {
#ifndef MULTICORE
        if (_PUMA_slit1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_slit1_var._position_relative, _PUMA_slit1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PUMA_slit1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_slit2
    if (!ABSORBED && _particle->_index == 144) {
#ifndef MULTICORE
        if (_PUMA_slit2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_slit2_var._position_relative, _PUMA_slit2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PUMA_slit2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_mon_src_e
    if (!ABSORBED && _particle->_index == 145) {
#ifndef MULTICORE
        if (_PUMA_mon_src_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_src_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_src_e_var._position_relative, _PUMA_mon_src_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_PUMA_mon_src_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_mon_src_xy
    if (!ABSORBED && _particle->_index == 146) {
#ifndef MULTICORE
        if (_PUMA_mon_src_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_src_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_src_xy_var._position_relative, _PUMA_mon_src_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_src_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_HFM_location
    if (!ABSORBED && _particle->_index == 147) {
        _particle->_index++;
      }

      // PUMA_HFM_rotated
    if (!ABSORBED && _particle->_index == 148) {
        _particle->_index++;
      }

      // PUMA_mirror_HFM
    if (!ABSORBED && _particle->_index == 149) {
#ifndef MULTICORE
        if (_PUMA_mirror_HFM_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mirror_HFM_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mirror_HFM_var._position_relative, _PUMA_mirror_HFM_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PUMA_mirror_HFM_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_HFM_out
    if (!ABSORBED && _particle->_index == 150) {
        _particle->_index++;
      }

      // PUMA_mon_HFM_out_xy
    if (!ABSORBED && _particle->_index == 151) {
#ifndef MULTICORE
        if (_PUMA_mon_HFM_out_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_HFM_out_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_HFM_out_xy_var._position_relative, _PUMA_mon_HFM_out_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_HFM_out_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_DCM_location
    if (!ABSORBED && _particle->_index == 152) {
        _particle->_index++;
      }

      // PUMA_DCM_xtal1
    if (!ABSORBED && _particle->_index == 153) {
#ifndef MULTICORE
        if (_PUMA_DCM_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_DCM_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_DCM_xtal1_var._position_relative, _PUMA_DCM_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_PUMA_DCM_xtal1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_DCM_xtal1_out
    if (!ABSORBED && _particle->_index == 154) {
        _particle->_index++;
      }

      // PUMA_mon_DCM_xtal1_only_xy
    if (!ABSORBED && _particle->_index == 155) {
#ifndef MULTICORE
        if (_PUMA_mon_DCM_xtal1_only_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_DCM_xtal1_only_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_DCM_xtal1_only_xy_var._position_relative, _PUMA_mon_DCM_xtal1_only_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_DCM_xtal1_only_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_DCM_xtal2
    if (!ABSORBED && _particle->_index == 156) {
#ifndef MULTICORE
        if (_PUMA_DCM_xtal2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_DCM_xtal2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_DCM_xtal2_var._position_relative, _PUMA_DCM_xtal2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_PUMA_DCM_xtal2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_DCM_xtal2_out
    if (!ABSORBED && _particle->_index == 157) {
        _particle->_index++;
      }

      // PUMA_mon_DCM_out_e
    if (!ABSORBED && _particle->_index == 158) {
#ifndef MULTICORE
        if (_PUMA_mon_DCM_out_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_DCM_out_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_DCM_out_e_var._position_relative, _PUMA_mon_DCM_out_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_PUMA_mon_DCM_out_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_mon_DCM_out_xy
    if (!ABSORBED && _particle->_index == 159) {
#ifndef MULTICORE
        if (_PUMA_mon_DCM_out_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_DCM_out_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_DCM_out_xy_var._position_relative, _PUMA_mon_DCM_out_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_DCM_out_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_slit3
    if (!ABSORBED && _particle->_index == 160) {
#ifndef MULTICORE
        if (_PUMA_slit3_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit3_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_slit3_var._position_relative, _PUMA_slit3_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PUMA_slit3_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_slit4
    if (!ABSORBED && _particle->_index == 161) {
#ifndef MULTICORE
        if (_PUMA_slit4_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit4_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_slit4_var._position_relative, _PUMA_slit4_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PUMA_slit4_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_slit5
    if (!ABSORBED && _particle->_index == 162) {
#ifndef MULTICORE
        if (_PUMA_slit5_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_slit5_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_slit5_var._position_relative, _PUMA_slit5_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PUMA_slit5_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_KB_VFM_location
    if (!ABSORBED && _particle->_index == 163) {
        _particle->_index++;
      }

      // PUMA_mon_KB_in_xy
    if (!ABSORBED && _particle->_index == 164) {
#ifndef MULTICORE
        if (_PUMA_mon_KB_in_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_KB_in_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_KB_in_xy_var._position_relative, _PUMA_mon_KB_in_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_KB_in_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_KB_VFM_rotated
    if (!ABSORBED && _particle->_index == 165) {
        _particle->_index++;
      }

      // PUMA_mirror_KB_VFM
    if (!ABSORBED && _particle->_index == 166) {
#ifndef MULTICORE
        if (_PUMA_mirror_KB_VFM_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mirror_KB_VFM_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mirror_KB_VFM_var._position_relative, _PUMA_mirror_KB_VFM_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PUMA_mirror_KB_VFM_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_KB_VFM_out
    if (!ABSORBED && _particle->_index == 167) {
        _particle->_index++;
      }

      // PUMA_mon_KB_VFM_out_xy
    if (!ABSORBED && _particle->_index == 168) {
#ifndef MULTICORE
        if (_PUMA_mon_KB_VFM_out_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_KB_VFM_out_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_KB_VFM_out_xy_var._position_relative, _PUMA_mon_KB_VFM_out_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_KB_VFM_out_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_KB_HFM_location
    if (!ABSORBED && _particle->_index == 169) {
        _particle->_index++;
      }

      // PUMA_KB_HFM_rotated
    if (!ABSORBED && _particle->_index == 170) {
        _particle->_index++;
      }

      // PUMA_mirror_KB_HFM
    if (!ABSORBED && _particle->_index == 171) {
#ifndef MULTICORE
        if (_PUMA_mirror_KB_HFM_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mirror_KB_HFM_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mirror_KB_HFM_var._position_relative, _PUMA_mirror_KB_HFM_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PUMA_mirror_KB_HFM_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_KB_HFM_out
    if (!ABSORBED && _particle->_index == 172) {
        _particle->_index++;
      }

      // PUMA_mon_KB_HFM_out_xy
    if (!ABSORBED && _particle->_index == 173) {
#ifndef MULTICORE
        if (_PUMA_mon_KB_HFM_out_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_KB_HFM_out_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_KB_HFM_out_xy_var._position_relative, _PUMA_mon_KB_HFM_out_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_KB_HFM_out_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_sample_location
    if (!ABSORBED && _particle->_index == 174) {
        _particle->_index++;
      }

      // PUMA_mon_sample_xy
    if (!ABSORBED && _particle->_index == 175) {
#ifndef MULTICORE
        if (_PUMA_mon_sample_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_sample_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_sample_xy_var._position_relative, _PUMA_mon_sample_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PUMA_mon_sample_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PUMA_mon_sample_e
    if (!ABSORBED && _particle->_index == 176) {
#ifndef MULTICORE
        if (_PUMA_mon_sample_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PUMA_mon_sample_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PUMA_mon_sample_e_var._position_relative, _PUMA_mon_sample_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_PUMA_mon_sample_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_181
    if (!ABSORBED && _particle->_index == 177) {
#ifndef MULTICORE
        if (_beamdump_181_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_181_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_181_var._position_relative, _beamdump_181_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_181_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_pos
    if (!ABSORBED && _particle->_index == 178) {
#ifndef MULTICORE
        if (_CRISTAL_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_pos_var._position_relative, _CRISTAL_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_CRISTAL_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL
    if (!ABSORBED && _particle->_index == 179) {
#ifndef MULTICORE
        if (_CRISTAL_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_var._position_relative, _CRISTAL_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // CRISTAL_Source
    if (!ABSORBED && _particle->_index == 180) {
#ifndef MULTICORE
        if (_CRISTAL_Source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_Source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_Source_var._position_relative, _CRISTAL_Source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_CRISTAL_Source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // CRISTAL_slit1
    if (!ABSORBED && _particle->_index == 181) {
#ifndef MULTICORE
        if (_CRISTAL_slit1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_slit1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_slit1_var._position_relative, _CRISTAL_slit1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_CRISTAL_slit1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_dcm_location
    if (!ABSORBED && _particle->_index == 182) {
        _particle->_index++;
      }

      // CRISTAL_dcm_xtal0
    if (!ABSORBED && _particle->_index == 183) {
#ifndef MULTICORE
        if (_CRISTAL_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_dcm_xtal0_var._position_relative, _CRISTAL_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_CRISTAL_dcm_xtal0_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_arm_xtal0
    if (!ABSORBED && _particle->_index == 184) {
        _particle->_index++;
      }

      // CRISTAL_dcm_xtal1
    if (!ABSORBED && _particle->_index == 185) {
#ifndef MULTICORE
        if (_CRISTAL_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_dcm_xtal1_var._position_relative, _CRISTAL_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_CRISTAL_dcm_xtal1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_arm_xtal1
    if (!ABSORBED && _particle->_index == 186) {
        _particle->_index++;
      }

      // CRISTAL_emon_dcm
    if (!ABSORBED && _particle->_index == 187) {
#ifndef MULTICORE
        if (_CRISTAL_emon_dcm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_emon_dcm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_emon_dcm_var._position_relative, _CRISTAL_emon_dcm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_CRISTAL_emon_dcm_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_M1_location
    if (!ABSORBED && _particle->_index == 188) {
        _particle->_index++;
      }

      // CRISTAL_M1_rotated
    if (!ABSORBED && _particle->_index == 189) {
        _particle->_index++;
      }

      // CRISTAL_M1
    if (!ABSORBED && _particle->_index == 190) {
#ifndef MULTICORE
        if (_CRISTAL_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_M1_var._position_relative, _CRISTAL_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_CRISTAL_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_M1_out
    if (!ABSORBED && _particle->_index == 191) {
        _particle->_index++;
      }

      // CRISTAL_M2_location
    if (!ABSORBED && _particle->_index == 192) {
        _particle->_index++;
      }

      // CRISTAL_M2_rotated
    if (!ABSORBED && _particle->_index == 193) {
        _particle->_index++;
      }

      // CRISTAL_M2
    if (!ABSORBED && _particle->_index == 194) {
#ifndef MULTICORE
        if (_CRISTAL_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_M2_var._position_relative, _CRISTAL_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_CRISTAL_M2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_M2_out
    if (!ABSORBED && _particle->_index == 195) {
        _particle->_index++;
      }

      // CRISTAL_slit2
    if (!ABSORBED && _particle->_index == 196) {
#ifndef MULTICORE
        if (_CRISTAL_slit2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_slit2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_slit2_var._position_relative, _CRISTAL_slit2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_CRISTAL_slit2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_psd_slit2
    if (!ABSORBED && _particle->_index == 197) {
#ifndef MULTICORE
        if (_CRISTAL_psd_slit2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_psd_slit2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_psd_slit2_var._position_relative, _CRISTAL_psd_slit2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_CRISTAL_psd_slit2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_sample_stage
    if (!ABSORBED && _particle->_index == 198) {
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_CRISTAL_fluo;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_CRISTAL_fluo);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // CRISTAL_fluo
    if (!ABSORBED && _particle->_index == 199) {
#ifndef MULTICORE
        if (_CRISTAL_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_fluo_var._position_relative, _CRISTAL_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoPowder_trace(&_CRISTAL_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // CRISTAL_detector_diffraction
    if (!ABSORBED && _particle->_index == 200) {
#ifndef MULTICORE
        if (_CRISTAL_detector_diffraction_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_detector_diffraction_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_detector_diffraction_var._position_relative, _CRISTAL_detector_diffraction_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( 0.75 * _instrument_var._parameters.CRISTAL_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN
        class_Monitor_nD_trace(&_CRISTAL_detector_diffraction_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CRISTAL_detector_fluo
    if (!ABSORBED && _particle->_index == 201) {
#ifndef MULTICORE
        if (_CRISTAL_detector_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CRISTAL_detector_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CRISTAL_detector_fluo_var._position_relative, _CRISTAL_detector_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( K2E * sqrt ( kx * kx + ky * ky + kz * kz ) < 0.95 * _instrument_var._parameters.CRISTAL_E0 ))) // conditional WHEN
        class_Monitor_nD_trace(&_CRISTAL_detector_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_207
    if (!ABSORBED && _particle->_index == 202) {
#ifndef MULTICORE
        if (_beamdump_207_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_207_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_207_var._position_relative, _beamdump_207_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_207_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DEIMOS_pos
    if (!ABSORBED && _particle->_index == 203) {
#ifndef MULTICORE
        if (_DEIMOS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DEIMOS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DEIMOS_pos_var._position_relative, _DEIMOS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_DEIMOS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_pos
    if (!ABSORBED && _particle->_index == 204) {
#ifndef MULTICORE
        if (_GALAXIES_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_pos_var._position_relative, _GALAXIES_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_GALAXIES_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES
    if (!ABSORBED && _particle->_index == 205) {
#ifndef MULTICORE
        if (_GALAXIES_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_var._position_relative, _GALAXIES_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // GALAXIES_Source_U20
    if (!ABSORBED && _particle->_index == 206) {
#ifndef MULTICORE
        if (_GALAXIES_Source_U20_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_Source_U20_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_Source_U20_var._position_relative, _GALAXIES_Source_U20_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_GALAXIES_Source_U20_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // GALAXIES_mon_src_xy
    if (!ABSORBED && _particle->_index == 207) {
#ifndef MULTICORE
        if (_GALAXIES_mon_src_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_src_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_src_xy_var._position_relative, _GALAXIES_mon_src_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_src_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_mon_src_e
    if (!ABSORBED && _particle->_index == 208) {
#ifndef MULTICORE
        if (_GALAXIES_mon_src_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_src_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_src_e_var._position_relative, _GALAXIES_mon_src_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_src_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_absorber
    if (!ABSORBED && _particle->_index == 209) {
#ifndef MULTICORE
        if (_GALAXIES_absorber_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_absorber_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_absorber_var._position_relative, _GALAXIES_absorber_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_GALAXIES_absorber_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_diaphragme
    if (!ABSORBED && _particle->_index == 210) {
#ifndef MULTICORE
        if (_GALAXIES_diaphragme_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_diaphragme_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_diaphragme_var._position_relative, _GALAXIES_diaphragme_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_GALAXIES_diaphragme_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_fentes_primaires
    if (!ABSORBED && _particle->_index == 211) {
#ifndef MULTICORE
        if (_GALAXIES_fentes_primaires_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_fentes_primaires_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_fentes_primaires_var._position_relative, _GALAXIES_fentes_primaires_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_GALAXIES_fentes_primaires_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_mon_prim_xy
    if (!ABSORBED && _particle->_index == 212) {
#ifndef MULTICORE
        if (_GALAXIES_mon_prim_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_prim_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_prim_xy_var._position_relative, _GALAXIES_mon_prim_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_prim_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_DCM_location
    if (!ABSORBED && _particle->_index == 213) {
        _particle->_index++;
      }

      // GALAXIES_dcm_xtal0
    if (!ABSORBED && _particle->_index == 214) {
#ifndef MULTICORE
        if (_GALAXIES_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_dcm_xtal0_var._position_relative, _GALAXIES_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_GALAXIES_dcm_xtal0_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_dcm0
    if (!ABSORBED && _particle->_index == 215) {
        _particle->_index++;
      }

      // GALAXIES_dcm_xtal1
    if (!ABSORBED && _particle->_index == 216) {
#ifndef MULTICORE
        if (_GALAXIES_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_dcm_xtal1_var._position_relative, _GALAXIES_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_GALAXIES_dcm_xtal1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_dcm1
    if (!ABSORBED && _particle->_index == 217) {
        _particle->_index++;
      }

      // GALAXIES_mon_dcm_e
    if (!ABSORBED && _particle->_index == 218) {
#ifndef MULTICORE
        if (_GALAXIES_mon_dcm_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_dcm_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_dcm_e_var._position_relative, _GALAXIES_mon_dcm_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_dcm_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_mon_dcm_xy
    if (!ABSORBED && _particle->_index == 219) {
#ifndef MULTICORE
        if (_GALAXIES_mon_dcm_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_dcm_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_dcm_xy_var._position_relative, _GALAXIES_mon_dcm_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_dcm_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_M1_location
    if (!ABSORBED && _particle->_index == 220) {
        _particle->_index++;
      }

      // GALAXIES_M1_rotated
    if (!ABSORBED && _particle->_index == 221) {
        _particle->_index++;
      }

      // GALAXIES_M1
    if (!ABSORBED && _particle->_index == 222) {
#ifndef MULTICORE
        if (_GALAXIES_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_M1_var._position_relative, _GALAXIES_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_GALAXIES_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_M1_out
    if (!ABSORBED && _particle->_index == 223) {
        _particle->_index++;
      }

      // GALAXIES_HRM_gate_in
    if (!ABSORBED && _particle->_index == 224) {
#ifndef MULTICORE
        if (_GALAXIES_HRM_gate_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_HRM_gate_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_HRM_gate_in_var._position_relative, _GALAXIES_HRM_gate_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_GALAXIES_HRM_gate_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_M2A_location
    if (!ABSORBED && _particle->_index == 225) {
        _particle->_index++;
      }

      // GALAXIES_M2A_rotated
    if (!ABSORBED && _particle->_index == 226) {
        _particle->_index++;
      }

      // GALAXIES_M2A
    if (!ABSORBED && _particle->_index == 227) {
#ifndef MULTICORE
        if (_GALAXIES_M2A_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_M2A_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_M2A_var._position_relative, _GALAXIES_M2A_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_trace(&_GALAXIES_M2A_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_M2A_out
    if (!ABSORBED && _particle->_index == 228) {
        _particle->_index++;
      }

      // GALAXIES_secondary_slits
    if (!ABSORBED && _particle->_index == 229) {
#ifndef MULTICORE
        if (_GALAXIES_secondary_slits_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_secondary_slits_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_secondary_slits_var._position_relative, _GALAXIES_secondary_slits_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_GALAXIES_secondary_slits_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_mon_sec_xy
    if (!ABSORBED && _particle->_index == 230) {
#ifndef MULTICORE
        if (_GALAXIES_mon_sec_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_sec_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_sec_xy_var._position_relative, _GALAXIES_mon_sec_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_sec_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_M2B_location
    if (!ABSORBED && _particle->_index == 231) {
        _particle->_index++;
      }

      // GALAXIES_M2B_rotated
    if (!ABSORBED && _particle->_index == 232) {
        _particle->_index++;
      }

      // GALAXIES_M2B
    if (!ABSORBED && _particle->_index == 233) {
#ifndef MULTICORE
        if (_GALAXIES_M2B_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_M2B_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_M2B_var._position_relative, _GALAXIES_M2B_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_trace(&_GALAXIES_M2B_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_M2B_out
    if (!ABSORBED && _particle->_index == 234) {
        _particle->_index++;
      }

      // GALAXIES_VFM_location
    if (!ABSORBED && _particle->_index == 235) {
        _particle->_index++;
      }

      // GALAXIES_VFM_rotated
    if (!ABSORBED && _particle->_index == 236) {
        _particle->_index++;
      }

      // GALAXIES_VFM
    if (!ABSORBED && _particle->_index == 237) {
#ifndef MULTICORE
        if (_GALAXIES_VFM_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_VFM_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_VFM_var._position_relative, _GALAXIES_VFM_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_GALAXIES_VFM_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_VFM_out
    if (!ABSORBED && _particle->_index == 238) {
        _particle->_index++;
      }

      // GALAXIES_HFM_rotated
    if (!ABSORBED && _particle->_index == 239) {
        _particle->_index++;
      }

      // GALAXIES_HFM
    if (!ABSORBED && _particle->_index == 240) {
#ifndef MULTICORE
        if (_GALAXIES_HFM_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_HFM_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_HFM_var._position_relative, _GALAXIES_HFM_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_GALAXIES_HFM_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_HFM_out
    if (!ABSORBED && _particle->_index == 241) {
        _particle->_index++;
      }

      // GALAXIES_mon_sample_xy_kb
    if (!ABSORBED && _particle->_index == 242) {
#ifndef MULTICORE
        if (_GALAXIES_mon_sample_xy_kb_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_sample_xy_kb_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_sample_xy_kb_var._position_relative, _GALAXIES_mon_sample_xy_kb_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_sample_xy_kb_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_mon_sample_e
    if (!ABSORBED && _particle->_index == 243) {
#ifndef MULTICORE
        if (_GALAXIES_mon_sample_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_mon_sample_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_mon_sample_e_var._position_relative, _GALAXIES_mon_sample_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_mon_sample_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_sample_stage
    if (!ABSORBED && _particle->_index == 244) {
#ifndef MULTICORE
        if (_GALAXIES_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_sample_stage_var._position_relative, _GALAXIES_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Arm_trace(&_GALAXIES_sample_stage_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_GALAXIES_sample;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_GALAXIES_sample);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // GALAXIES_sample
    if (!ABSORBED && _particle->_index == 245) {
#ifndef MULTICORE
        if (_GALAXIES_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_sample_var._position_relative, _GALAXIES_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoCrystal_trace(&_GALAXIES_sample_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // GALAXIES_sample_out
    if (!ABSORBED && _particle->_index == 246) {
#ifndef MULTICORE
        if (_GALAXIES_sample_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_sample_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_sample_out_var._position_relative, _GALAXIES_sample_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Arm_trace(&_GALAXIES_sample_out_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_ana_arm
    if (!ABSORBED && _particle->_index == 247) {
        _particle->_index++;
      }

      // GALAXIES_analyzer
    if (!ABSORBED && _particle->_index == 248) {
#ifndef MULTICORE
        if (_GALAXIES_analyzer_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_analyzer_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_analyzer_var._position_relative, _GALAXIES_analyzer_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_GALAXIES_analyzer_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // GALAXIES_ana_out
    if (!ABSORBED && _particle->_index == 249) {
        _particle->_index++;
      }

      // GALAXIES_IXS_det
    if (!ABSORBED && _particle->_index == 250) {
#ifndef MULTICORE
        if (_GALAXIES_IXS_det_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _GALAXIES_IXS_det_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_GALAXIES_IXS_det_var._position_relative, _GALAXIES_IXS_det_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_GALAXIES_IXS_det_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_257
    if (!ABSORBED && _particle->_index == 251) {
#ifndef MULTICORE
        if (_beamdump_257_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_257_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_257_var._position_relative, _beamdump_257_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_257_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // TEMPO_pos
    if (!ABSORBED && _particle->_index == 252) {
#ifndef MULTICORE
        if (_TEMPO_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _TEMPO_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_TEMPO_pos_var._position_relative, _TEMPO_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_TEMPO_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_pos
    if (!ABSORBED && _particle->_index == 253) {
#ifndef MULTICORE
        if (_SAMBA_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_pos_var._position_relative, _SAMBA_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_SAMBA_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA
    if (!ABSORBED && _particle->_index == 254) {
#ifndef MULTICORE
        if (_SAMBA_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_var._position_relative, _SAMBA_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // SAMBA_BM_source
    if (!ABSORBED && _particle->_index == 255) {
#ifndef MULTICORE
        if (_SAMBA_BM_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_BM_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_BM_source_var._position_relative, _SAMBA_BM_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bending_magnet_trace(&_SAMBA_BM_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_M1_location
    if (!ABSORBED && _particle->_index == 256) {
        _particle->_index++;
      }

      // SAMBA_M1_rotated
    if (!ABSORBED && _particle->_index == 257) {
        _particle->_index++;
      }

      // SAMBA_M1
    if (!ABSORBED && _particle->_index == 258) {
#ifndef MULTICORE
        if (_SAMBA_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_M1_var._position_relative, _SAMBA_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SAMBA_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_M1_out
    if (!ABSORBED && _particle->_index == 259) {
#ifndef MULTICORE
        if (_SAMBA_M1_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M1_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_M1_out_var._position_relative, _SAMBA_M1_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_M1_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_DCM_location
    if (!ABSORBED && _particle->_index == 260) {
        _particle->_index++;
      }

      // SAMBA_bragg_crystal
    if (!ABSORBED && _particle->_index == 261) {
#ifndef MULTICORE
        if (_SAMBA_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_bragg_crystal_var._position_relative, _SAMBA_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SAMBA_bragg_crystal_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_arm_crystal1
    if (!ABSORBED && _particle->_index == 262) {
        _particle->_index++;
      }

      // SAMBA_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 263) {
#ifndef MULTICORE
        if (_SAMBA_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_bragg_crystal_two_var._position_relative, _SAMBA_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SAMBA_bragg_crystal_two_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_arm_crystal2
    if (!ABSORBED && _particle->_index == 264) {
        _particle->_index++;
      }

      // SAMBA_DCM_out
    if (!ABSORBED && _particle->_index == 265) {
#ifndef MULTICORE
        if (_SAMBA_DCM_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_DCM_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_DCM_out_var._position_relative, _SAMBA_DCM_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_DCM_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_DCM_out_div
    if (!ABSORBED && _particle->_index == 266) {
#ifndef MULTICORE
        if (_SAMBA_DCM_out_div_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_DCM_out_div_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_DCM_out_div_var._position_relative, _SAMBA_DCM_out_div_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_DCM_out_div_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_DCM_out_e
    if (!ABSORBED && _particle->_index == 267) {
#ifndef MULTICORE
        if (_SAMBA_DCM_out_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_DCM_out_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_DCM_out_e_var._position_relative, _SAMBA_DCM_out_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_DCM_out_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_M2_loc
    if (!ABSORBED && _particle->_index == 268) {
        _particle->_index++;
      }

      // SAMBA_M2_rotated
    if (!ABSORBED && _particle->_index == 269) {
        _particle->_index++;
      }

      // SAMBA_M2
    if (!ABSORBED && _particle->_index == 270) {
#ifndef MULTICORE
        if (_SAMBA_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_M2_var._position_relative, _SAMBA_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SAMBA_M2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_M2_out
    if (!ABSORBED && _particle->_index == 271) {
#ifndef MULTICORE
        if (_SAMBA_M2_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_M2_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_M2_out_var._position_relative, _SAMBA_M2_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_M2_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_sample_stage
    if (!ABSORBED && _particle->_index == 272) {
#ifndef MULTICORE
        if (_SAMBA_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_sample_stage_var._position_relative, _SAMBA_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_sample_stage_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_SAMBA_fluo;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_SAMBA_fluo);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SAMBA_fluo
    if (!ABSORBED && _particle->_index == 273) {
#ifndef MULTICORE
        if (_SAMBA_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_fluo_var._position_relative, _SAMBA_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoPowder_trace(&_SAMBA_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SAMBA_det_trans
    if (!ABSORBED && _particle->_index == 274) {
#ifndef MULTICORE
        if (_SAMBA_det_trans_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_det_trans_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_det_trans_var._position_relative, _SAMBA_det_trans_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_det_trans_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SAMBA_det_fluo
    if (!ABSORBED && _particle->_index == 275) {
#ifndef MULTICORE
        if (_SAMBA_det_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SAMBA_det_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SAMBA_det_fluo_var._position_relative, _SAMBA_det_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SAMBA_det_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_283
    if (!ABSORBED && _particle->_index == 276) {
#ifndef MULTICORE
        if (_beamdump_283_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_283_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_283_var._position_relative, _beamdump_283_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_283_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // HERMES_pos
    if (!ABSORBED && _particle->_index == 277) {
#ifndef MULTICORE
        if (_HERMES_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _HERMES_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_HERMES_pos_var._position_relative, _HERMES_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_HERMES_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_pos
    if (!ABSORBED && _particle->_index == 278) {
#ifndef MULTICORE
        if (_PX1_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_pos_var._position_relative, _PX1_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_PX1_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1
    if (!ABSORBED && _particle->_index == 279) {
#ifndef MULTICORE
        if (_PX1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_var._position_relative, _PX1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PX1_undulator
    if (!ABSORBED && _particle->_index == 280) {
#ifndef MULTICORE
        if (_PX1_undulator_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_undulator_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_undulator_var._position_relative, _PX1_undulator_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_PX1_undulator_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PX1_bragg_crystal_location
    if (!ABSORBED && _particle->_index == 281) {
        _particle->_index++;
      }

      // PX1_bragg_crystal
    if (!ABSORBED && _particle->_index == 282) {
#ifndef MULTICORE
        if (_PX1_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_bragg_crystal_var._position_relative, _PX1_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_PX1_bragg_crystal_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_arm
    if (!ABSORBED && _particle->_index == 283) {
        _particle->_index++;
      }

      // PX1_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 284) {
#ifndef MULTICORE
        if (_PX1_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_bragg_crystal_two_var._position_relative, _PX1_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_PX1_bragg_crystal_two_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_arm_two
    if (!ABSORBED && _particle->_index == 285) {
        _particle->_index++;
      }

      // PX1_bragg_crystal_out
    if (!ABSORBED && _particle->_index == 286) {
#ifndef MULTICORE
        if (_PX1_bragg_crystal_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_bragg_crystal_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_bragg_crystal_out_var._position_relative, _PX1_bragg_crystal_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_PX1_bragg_crystal_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_secondary_slits
    if (!ABSORBED && _particle->_index == 287) {
#ifndef MULTICORE
        if (_PX1_secondary_slits_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_secondary_slits_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_secondary_slits_var._position_relative, _PX1_secondary_slits_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_PX1_secondary_slits_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_vfm_location
    if (!ABSORBED && _particle->_index == 288) {
#ifndef MULTICORE
        if (_PX1_vfm_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_vfm_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_vfm_location_var._position_relative, _PX1_vfm_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX1_vfm_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_vfm_in_xz_plane
    if (!ABSORBED && _particle->_index == 289) {
        _particle->_index++;
      }

      // PX1_vfm
    if (!ABSORBED && _particle->_index == 290) {
#ifndef MULTICORE
        if (_PX1_vfm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_vfm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_vfm_var._position_relative, _PX1_vfm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PX1_vfm_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_vfm_takeoff
    if (!ABSORBED && _particle->_index == 291) {
#ifndef MULTICORE
        if (_PX1_vfm_takeoff_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_vfm_takeoff_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_vfm_takeoff_var._position_relative, _PX1_vfm_takeoff_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX1_vfm_takeoff_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_hfm_location
    if (!ABSORBED && _particle->_index == 292) {
#ifndef MULTICORE
        if (_PX1_hfm_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_hfm_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_hfm_location_var._position_relative, _PX1_hfm_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX1_hfm_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_hfm
    if (!ABSORBED && _particle->_index == 293) {
#ifndef MULTICORE
        if (_PX1_hfm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_hfm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_hfm_var._position_relative, _PX1_hfm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PX1_hfm_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_hfm_takeoff
    if (!ABSORBED && _particle->_index == 294) {
#ifndef MULTICORE
        if (_PX1_hfm_takeoff_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_hfm_takeoff_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_hfm_takeoff_var._position_relative, _PX1_hfm_takeoff_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX1_hfm_takeoff_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_sample_stage
    if (!ABSORBED && _particle->_index == 295) {
#ifndef MULTICORE
        if (_PX1_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_sample_stage_var._position_relative, _PX1_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Arm_trace(&_PX1_sample_stage_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_sample_monitor
    if (!ABSORBED && _particle->_index == 296) {
#ifndef MULTICORE
        if (_PX1_sample_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_sample_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_sample_monitor_var._position_relative, _PX1_sample_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX1_sample_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    // SPLIT with available livebatchsize 
    long mult_PX1_sample;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_PX1_sample);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PX1_sample
    if (!ABSORBED && _particle->_index == 297) {
#ifndef MULTICORE
        if (_PX1_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_sample_var._position_relative, _PX1_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Single_crystal_trace(&_PX1_sample_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_psd4pi
    if (!ABSORBED && _particle->_index == 298) {
#ifndef MULTICORE
        if (_PX1_psd4pi_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_psd4pi_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_psd4pi_var._position_relative, _PX1_psd4pi_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_4PI_trace(&_PX1_psd4pi_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX1_EigerX16M
    if (!ABSORBED && _particle->_index == 299) {
#ifndef MULTICORE
        if (_PX1_EigerX16M_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX1_EigerX16M_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX1_EigerX16M_var._position_relative, _PX1_EigerX16M_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PX1_EigerX16M_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_308
    if (!ABSORBED && _particle->_index == 300) {
#ifndef MULTICORE
        if (_beamdump_308_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_308_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_308_var._position_relative, _beamdump_308_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_308_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_pos
    if (!ABSORBED && _particle->_index == 301) {
#ifndef MULTICORE
        if (_PX2a_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_pos_var._position_relative, _PX2a_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_PX2a_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a
    if (!ABSORBED && _particle->_index == 302) {
#ifndef MULTICORE
        if (_PX2a_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_var._position_relative, _PX2a_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PX2a_undulator
    if (!ABSORBED && _particle->_index == 303) {
#ifndef MULTICORE
        if (_PX2a_undulator_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_undulator_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_undulator_var._position_relative, _PX2a_undulator_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_PX2a_undulator_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PX2a_bragg_crystal_location
    if (!ABSORBED && _particle->_index == 304) {
        _particle->_index++;
      }

      // PX2a_bragg_crystal
    if (!ABSORBED && _particle->_index == 305) {
#ifndef MULTICORE
        if (_PX2a_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_bragg_crystal_var._position_relative, _PX2a_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_PX2a_bragg_crystal_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_arm
    if (!ABSORBED && _particle->_index == 306) {
        _particle->_index++;
      }

      // PX2a_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 307) {
#ifndef MULTICORE
        if (_PX2a_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_bragg_crystal_two_var._position_relative, _PX2a_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_PX2a_bragg_crystal_two_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_arm_two
    if (!ABSORBED && _particle->_index == 308) {
        _particle->_index++;
      }

      // PX2a_bragg_crystal_out
    if (!ABSORBED && _particle->_index == 309) {
#ifndef MULTICORE
        if (_PX2a_bragg_crystal_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_bragg_crystal_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_bragg_crystal_out_var._position_relative, _PX2a_bragg_crystal_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_PX2a_bragg_crystal_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_hpm_location
    if (!ABSORBED && _particle->_index == 310) {
        _particle->_index++;
      }

      // PX2a_hpm_in_yz_plane
    if (!ABSORBED && _particle->_index == 311) {
        _particle->_index++;
      }

      // PX2a_hpm
    if (!ABSORBED && _particle->_index == 312) {
#ifndef MULTICORE
        if (_PX2a_hpm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hpm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_hpm_var._position_relative, _PX2a_hpm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_trace(&_PX2a_hpm_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_hpm_takeoff
    if (!ABSORBED && _particle->_index == 313) {
        _particle->_index++;
      }

      // PX2a_vfm_location
    if (!ABSORBED && _particle->_index == 314) {
#ifndef MULTICORE
        if (_PX2a_vfm_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_vfm_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_vfm_location_var._position_relative, _PX2a_vfm_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX2a_vfm_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_vfm_in_xz_plane
    if (!ABSORBED && _particle->_index == 315) {
        _particle->_index++;
      }

      // PX2a_vfm
    if (!ABSORBED && _particle->_index == 316) {
#ifndef MULTICORE
        if (_PX2a_vfm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_vfm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_vfm_var._position_relative, _PX2a_vfm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PX2a_vfm_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_vfm_takeoff
    if (!ABSORBED && _particle->_index == 317) {
#ifndef MULTICORE
        if (_PX2a_vfm_takeoff_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_vfm_takeoff_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_vfm_takeoff_var._position_relative, _PX2a_vfm_takeoff_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX2a_vfm_takeoff_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_hfm_location
    if (!ABSORBED && _particle->_index == 318) {
#ifndef MULTICORE
        if (_PX2a_hfm_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hfm_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_hfm_location_var._position_relative, _PX2a_hfm_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX2a_hfm_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_hfm
    if (!ABSORBED && _particle->_index == 319) {
#ifndef MULTICORE
        if (_PX2a_hfm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hfm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_hfm_var._position_relative, _PX2a_hfm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_PX2a_hfm_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_hfm_takeoff
    if (!ABSORBED && _particle->_index == 320) {
#ifndef MULTICORE
        if (_PX2a_hfm_takeoff_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_hfm_takeoff_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_hfm_takeoff_var._position_relative, _PX2a_hfm_takeoff_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX2a_hfm_takeoff_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_sample_stage
    if (!ABSORBED && _particle->_index == 321) {
#ifndef MULTICORE
        if (_PX2a_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_sample_stage_var._position_relative, _PX2a_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Arm_trace(&_PX2a_sample_stage_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_sample_monitor
    if (!ABSORBED && _particle->_index == 322) {
#ifndef MULTICORE
        if (_PX2a_sample_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_sample_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_sample_monitor_var._position_relative, _PX2a_sample_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_PX2a_sample_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    // SPLIT with available livebatchsize 
    long mult_PX2a_sample;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_PX2a_sample);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // PX2a_sample
    if (!ABSORBED && _particle->_index == 323) {
#ifndef MULTICORE
        if (_PX2a_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_sample_var._position_relative, _PX2a_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Single_crystal_trace(&_PX2a_sample_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_psd4pi
    if (!ABSORBED && _particle->_index == 324) {
#ifndef MULTICORE
        if (_PX2a_psd4pi_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_psd4pi_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_psd4pi_var._position_relative, _PX2a_psd4pi_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_4PI_trace(&_PX2a_psd4pi_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // PX2a_Eiger9M
    if (!ABSORBED && _particle->_index == 325) {
#ifndef MULTICORE
        if (_PX2a_Eiger9M_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _PX2a_Eiger9M_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_PX2a_Eiger9M_var._position_relative, _PX2a_Eiger9M_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_PX2a_Eiger9M_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_335
    if (!ABSORBED && _particle->_index == 326) {
#ifndef MULTICORE
        if (_beamdump_335_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_335_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_335_var._position_relative, _beamdump_335_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_335_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_pos
    if (!ABSORBED && _particle->_index == 327) {
#ifndef MULTICORE
        if (_SWING_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_pos_var._position_relative, _SWING_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_SWING_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING
    if (!ABSORBED && _particle->_index == 328) {
#ifndef MULTICORE
        if (_SWING_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_var._position_relative, _SWING_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SWING_Source_U20
    if (!ABSORBED && _particle->_index == 329) {
#ifndef MULTICORE
        if (_SWING_Source_U20_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_Source_U20_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_Source_U20_var._position_relative, _SWING_Source_U20_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_SWING_Source_U20_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SWING_mon_src_xy
    if (!ABSORBED && _particle->_index == 330) {
#ifndef MULTICORE
        if (_SWING_mon_src_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_src_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_mon_src_xy_var._position_relative, _SWING_mon_src_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_mon_src_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_mon_src_e
    if (!ABSORBED && _particle->_index == 331) {
#ifndef MULTICORE
        if (_SWING_mon_src_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_src_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_mon_src_e_var._position_relative, _SWING_mon_src_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_mon_src_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_slit
    if (!ABSORBED && _particle->_index == 332) {
#ifndef MULTICORE
        if (_SWING_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_slit_var._position_relative, _SWING_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_SWING_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_slit_mon_xy
    if (!ABSORBED && _particle->_index == 333) {
#ifndef MULTICORE
        if (_SWING_slit_mon_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_slit_mon_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_slit_mon_xy_var._position_relative, _SWING_slit_mon_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_slit_mon_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_DCM_location
    if (!ABSORBED && _particle->_index == 334) {
        _particle->_index++;
      }

      // SWING_dcm_xtal0
    if (!ABSORBED && _particle->_index == 335) {
#ifndef MULTICORE
        if (_SWING_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_dcm_xtal0_var._position_relative, _SWING_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SWING_dcm_xtal0_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_dcm0
    if (!ABSORBED && _particle->_index == 336) {
        _particle->_index++;
      }

      // SWING_dcm_xtal1
    if (!ABSORBED && _particle->_index == 337) {
#ifndef MULTICORE
        if (_SWING_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_dcm_xtal1_var._position_relative, _SWING_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SWING_dcm_xtal1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_dcm1
    if (!ABSORBED && _particle->_index == 338) {
        _particle->_index++;
      }

      // SWING_mon_dcm_e
    if (!ABSORBED && _particle->_index == 339) {
#ifndef MULTICORE
        if (_SWING_mon_dcm_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_dcm_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_mon_dcm_e_var._position_relative, _SWING_mon_dcm_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_mon_dcm_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_mon_dcm_xy
    if (!ABSORBED && _particle->_index == 340) {
#ifndef MULTICORE
        if (_SWING_mon_dcm_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_mon_dcm_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_mon_dcm_xy_var._position_relative, _SWING_mon_dcm_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_mon_dcm_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_vfm_location
    if (!ABSORBED && _particle->_index == 341) {
#ifndef MULTICORE
        if (_SWING_vfm_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_vfm_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_vfm_location_var._position_relative, _SWING_vfm_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_vfm_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_vfm_in_xz_plane
    if (!ABSORBED && _particle->_index == 342) {
        _particle->_index++;
      }

      // SWING_vfm
    if (!ABSORBED && _particle->_index == 343) {
#ifndef MULTICORE
        if (_SWING_vfm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_vfm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_vfm_var._position_relative, _SWING_vfm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SWING_vfm_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_vfm_takeoff
    if (!ABSORBED && _particle->_index == 344) {
#ifndef MULTICORE
        if (_SWING_vfm_takeoff_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_vfm_takeoff_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_vfm_takeoff_var._position_relative, _SWING_vfm_takeoff_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_vfm_takeoff_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_hfm_location
    if (!ABSORBED && _particle->_index == 345) {
#ifndef MULTICORE
        if (_SWING_hfm_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_hfm_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_hfm_location_var._position_relative, _SWING_hfm_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_hfm_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_hfm
    if (!ABSORBED && _particle->_index == 346) {
#ifndef MULTICORE
        if (_SWING_hfm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_hfm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_hfm_var._position_relative, _SWING_hfm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SWING_hfm_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_hfm_takeoff
    if (!ABSORBED && _particle->_index == 347) {
#ifndef MULTICORE
        if (_SWING_hfm_takeoff_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_hfm_takeoff_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_hfm_takeoff_var._position_relative, _SWING_hfm_takeoff_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_hfm_takeoff_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    // SPLIT with available livebatchsize 
    long mult_SWING_sample_stage;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_SWING_sample_stage);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SWING_sample_stage
    if (!ABSORBED && _particle->_index == 348) {
#ifndef MULTICORE
        if (_SWING_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_sample_stage_var._position_relative, _SWING_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_sample_stage_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_sample_test
    if (!ABSORBED && _particle->_index == 349) {
#ifndef MULTICORE
        if (_SWING_sample_test_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_sample_test_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_sample_test_var._position_relative, _SWING_sample_test_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( SWING_flag_sample_sphere ))) // conditional WHEN
        class_Saxs_spheres_trace(&_SWING_sample_test_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SWING_sample
    if (!ABSORBED && _particle->_index == 350) {
#ifndef MULTICORE
        if (_SWING_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_sample_var._position_relative, _SWING_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( ! SWING_flag_sample_sphere ))) // conditional WHEN
        class_SAXSPDBFast_trace(&_SWING_sample_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SWING_sample_out
    if (!ABSORBED && _particle->_index == 351) {
        _particle->_index++;
      }

      // SWING_Eiger4M
    if (!ABSORBED && _particle->_index == 352) {
#ifndef MULTICORE
        if (_SWING_Eiger4M_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_Eiger4M_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_Eiger4M_var._position_relative, _SWING_Eiger4M_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SWING_Eiger4M_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SWING_QMonitor
    if (!ABSORBED && _particle->_index == 353) {
#ifndef MULTICORE
        if (_SWING_QMonitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SWING_QMonitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SWING_QMonitor_var._position_relative, _SWING_QMonitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_SAXSQMonitor_trace(&_SWING_QMonitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_364
    if (!ABSORBED && _particle->_index == 354) {
#ifndef MULTICORE
        if (_beamdump_364_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_364_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_364_var._position_relative, _beamdump_364_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_364_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANTARES_pos
    if (!ABSORBED && _particle->_index == 355) {
#ifndef MULTICORE
        if (_ANTARES_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANTARES_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANTARES_pos_var._position_relative, _ANTARES_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_ANTARES_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_pos
    if (!ABSORBED && _particle->_index == 356) {
#ifndef MULTICORE
        if (_ROCK_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_pos_var._position_relative, _ROCK_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_ROCK_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK
    if (!ABSORBED && _particle->_index == 357) {
#ifndef MULTICORE
        if (_ROCK_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_var._position_relative, _ROCK_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // ROCK_Source
    if (!ABSORBED && _particle->_index == 358) {
#ifndef MULTICORE
        if (_ROCK_Source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_Source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_Source_var._position_relative, _ROCK_Source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bending_magnet_trace(&_ROCK_Source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit1
    if (!ABSORBED && _particle->_index == 359) {
#ifndef MULTICORE
        if (_ROCK_slit1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit1_var._position_relative, _ROCK_slit1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_ROCK_slit1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit2
    if (!ABSORBED && _particle->_index == 360) {
#ifndef MULTICORE
        if (_ROCK_slit2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit2_var._position_relative, _ROCK_slit2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_ROCK_slit2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_mirror_m1
    if (!ABSORBED && _particle->_index == 361) {
#ifndef MULTICORE
        if (_ROCK_mirror_m1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_mirror_m1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_mirror_m1_var._position_relative, _ROCK_mirror_m1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_toroid_pothole_trace(&_ROCK_mirror_m1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_mirror_m1_out
    if (!ABSORBED && _particle->_index == 362) {
        _particle->_index++;
      }

      // ROCK_slit3_xy
    if (!ABSORBED && _particle->_index == 363) {
#ifndef MULTICORE
        if (_ROCK_slit3_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit3_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit3_xy_var._position_relative, _ROCK_slit3_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ROCK_slit3_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit3_div
    if (!ABSORBED && _particle->_index == 364) {
#ifndef MULTICORE
        if (_ROCK_slit3_div_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit3_div_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit3_div_var._position_relative, _ROCK_slit3_div_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Divergence_monitor_trace(&_ROCK_slit3_div_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit3
    if (!ABSORBED && _particle->_index == 365) {
#ifndef MULTICORE
        if (_ROCK_slit3_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit3_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit3_var._position_relative, _ROCK_slit3_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_ROCK_slit3_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_mirror_m2a
    if (!ABSORBED && _particle->_index == 366) {
#ifndef MULTICORE
        if (_ROCK_mirror_m2a_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_mirror_m2a_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_mirror_m2a_var._position_relative, _ROCK_mirror_m2a_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_trace(&_ROCK_mirror_m2a_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_mirror_m2a_out
    if (!ABSORBED && _particle->_index == 367) {
        _particle->_index++;
      }

      // ROCK_slit4_in
    if (!ABSORBED && _particle->_index == 368) {
#ifndef MULTICORE
        if (_ROCK_slit4_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit4_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit4_in_var._position_relative, _ROCK_slit4_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ROCK_slit4_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit4
    if (!ABSORBED && _particle->_index == 369) {
#ifndef MULTICORE
        if (_ROCK_slit4_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit4_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit4_var._position_relative, _ROCK_slit4_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_ROCK_slit4_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_arm_crystal0
    if (!ABSORBED && _particle->_index == 370) {
        _particle->_index++;
      }

      // ROCK_bragg_crystal
    if (!ABSORBED && _particle->_index == 371) {
#ifndef MULTICORE
        if (_ROCK_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_bragg_crystal_var._position_relative, _ROCK_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_ROCK_bragg_crystal_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_arm_crystal1
    if (!ABSORBED && _particle->_index == 372) {
        _particle->_index++;
      }

      // ROCK_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 373) {
#ifndef MULTICORE
        if (_ROCK_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_bragg_crystal_two_var._position_relative, _ROCK_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_ROCK_bragg_crystal_two_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_arm_crystal2
    if (!ABSORBED && _particle->_index == 374) {
        _particle->_index++;
      }

      // ROCK_bragg_crystal_out
    if (!ABSORBED && _particle->_index == 375) {
#ifndef MULTICORE
        if (_ROCK_bragg_crystal_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_bragg_crystal_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_bragg_crystal_out_var._position_relative, _ROCK_bragg_crystal_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ROCK_bragg_crystal_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit5
    if (!ABSORBED && _particle->_index == 376) {
#ifndef MULTICORE
        if (_ROCK_slit5_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit5_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit5_var._position_relative, _ROCK_slit5_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_ROCK_slit5_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_slit6
    if (!ABSORBED && _particle->_index == 377) {
#ifndef MULTICORE
        if (_ROCK_slit6_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_slit6_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_slit6_var._position_relative, _ROCK_slit6_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_ROCK_slit6_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_mirror_m2b
    if (!ABSORBED && _particle->_index == 378) {
#ifndef MULTICORE
        if (_ROCK_mirror_m2b_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_mirror_m2b_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_mirror_m2b_var._position_relative, _ROCK_mirror_m2b_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_ROCK_mirror_m2b_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_mirror_m2b_out
    if (!ABSORBED && _particle->_index == 379) {
        _particle->_index++;
      }

      // ROCK_EnergyMonitor_before_sample
    if (!ABSORBED && _particle->_index == 380) {
#ifndef MULTICORE
        if (_ROCK_EnergyMonitor_before_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_EnergyMonitor_before_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_EnergyMonitor_before_sample_var._position_relative, _ROCK_EnergyMonitor_before_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_ROCK_EnergyMonitor_before_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_e_repartition_after_m2b
    if (!ABSORBED && _particle->_index == 381) {
#ifndef MULTICORE
        if (_ROCK_e_repartition_after_m2b_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_e_repartition_after_m2b_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_e_repartition_after_m2b_var._position_relative, _ROCK_e_repartition_after_m2b_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_ROCK_e_repartition_after_m2b_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_sample_in
    if (!ABSORBED && _particle->_index == 382) {
#ifndef MULTICORE
        if (_ROCK_sample_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_sample_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_sample_in_var._position_relative, _ROCK_sample_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ROCK_sample_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_ROCK_absorption_sample;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_ROCK_absorption_sample);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // ROCK_absorption_sample
    if (!ABSORBED && _particle->_index == 383) {
#ifndef MULTICORE
        if (_ROCK_absorption_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_absorption_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_absorption_sample_var._position_relative, _ROCK_absorption_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Fluorescence_trace(&_ROCK_absorption_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // ROCK_fluo_monitor
    if (!ABSORBED && _particle->_index == 384) {
#ifndef MULTICORE
        if (_ROCK_fluo_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_fluo_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_fluo_monitor_var._position_relative, _ROCK_fluo_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_ROCK_fluo_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_EnergyMonitor_after_sample
    if (!ABSORBED && _particle->_index == 385) {
#ifndef MULTICORE
        if (_ROCK_EnergyMonitor_after_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_EnergyMonitor_after_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_EnergyMonitor_after_sample_var._position_relative, _ROCK_EnergyMonitor_after_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_ROCK_EnergyMonitor_after_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ROCK_psd_monitor
    if (!ABSORBED && _particle->_index == 386) {
#ifndef MULTICORE
        if (_ROCK_psd_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ROCK_psd_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ROCK_psd_monitor_var._position_relative, _ROCK_psd_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ROCK_psd_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_398
    if (!ABSORBED && _particle->_index == 387) {
#ifndef MULTICORE
        if (_beamdump_398_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_398_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_398_var._position_relative, _beamdump_398_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_398_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_pos
    if (!ABSORBED && _particle->_index == 388) {
#ifndef MULTICORE
        if (_ANATOMIX_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_pos_var._position_relative, _ANATOMIX_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_ANATOMIX_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX
    if (!ABSORBED && _particle->_index == 389) {
#ifndef MULTICORE
        if (_ANATOMIX_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_var._position_relative, _ANATOMIX_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // ANATOMIX_source
    if (!ABSORBED && _particle->_index == 390) {
#ifndef MULTICORE
        if (_ANATOMIX_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_source_var._position_relative, _ANATOMIX_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_ANATOMIX_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // ANATOMIX_e_repartition_before_cc
    if (!ABSORBED && _particle->_index == 391) {
#ifndef MULTICORE
        if (_ANATOMIX_e_repartition_before_cc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_e_repartition_before_cc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_e_repartition_before_cc_var._position_relative, _ANATOMIX_e_repartition_before_cc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_ANATOMIX_e_repartition_before_cc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_psd_monitor_before_cc
    if (!ABSORBED && _particle->_index == 392) {
#ifndef MULTICORE
        if (_ANATOMIX_psd_monitor_before_cc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_monitor_before_cc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_psd_monitor_before_cc_var._position_relative, _ANATOMIX_psd_monitor_before_cc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ANATOMIX_psd_monitor_before_cc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_bragg_crystal
    if (!ABSORBED && _particle->_index == 393) {
#ifndef MULTICORE
        if (_ANATOMIX_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_bragg_crystal_var._position_relative, _ANATOMIX_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_ANATOMIX_bragg_crystal_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_arm
    if (!ABSORBED && _particle->_index == 394) {
        _particle->_index++;
      }

      // ANATOMIX_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 395) {
#ifndef MULTICORE
        if (_ANATOMIX_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_bragg_crystal_two_var._position_relative, _ANATOMIX_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_ANATOMIX_bragg_crystal_two_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_arm_two
    if (!ABSORBED && _particle->_index == 396) {
        _particle->_index++;
      }

      // ANATOMIX_psd_after_cc
    if (!ABSORBED && _particle->_index == 397) {
#ifndef MULTICORE
        if (_ANATOMIX_psd_after_cc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_after_cc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_psd_after_cc_var._position_relative, _ANATOMIX_psd_after_cc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ANATOMIX_psd_after_cc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_e_monitor_before_sample
    if (!ABSORBED && _particle->_index == 398) {
#ifndef MULTICORE
        if (_ANATOMIX_e_monitor_before_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_e_monitor_before_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_e_monitor_before_sample_var._position_relative, _ANATOMIX_e_monitor_before_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_ANATOMIX_e_monitor_before_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_psd_repartition_after_cc
    if (!ABSORBED && _particle->_index == 399) {
#ifndef MULTICORE
        if (_ANATOMIX_psd_repartition_after_cc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_repartition_after_cc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_psd_repartition_after_cc_var._position_relative, _ANATOMIX_psd_repartition_after_cc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ANATOMIX_psd_repartition_after_cc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_sample_rotation_stage
    if (!ABSORBED && _particle->_index == 400) {
        _particle->_index++;
      }

      // ANATOMIX_sample
    if (!ABSORBED && _particle->_index == 401) {
#ifndef MULTICORE
        if (_ANATOMIX_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_sample_var._position_relative, _ANATOMIX_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Filter_trace(&_ANATOMIX_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_e_monitor_after_sample
    if (!ABSORBED && _particle->_index == 402) {
#ifndef MULTICORE
        if (_ANATOMIX_e_monitor_after_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_e_monitor_after_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_e_monitor_after_sample_var._position_relative, _ANATOMIX_e_monitor_after_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_ANATOMIX_e_monitor_after_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_psd_monitor_after_cc
    if (!ABSORBED && _particle->_index == 403) {
#ifndef MULTICORE
        if (_ANATOMIX_psd_monitor_after_cc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_psd_monitor_after_cc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_psd_monitor_after_cc_var._position_relative, _ANATOMIX_psd_monitor_after_cc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_ANATOMIX_psd_monitor_after_cc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_416
    if (!ABSORBED && _particle->_index == 404) {
#ifndef MULTICORE
        if (_beamdump_416_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_416_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_416_var._position_relative, _beamdump_416_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_416_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANOSCOPIUM_pos
    if (!ABSORBED && _particle->_index == 405) {
#ifndef MULTICORE
        if (_NANOSCOPIUM_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANOSCOPIUM_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANOSCOPIUM_pos_var._position_relative, _NANOSCOPIUM_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_NANOSCOPIUM_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANOSCOPIUM
    if (!ABSORBED && _particle->_index == 406) {
#ifndef MULTICORE
        if (_NANOSCOPIUM_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANOSCOPIUM_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANOSCOPIUM_var._position_relative, _NANOSCOPIUM_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // NANO_source
    if (!ABSORBED && _particle->_index == 407) {
#ifndef MULTICORE
        if (_NANO_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_source_var._position_relative, _NANO_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_NANO_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // NANO_e_monitor_source
    if (!ABSORBED && _particle->_index == 408) {
#ifndef MULTICORE
        if (_NANO_e_monitor_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_e_monitor_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_e_monitor_source_var._position_relative, _NANO_e_monitor_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_NANO_e_monitor_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_psd_source
    if (!ABSORBED && _particle->_index == 409) {
#ifndef MULTICORE
        if (_NANO_psd_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_psd_source_var._position_relative, _NANO_psd_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_coh_trace(&_NANO_psd_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_slit_1
    if (!ABSORBED && _particle->_index == 410) {
#ifndef MULTICORE
        if (_NANO_slit_1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_slit_1_var._position_relative, _NANO_slit_1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_NANO_slit_1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_m1_in
    if (!ABSORBED && _particle->_index == 411) {
        _particle->_index++;
      }

      // NANO_m1_roll
    if (!ABSORBED && _particle->_index == 412) {
        _particle->_index++;
      }

      // NANO_mirror_m1
    if (!ABSORBED && _particle->_index == 413) {
#ifndef MULTICORE
        if (_NANO_mirror_m1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_mirror_m1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_mirror_m1_var._position_relative, _NANO_mirror_m1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_NANO_mirror_m1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_beam_deviation
    if (!ABSORBED && _particle->_index == 414) {
        _particle->_index++;
      }

      // NANO_m2_in
    if (!ABSORBED && _particle->_index == 415) {
        _particle->_index++;
      }

      // NANO_mirror_m2
    if (!ABSORBED && _particle->_index == 416) {
#ifndef MULTICORE
        if (_NANO_mirror_m2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_mirror_m2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_mirror_m2_var._position_relative, _NANO_mirror_m2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_NANO_mirror_m2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_mirror_m2_out
    if (!ABSORBED && _particle->_index == 417) {
        _particle->_index++;
      }

      // NANO_slit_2
    if (!ABSORBED && _particle->_index == 418) {
#ifndef MULTICORE
        if (_NANO_slit_2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_slit_2_var._position_relative, _NANO_slit_2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_NANO_slit_2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_dcm_in
    if (!ABSORBED && _particle->_index == 419) {
        _particle->_index++;
      }

      // NANO_PSD_dcm_in
    if (!ABSORBED && _particle->_index == 420) {
#ifndef MULTICORE
        if (_NANO_PSD_dcm_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_PSD_dcm_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_PSD_dcm_in_var._position_relative, _NANO_PSD_dcm_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_NANO_PSD_dcm_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_bragg_roll
    if (!ABSORBED && _particle->_index == 421) {
        _particle->_index++;
      }

      // NANO_bragg_crystal_1
    if (!ABSORBED && _particle->_index == 422) {
#ifndef MULTICORE
        if (_NANO_bragg_crystal_1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_bragg_crystal_1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_bragg_crystal_1_var._position_relative, _NANO_bragg_crystal_1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_NANO_bragg_crystal_1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_dcm2_rot
    if (!ABSORBED && _particle->_index == 423) {
        _particle->_index++;
      }

      // NANO_dcm_transl
    if (!ABSORBED && _particle->_index == 424) {
        _particle->_index++;
      }

      // NANO_bragg_crystal_2
    if (!ABSORBED && _particle->_index == 425) {
#ifndef MULTICORE
        if (_NANO_bragg_crystal_2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_bragg_crystal_2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_bragg_crystal_2_var._position_relative, _NANO_bragg_crystal_2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_NANO_bragg_crystal_2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_bragg2_out
    if (!ABSORBED && _particle->_index == 426) {
        _particle->_index++;
      }

      // NANO_dcm_out
    if (!ABSORBED && _particle->_index == 427) {
        _particle->_index++;
      }

      // NANO_e_dcm_out
    if (!ABSORBED && _particle->_index == 428) {
#ifndef MULTICORE
        if (_NANO_e_dcm_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_e_dcm_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_e_dcm_out_var._position_relative, _NANO_e_dcm_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_E_monitor_trace(&_NANO_e_dcm_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_secondary_source_slits
    if (!ABSORBED && _particle->_index == 429) {
        _particle->_index++;
      }

      // NANO_psd_ss_in
    if (!ABSORBED && _particle->_index == 430) {
#ifndef MULTICORE
        if (_NANO_psd_ss_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_ss_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_psd_ss_in_var._position_relative, _NANO_psd_ss_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_NANO_psd_ss_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_slit_3
    if (!ABSORBED && _particle->_index == 431) {
#ifndef MULTICORE
        if (_NANO_slit_3_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_3_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_slit_3_var._position_relative, _NANO_slit_3_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_NANO_slit_3_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_psd_ss_out
    if (!ABSORBED && _particle->_index == 432) {
#ifndef MULTICORE
        if (_NANO_psd_ss_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_ss_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_psd_ss_out_var._position_relative, _NANO_psd_ss_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_NANO_psd_ss_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_jjxray2_slits
    if (!ABSORBED && _particle->_index == 433) {
        _particle->_index++;
      }

      // NANO_slit_5
    if (!ABSORBED && _particle->_index == 434) {
#ifndef MULTICORE
        if (_NANO_slit_5_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_5_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_slit_5_var._position_relative, _NANO_slit_5_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_NANO_slit_5_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_kb_in
    if (!ABSORBED && _particle->_index == 435) {
        _particle->_index++;
      }

      // NANO_kb_1
    if (!ABSORBED && _particle->_index == 436) {
#ifndef MULTICORE
        if (_NANO_kb_1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_kb_1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_kb_1_var._position_relative, _NANO_kb_1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_NANO_kb_1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_kb_beam_deviation
    if (!ABSORBED && _particle->_index == 437) {
        _particle->_index++;
      }

      // NANO_kb1_out
    if (!ABSORBED && _particle->_index == 438) {
        _particle->_index++;
      }

      // NANO_kb2
    if (!ABSORBED && _particle->_index == 439) {
#ifndef MULTICORE
        if (_NANO_kb2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_kb2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_kb2_var._position_relative, _NANO_kb2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_NANO_kb2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_kb_out
    if (!ABSORBED && _particle->_index == 440) {
        _particle->_index++;
      }

      // NANO_slit
    if (!ABSORBED && _particle->_index == 441) {
#ifndef MULTICORE
        if (_NANO_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_slit_var._position_relative, _NANO_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_NANO_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // NANO_psd_sample_stage
    if (!ABSORBED && _particle->_index == 442) {
#ifndef MULTICORE
        if (_NANO_psd_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _NANO_psd_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_NANO_psd_sample_stage_var._position_relative, _NANO_psd_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_PSD_monitor_trace(&_NANO_psd_sample_stage_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_456
    if (!ABSORBED && _particle->_index == 443) {
#ifndef MULTICORE
        if (_beamdump_456_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_456_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_456_var._position_relative, _beamdump_456_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_456_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_pos
    if (!ABSORBED && _particle->_index == 444) {
#ifndef MULTICORE
        if (_DIFFABS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_pos_var._position_relative, _DIFFABS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_DIFFABS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS
    if (!ABSORBED && _particle->_index == 445) {
#ifndef MULTICORE
        if (_DIFFABS_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_var._position_relative, _DIFFABS_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // DIFFABS_BM_D13_1
    if (!ABSORBED && _particle->_index == 446) {
#ifndef MULTICORE
        if (_DIFFABS_BM_D13_1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_BM_D13_1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_BM_D13_1_var._position_relative, _DIFFABS_BM_D13_1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bending_magnet_trace(&_DIFFABS_BM_D13_1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_primary_slit
    if (!ABSORBED && _particle->_index == 447) {
#ifndef MULTICORE
        if (_DIFFABS_primary_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_primary_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_primary_slit_var._position_relative, _DIFFABS_primary_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_DIFFABS_primary_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_M1_location
    if (!ABSORBED && _particle->_index == 448) {
        _particle->_index++;
      }

      // DIFFABS_M1_rotated
    if (!ABSORBED && _particle->_index == 449) {
        _particle->_index++;
      }

      // DIFFABS_M1
    if (!ABSORBED && _particle->_index == 450) {
#ifndef MULTICORE
        if (_DIFFABS_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_M1_var._position_relative, _DIFFABS_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_DIFFABS_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_M1_out
    if (!ABSORBED && _particle->_index == 451) {
        _particle->_index++;
      }

      // DIFFABS_DCM_slit_in
    if (!ABSORBED && _particle->_index == 452) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_slit_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_slit_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_slit_in_var._position_relative, _DIFFABS_DCM_slit_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_DIFFABS_DCM_slit_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_DCM_in
    if (!ABSORBED && _particle->_index == 453) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_in_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_in_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_in_var._position_relative, _DIFFABS_DCM_in_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_DCM_in_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_DCM_in_div
    if (!ABSORBED && _particle->_index == 454) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_in_div_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_in_div_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_in_div_var._position_relative, _DIFFABS_DCM_in_div_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_DCM_in_div_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_DCM_location
    if (!ABSORBED && _particle->_index == 455) {
        _particle->_index++;
      }

      // DIFFABS_bragg_crystal
    if (!ABSORBED && _particle->_index == 456) {
#ifndef MULTICORE
        if (_DIFFABS_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_bragg_crystal_var._position_relative, _DIFFABS_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_DIFFABS_bragg_crystal_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_arm_crystal1
    if (!ABSORBED && _particle->_index == 457) {
        _particle->_index++;
      }

      // DIFFABS_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 458) {
#ifndef MULTICORE
        if (_DIFFABS_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_bragg_crystal_two_var._position_relative, _DIFFABS_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_DIFFABS_bragg_crystal_two_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_arm_crystal2
    if (!ABSORBED && _particle->_index == 459) {
        _particle->_index++;
      }

      // DIFFABS_DCM_out
    if (!ABSORBED && _particle->_index == 460) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_out_var._position_relative, _DIFFABS_DCM_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_DCM_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_DCM_out_div
    if (!ABSORBED && _particle->_index == 461) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_out_div_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_out_div_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_out_div_var._position_relative, _DIFFABS_DCM_out_div_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_DCM_out_div_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_DCM_out_e
    if (!ABSORBED && _particle->_index == 462) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_out_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_out_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_out_e_var._position_relative, _DIFFABS_DCM_out_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_DCM_out_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_DCM_slit_out
    if (!ABSORBED && _particle->_index == 463) {
#ifndef MULTICORE
        if (_DIFFABS_DCM_slit_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_DCM_slit_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_DCM_slit_out_var._position_relative, _DIFFABS_DCM_slit_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_DIFFABS_DCM_slit_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_M2_location
    if (!ABSORBED && _particle->_index == 464) {
        _particle->_index++;
      }

      // DIFFABS_M2_rotated
    if (!ABSORBED && _particle->_index == 465) {
        _particle->_index++;
      }

      // DIFFABS_M2
    if (!ABSORBED && _particle->_index == 466) {
#ifndef MULTICORE
        if (_DIFFABS_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_M2_var._position_relative, _DIFFABS_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_DIFFABS_M2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_M2_out
    if (!ABSORBED && _particle->_index == 467) {
        _particle->_index++;
      }

      // DIFFABS_sample_stage
    if (!ABSORBED && _particle->_index == 468) {
#ifndef MULTICORE
        if (_DIFFABS_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_sample_stage_var._position_relative, _DIFFABS_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_sample_stage_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_DIFFABS_fluo;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_DIFFABS_fluo);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // DIFFABS_fluo
    if (!ABSORBED && _particle->_index == 469) {
#ifndef MULTICORE
        if (_DIFFABS_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_fluo_var._position_relative, _DIFFABS_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoPowder_trace(&_DIFFABS_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // DIFFABS_fluo_monitor
    if (!ABSORBED && _particle->_index == 470) {
#ifndef MULTICORE
        if (_DIFFABS_fluo_monitor_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_fluo_monitor_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_fluo_monitor_var._position_relative, _DIFFABS_fluo_monitor_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_DIFFABS_fluo_monitor_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_det_angle
    if (!ABSORBED && _particle->_index == 471) {
#ifndef MULTICORE
        if (_DIFFABS_det_angle_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_det_angle_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_det_angle_var._position_relative, _DIFFABS_det_angle_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( 0.75 * _instrument_var._parameters.DIFFABS_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN
        class_Monitor_nD_trace(&_DIFFABS_det_angle_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // DIFFABS_xpad
    if (!ABSORBED && _particle->_index == 472) {
#ifndef MULTICORE
        if (_DIFFABS_xpad_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _DIFFABS_xpad_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_DIFFABS_xpad_var._position_relative, _DIFFABS_xpad_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( 0.75 * _instrument_var._parameters.DIFFABS_E0 < K2E * sqrt ( kx * kx + ky * ky + kz * kz ) ))) // conditional WHEN
        class_Monitor_nD_trace(&_DIFFABS_xpad_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_487
    if (!ABSORBED && _particle->_index == 473) {
#ifndef MULTICORE
        if (_beamdump_487_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_487_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_487_var._position_relative, _beamdump_487_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_487_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SEXTANTS
    if (!ABSORBED && _particle->_index == 474) {
#ifndef MULTICORE
        if (_SEXTANTS_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SEXTANTS_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SEXTANTS_var._position_relative, _SEXTANTS_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_SEXTANTS_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_pos
    if (!ABSORBED && _particle->_index == 475) {
#ifndef MULTICORE
        if (_SIXS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_pos_var._position_relative, _SIXS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_SIXS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS
    if (!ABSORBED && _particle->_index == 476) {
#ifndef MULTICORE
        if (_SIXS_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_var._position_relative, _SIXS_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SIXS_Source_U20
    if (!ABSORBED && _particle->_index == 477) {
#ifndef MULTICORE
        if (_SIXS_Source_U20_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_Source_U20_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_Source_U20_var._position_relative, _SIXS_Source_U20_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_SIXS_Source_U20_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SIXS_mon_src_xy
    if (!ABSORBED && _particle->_index == 478) {
#ifndef MULTICORE
        if (_SIXS_mon_src_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_src_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_mon_src_xy_var._position_relative, _SIXS_mon_src_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_mon_src_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_mon_src_e
    if (!ABSORBED && _particle->_index == 479) {
#ifndef MULTICORE
        if (_SIXS_mon_src_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_src_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_mon_src_e_var._position_relative, _SIXS_mon_src_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_mon_src_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_slit
    if (!ABSORBED && _particle->_index == 480) {
#ifndef MULTICORE
        if (_SIXS_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_slit_var._position_relative, _SIXS_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_SIXS_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_slit_mon_xy
    if (!ABSORBED && _particle->_index == 481) {
#ifndef MULTICORE
        if (_SIXS_slit_mon_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_slit_mon_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_slit_mon_xy_var._position_relative, _SIXS_slit_mon_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_slit_mon_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_DCM_location
    if (!ABSORBED && _particle->_index == 482) {
        _particle->_index++;
      }

      // SIXS_dcm_xtal0
    if (!ABSORBED && _particle->_index == 483) {
#ifndef MULTICORE
        if (_SIXS_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_dcm_xtal0_var._position_relative, _SIXS_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SIXS_dcm_xtal0_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_dcm0
    if (!ABSORBED && _particle->_index == 484) {
        _particle->_index++;
      }

      // SIXS_dcm_xtal1
    if (!ABSORBED && _particle->_index == 485) {
#ifndef MULTICORE
        if (_SIXS_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_dcm_xtal1_var._position_relative, _SIXS_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SIXS_dcm_xtal1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_dcm1
    if (!ABSORBED && _particle->_index == 486) {
        _particle->_index++;
      }

      // SIXS_mon_dcm_e
    if (!ABSORBED && _particle->_index == 487) {
#ifndef MULTICORE
        if (_SIXS_mon_dcm_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_dcm_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_mon_dcm_e_var._position_relative, _SIXS_mon_dcm_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_mon_dcm_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_mon_dcm_xy
    if (!ABSORBED && _particle->_index == 488) {
#ifndef MULTICORE
        if (_SIXS_mon_dcm_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_mon_dcm_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_mon_dcm_xy_var._position_relative, _SIXS_mon_dcm_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_mon_dcm_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_M1_location
    if (!ABSORBED && _particle->_index == 489) {
        _particle->_index++;
      }

      // SIXS_M1_rotated
    if (!ABSORBED && _particle->_index == 490) {
        _particle->_index++;
      }

      // SIXS_M1
    if (!ABSORBED && _particle->_index == 491) {
#ifndef MULTICORE
        if (_SIXS_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_M1_var._position_relative, _SIXS_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SIXS_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_M1_out
    if (!ABSORBED && _particle->_index == 492) {
        _particle->_index++;
      }

      // SIXS_M2_location
    if (!ABSORBED && _particle->_index == 493) {
        _particle->_index++;
      }

      // SIXS_M2_rotated
    if (!ABSORBED && _particle->_index == 494) {
        _particle->_index++;
      }

      // SIXS_M2
    if (!ABSORBED && _particle->_index == 495) {
#ifndef MULTICORE
        if (_SIXS_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_M2_var._position_relative, _SIXS_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SIXS_M2_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_M2_out
    if (!ABSORBED && _particle->_index == 496) {
        _particle->_index++;
      }
    }

    // SPLIT with available livebatchsize 
    long mult_SIXS_sample_stage;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_SIXS_sample_stage);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SIXS_sample_stage
    if (!ABSORBED && _particle->_index == 497) {
#ifndef MULTICORE
        if (_SIXS_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_sample_stage_var._position_relative, _SIXS_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_sample_stage_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_sx_layer
    if (!ABSORBED && _particle->_index == 498) {
#ifndef MULTICORE
        if (_SIXS_sx_layer_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sx_layer_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_sx_layer_var._position_relative, _SIXS_sx_layer_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((_instrument_var._parameters.SIXS_sample_thickness > 0)) // conditional WHEN
        class_Single_crystal_trace(&_SIXS_sx_layer_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_sx_bulk
    if (!ABSORBED && _particle->_index == 499) {
#ifndef MULTICORE
        if (_SIXS_sx_bulk_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sx_bulk_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_sx_bulk_var._position_relative, _SIXS_sx_bulk_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Single_crystal_trace(&_SIXS_sx_bulk_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_sample_out
    if (!ABSORBED && _particle->_index == 500) {
#ifndef MULTICORE
        if (_SIXS_sample_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_sample_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_sample_out_var._position_relative, _SIXS_sample_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Arm_trace(&_SIXS_sample_out_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_det4pi
    if (!ABSORBED && _particle->_index == 501) {
#ifndef MULTICORE
        if (_SIXS_det4pi_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_det4pi_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_det4pi_var._position_relative, _SIXS_det4pi_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIXS_det4pi_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_detector_layer
    if (!ABSORBED && _particle->_index == 502) {
#ifndef MULTICORE
        if (_SIXS_detector_layer_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_detector_layer_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_detector_layer_var._position_relative, _SIXS_detector_layer_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( SIXS_flag_scatt == 1 || SIXS_flag_scatt == 3 ))) // conditional WHEN
        class_Monitor_nD_trace(&_SIXS_detector_layer_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIXS_detector_bulk
    if (!ABSORBED && _particle->_index == 503) {
#ifndef MULTICORE
        if (_SIXS_detector_bulk_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIXS_detector_bulk_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIXS_detector_bulk_var._position_relative, _SIXS_detector_bulk_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((( SIXS_flag_scatt > 1 ))) // conditional WHEN
        class_Monitor_nD_trace(&_SIXS_detector_bulk_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_519
    if (!ABSORBED && _particle->_index == 504) {
#ifndef MULTICORE
        if (_beamdump_519_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_519_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_519_var._position_relative, _beamdump_519_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_519_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_pos
    if (!ABSORBED && _particle->_index == 505) {
#ifndef MULTICORE
        if (_CASSIOPEE_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_pos_var._position_relative, _CASSIOPEE_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_CASSIOPEE_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE
    if (!ABSORBED && _particle->_index == 506) {
#ifndef MULTICORE
        if (_CASSIOPEE_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_var._position_relative, _CASSIOPEE_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // CASSIOPEE_Source_HU60
    if (!ABSORBED && _particle->_index == 507) {
#ifndef MULTICORE
        if (_CASSIOPEE_Source_HU60_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_Source_HU60_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_Source_HU60_var._position_relative, _CASSIOPEE_Source_HU60_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 1)) // conditional WHEN
        class_Undulator_trace(&_CASSIOPEE_Source_HU60_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL

      // CASSIOPEE_Source_HU256
    if (!ABSORBED && _particle->_index == 508) {
#ifndef MULTICORE
        if (_CASSIOPEE_Source_HU256_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_Source_HU256_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_Source_HU256_var._position_relative, _CASSIOPEE_Source_HU256_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 2)) // conditional WHEN
        class_Undulator_trace(&_CASSIOPEE_Source_HU256_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // CASSIOPEE_M1a_location
    if (!ABSORBED && _particle->_index == 509) {
        _particle->_index++;
      }

      // CASSIOPEE_M1a
    if (!ABSORBED && _particle->_index == 510) {
#ifndef MULTICORE
        if (_CASSIOPEE_M1a_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M1a_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_M1a_var._position_relative, _CASSIOPEE_M1a_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_CASSIOPEE_M1a_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_M1a_out
    if (!ABSORBED && _particle->_index == 511) {
        _particle->_index++;
      }

      // CASSIOPEE_M1b
    if (!ABSORBED && _particle->_index == 512) {
#ifndef MULTICORE
        if (_CASSIOPEE_M1b_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M1b_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_M1b_var._position_relative, _CASSIOPEE_M1b_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 2)) // conditional WHEN
        class_Mirror_curved_trace(&_CASSIOPEE_M1b_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_M1c
    if (!ABSORBED && _particle->_index == 513) {
#ifndef MULTICORE
        if (_CASSIOPEE_M1c_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M1c_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_M1c_var._position_relative, _CASSIOPEE_M1c_var._rotation_relative, _particle);
        _particle_save = *_particle;
        if ((_instrument_var._parameters.CASSIOPEE_undulator_index == 1)) // conditional WHEN
        class_Mirror_curved_trace(&_CASSIOPEE_M1c_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_M1bc_out
    if (!ABSORBED && _particle->_index == 514) {
        _particle->_index++;
      }

      // CASSIOPEE_PSD_M1out
    if (!ABSORBED && _particle->_index == 515) {
#ifndef MULTICORE
        if (_CASSIOPEE_PSD_M1out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_PSD_M1out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_PSD_M1out_var._position_relative, _CASSIOPEE_PSD_M1out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_CASSIOPEE_PSD_M1out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_PG_location
    if (!ABSORBED && _particle->_index == 516) {
        _particle->_index++;
      }

      // CASSIOPEE_PG
    if (!ABSORBED && _particle->_index == 517) {
#ifndef MULTICORE
        if (_CASSIOPEE_PG_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_PG_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_PG_var._position_relative, _CASSIOPEE_PG_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Grating_reflect_trace(&_CASSIOPEE_PG_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_M2_rotation_axis
    if (!ABSORBED && _particle->_index == 518) {
#ifndef MULTICORE
        if (_CASSIOPEE_M2_rotation_axis_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M2_rotation_axis_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_M2_rotation_axis_var._position_relative, _CASSIOPEE_M2_rotation_axis_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_CASSIOPEE_M2_rotation_axis_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_M2
    if (!ABSORBED && _particle->_index == 519) {
#ifndef MULTICORE
        if (_CASSIOPEE_M2_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M2_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_M2_var._position_relative, _CASSIOPEE_M2_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_trace(&_CASSIOPEE_M2_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_PM_takeoff
    if (!ABSORBED && _particle->_index == 520) {
        _particle->_index++;
      }

      // CASSIOPEE_slit
    if (!ABSORBED && _particle->_index == 521) {
#ifndef MULTICORE
        if (_CASSIOPEE_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_slit_var._position_relative, _CASSIOPEE_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_CASSIOPEE_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_M4
    if (!ABSORBED && _particle->_index == 522) {
#ifndef MULTICORE
        if (_CASSIOPEE_M4_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_M4_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_M4_var._position_relative, _CASSIOPEE_M4_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_CASSIOPEE_M4_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // CASSIOPEE_PSD
    if (!ABSORBED && _particle->_index == 523) {
#ifndef MULTICORE
        if (_CASSIOPEE_PSD_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _CASSIOPEE_PSD_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_CASSIOPEE_PSD_var._position_relative, _CASSIOPEE_PSD_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_CASSIOPEE_PSD_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_540
    if (!ABSORBED && _particle->_index == 524) {
#ifndef MULTICORE
        if (_beamdump_540_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_540_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_540_var._position_relative, _beamdump_540_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_540_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_pos
    if (!ABSORBED && _particle->_index == 525) {
#ifndef MULTICORE
        if (_SIRIUS_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_pos_var._position_relative, _SIRIUS_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_SIRIUS_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS
    if (!ABSORBED && _particle->_index == 526) {
#ifndef MULTICORE
        if (_SIRIUS_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_var._position_relative, _SIRIUS_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }

      // SIRIUS_source
    if (!ABSORBED && _particle->_index == 527) {
#ifndef MULTICORE
        if (_SIRIUS_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_source_var._position_relative, _SIRIUS_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bending_magnet_trace(&_SIRIUS_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_M1_loc
    if (!ABSORBED && _particle->_index == 528) {
#ifndef MULTICORE
        if (_SIRIUS_M1_loc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_M1_loc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_M1_loc_var._position_relative, _SIRIUS_M1_loc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_M1_loc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_M1_rot
    if (!ABSORBED && _particle->_index == 529) {
        _particle->_index++;
      }

      // SIRIUS_M1
    if (!ABSORBED && _particle->_index == 530) {
#ifndef MULTICORE
        if (_SIRIUS_M1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_M1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_M1_var._position_relative, _SIRIUS_M1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_curved_trace(&_SIRIUS_M1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_M1_out
    if (!ABSORBED && _particle->_index == 531) {
        _particle->_index++;
      }

      // SIRIUS_DCM_location
    if (!ABSORBED && _particle->_index == 532) {
#ifndef MULTICORE
        if (_SIRIUS_DCM_location_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_location_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_DCM_location_var._position_relative, _SIRIUS_DCM_location_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_DCM_location_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_bragg_crystal
    if (!ABSORBED && _particle->_index == 533) {
#ifndef MULTICORE
        if (_SIRIUS_bragg_crystal_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_bragg_crystal_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_bragg_crystal_var._position_relative, _SIRIUS_bragg_crystal_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SIRIUS_bragg_crystal_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_arm_crystal1
    if (!ABSORBED && _particle->_index == 534) {
        _particle->_index++;
      }

      // SIRIUS_bragg_crystal_two
    if (!ABSORBED && _particle->_index == 535) {
#ifndef MULTICORE
        if (_SIRIUS_bragg_crystal_two_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_bragg_crystal_two_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_bragg_crystal_two_var._position_relative, _SIRIUS_bragg_crystal_two_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_SIRIUS_bragg_crystal_two_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_arm_crystal2
    if (!ABSORBED && _particle->_index == 536) {
        _particle->_index++;
      }

      // SIRIUS_DCM_out
    if (!ABSORBED && _particle->_index == 537) {
#ifndef MULTICORE
        if (_SIRIUS_DCM_out_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_out_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_DCM_out_var._position_relative, _SIRIUS_DCM_out_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_DCM_out_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_DCM_out_div
    if (!ABSORBED && _particle->_index == 538) {
#ifndef MULTICORE
        if (_SIRIUS_DCM_out_div_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_out_div_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_DCM_out_div_var._position_relative, _SIRIUS_DCM_out_div_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_DCM_out_div_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_DCM_out_e
    if (!ABSORBED && _particle->_index == 539) {
#ifndef MULTICORE
        if (_SIRIUS_DCM_out_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_DCM_out_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_DCM_out_e_var._position_relative, _SIRIUS_DCM_out_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_DCM_out_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_def_loc
    if (!ABSORBED && _particle->_index == 540) {
#ifndef MULTICORE
        if (_SIRIUS_def_loc_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_def_loc_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_def_loc_var._position_relative, _SIRIUS_def_loc_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_def_loc_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_def_rot
    if (!ABSORBED && _particle->_index == 541) {
        _particle->_index++;
      }

      // SIRIUS_def_mirror
    if (!ABSORBED && _particle->_index == 542) {
#ifndef MULTICORE
        if (_SIRIUS_def_mirror_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_def_mirror_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_def_mirror_var._position_relative, _SIRIUS_def_mirror_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Mirror_trace(&_SIRIUS_def_mirror_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_def_out
    if (!ABSORBED && _particle->_index == 543) {
        _particle->_index++;
      }

      // SIRIUS_sample_stage
    if (!ABSORBED && _particle->_index == 544) {
#ifndef MULTICORE
        if (_SIRIUS_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_sample_stage_var._position_relative, _SIRIUS_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_sample_stage_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_SIRIUS_fluo;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_SIRIUS_fluo);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SIRIUS_fluo
    if (!ABSORBED && _particle->_index == 545) {
#ifndef MULTICORE
        if (_SIRIUS_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_fluo_var._position_relative, _SIRIUS_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_FluoPowder_trace(&_SIRIUS_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // SIRIUS_det_2d
    if (!ABSORBED && _particle->_index == 546) {
#ifndef MULTICORE
        if (_SIRIUS_det_2d_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_det_2d_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_det_2d_var._position_relative, _SIRIUS_det_2d_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_det_2d_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // SIRIUS_det_fluo
    if (!ABSORBED && _particle->_index == 547) {
#ifndef MULTICORE
        if (_SIRIUS_det_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _SIRIUS_det_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_SIRIUS_det_fluo_var._position_relative, _SIRIUS_det_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_SIRIUS_det_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_565
    if (!ABSORBED && _particle->_index == 548) {
#ifndef MULTICORE
        if (_beamdump_565_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_565_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_565_var._position_relative, _beamdump_565_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_565_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_pos
    if (!ABSORBED && _particle->_index == 549) {
#ifndef MULTICORE
        if (_LUCIA_pos_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_pos_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_pos_var._position_relative, _LUCIA_pos_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_LUCIA_pos_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA
    if (!ABSORBED && _particle->_index == 550) {
#ifndef MULTICORE
        if (_LUCIA_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_var._position_relative, _LUCIA_var._rotation_relative, _particle);
        _particle_save = *_particle;
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // LUCIA_source
    if (!ABSORBED && _particle->_index == 551) {
#ifndef MULTICORE
        if (_LUCIA_source_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_source_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_source_var._position_relative, _LUCIA_source_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Undulator_trace(&_LUCIA_source_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // LUCIA_mon_src_xy
    if (!ABSORBED && _particle->_index == 552) {
#ifndef MULTICORE
        if (_LUCIA_mon_src_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_src_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_mon_src_xy_var._position_relative, _LUCIA_mon_src_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_mon_src_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_mon_src_e
    if (!ABSORBED && _particle->_index == 553) {
#ifndef MULTICORE
        if (_LUCIA_mon_src_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_src_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_mon_src_e_var._position_relative, _LUCIA_mon_src_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_mon_src_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_slit
    if (!ABSORBED && _particle->_index == 554) {
#ifndef MULTICORE
        if (_LUCIA_slit_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_slit_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_slit_var._position_relative, _LUCIA_slit_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_LUCIA_slit_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_slit_mon_xy
    if (!ABSORBED && _particle->_index == 555) {
#ifndef MULTICORE
        if (_LUCIA_slit_mon_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_slit_mon_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_slit_mon_xy_var._position_relative, _LUCIA_slit_mon_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_slit_mon_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_DCM_location
    if (!ABSORBED && _particle->_index == 556) {
        _particle->_index++;
      }

      // LUCIA_dcm_xtal0
    if (!ABSORBED && _particle->_index == 557) {
#ifndef MULTICORE
        if (_LUCIA_dcm_xtal0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_dcm_xtal0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_dcm_xtal0_var._position_relative, _LUCIA_dcm_xtal0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_LUCIA_dcm_xtal0_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_dcm0
    if (!ABSORBED && _particle->_index == 558) {
        _particle->_index++;
      }

      // LUCIA_dcm_xtal1
    if (!ABSORBED && _particle->_index == 559) {
#ifndef MULTICORE
        if (_LUCIA_dcm_xtal1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_dcm_xtal1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_dcm_xtal1_var._position_relative, _LUCIA_dcm_xtal1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Bragg_crystal_trace(&_LUCIA_dcm_xtal1_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_dcm1
    if (!ABSORBED && _particle->_index == 560) {
        _particle->_index++;
      }

      // LUCIA_mon_dcm_e
    if (!ABSORBED && _particle->_index == 561) {
#ifndef MULTICORE
        if (_LUCIA_mon_dcm_e_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_dcm_e_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_mon_dcm_e_var._position_relative, _LUCIA_mon_dcm_e_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_mon_dcm_e_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_mon_dcm_xy
    if (!ABSORBED && _particle->_index == 562) {
#ifndef MULTICORE
        if (_LUCIA_mon_dcm_xy_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_dcm_xy_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_mon_dcm_xy_var._position_relative, _LUCIA_mon_dcm_xy_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_mon_dcm_xy_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_diaphragm
    if (!ABSORBED && _particle->_index == 563) {
#ifndef MULTICORE
        if (_LUCIA_diaphragm_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_diaphragm_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_diaphragm_var._position_relative, _LUCIA_diaphragm_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Slit_trace(&_LUCIA_diaphragm_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_sample_stage
    if (!ABSORBED && _particle->_index == 564) {
#ifndef MULTICORE
        if (_LUCIA_sample_stage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_sample_stage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_sample_stage_var._position_relative, _LUCIA_sample_stage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_sample_stage_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_fluo_rotated
    if (!ABSORBED && _particle->_index == 565) {
        _particle->_index++;
      }
        #define JUMP_FUNNEL
    }

    // SPLIT with available livebatchsize 
    long mult_LUCIA_sample;
    livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, gpu_innerloop, 1, &mult_LUCIA_sample);
    //printf("livebatchsize: %ld, split: %ld\n",  livebatchsize, mult);

    #ifdef MULTICORE
    #pragma acc parallel loop device_type(host)
    #endif
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // LUCIA_sample
    if (!ABSORBED && _particle->_index == 566) {
#ifndef MULTICORE
        if (_LUCIA_sample_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_sample_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_sample_var._position_relative, _LUCIA_sample_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Fluorescence_trace(&_LUCIA_sample_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }
    }

    #pragma acc parallel loop present(particles[0:livebatchsize])
    for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) {
      _class_particle* _particle = &particles[pidx];
      _class_particle _particle_save;

      // LUCIA_transmission
    if (!ABSORBED && _particle->_index == 567) {
#ifndef MULTICORE
        if (_LUCIA_transmission_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_transmission_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_transmission_var._position_relative, _LUCIA_transmission_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_transmission_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_mon_spl_SDD
    if (!ABSORBED && _particle->_index == 568) {
#ifndef MULTICORE
        if (_LUCIA_mon_spl_SDD_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_spl_SDD_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_mon_spl_SDD_var._position_relative, _LUCIA_mon_spl_SDD_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Fluo_detector_trace(&_LUCIA_mon_spl_SDD_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // LUCIA_mon_spl_fluo
    if (!ABSORBED && _particle->_index == 569) {
#ifndef MULTICORE
        if (_LUCIA_mon_spl_fluo_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _LUCIA_mon_spl_fluo_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_LUCIA_mon_spl_fluo_var._position_relative, _LUCIA_mon_spl_fluo_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Monitor_nD_trace(&_LUCIA_mon_spl_fluo_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // beamdump_588
    if (!ABSORBED && _particle->_index == 570) {
#ifndef MULTICORE
        if (_beamdump_588_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _beamdump_588_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_beamdump_588_var._position_relative, _beamdump_588_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Beamstop_trace(&_beamdump_588_var, _particle); /* contains EXTEND code */
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // storage
    if (!ABSORBED && _particle->_index == 571) {
#ifndef MULTICORE
        if (_storage_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _storage_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_storage_var._position_relative, _storage_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Shape_trace(&_storage_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // hall0
    if (!ABSORBED && _particle->_index == 572) {
#ifndef MULTICORE
        if (_hall0_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _hall0_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_hall0_var._position_relative, _hall0_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Shape_trace(&_hall0_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // hall1
    if (!ABSORBED && _particle->_index == 573) {
#ifndef MULTICORE
        if (_hall1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _hall1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_hall1_var._position_relative, _hall1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Shape_trace(&_hall1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // entrance_0
    if (!ABSORBED && _particle->_index == 574) {
        _particle->_index++;
      }

      // entrance_1
    if (!ABSORBED && _particle->_index == 575) {
#ifndef MULTICORE
        if (_entrance_1_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _entrance_1_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_entrance_1_var._position_relative, _entrance_1_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Shape_trace(&_entrance_1_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // ANATOMIX_building
    if (!ABSORBED && _particle->_index == 576) {
#ifndef MULTICORE
        if (_ANATOMIX_building_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _ANATOMIX_building_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_ANATOMIX_building_var._position_relative, _ANATOMIX_building_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Shape_trace(&_ANATOMIX_building_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

      // soleil_label
    if (!ABSORBED && _particle->_index == 577) {
#ifndef MULTICORE
        if (_soleil_label_var._rotation_is_identity)
          coords_get(coords_add(coords_set(x,y,z), _soleil_label_var._position_relative),&x, &y, &z);
        else
#endif
          mccoordschange(_soleil_label_var._position_relative, _soleil_label_var._rotation_relative, _particle);
        _particle_save = *_particle;
        class_Text_trace(&_soleil_label_var, _particle);
        if (_particle->_restore)
        particle_restore(_particle, &_particle_save);
        _particle->_index++;
      }

    }

  } // outer loop / particle batches

  free(particles);
  free(pbuffer);

  printf("\n");
  // if on GPU and mcdotrace just exit
  #ifdef OPENACC
  }
  #endif
} /* raytrace_all_funnel */
#endif // FUNNEL

#undef PUMA_scat_before_VFM
#undef flag_scatt
#undef flag_hfm
#undef flag_vfm
#undef PX2a_flag_hfm
#undef PX2a_flag_vfm
#undef SWING_flag_hfm
#undef SWING_flag_vfm
#undef SIXS_flag_scatt
#undef beamline
#undef x
#undef y
#undef z
#undef kx
#undef ky
#undef kz
#undef phi
#undef t
#undef Ex
#undef Ey
#undef Ez
#undef p
#undef allow_backprop
#undef _mctmp_a
#undef _mctmp_b
#undef _mctmp_c
#ifdef OPENACC
#undef strlen
#undef strcmp
#undef exit
#undef printf
#undef sprintf
#undef fprintf
#endif
#undef SCATTERED
#undef RESTORE
#undef RESTORE_XRAY
#undef STORE_XRAY
#undef ABSORBED
#undef ABSORB
#undef ABSORB0
/* *****************************************************************************
* instrument 'SOLEIL' and components SAVE
***************************************************************************** */

_class_Monitor_nD *class_Monitor_nD_save(_class_Monitor_nD *_comp
) {
  #define user0 (_comp->_parameters.user0)
  #define user1 (_comp->_parameters.user1)
  #define user2 (_comp->_parameters.user2)
  #define user3 (_comp->_parameters.user3)
  #define user4 (_comp->_parameters.user4)
  #define user5 (_comp->_parameters.user5)
  #define user6 (_comp->_parameters.user6)
  #define user7 (_comp->_parameters.user7)
  #define user8 (_comp->_parameters.user8)
  #define user9 (_comp->_parameters.user9)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define bins (_comp->_parameters.bins)
  #define min (_comp->_parameters.min)
  #define max (_comp->_parameters.max)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define radius (_comp->_parameters.radius)
  #define options (_comp->_parameters.options)
  #define filename (_comp->_parameters.filename)
  #define geometry (_comp->_parameters.geometry)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define username0 (_comp->_parameters.username0)
  #define username1 (_comp->_parameters.username1)
  #define username2 (_comp->_parameters.username2)
  #define username3 (_comp->_parameters.username3)
  #define username4 (_comp->_parameters.username4)
  #define username5 (_comp->_parameters.username5)
  #define username6 (_comp->_parameters.username6)
  #define username7 (_comp->_parameters.username7)
  #define username8 (_comp->_parameters.username8)
  #define username9 (_comp->_parameters.username9)
  #define DEFS (_comp->_parameters.DEFS)
  #define Vars (_comp->_parameters.Vars)
  #define detector (_comp->_parameters.detector)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_MARS_displaySourceLength_save] component MARS_displaySourceLength=Monitor_nD() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:592]");

  if (!nowritefile) {
    /* save results, but do not free pointers */
    detector = Monitor_nD_Save (&DEFS, &Vars);
  }
  #undef user0
  #undef user1
  #undef user2
  #undef user3
  #undef user4
  #undef user5
  #undef user6
  #undef user7
  #undef user8
  #undef user9
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef bins
  #undef min
  #undef max
  #undef restore_xray
  #undef radius
  #undef options
  #undef filename
  #undef geometry
  #undef nowritefile
  #undef username0
  #undef username1
  #undef username2
  #undef username3
  #undef username4
  #undef username5
  #undef username6
  #undef username7
  #undef username8
  #undef username9
  #undef DEFS
  #undef Vars
  #undef detector
  #undef offdata
  return(_comp);
} /* class_Monitor_nD_save */

_class_PSD_monitor *class_PSD_monitor_save(_class_PSD_monitor *_comp
) {
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nr (_comp->_parameters.nr)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_displaySource_save] component MARS_displaySource=PSD_monitor() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:131]");

  if (!nowritefile) {
    if (!radius) {
      if (nx == 1 && ny == 1) {
        char title[256];
        snprintf (title, 255, "Intensity monitor %s", NAME_CURRENT_COMP);
        DETECTOR_OUT_0D (title, (double)PSD_N[0][0], PSD_p[0][0], PSD_p2[0][0]);
      } else if (nx == 1) {
        DETECTOR_OUT_1D ("PSD_monitor", "Y Position[m]", "Intensity", "Y", ymin, ymax, ny, &PSD_N[0][0], &PSD_p[0][0], &PSD_p2[0][0], filename);
      } else if (ny == 1) {
        DETECTOR_OUT_1D ("PSD_monitor", "X Position[m]", "Intensity", "X", xmin, xmax, nx, &PSD_N[0][0], &PSD_p[0][0], &PSD_p2[0][0], filename);
      } else {
        DETECTOR_OUT_2D ("PSD monitor", "X position [m]", "Y position [m]", xmin, xmax, ymin, ymax, nx, ny, *PSD_N, *PSD_p, *PSD_p2, filename);
      }
    } else {
      DETECTOR_OUT_1D ("PSD_monitor", "Radial Position[m]", "Intensity", "R", 0, radius, nr, &PSD_N[0][0], &PSD_p[0][0], &PSD_p2[0][0], filename);
    }
  }
  #undef filename
  #undef xwidth
  #undef yheight
  #undef radius
  #undef restore_xray
  #undef nowritefile
  #undef nx
  #undef ny
  #undef nr
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_save */

_class_E_monitor *class_E_monitor_save(_class_E_monitor *_comp
) {
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_emon_dcm0_save] component MARS_emon_dcm0=E_monitor() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:116]");

  DETECTOR_OUT_1D ("Energy monitor", "Energy [keV]", "Intensity", "E", Emin, Emax, nE, &E_N[0], &E_p[0], &E_p2[0], filename);
  #undef nE
  #undef filename
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef restore_xray
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_E_monitor_save */

_class_PSD_monitor_4PI *class_PSD_monitor_4PI_save(_class_PSD_monitor_4PI *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  SIG_MESSAGE("[_PX1_psd4pi_save] component PX1_psd4pi=PSD_monitor_4PI() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:106]");

  DETECTOR_OUT_2D ("4PI PSD monitor", "Longitude [deg]", "Lattitude [deg]", -180, 180, -90, 90, nx, ny, &PSD_N[0][0], &PSD_p[0][0], &PSD_p2[0][0], filename);
  #undef radius
  #undef restore_xray
  #undef nx
  #undef ny
  #undef filename
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  return(_comp);
} /* class_PSD_monitor_4PI_save */

_class_SAXSQMonitor *class_SAXSQMonitor_save(_class_SAXSQMonitor *_comp
) {
  #define RFilename (_comp->_parameters.RFilename)
  #define qFilename (_comp->_parameters.qFilename)
  #define NumberOfBins (_comp->_parameters.NumberOfBins)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define RadiusDetector (_comp->_parameters.RadiusDetector)
  #define DistanceFromSample (_comp->_parameters.DistanceFromSample)
  #define LambdaMin (_comp->_parameters.LambdaMin)
  #define Lambda0 (_comp->_parameters.Lambda0)
  #define qMax (_comp->_parameters.qMax)
  #define Nofq (_comp->_parameters.Nofq)
  #define Iofq (_comp->_parameters.Iofq)
  #define IofqSquared (_comp->_parameters.IofqSquared)
  #define NofR (_comp->_parameters.NofR)
  #define IofR (_comp->_parameters.IofR)
  #define IofRSquared (_comp->_parameters.IofRSquared)
  SIG_MESSAGE("[_SWING_QMonitor_save] component SWING_QMonitor=SAXSQMonitor() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSQMonitor.comp:171]");

  // Output I(r)
  DETECTOR_OUT_1D ("QMonitor - Radially averaged distribution", "Radius [m]", "I(r)", "r", 0.0, RadiusDetector, NumberOfBins, NofR, IofR, IofRSquared, RFilename);

  // Output I(q)
  char fname1[256];
  snprintf (fname1, 256, "%s_q", NAME_CURRENT_COMP);
  // we use mcdetector_out_nD in order to update the [comp_name]_I symbol for the 2nd output
  mcdetector_out_1D ("QMonitor - Distribution in q (Radially averaged)", "q [1 / AA]", "I(q)", "q", 0.0, qMax, NumberOfBins, Nofq, Iofq, IofqSquared, qFilename,
                     fname1, POS_A_CURRENT_COMP, ROT_A_CURRENT_COMP, INDEX_CURRENT_COMP);
  #undef RFilename
  #undef qFilename
  #undef NumberOfBins
  #undef restore_xray
  #undef RadiusDetector
  #undef DistanceFromSample
  #undef LambdaMin
  #undef Lambda0
  #undef qMax
  #undef Nofq
  #undef Iofq
  #undef IofqSquared
  #undef NofR
  #undef IofR
  #undef IofRSquared
  return(_comp);
} /* class_SAXSQMonitor_save */

_class_Divergence_monitor *class_Divergence_monitor_save(_class_Divergence_monitor *_comp
) {
  #define nh (_comp->_parameters.nh)
  #define nv (_comp->_parameters.nv)
  #define rad (_comp->_parameters.rad)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define maxdiv_h (_comp->_parameters.maxdiv_h)
  #define maxdiv_v (_comp->_parameters.maxdiv_v)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define Div_N (_comp->_parameters.Div_N)
  #define Div_p (_comp->_parameters.Div_p)
  #define Div_p2 (_comp->_parameters.Div_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_ROCK_slit3_div_save] component ROCK_slit3_div=Divergence_monitor() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Divergence_monitor.comp:130]");

  if (!nowritefile) {
    if (rad) {
      DETECTOR_OUT_2D ("Divergence monitor", "X divergence [rad]", "Y divergence [rad]", -maxdiv_h, maxdiv_h, -maxdiv_v, maxdiv_v, nh, nv, &Div_N[0][0],
                       &Div_p[0][0], &Div_p2[0][0], filename);
    } else {
      DETECTOR_OUT_2D ("Divergence monitor", "X divergence [deg]", "Y divergence [deg]", -maxdiv_h, maxdiv_h, -maxdiv_v, maxdiv_v, nh, nv, &Div_N[0][0],
                       &Div_p[0][0], &Div_p2[0][0], filename);
    }
  }
  #undef nh
  #undef nv
  #undef rad
  #undef filename
  #undef xwidth
  #undef yheight
  #undef maxdiv_h
  #undef maxdiv_v
  #undef restore_xray
  #undef nx
  #undef ny
  #undef nz
  #undef nowritefile
  #undef Div_N
  #undef Div_p
  #undef Div_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_Divergence_monitor_save */

_class_PSD_monitor_coh *class_PSD_monitor_coh_save(_class_PSD_monitor_coh *_comp
) {
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define ratio (_comp->_parameters.ratio)
  #define centering (_comp->_parameters.centering)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define PSD_phi_real (_comp->_parameters.PSD_phi_real)
  #define PSD_phi_imag (_comp->_parameters.PSD_phi_imag)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_NANO_psd_source_save] component NANO_psd_source=PSD_monitor_coh() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_coh.comp:159]");

  if (!nowritefile) {
    char filename_abs[255], filename_arg[255];

    double *PSD_p_abs, *PSD_p_arg;
    int i, j;

    snprintf (filename_abs, 255, "%s.abs", filename);
    snprintf (filename_arg, 255, "%s.arg", filename);

    /*This should be done differently if MPI*/
    PSD_p_abs = calloc (nx * ny, sizeof (double));
    PSD_p_arg = calloc (nx * ny, sizeof (double));
    if (PSD_p_abs == NULL || PSD_p_arg == NULL) {
      fprintf (stderr, "Error (%s): Buffer memory allocation error\nAborting\n.", NAME_CURRENT_COMP);
      exit (-1);
      exit (-1);
    }

    for (i = 0; i < nx; i++) {
      for (j = 0; j < ny; j++) {
        PSD_p_abs[i * ny + j] = cabs (cplx(PSD_phi_real[i][j],PSD_phi_imag[i][j]));
        PSD_p_arg[i * ny + j] = carg (cplx(PSD_phi_real[i][j],PSD_phi_imag[i][j]));
      }
    }

    #ifdef USE_MPI
    double *PSD_p_absbuf, *PSD_p_argbuf;
    double* N_buf;
    if (mpi_node_rank == 0) {
      PSD_p_absbuf = calloc (mpi_node_count * ny, sizeof (double));
      PSD_p_argbuf = calloc (mpi_node_count * ny, sizeof (double));
      N_buf = calloc (mpi_node_count * ny, sizeof (double));
    } else {
      PSD_p_absbuf = NULL;
      PSD_p_absbuf = NULL;
      N_buf = NULL;
    }

    for (i = 0; i < nx; i++) {
      MPI_Gather (&(PSD_p_abs[i * ny]), ny, MPI_DOUBLE, PSD_p_absbuf, ny, MPI_DOUBLE, 0, MPI_COMM_WORLD);
      MPI_Gather (&(PSD_p_arg[i * ny]), ny, MPI_DOUBLE, PSD_p_argbuf, ny, MPI_DOUBLE, 0, MPI_COMM_WORLD);
      MPI_Gather (&(PSD_N[i][0]), ny, MPI_DOUBLE, N_buf, ny, MPI_DOUBLE, 0, MPI_COMM_WORLD);
      if (mpi_node_rank == 0) {
        for (j = 0; j < ny; j++) {
          cdouble tmp_phi = cplx(0,0);
          unsigned long tmp_N = 0;
          int k;
          for (k = 0; k < mpi_node_count; k++) {
            tmp_phi = cadd(tmp_phi, rmul(PSD_p_absbuf[k * ny + j],cexp (rmul(PSD_p_argbuf[k * ny + j],cplx(0,1)))));
            tmp_N += (unsigned long)N_buf[k * ny + j];
          }
          PSD_p_abs[i * ny + j] = cabs (tmp_phi);
          PSD_p_arg[i * ny + j] = carg (tmp_phi);
          PSD_N[i][j] = tmp_N;
        }
      } else {
        /*set all the other nodes' data to zero. The DETECTOR_OUT macros will do an unnecessary gather,
          and so we don't want to add things twice.*/
        for (j = 0; j < ny; j++) {
          PSD_p_abs[i * ny + j] = 0;
          PSD_p_arg[i * ny + j] = 0;
          PSD_N[i][j] = 0;
        }
      }
    }
    /*doing it this way is inefficient since we send a lot of zeros across the network - but it should work*/
    #endif

    char fname1[256];
    snprintf (fname1, 256, "%s_arg", NAME_CURRENT_COMP);

    // we use mcdetector_out_nD in order to update the [comp_name]_I symbol for the 2nd output
    if (nx == 1 && ny == 1) {
      DETECTOR_OUT_0D ("Coh. Intensity monitor (magnitude)", (double)PSD_N[0][0], PSD_p_abs[0], PSD_p2[0][0]);

      mcdetector_out_0D ("Coh. Phase monitor (argument)", (double)PSD_N[0][0], PSD_p_arg[0], PSD_p2[0][0], fname1, POS_A_CURRENT_COMP, ROT_A_CURRENT_COMP,
                         INDEX_CURRENT_COMP);
    } else if (nx == 1) {
      DETECTOR_OUT_1D ("Coh. PSD_monitor (magnitude)", "Y Position[m]", "Intensity", "Y", ymin, ymax, ny, PSD_N[0], PSD_p_abs, PSD_p2[0], filename_abs);

      mcdetector_out_1D ("Coh. PSD_monitor (argument)", "Y Position[m]", "Phase", "Y", ymin, ymax, ny, PSD_N[0], PSD_p_arg, PSD_p2[0], filename_arg, fname1,
                         POS_A_CURRENT_COMP, ROT_A_CURRENT_COMP, INDEX_CURRENT_COMP);
    } else if (ny == 1) {
      DETECTOR_OUT_1D ("Coh. PSD_monitor (magnitude)", "X Position[m]", "Intensity", "X", xmin, xmax, nx, PSD_N[0], PSD_p_abs, PSD_p2[0], filename_abs);
      mcdetector_out_1D ("Coh. PSD_monitor (argument)", "X Position[m]", "Phase", "X", xmin, xmax, nx, PSD_N[0], PSD_p_arg, PSD_p2[0], filename_arg, fname1,
                         POS_A_CURRENT_COMP, ROT_A_CURRENT_COMP, INDEX_CURRENT_COMP);
    } else {
      /*don't do the internal gather in DETECTOR_OUT_2D*/
      // MPI_NOGATHER;
      DETECTOR_OUT_2D ("Coh. PSD_monitor (magnitude)", "X position [m]", "Y position [m]", xmin, xmax, ymin, ymax, nx, ny, PSD_N[0], PSD_p_abs, PSD_p2[0],
                       filename_abs);

      /*don't do the internal gather in DETECTOR_OUT_2D*/
      // MPI_NOGATHER;
      mcdetector_out_2D ("Coh. PSD_monitor (argument)", "X position [m]", "Y position [m]", xmin, xmax, ymin, ymax, nx, ny, (PSD_N[0]), PSD_p_arg, PSD_p2[0],
                         filename_arg, fname1, POS_A_CURRENT_COMP, ROT_A_CURRENT_COMP, INDEX_CURRENT_COMP);
    }
  }
  #undef nx
  #undef ny
  #undef filename
  #undef restore_xray
  #undef xwidth
  #undef yheight
  #undef ratio
  #undef centering
  #undef nowritefile
  #undef PSD_N
  #undef PSD_p2
  #undef PSD_phi_real
  #undef PSD_phi_imag
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_coh_save */

_class_Fluo_detector *class_Fluo_detector_save(_class_Fluo_detector *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define escape_ratio (_comp->_parameters.escape_ratio)
  #define escape_energy (_comp->_parameters.escape_energy)
  #define pileup_ratio (_comp->_parameters.pileup_ratio)
  #define electronic_noise (_comp->_parameters.electronic_noise)
  #define resolution_energy (_comp->_parameters.resolution_energy)
  #define resolution (_comp->_parameters.resolution)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define E_N_pileup (_comp->_parameters.E_N_pileup)
  #define E_p_pileup (_comp->_parameters.E_p_pileup)
  #define E_p2_pileup (_comp->_parameters.E_p2_pileup)
  #define E_N_escape (_comp->_parameters.E_N_escape)
  #define E_p_escape (_comp->_parameters.E_p_escape)
  #define E_p2_escape (_comp->_parameters.E_p2_escape)
  #define shape (_comp->_parameters.shape)
  #define K (_comp->_parameters.K)
  #define p_sum (_comp->_parameters.p_sum)
  #define N_sum (_comp->_parameters.N_sum)
  SIG_MESSAGE("[_LUCIA_mon_spl_SDD_save] component LUCIA_mon_spl_SDD=Fluo_detector() SAVE [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Fluo_detector.comp:254]");

  DETECTOR_OUT_1D ("Energy monitor", "Energy [keV]", "Intensity", "E", Emin, Emax, nE, &E_N[0], &E_p[0], &E_p2[0], filename);
  if (escape_ratio) {
    char f_escape[1024];
    snprintf (f_escape, 1024, "Escape_%s", filename);
    DETECTOR_OUT_1D ("Energy monitor (escape)", "Energy [keV]", "Intensity (escape)", "E", Emin, Emax, nE, &E_N_escape[0], &E_p_escape[0], &E_p2_escape[0],
                     f_escape);
  }
  if (pileup_ratio) {
    char f_pileup[1024];
    snprintf (f_pileup, 1024, "PileUp_%s", filename);
    DETECTOR_OUT_1D ("Energy monitor (pile-up)", "Energy [keV]", "Intensity (pile-up)", "E", Emin, Emax, nE, &E_N_pileup[0], &E_p_pileup[0], &E_p2_pileup[0],
                     f_pileup);
  }
  #undef radius
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef nE
  #undef filename
  #undef restore_xray
  #undef escape_ratio
  #undef escape_energy
  #undef pileup_ratio
  #undef electronic_noise
  #undef resolution_energy
  #undef resolution
  #undef flag_lorentzian
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef E_N_pileup
  #undef E_p_pileup
  #undef E_p2_pileup
  #undef E_N_escape
  #undef E_p_escape
  #undef E_p2_escape
  #undef shape
  #undef K
  #undef p_sum
  #undef N_sum
  return(_comp);
} /* class_Fluo_detector_save */



int save(FILE *handle) { /* called by mccode_main for SOLEIL:SAVE */
  if (!handle) siminfo_init(NULL);

  /* call iteratively all components SAVE */









  class_Monitor_nD_save(&_MARS_displaySourceLength_var);

  class_PSD_monitor_save(&_MARS_displaySource_var);













  class_E_monitor_save(&_MARS_emon_dcm0_var);

  class_PSD_monitor_save(&_MARS_displayMono_var);

  class_E_monitor_save(&_MARS_displayMonoLength_var);








  class_E_monitor_save(&_MARS_emon_dcm1_var);

  class_PSD_monitor_save(&_MARS_displaySlit2_var);


  class_Monitor_nD_save(&_MARS_detector_diffraction_var);

  class_Monitor_nD_save(&_MARS_detector_fluo_var);





  class_Monitor_nD_save(&_PSICHE_mon_src_e_var);

  class_Monitor_nD_save(&_PSICHE_mon_src_xy_var);






  class_Monitor_nD_save(&_PSICHE_mon_dcm_e_var);

  class_Monitor_nD_save(&_PSICHE_mon_dcm_xy_var);





  class_Monitor_nD_save(&_PSICHE_mon_spl_fluo_var);

  class_Monitor_nD_save(&_PSICHE_mon_spl_e_var);

  class_Monitor_nD_save(&_PSICHE_mon_spl_xy_var);





















  class_PSD_monitor_save(&_DISCO_HFP_var);










  class_PSD_monitor_save(&_DISCO_VFP_var);












  class_PSD_monitor_save(&_DISCO_second_HFP_var);






























  class_PSD_monitor_save(&_DISCO_psd_before_slit_var);


  class_PSD_monitor_save(&_DISCO_psd_monitor_var);

  class_PSD_monitor_save(&_DISCO_psd_giant_after_grating_var);

  class_Monitor_nD_save(&_DISCO_e_monitor_var);

  class_Monitor_nD_save(&_DISCO_w_monitor_var);









  class_E_monitor_save(&_PUMA_mon_src_e_var);

  class_PSD_monitor_save(&_PUMA_mon_src_xy_var);





  class_PSD_monitor_save(&_PUMA_mon_HFM_out_xy_var);




  class_PSD_monitor_save(&_PUMA_mon_DCM_xtal1_only_xy_var);



  class_E_monitor_save(&_PUMA_mon_DCM_out_e_var);

  class_PSD_monitor_save(&_PUMA_mon_DCM_out_xy_var);





  class_PSD_monitor_save(&_PUMA_mon_KB_in_xy_var);




  class_PSD_monitor_save(&_PUMA_mon_KB_VFM_out_xy_var);





  class_PSD_monitor_save(&_PUMA_mon_KB_HFM_out_xy_var);


  class_PSD_monitor_save(&_PUMA_mon_sample_xy_var);

  class_E_monitor_save(&_PUMA_mon_sample_e_var);











  class_E_monitor_save(&_CRISTAL_emon_dcm_var);










  class_PSD_monitor_save(&_CRISTAL_psd_slit2_var);



  class_Monitor_nD_save(&_CRISTAL_detector_diffraction_var);

  class_Monitor_nD_save(&_CRISTAL_detector_fluo_var);






  class_Monitor_nD_save(&_GALAXIES_mon_src_xy_var);

  class_Monitor_nD_save(&_GALAXIES_mon_src_e_var);




  class_Monitor_nD_save(&_GALAXIES_mon_prim_xy_var);






  class_Monitor_nD_save(&_GALAXIES_mon_dcm_e_var);

  class_Monitor_nD_save(&_GALAXIES_mon_dcm_xy_var);











  class_Monitor_nD_save(&_GALAXIES_mon_sec_xy_var);












  class_Monitor_nD_save(&_GALAXIES_mon_sample_xy_kb_var);

  class_Monitor_nD_save(&_GALAXIES_mon_sample_e_var);







  class_Monitor_nD_save(&_GALAXIES_IXS_det_var);









  class_Monitor_nD_save(&_SAMBA_M1_out_var);






  class_Monitor_nD_save(&_SAMBA_DCM_out_var);

  class_Monitor_nD_save(&_SAMBA_DCM_out_div_var);

  class_Monitor_nD_save(&_SAMBA_DCM_out_e_var);




  class_Monitor_nD_save(&_SAMBA_M2_out_var);

  class_Monitor_nD_save(&_SAMBA_sample_stage_var);


  class_Monitor_nD_save(&_SAMBA_det_trans_var);

  class_Monitor_nD_save(&_SAMBA_det_fluo_var);











  class_E_monitor_save(&_PX1_bragg_crystal_out_var);


  class_Monitor_nD_save(&_PX1_vfm_location_var);



  class_Monitor_nD_save(&_PX1_vfm_takeoff_var);

  class_Monitor_nD_save(&_PX1_hfm_location_var);


  class_Monitor_nD_save(&_PX1_hfm_takeoff_var);


  class_Monitor_nD_save(&_PX1_sample_monitor_var);


  class_PSD_monitor_4PI_save(&_PX1_psd4pi_var);

  class_PSD_monitor_save(&_PX1_EigerX16M_var);










  class_E_monitor_save(&_PX2a_bragg_crystal_out_var);





  class_Monitor_nD_save(&_PX2a_vfm_location_var);



  class_Monitor_nD_save(&_PX2a_vfm_takeoff_var);

  class_Monitor_nD_save(&_PX2a_hfm_location_var);


  class_Monitor_nD_save(&_PX2a_hfm_takeoff_var);


  class_Monitor_nD_save(&_PX2a_sample_monitor_var);


  class_PSD_monitor_4PI_save(&_PX2a_psd4pi_var);

  class_PSD_monitor_save(&_PX2a_Eiger9M_var);





  class_Monitor_nD_save(&_SWING_mon_src_xy_var);

  class_Monitor_nD_save(&_SWING_mon_src_e_var);


  class_Monitor_nD_save(&_SWING_slit_mon_xy_var);






  class_Monitor_nD_save(&_SWING_mon_dcm_e_var);

  class_Monitor_nD_save(&_SWING_mon_dcm_xy_var);

  class_Monitor_nD_save(&_SWING_vfm_location_var);



  class_Monitor_nD_save(&_SWING_vfm_takeoff_var);

  class_Monitor_nD_save(&_SWING_hfm_location_var);


  class_Monitor_nD_save(&_SWING_hfm_takeoff_var);

  class_Monitor_nD_save(&_SWING_sample_stage_var);




  class_Monitor_nD_save(&_SWING_Eiger4M_var);

  class_SAXSQMonitor_save(&_SWING_QMonitor_var);










  class_PSD_monitor_save(&_ROCK_slit3_xy_var);

  class_Divergence_monitor_save(&_ROCK_slit3_div_var);




  class_PSD_monitor_save(&_ROCK_slit4_in_var);







  class_PSD_monitor_save(&_ROCK_bragg_crystal_out_var);





  class_Monitor_nD_save(&_ROCK_EnergyMonitor_before_sample_var);

  class_Monitor_nD_save(&_ROCK_e_repartition_after_m2b_var);

  class_PSD_monitor_save(&_ROCK_sample_in_var);


  class_Monitor_nD_save(&_ROCK_fluo_monitor_var);

  class_Monitor_nD_save(&_ROCK_EnergyMonitor_after_sample_var);

  class_PSD_monitor_save(&_ROCK_psd_monitor_var);





  class_Monitor_nD_save(&_ANATOMIX_e_repartition_before_cc_var);

  class_PSD_monitor_save(&_ANATOMIX_psd_monitor_before_cc_var);





  class_PSD_monitor_save(&_ANATOMIX_psd_after_cc_var);

  class_E_monitor_save(&_ANATOMIX_e_monitor_before_sample_var);

  class_PSD_monitor_save(&_ANATOMIX_psd_repartition_after_cc_var);



  class_E_monitor_save(&_ANATOMIX_e_monitor_after_sample_var);

  class_PSD_monitor_save(&_ANATOMIX_psd_monitor_after_cc_var);





  class_E_monitor_save(&_NANO_e_monitor_source_var);

  class_PSD_monitor_coh_save(&_NANO_psd_source_var);











  class_PSD_monitor_save(&_NANO_PSD_dcm_in_var);








  class_E_monitor_save(&_NANO_e_dcm_out_var);


  class_PSD_monitor_save(&_NANO_psd_ss_in_var);


  class_PSD_monitor_save(&_NANO_psd_ss_out_var);










  class_PSD_monitor_save(&_NANO_psd_sample_stage_var);











  class_Monitor_nD_save(&_DIFFABS_DCM_in_var);

  class_Monitor_nD_save(&_DIFFABS_DCM_in_div_var);






  class_Monitor_nD_save(&_DIFFABS_DCM_out_var);

  class_Monitor_nD_save(&_DIFFABS_DCM_out_div_var);

  class_Monitor_nD_save(&_DIFFABS_DCM_out_e_var);






  class_Monitor_nD_save(&_DIFFABS_sample_stage_var);


  class_Monitor_nD_save(&_DIFFABS_fluo_monitor_var);

  class_Monitor_nD_save(&_DIFFABS_det_angle_var);

  class_Monitor_nD_save(&_DIFFABS_xpad_var);






  class_Monitor_nD_save(&_SIXS_mon_src_xy_var);

  class_Monitor_nD_save(&_SIXS_mon_src_e_var);


  class_Monitor_nD_save(&_SIXS_slit_mon_xy_var);






  class_Monitor_nD_save(&_SIXS_mon_dcm_e_var);

  class_Monitor_nD_save(&_SIXS_mon_dcm_xy_var);









  class_Monitor_nD_save(&_SIXS_sample_stage_var);




  class_Monitor_nD_save(&_SIXS_det4pi_var);

  class_Monitor_nD_save(&_SIXS_detector_layer_var);

  class_Monitor_nD_save(&_SIXS_detector_bulk_var);












  class_Monitor_nD_save(&_CASSIOPEE_PSD_M1out_var);



  class_Monitor_nD_save(&_CASSIOPEE_M2_rotation_axis_var);





  class_Monitor_nD_save(&_CASSIOPEE_PSD_var);





  class_Monitor_nD_save(&_SIRIUS_M1_loc_var);




  class_Monitor_nD_save(&_SIRIUS_DCM_location_var);





  class_Monitor_nD_save(&_SIRIUS_DCM_out_var);

  class_Monitor_nD_save(&_SIRIUS_DCM_out_div_var);

  class_Monitor_nD_save(&_SIRIUS_DCM_out_e_var);

  class_Monitor_nD_save(&_SIRIUS_def_loc_var);




  class_Monitor_nD_save(&_SIRIUS_sample_stage_var);


  class_Monitor_nD_save(&_SIRIUS_det_2d_var);

  class_Monitor_nD_save(&_SIRIUS_det_fluo_var);





  class_Monitor_nD_save(&_LUCIA_mon_src_xy_var);

  class_Monitor_nD_save(&_LUCIA_mon_src_e_var);


  class_Monitor_nD_save(&_LUCIA_slit_mon_xy_var);






  class_Monitor_nD_save(&_LUCIA_mon_dcm_e_var);

  class_Monitor_nD_save(&_LUCIA_mon_dcm_xy_var);


  class_Monitor_nD_save(&_LUCIA_sample_stage_var);



  class_Monitor_nD_save(&_LUCIA_transmission_var);

  class_Fluo_detector_save(&_LUCIA_mon_spl_SDD_var);

  class_Monitor_nD_save(&_LUCIA_mon_spl_fluo_var);









  if (!handle) siminfo_close(); 

  return(0);
} /* save */

/* *****************************************************************************
* instrument 'SOLEIL' and components FINALLY
***************************************************************************** */

_class_Monitor_nD *class_Monitor_nD_finally(_class_Monitor_nD *_comp
) {
  #define user0 (_comp->_parameters.user0)
  #define user1 (_comp->_parameters.user1)
  #define user2 (_comp->_parameters.user2)
  #define user3 (_comp->_parameters.user3)
  #define user4 (_comp->_parameters.user4)
  #define user5 (_comp->_parameters.user5)
  #define user6 (_comp->_parameters.user6)
  #define user7 (_comp->_parameters.user7)
  #define user8 (_comp->_parameters.user8)
  #define user9 (_comp->_parameters.user9)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define bins (_comp->_parameters.bins)
  #define min (_comp->_parameters.min)
  #define max (_comp->_parameters.max)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define radius (_comp->_parameters.radius)
  #define options (_comp->_parameters.options)
  #define filename (_comp->_parameters.filename)
  #define geometry (_comp->_parameters.geometry)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define username0 (_comp->_parameters.username0)
  #define username1 (_comp->_parameters.username1)
  #define username2 (_comp->_parameters.username2)
  #define username3 (_comp->_parameters.username3)
  #define username4 (_comp->_parameters.username4)
  #define username5 (_comp->_parameters.username5)
  #define username6 (_comp->_parameters.username6)
  #define username7 (_comp->_parameters.username7)
  #define username8 (_comp->_parameters.username8)
  #define username9 (_comp->_parameters.username9)
  #define DEFS (_comp->_parameters.DEFS)
  #define Vars (_comp->_parameters.Vars)
  #define detector (_comp->_parameters.detector)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_MARS_displaySourceLength_finally] component MARS_displaySourceLength=Monitor_nD() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:600]");

  /* free pointers */
  Monitor_nD_Finally (&DEFS, &Vars);
  #undef user0
  #undef user1
  #undef user2
  #undef user3
  #undef user4
  #undef user5
  #undef user6
  #undef user7
  #undef user8
  #undef user9
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef bins
  #undef min
  #undef max
  #undef restore_xray
  #undef radius
  #undef options
  #undef filename
  #undef geometry
  #undef nowritefile
  #undef username0
  #undef username1
  #undef username2
  #undef username3
  #undef username4
  #undef username5
  #undef username6
  #undef username7
  #undef username8
  #undef username9
  #undef DEFS
  #undef Vars
  #undef detector
  #undef offdata
  return(_comp);
} /* class_Monitor_nD_finally */

_class_PSD_monitor *class_PSD_monitor_finally(_class_PSD_monitor *_comp
) {
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nr (_comp->_parameters.nr)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_displaySource_finally] component MARS_displaySource=PSD_monitor() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:152]");

  destroy_darr2d (PSD_N);
  destroy_darr2d (PSD_p);
  destroy_darr2d (PSD_p2);
  #undef filename
  #undef xwidth
  #undef yheight
  #undef radius
  #undef restore_xray
  #undef nowritefile
  #undef nx
  #undef ny
  #undef nr
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_finally */

_class_FluoPowder *class_FluoPowder_finally(_class_FluoPowder *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_powder (_comp->_parameters.flag_powder)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define powder_refl (_comp->_parameters.powder_refl)
  #define powder_format (_comp->_parameters.powder_format)
  #define Vc (_comp->_parameters.Vc)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define DW (_comp->_parameters.DW)
  #define d_phi (_comp->_parameters.d_phi)
  #define nb_atoms (_comp->_parameters.nb_atoms)
  #define barns (_comp->_parameters.barns)
  #define tth_sign (_comp->_parameters.tth_sign)
  #define order (_comp->_parameters.order)
  #define line_info (_comp->_parameters.line_info)
  #define columns (_comp->_parameters.columns)
  #define mat_columns (_comp->_parameters.mat_columns)
  #define offdata (_comp->_parameters.offdata)
  #define tgt_x (_comp->_parameters.tgt_x)
  #define tgt_y (_comp->_parameters.tgt_y)
  #define tgt_z (_comp->_parameters.tgt_z)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_Nq (_comp->_parameters.reuse_Nq)
  #define reuse_my_s_k2_sum (_comp->_parameters.reuse_my_s_k2_sum)
  SIG_MESSAGE("[_MARS_Sample_finally] component MARS_Sample=FluoPowder() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoPowder.comp:921]");

  FreeCompoundData(compound);

  if (n_fluo || n_Compton || n_Rayleigh || n_diff)
    MPI_MASTER(
      printf("INFO: %s: scattered intensity: fluo=%g Compton=%g Rayleigh=%g Diffraction=%g\n",
        NAME_CURRENT_COMP, p_fluo, p_Compton, p_Rayleigh, p_diff);
    );
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_powder
  #undef flag_kissel
  #undef powder_refl
  #undef powder_format
  #undef Vc
  #undef delta_d_d
  #undef DW
  #undef d_phi
  #undef nb_atoms
  #undef barns
  #undef tth_sign
  #undef order
  #undef line_info
  #undef columns
  #undef mat_columns
  #undef offdata
  #undef tgt_x
  #undef tgt_y
  #undef tgt_z
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef n_diff
  #undef p_diff
  #undef fluo_rho
  #undef reuse_cum_xs_diffraction
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_Nq
  #undef reuse_my_s_k2_sum
  return(_comp);
} /* class_FluoPowder_finally */

_class_Undulator *class_Undulator_finally(_class_Undulator *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define dEe (_comp->_parameters.dEe)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define lu (_comp->_parameters.lu)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define sigepx (_comp->_parameters.sigepx)
  #define sigepy (_comp->_parameters.sigepy)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define quick_integ (_comp->_parameters.quick_integ)
  #define E1st (_comp->_parameters.E1st)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define length (_comp->_parameters.length)
  #define kc (_comp->_parameters.kc)
  #define pmul (_comp->_parameters.pmul)
  #define gap (_comp->_parameters.gap)
  #define Bsig (_comp->_parameters.Bsig)
  #define Bpi (_comp->_parameters.Bpi)
  #define gsl_int_ws (_comp->_parameters.gsl_int_ws)
  #define alpha (_comp->_parameters.alpha)
  #define MELE (_comp->_parameters.MELE)
  SIG_MESSAGE("[_CRISTAL_Source_finally] component CRISTAL_Source=Undulator() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:348]");

  if (!quick_integ) {
    gsl_integration_workspace_free (gsl_int_ws);
  }
  #undef E0
  #undef dE
  #undef phase
  #undef randomphase
  #undef Ee
  #undef dEe
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef lu
  #undef sigey
  #undef sigex
  #undef sigepx
  #undef sigepy
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef quick_integ
  #undef E1st
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef s1x
  #undef s1y
  #undef length
  #undef kc
  #undef pmul
  #undef gap
  #undef Bsig
  #undef Bpi
  #undef gsl_int_ws
  #undef alpha
  #undef MELE
  return(_comp);
} /* class_Undulator_finally */

_class_FluoCrystal *class_FluoCrystal_finally(_class_FluoCrystal *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define sx_refl (_comp->_parameters.sx_refl)
  #define flag_sx (_comp->_parameters.flag_sx)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define barns (_comp->_parameters.barns)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define order (_comp->_parameters.order)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_coh_refl (_comp->_parameters.reuse_coh_refl)
  #define reuse_coh_xsect (_comp->_parameters.reuse_coh_xsect)
  #define reuse_tau_count (_comp->_parameters.reuse_tau_count)
  SIG_MESSAGE("[_GALAXIES_sample_finally] component GALAXIES_sample=FluoCrystal() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/FluoCrystal.comp:902]");

  FreeCompoundData(compound);

  if (n_fluo || n_Compton || n_Rayleigh || n_diff)
    MPI_MASTER(
      printf("FluoCrystal: %s: scattered intensity: fluo=%g Compton=%g Rayleigh=%g Diffraction=%g\n",
        NAME_CURRENT_COMP, p_fluo, p_Compton, p_Rayleigh, p_diff);
    );
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef sx_refl
  #undef flag_sx
  #undef delta_d_d
  #undef barns
  #undef recip_cell
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef aa
  #undef bb
  #undef cc
  #undef mosaic_AB
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef order
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef n_diff
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef p_diff
  #undef fluo_rho
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_cum_xs_diffraction
  #undef reuse_coh_refl
  #undef reuse_coh_xsect
  #undef reuse_tau_count
  return(_comp);
} /* class_FluoCrystal_finally */

_class_Single_crystal *class_Single_crystal_finally(_class_Single_crystal *_comp
) {
  #define reflections (_comp->_parameters.reflections)
  #define geometry (_comp->_parameters.geometry)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define barns (_comp->_parameters.barns)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define p_transmit (_comp->_parameters.p_transmit)
  #define sigma_inc (_comp->_parameters.sigma_inc)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define order (_comp->_parameters.order)
  #define extra_order (_comp->_parameters.extra_order)
  #define RX (_comp->_parameters.RX)
  #define RY (_comp->_parameters.RY)
  #define powder (_comp->_parameters.powder)
  #define deltak (_comp->_parameters.deltak)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define surf_size (_comp->_parameters.surf_size)
  #define surf_k (_comp->_parameters.surf_k)
  #define surf_FT2 (_comp->_parameters.surf_FT2)
  #define surf_dir (_comp->_parameters.surf_dir)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  SIG_MESSAGE("[_PX1_sample_finally] component PX1_sample=Single_crystal() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1897]");

  MPI_MASTER (
      if (hkl_info.flag_warning > 10) fprintf (stderr, "Single_crystal: %s: Warning messages were repeated %i times with absorbed photons/illegal tau search.\n",
                                               NAME_CURRENT_COMP, hkl_info.flag_warning);

      /* in case this instance is used in a SPLIT, we can recommend the
         optimal iteration value */
      if (hkl_info.max_tau_count >= MCSX_REFL_SLIST_SIZE) {
        fprintf (
            stderr,
            "Single_crystal: %s: WARNING: The reflection short list buffer was exhausted at least once. Please consider redefining MCSX_REFL_SLIST_SIZE > %d\n",
            NAME_CURRENT_COMP, MCSX_REFL_SLIST_SIZE);
      }

      if (hkl_info.nb_refl_count) {
        double split_iterations = (double)hkl_info.nb_reuses / hkl_info.nb_refl_count + 1;
        double split_optimal = (double)hkl_info.nb_refl / hkl_info.nb_refl_count;
        if (split_optimal > split_iterations + 5) {
          printf ("Single_crystal: %s: Info: you may improve the computation efficiency by using\n"
                  "    SPLIT %i COMPONENT %s=Single_crystal(order=1, ...)\n"
                  "  in the instrument description %s.\n",
                  NAME_CURRENT_COMP, (int)split_optimal, NAME_CURRENT_COMP, instrument_source);
        }
      });
  #undef reflections
  #undef geometry
  #undef mosaic_AB
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef delta_d_d
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef recip_cell
  #undef barns
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef p_transmit
  #undef sigma_inc
  #undef aa
  #undef bb
  #undef cc
  #undef order
  #undef extra_order
  #undef RX
  #undef RY
  #undef powder
  #undef deltak
  #undef material_datafile
  #undef surf_size
  #undef surf_k
  #undef surf_FT2
  #undef surf_dir
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  return(_comp);
} /* class_Single_crystal_finally */

_class_PSD_monitor_4PI *class_PSD_monitor_4PI_finally(_class_PSD_monitor_4PI *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  SIG_MESSAGE("[_PX1_psd4pi_finally] component PX1_psd4pi=PSD_monitor_4PI() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:111]");

  destroy_darr2d (PSD_N);
  destroy_darr2d (PSD_p);
  destroy_darr2d (PSD_p2);
  #undef radius
  #undef restore_xray
  #undef nx
  #undef ny
  #undef filename
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  return(_comp);
} /* class_PSD_monitor_4PI_finally */

_class_SAXSQMonitor *class_SAXSQMonitor_finally(_class_SAXSQMonitor *_comp
) {
  #define RFilename (_comp->_parameters.RFilename)
  #define qFilename (_comp->_parameters.qFilename)
  #define NumberOfBins (_comp->_parameters.NumberOfBins)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define RadiusDetector (_comp->_parameters.RadiusDetector)
  #define DistanceFromSample (_comp->_parameters.DistanceFromSample)
  #define LambdaMin (_comp->_parameters.LambdaMin)
  #define Lambda0 (_comp->_parameters.Lambda0)
  #define qMax (_comp->_parameters.qMax)
  #define Nofq (_comp->_parameters.Nofq)
  #define Iofq (_comp->_parameters.Iofq)
  #define IofqSquared (_comp->_parameters.IofqSquared)
  #define NofR (_comp->_parameters.NofR)
  #define IofR (_comp->_parameters.IofR)
  #define IofRSquared (_comp->_parameters.IofRSquared)
  SIG_MESSAGE("[_SWING_QMonitor_finally] component SWING_QMonitor=SAXSQMonitor() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSQMonitor.comp:184]");

  destroy_darr1d (Nofq);
  destroy_darr1d (Iofq);
  destroy_darr1d (IofqSquared);
  destroy_darr1d (NofR);
  destroy_darr1d (IofR);
  destroy_darr1d (IofRSquared);
  #undef RFilename
  #undef qFilename
  #undef NumberOfBins
  #undef restore_xray
  #undef RadiusDetector
  #undef DistanceFromSample
  #undef LambdaMin
  #undef Lambda0
  #undef qMax
  #undef Nofq
  #undef Iofq
  #undef IofqSquared
  #undef NofR
  #undef IofR
  #undef IofRSquared
  return(_comp);
} /* class_SAXSQMonitor_finally */

_class_Divergence_monitor *class_Divergence_monitor_finally(_class_Divergence_monitor *_comp
) {
  #define nh (_comp->_parameters.nh)
  #define nv (_comp->_parameters.nv)
  #define rad (_comp->_parameters.rad)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define maxdiv_h (_comp->_parameters.maxdiv_h)
  #define maxdiv_v (_comp->_parameters.maxdiv_v)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define Div_N (_comp->_parameters.Div_N)
  #define Div_p (_comp->_parameters.Div_p)
  #define Div_p2 (_comp->_parameters.Div_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_ROCK_slit3_div_finally] component ROCK_slit3_div=Divergence_monitor() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Divergence_monitor.comp:142]");

  destroy_darr2d (Div_N);
  destroy_darr2d (Div_p);
  destroy_darr2d (Div_p2);
  #undef nh
  #undef nv
  #undef rad
  #undef filename
  #undef xwidth
  #undef yheight
  #undef maxdiv_h
  #undef maxdiv_v
  #undef restore_xray
  #undef nx
  #undef ny
  #undef nz
  #undef nowritefile
  #undef Div_N
  #undef Div_p
  #undef Div_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_Divergence_monitor_finally */

_class_Fluorescence *class_Fluorescence_finally(_class_Fluorescence *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define rho (_comp->_parameters.rho)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define flag_low_z (_comp->_parameters.flag_low_z)
  #define order (_comp->_parameters.order)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define xs_fluo (_comp->_parameters.xs_fluo)
  #define xs_Compton (_comp->_parameters.xs_Compton)
  #define xs_Rayleigh (_comp->_parameters.xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_xs_fluo (_comp->_parameters.reuse_xs_fluo)
  #define reuse_xs_Compton (_comp->_parameters.reuse_xs_Compton)
  #define reuse_xs_Rayleigh (_comp->_parameters.reuse_xs_Rayleigh)
  SIG_MESSAGE("[_ROCK_absorption_sample_finally] component ROCK_absorption_sample=Fluorescence() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:992]");

  FreeCompoundData(compound);

  if (n_fluo || n_Compton || n_Rayleigh)
    MPI_MASTER(
      printf("INFO: %s: scattered intensity: fluo=%g Compton=%g Rayleigh=%g\n",
             NAME_CURRENT_COMP, p_fluo, p_Compton, p_Rayleigh);
    );
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef rho
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef flag_low_z
  #undef order
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef xs_fluo
  #undef xs_Compton
  #undef xs_Rayleigh
  #undef shape
  #undef offdata
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_xs_fluo
  #undef reuse_xs_Compton
  #undef reuse_xs_Rayleigh
  return(_comp);
} /* class_Fluorescence_finally */

_class_Filter *class_Filter_finally(_class_Filter *_comp
) {
  #define refraction (_comp->_parameters.refraction)
  #define fixed_delta (_comp->_parameters.fixed_delta)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define geometry (_comp->_parameters.geometry)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define mu_col (_comp->_parameters.mu_col)
  #define Z (_comp->_parameters.Z)
  #define mu_c (_comp->_parameters.mu_c)
  #define Ar (_comp->_parameters.Ar)
  #define rho (_comp->_parameters.rho)
  #define delta_prefactor (_comp->_parameters.delta_prefactor)
  #define betafact (_comp->_parameters.betafact)
  #define table (_comp->_parameters.table)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define filter_row (_comp->_parameters.filter_row)
  SIG_MESSAGE("[_ANATOMIX_sample_finally] component ANATOMIX_sample=Filter() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Filter.comp:339]");

  Table_Free (&(table));
  #undef refraction
  #undef fixed_delta
  #undef material_datafile
  #undef geometry
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef mu_col
  #undef Z
  #undef mu_c
  #undef Ar
  #undef rho
  #undef delta_prefactor
  #undef betafact
  #undef table
  #undef shape
  #undef offdata
  #undef filter_row
  return(_comp);
} /* class_Filter_finally */

_class_PSD_monitor_coh *class_PSD_monitor_coh_finally(_class_PSD_monitor_coh *_comp
) {
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define ratio (_comp->_parameters.ratio)
  #define centering (_comp->_parameters.centering)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define PSD_phi_real (_comp->_parameters.PSD_phi_real)
  #define PSD_phi_imag (_comp->_parameters.PSD_phi_imag)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_NANO_psd_source_finally] component NANO_psd_source=PSD_monitor_coh() FINALLY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_coh.comp:261]");

  destroy_darr2d (PSD_N);
  destroy_darr2d (PSD_p2);
  destroy_darr2d (PSD_phi_real);
  destroy_darr2d (PSD_phi_imag);
  #undef nx
  #undef ny
  #undef filename
  #undef restore_xray
  #undef xwidth
  #undef yheight
  #undef ratio
  #undef centering
  #undef nowritefile
  #undef PSD_N
  #undef PSD_p2
  #undef PSD_phi_real
  #undef PSD_phi_imag
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_coh_finally */



int finally(void) { /* called by mccode_main for SOLEIL:FINALLY */
#pragma acc update host(_origin_var)
#pragma acc update host(_jumper_var)
#pragma acc update host(_beamdump_var)
#pragma acc update host(_ODE_pos_var)
#pragma acc update host(_SMIS_pos_var)
#pragma acc update host(_AILES_pos_var)
#pragma acc update host(_MARS_pos_var)
#pragma acc update host(_MARS_var)
#pragma acc update host(_MARS_Source_var)
#pragma acc update host(_MARS_displaySourceLength_var)
#pragma acc update host(_MARS_displaySource_var)
#pragma acc update host(_MARS_slit1_var)
#pragma acc update host(_MARS_slit2_var)
#pragma acc update host(_MARS_M1_arm_translation_var)
#pragma acc update host(_MARS_M1_arm_rotation_1_var)
#pragma acc update host(_MARS_mirror_M1_var)
#pragma acc update host(_MARS_M1_arm_rotation_2_var)
#pragma acc update host(_MARS_M1_arm_rotation_2_undo_var)
#pragma acc update host(_MARS_beam_arm_before_crystal_var)
#pragma acc update host(_MARS_dcm_xtal0_var)
#pragma acc update host(_MARS_dcm0_var)
#pragma acc update host(_MARS_dcm_xtal1_var)
#pragma acc update host(_MARS_dcm1_var)
#pragma acc update host(_MARS_emon_dcm0_var)
#pragma acc update host(_MARS_displayMono_var)
#pragma acc update host(_MARS_displayMonoLength_var)
#pragma acc update host(_MARS_M2_arm_translation_var)
#pragma acc update host(_MARS_M2_arm_rotation_1_var)
#pragma acc update host(_MARS_mirror_M2_var)
#pragma acc update host(_MARS_M2_arm_rotation_2_var)
#pragma acc update host(_MARS_M2_arm_rotation_2_undo_var)
#pragma acc update host(_MARS_slitSecon1_var)
#pragma acc update host(_MARS_slitSecon2_var)
#pragma acc update host(_MARS_emon_dcm1_var)
#pragma acc update host(_MARS_displaySlit2_var)
#pragma acc update host(_MARS_Sample_var)
#pragma acc update host(_MARS_detector_diffraction_var)
#pragma acc update host(_MARS_detector_fluo_var)
#pragma acc update host(_beamdump_40_var)
#pragma acc update host(_PSICHE_pos_var)
#pragma acc update host(_PSICHE_var)
#pragma acc update host(_PSICHE_source_var)
#pragma acc update host(_PSICHE_mon_src_e_var)
#pragma acc update host(_PSICHE_mon_src_xy_var)
#pragma acc update host(_PSICHE_DCM_location_var)
#pragma acc update host(_PSICHE_dcm_xtal0_var)
#pragma acc update host(_PSICHE_dcm0_var)
#pragma acc update host(_PSICHE_dcm_xtal1_var)
#pragma acc update host(_PSICHE_dcm1_var)
#pragma acc update host(_PSICHE_mon_dcm_e_var)
#pragma acc update host(_PSICHE_mon_dcm_xy_var)
#pragma acc update host(_PSICHE_slit_var)
#pragma acc update host(_PSICHE_sample_stage_var)
#pragma acc update host(_PSICHE_sample_var)
#pragma acc update host(_PSICHE_fluo_holder_var)
#pragma acc update host(_PSICHE_mon_spl_fluo_var)
#pragma acc update host(_PSICHE_mon_spl_e_var)
#pragma acc update host(_PSICHE_mon_spl_xy_var)
#pragma acc update host(_beamdump_61_var)
#pragma acc update host(_PLEIADES_pos_var)
#pragma acc update host(_DISCO_pos_var)
#pragma acc update host(_DISCO_var)
#pragma acc update host(_DISCO_Source_var)
#pragma acc update host(_DISCO_ColdFinger_var)
#pragma acc update host(_DISCO_M1_location_var)
#pragma acc update host(_DISCO_M1_rotated_var)
#pragma acc update host(_DISCO_M1_x_var)
#pragma acc update host(_DISCO_M1_var)
#pragma acc update host(_DISCO_M1_takeoff_var)
#pragma acc update host(_DISCO_M1_x_takeoff_var)
#pragma acc update host(_DISCO_M2_location_var)
#pragma acc update host(_DISCO_M2_rotated_x_var)
#pragma acc update host(_DISCO_M2_rotated_var)
#pragma acc update host(_DISCO_M2_other_side_var)
#pragma acc update host(_DISCO_M2_var)
#pragma acc update host(_DISCO_M2_other_side_back_var)
#pragma acc update host(_DISCO_M2_takeoff_var)
#pragma acc update host(_DISCO_HFP_location_var)
#pragma acc update host(_DISCO_HFP_var)
#pragma acc update host(_DISCO_M3_arm_var)
#pragma acc update host(_DISCO_M3_var)
#pragma acc update host(_DISCO_M3_takeoff_var)
#pragma acc update host(_DISCO_M3_yz_var)
#pragma acc update host(_DISCO_M4_yz_var)
#pragma acc update host(_DISCO_M4_var)
#pragma acc update host(_DISCO_M4_takeoff_var)
#pragma acc update host(_DISCO_M4_arm_back_var)
#pragma acc update host(_DISCO_VFP_location_var)
#pragma acc update host(_DISCO_VFP_var)
#pragma acc update host(_DISCO_M51_position_var)
#pragma acc update host(_DISCO_M51_rotation_var)
#pragma acc update host(_DISCO_M51_var)
#pragma acc update host(_DISCO_arm_var)
#pragma acc update host(_DISCO_M51_arm_back_var)
#pragma acc update host(_DISCO_M52_position_var)
#pragma acc update host(_DISCO_M52_x_var)
#pragma acc update host(_DISCO_M52_var)
#pragma acc update host(_DISCO_M52_takeoff_var)
#pragma acc update host(_DISCO_M52_x_takeoff_var)
#pragma acc update host(_DISCO_second_HFP_location_var)
#pragma acc update host(_DISCO_second_HFP_var)
#pragma acc update host(_DISCO_M53_location_var)
#pragma acc update host(_DISCO_M53_rotated_var)
#pragma acc update host(_DISCO_M53_var)
#pragma acc update host(_DISCO_M53_takeoff_var)
#pragma acc update host(_DISCO_M54_location_var)
#pragma acc update host(_DISCO_M54_rotated_var)
#pragma acc update host(_DISCO_M54_var)
#pragma acc update host(_DISCO_M54_takeoff_var)
#pragma acc update host(_DISCO_Mtoroids_arm_back_var)
#pragma acc update host(_DISCO_M1_position_var)
#pragma acc update host(_DISCO_M1_rotation_var)
#pragma acc update host(_DISCO_mirror_m1_var)
#pragma acc update host(_DISCO_armm_var)
#pragma acc update host(_DISCO_M1_arm_back_var)
#pragma acc update host(_DISCO_Grating_position_var)
#pragma acc update host(_DISCO_Grating_rotation_var)
#pragma acc update host(_DISCO_Grating_rotation_lines_grating_var)
#pragma acc update host(_DISCO_Grating_rotation_nine_degrees_var)
#pragma acc update host(_DISCO_reflective_grating_var)
#pragma acc update host(_DISCO_Grating_rotation_lines_grating_back_var)
#pragma acc update host(_DISCO_Grating_arm_back_var)
#pragma acc update host(_DISCO_Grating_arm_back_2_var)
#pragma acc update host(_DISCO_Grating_arm_back_3_var)
#pragma acc update host(_DISCO_M22_location_var)
#pragma acc update host(_DISCO_M22_rotated_var)
#pragma acc update host(_DISCO_mirror_m2_var)
#pragma acc update host(_DISCO_arm2_var)
#pragma acc update host(_DISCO_M44_arm_back_var)
#pragma acc update host(_DISCO_arm3_var)
#pragma acc update host(_DISCO_psd_before_slit_var)
#pragma acc update host(_DISCO_slit_var)
#pragma acc update host(_DISCO_psd_monitor_var)
#pragma acc update host(_DISCO_psd_giant_after_grating_var)
#pragma acc update host(_DISCO_e_monitor_var)
#pragma acc update host(_DISCO_w_monitor_var)
#pragma acc update host(_beamdump_140_var)
#pragma acc update host(_DESIRS_pos_var)
#pragma acc update host(_METRO_pos_var)
#pragma acc update host(_PUMA_pos_var)
#pragma acc update host(_PUMA_var)
#pragma acc update host(_PUMA_Source_var)
#pragma acc update host(_PUMA_slit1_var)
#pragma acc update host(_PUMA_slit2_var)
#pragma acc update host(_PUMA_mon_src_e_var)
#pragma acc update host(_PUMA_mon_src_xy_var)
#pragma acc update host(_PUMA_HFM_location_var)
#pragma acc update host(_PUMA_HFM_rotated_var)
#pragma acc update host(_PUMA_mirror_HFM_var)
#pragma acc update host(_PUMA_HFM_out_var)
#pragma acc update host(_PUMA_mon_HFM_out_xy_var)
#pragma acc update host(_PUMA_DCM_location_var)
#pragma acc update host(_PUMA_DCM_xtal1_var)
#pragma acc update host(_PUMA_DCM_xtal1_out_var)
#pragma acc update host(_PUMA_mon_DCM_xtal1_only_xy_var)
#pragma acc update host(_PUMA_DCM_xtal2_var)
#pragma acc update host(_PUMA_DCM_xtal2_out_var)
#pragma acc update host(_PUMA_mon_DCM_out_e_var)
#pragma acc update host(_PUMA_mon_DCM_out_xy_var)
#pragma acc update host(_PUMA_slit3_var)
#pragma acc update host(_PUMA_slit4_var)
#pragma acc update host(_PUMA_slit5_var)
#pragma acc update host(_PUMA_KB_VFM_location_var)
#pragma acc update host(_PUMA_mon_KB_in_xy_var)
#pragma acc update host(_PUMA_KB_VFM_rotated_var)
#pragma acc update host(_PUMA_mirror_KB_VFM_var)
#pragma acc update host(_PUMA_KB_VFM_out_var)
#pragma acc update host(_PUMA_mon_KB_VFM_out_xy_var)
#pragma acc update host(_PUMA_KB_HFM_location_var)
#pragma acc update host(_PUMA_KB_HFM_rotated_var)
#pragma acc update host(_PUMA_mirror_KB_HFM_var)
#pragma acc update host(_PUMA_KB_HFM_out_var)
#pragma acc update host(_PUMA_mon_KB_HFM_out_xy_var)
#pragma acc update host(_PUMA_sample_location_var)
#pragma acc update host(_PUMA_mon_sample_xy_var)
#pragma acc update host(_PUMA_mon_sample_e_var)
#pragma acc update host(_beamdump_181_var)
#pragma acc update host(_CRISTAL_pos_var)
#pragma acc update host(_CRISTAL_var)
#pragma acc update host(_CRISTAL_Source_var)
#pragma acc update host(_CRISTAL_slit1_var)
#pragma acc update host(_CRISTAL_dcm_location_var)
#pragma acc update host(_CRISTAL_dcm_xtal0_var)
#pragma acc update host(_CRISTAL_arm_xtal0_var)
#pragma acc update host(_CRISTAL_dcm_xtal1_var)
#pragma acc update host(_CRISTAL_arm_xtal1_var)
#pragma acc update host(_CRISTAL_emon_dcm_var)
#pragma acc update host(_CRISTAL_M1_location_var)
#pragma acc update host(_CRISTAL_M1_rotated_var)
#pragma acc update host(_CRISTAL_M1_var)
#pragma acc update host(_CRISTAL_M1_out_var)
#pragma acc update host(_CRISTAL_M2_location_var)
#pragma acc update host(_CRISTAL_M2_rotated_var)
#pragma acc update host(_CRISTAL_M2_var)
#pragma acc update host(_CRISTAL_M2_out_var)
#pragma acc update host(_CRISTAL_slit2_var)
#pragma acc update host(_CRISTAL_psd_slit2_var)
#pragma acc update host(_CRISTAL_sample_stage_var)
#pragma acc update host(_CRISTAL_fluo_var)
#pragma acc update host(_CRISTAL_detector_diffraction_var)
#pragma acc update host(_CRISTAL_detector_fluo_var)
#pragma acc update host(_beamdump_207_var)
#pragma acc update host(_DEIMOS_pos_var)
#pragma acc update host(_GALAXIES_pos_var)
#pragma acc update host(_GALAXIES_var)
#pragma acc update host(_GALAXIES_Source_U20_var)
#pragma acc update host(_GALAXIES_mon_src_xy_var)
#pragma acc update host(_GALAXIES_mon_src_e_var)
#pragma acc update host(_GALAXIES_absorber_var)
#pragma acc update host(_GALAXIES_diaphragme_var)
#pragma acc update host(_GALAXIES_fentes_primaires_var)
#pragma acc update host(_GALAXIES_mon_prim_xy_var)
#pragma acc update host(_GALAXIES_DCM_location_var)
#pragma acc update host(_GALAXIES_dcm_xtal0_var)
#pragma acc update host(_GALAXIES_dcm0_var)
#pragma acc update host(_GALAXIES_dcm_xtal1_var)
#pragma acc update host(_GALAXIES_dcm1_var)
#pragma acc update host(_GALAXIES_mon_dcm_e_var)
#pragma acc update host(_GALAXIES_mon_dcm_xy_var)
#pragma acc update host(_GALAXIES_M1_location_var)
#pragma acc update host(_GALAXIES_M1_rotated_var)
#pragma acc update host(_GALAXIES_M1_var)
#pragma acc update host(_GALAXIES_M1_out_var)
#pragma acc update host(_GALAXIES_HRM_gate_in_var)
#pragma acc update host(_GALAXIES_M2A_location_var)
#pragma acc update host(_GALAXIES_M2A_rotated_var)
#pragma acc update host(_GALAXIES_M2A_var)
#pragma acc update host(_GALAXIES_M2A_out_var)
#pragma acc update host(_GALAXIES_secondary_slits_var)
#pragma acc update host(_GALAXIES_mon_sec_xy_var)
#pragma acc update host(_GALAXIES_M2B_location_var)
#pragma acc update host(_GALAXIES_M2B_rotated_var)
#pragma acc update host(_GALAXIES_M2B_var)
#pragma acc update host(_GALAXIES_M2B_out_var)
#pragma acc update host(_GALAXIES_VFM_location_var)
#pragma acc update host(_GALAXIES_VFM_rotated_var)
#pragma acc update host(_GALAXIES_VFM_var)
#pragma acc update host(_GALAXIES_VFM_out_var)
#pragma acc update host(_GALAXIES_HFM_rotated_var)
#pragma acc update host(_GALAXIES_HFM_var)
#pragma acc update host(_GALAXIES_HFM_out_var)
#pragma acc update host(_GALAXIES_mon_sample_xy_kb_var)
#pragma acc update host(_GALAXIES_mon_sample_e_var)
#pragma acc update host(_GALAXIES_sample_stage_var)
#pragma acc update host(_GALAXIES_sample_var)
#pragma acc update host(_GALAXIES_sample_out_var)
#pragma acc update host(_GALAXIES_ana_arm_var)
#pragma acc update host(_GALAXIES_analyzer_var)
#pragma acc update host(_GALAXIES_ana_out_var)
#pragma acc update host(_GALAXIES_IXS_det_var)
#pragma acc update host(_beamdump_257_var)
#pragma acc update host(_TEMPO_pos_var)
#pragma acc update host(_SAMBA_pos_var)
#pragma acc update host(_SAMBA_var)
#pragma acc update host(_SAMBA_BM_source_var)
#pragma acc update host(_SAMBA_M1_location_var)
#pragma acc update host(_SAMBA_M1_rotated_var)
#pragma acc update host(_SAMBA_M1_var)
#pragma acc update host(_SAMBA_M1_out_var)
#pragma acc update host(_SAMBA_DCM_location_var)
#pragma acc update host(_SAMBA_bragg_crystal_var)
#pragma acc update host(_SAMBA_arm_crystal1_var)
#pragma acc update host(_SAMBA_bragg_crystal_two_var)
#pragma acc update host(_SAMBA_arm_crystal2_var)
#pragma acc update host(_SAMBA_DCM_out_var)
#pragma acc update host(_SAMBA_DCM_out_div_var)
#pragma acc update host(_SAMBA_DCM_out_e_var)
#pragma acc update host(_SAMBA_M2_loc_var)
#pragma acc update host(_SAMBA_M2_rotated_var)
#pragma acc update host(_SAMBA_M2_var)
#pragma acc update host(_SAMBA_M2_out_var)
#pragma acc update host(_SAMBA_sample_stage_var)
#pragma acc update host(_SAMBA_fluo_var)
#pragma acc update host(_SAMBA_det_trans_var)
#pragma acc update host(_SAMBA_det_fluo_var)
#pragma acc update host(_beamdump_283_var)
#pragma acc update host(_HERMES_pos_var)
#pragma acc update host(_PX1_pos_var)
#pragma acc update host(_PX1_var)
#pragma acc update host(_PX1_undulator_var)
#pragma acc update host(_PX1_bragg_crystal_location_var)
#pragma acc update host(_PX1_bragg_crystal_var)
#pragma acc update host(_PX1_arm_var)
#pragma acc update host(_PX1_bragg_crystal_two_var)
#pragma acc update host(_PX1_arm_two_var)
#pragma acc update host(_PX1_bragg_crystal_out_var)
#pragma acc update host(_PX1_secondary_slits_var)
#pragma acc update host(_PX1_vfm_location_var)
#pragma acc update host(_PX1_vfm_in_xz_plane_var)
#pragma acc update host(_PX1_vfm_var)
#pragma acc update host(_PX1_vfm_takeoff_var)
#pragma acc update host(_PX1_hfm_location_var)
#pragma acc update host(_PX1_hfm_var)
#pragma acc update host(_PX1_hfm_takeoff_var)
#pragma acc update host(_PX1_sample_stage_var)
#pragma acc update host(_PX1_sample_monitor_var)
#pragma acc update host(_PX1_sample_var)
#pragma acc update host(_PX1_psd4pi_var)
#pragma acc update host(_PX1_EigerX16M_var)
#pragma acc update host(_beamdump_308_var)
#pragma acc update host(_PX2a_pos_var)
#pragma acc update host(_PX2a_var)
#pragma acc update host(_PX2a_undulator_var)
#pragma acc update host(_PX2a_bragg_crystal_location_var)
#pragma acc update host(_PX2a_bragg_crystal_var)
#pragma acc update host(_PX2a_arm_var)
#pragma acc update host(_PX2a_bragg_crystal_two_var)
#pragma acc update host(_PX2a_arm_two_var)
#pragma acc update host(_PX2a_bragg_crystal_out_var)
#pragma acc update host(_PX2a_hpm_location_var)
#pragma acc update host(_PX2a_hpm_in_yz_plane_var)
#pragma acc update host(_PX2a_hpm_var)
#pragma acc update host(_PX2a_hpm_takeoff_var)
#pragma acc update host(_PX2a_vfm_location_var)
#pragma acc update host(_PX2a_vfm_in_xz_plane_var)
#pragma acc update host(_PX2a_vfm_var)
#pragma acc update host(_PX2a_vfm_takeoff_var)
#pragma acc update host(_PX2a_hfm_location_var)
#pragma acc update host(_PX2a_hfm_var)
#pragma acc update host(_PX2a_hfm_takeoff_var)
#pragma acc update host(_PX2a_sample_stage_var)
#pragma acc update host(_PX2a_sample_monitor_var)
#pragma acc update host(_PX2a_sample_var)
#pragma acc update host(_PX2a_psd4pi_var)
#pragma acc update host(_PX2a_Eiger9M_var)
#pragma acc update host(_beamdump_335_var)
#pragma acc update host(_SWING_pos_var)
#pragma acc update host(_SWING_var)
#pragma acc update host(_SWING_Source_U20_var)
#pragma acc update host(_SWING_mon_src_xy_var)
#pragma acc update host(_SWING_mon_src_e_var)
#pragma acc update host(_SWING_slit_var)
#pragma acc update host(_SWING_slit_mon_xy_var)
#pragma acc update host(_SWING_DCM_location_var)
#pragma acc update host(_SWING_dcm_xtal0_var)
#pragma acc update host(_SWING_dcm0_var)
#pragma acc update host(_SWING_dcm_xtal1_var)
#pragma acc update host(_SWING_dcm1_var)
#pragma acc update host(_SWING_mon_dcm_e_var)
#pragma acc update host(_SWING_mon_dcm_xy_var)
#pragma acc update host(_SWING_vfm_location_var)
#pragma acc update host(_SWING_vfm_in_xz_plane_var)
#pragma acc update host(_SWING_vfm_var)
#pragma acc update host(_SWING_vfm_takeoff_var)
#pragma acc update host(_SWING_hfm_location_var)
#pragma acc update host(_SWING_hfm_var)
#pragma acc update host(_SWING_hfm_takeoff_var)
#pragma acc update host(_SWING_sample_stage_var)
#pragma acc update host(_SWING_sample_test_var)
#pragma acc update host(_SWING_sample_var)
#pragma acc update host(_SWING_sample_out_var)
#pragma acc update host(_SWING_Eiger4M_var)
#pragma acc update host(_SWING_QMonitor_var)
#pragma acc update host(_beamdump_364_var)
#pragma acc update host(_ANTARES_pos_var)
#pragma acc update host(_ROCK_pos_var)
#pragma acc update host(_ROCK_var)
#pragma acc update host(_ROCK_Source_var)
#pragma acc update host(_ROCK_slit1_var)
#pragma acc update host(_ROCK_slit2_var)
#pragma acc update host(_ROCK_mirror_m1_var)
#pragma acc update host(_ROCK_mirror_m1_out_var)
#pragma acc update host(_ROCK_slit3_xy_var)
#pragma acc update host(_ROCK_slit3_div_var)
#pragma acc update host(_ROCK_slit3_var)
#pragma acc update host(_ROCK_mirror_m2a_var)
#pragma acc update host(_ROCK_mirror_m2a_out_var)
#pragma acc update host(_ROCK_slit4_in_var)
#pragma acc update host(_ROCK_slit4_var)
#pragma acc update host(_ROCK_arm_crystal0_var)
#pragma acc update host(_ROCK_bragg_crystal_var)
#pragma acc update host(_ROCK_arm_crystal1_var)
#pragma acc update host(_ROCK_bragg_crystal_two_var)
#pragma acc update host(_ROCK_arm_crystal2_var)
#pragma acc update host(_ROCK_bragg_crystal_out_var)
#pragma acc update host(_ROCK_slit5_var)
#pragma acc update host(_ROCK_slit6_var)
#pragma acc update host(_ROCK_mirror_m2b_var)
#pragma acc update host(_ROCK_mirror_m2b_out_var)
#pragma acc update host(_ROCK_EnergyMonitor_before_sample_var)
#pragma acc update host(_ROCK_e_repartition_after_m2b_var)
#pragma acc update host(_ROCK_sample_in_var)
#pragma acc update host(_ROCK_absorption_sample_var)
#pragma acc update host(_ROCK_fluo_monitor_var)
#pragma acc update host(_ROCK_EnergyMonitor_after_sample_var)
#pragma acc update host(_ROCK_psd_monitor_var)
#pragma acc update host(_beamdump_398_var)
#pragma acc update host(_ANATOMIX_pos_var)
#pragma acc update host(_ANATOMIX_var)
#pragma acc update host(_ANATOMIX_source_var)
#pragma acc update host(_ANATOMIX_e_repartition_before_cc_var)
#pragma acc update host(_ANATOMIX_psd_monitor_before_cc_var)
#pragma acc update host(_ANATOMIX_bragg_crystal_var)
#pragma acc update host(_ANATOMIX_arm_var)
#pragma acc update host(_ANATOMIX_bragg_crystal_two_var)
#pragma acc update host(_ANATOMIX_arm_two_var)
#pragma acc update host(_ANATOMIX_psd_after_cc_var)
#pragma acc update host(_ANATOMIX_e_monitor_before_sample_var)
#pragma acc update host(_ANATOMIX_psd_repartition_after_cc_var)
#pragma acc update host(_ANATOMIX_sample_rotation_stage_var)
#pragma acc update host(_ANATOMIX_sample_var)
#pragma acc update host(_ANATOMIX_e_monitor_after_sample_var)
#pragma acc update host(_ANATOMIX_psd_monitor_after_cc_var)
#pragma acc update host(_beamdump_416_var)
#pragma acc update host(_NANOSCOPIUM_pos_var)
#pragma acc update host(_NANOSCOPIUM_var)
#pragma acc update host(_NANO_source_var)
#pragma acc update host(_NANO_e_monitor_source_var)
#pragma acc update host(_NANO_psd_source_var)
#pragma acc update host(_NANO_slit_1_var)
#pragma acc update host(_NANO_m1_in_var)
#pragma acc update host(_NANO_m1_roll_var)
#pragma acc update host(_NANO_mirror_m1_var)
#pragma acc update host(_NANO_beam_deviation_var)
#pragma acc update host(_NANO_m2_in_var)
#pragma acc update host(_NANO_mirror_m2_var)
#pragma acc update host(_NANO_mirror_m2_out_var)
#pragma acc update host(_NANO_slit_2_var)
#pragma acc update host(_NANO_dcm_in_var)
#pragma acc update host(_NANO_PSD_dcm_in_var)
#pragma acc update host(_NANO_bragg_roll_var)
#pragma acc update host(_NANO_bragg_crystal_1_var)
#pragma acc update host(_NANO_dcm2_rot_var)
#pragma acc update host(_NANO_dcm_transl_var)
#pragma acc update host(_NANO_bragg_crystal_2_var)
#pragma acc update host(_NANO_bragg2_out_var)
#pragma acc update host(_NANO_dcm_out_var)
#pragma acc update host(_NANO_e_dcm_out_var)
#pragma acc update host(_NANO_secondary_source_slits_var)
#pragma acc update host(_NANO_psd_ss_in_var)
#pragma acc update host(_NANO_slit_3_var)
#pragma acc update host(_NANO_psd_ss_out_var)
#pragma acc update host(_NANO_jjxray2_slits_var)
#pragma acc update host(_NANO_slit_5_var)
#pragma acc update host(_NANO_kb_in_var)
#pragma acc update host(_NANO_kb_1_var)
#pragma acc update host(_NANO_kb_beam_deviation_var)
#pragma acc update host(_NANO_kb1_out_var)
#pragma acc update host(_NANO_kb2_var)
#pragma acc update host(_NANO_kb_out_var)
#pragma acc update host(_NANO_slit_var)
#pragma acc update host(_NANO_psd_sample_stage_var)
#pragma acc update host(_beamdump_456_var)
#pragma acc update host(_DIFFABS_pos_var)
#pragma acc update host(_DIFFABS_var)
#pragma acc update host(_DIFFABS_BM_D13_1_var)
#pragma acc update host(_DIFFABS_primary_slit_var)
#pragma acc update host(_DIFFABS_M1_location_var)
#pragma acc update host(_DIFFABS_M1_rotated_var)
#pragma acc update host(_DIFFABS_M1_var)
#pragma acc update host(_DIFFABS_M1_out_var)
#pragma acc update host(_DIFFABS_DCM_slit_in_var)
#pragma acc update host(_DIFFABS_DCM_in_var)
#pragma acc update host(_DIFFABS_DCM_in_div_var)
#pragma acc update host(_DIFFABS_DCM_location_var)
#pragma acc update host(_DIFFABS_bragg_crystal_var)
#pragma acc update host(_DIFFABS_arm_crystal1_var)
#pragma acc update host(_DIFFABS_bragg_crystal_two_var)
#pragma acc update host(_DIFFABS_arm_crystal2_var)
#pragma acc update host(_DIFFABS_DCM_out_var)
#pragma acc update host(_DIFFABS_DCM_out_div_var)
#pragma acc update host(_DIFFABS_DCM_out_e_var)
#pragma acc update host(_DIFFABS_DCM_slit_out_var)
#pragma acc update host(_DIFFABS_M2_location_var)
#pragma acc update host(_DIFFABS_M2_rotated_var)
#pragma acc update host(_DIFFABS_M2_var)
#pragma acc update host(_DIFFABS_M2_out_var)
#pragma acc update host(_DIFFABS_sample_stage_var)
#pragma acc update host(_DIFFABS_fluo_var)
#pragma acc update host(_DIFFABS_fluo_monitor_var)
#pragma acc update host(_DIFFABS_det_angle_var)
#pragma acc update host(_DIFFABS_xpad_var)
#pragma acc update host(_beamdump_487_var)
#pragma acc update host(_SEXTANTS_var)
#pragma acc update host(_SIXS_pos_var)
#pragma acc update host(_SIXS_var)
#pragma acc update host(_SIXS_Source_U20_var)
#pragma acc update host(_SIXS_mon_src_xy_var)
#pragma acc update host(_SIXS_mon_src_e_var)
#pragma acc update host(_SIXS_slit_var)
#pragma acc update host(_SIXS_slit_mon_xy_var)
#pragma acc update host(_SIXS_DCM_location_var)
#pragma acc update host(_SIXS_dcm_xtal0_var)
#pragma acc update host(_SIXS_dcm0_var)
#pragma acc update host(_SIXS_dcm_xtal1_var)
#pragma acc update host(_SIXS_dcm1_var)
#pragma acc update host(_SIXS_mon_dcm_e_var)
#pragma acc update host(_SIXS_mon_dcm_xy_var)
#pragma acc update host(_SIXS_M1_location_var)
#pragma acc update host(_SIXS_M1_rotated_var)
#pragma acc update host(_SIXS_M1_var)
#pragma acc update host(_SIXS_M1_out_var)
#pragma acc update host(_SIXS_M2_location_var)
#pragma acc update host(_SIXS_M2_rotated_var)
#pragma acc update host(_SIXS_M2_var)
#pragma acc update host(_SIXS_M2_out_var)
#pragma acc update host(_SIXS_sample_stage_var)
#pragma acc update host(_SIXS_sx_layer_var)
#pragma acc update host(_SIXS_sx_bulk_var)
#pragma acc update host(_SIXS_sample_out_var)
#pragma acc update host(_SIXS_det4pi_var)
#pragma acc update host(_SIXS_detector_layer_var)
#pragma acc update host(_SIXS_detector_bulk_var)
#pragma acc update host(_beamdump_519_var)
#pragma acc update host(_CASSIOPEE_pos_var)
#pragma acc update host(_CASSIOPEE_var)
#pragma acc update host(_CASSIOPEE_Source_HU60_var)
#pragma acc update host(_CASSIOPEE_Source_HU256_var)
#pragma acc update host(_CASSIOPEE_M1a_location_var)
#pragma acc update host(_CASSIOPEE_M1a_var)
#pragma acc update host(_CASSIOPEE_M1a_out_var)
#pragma acc update host(_CASSIOPEE_M1b_var)
#pragma acc update host(_CASSIOPEE_M1c_var)
#pragma acc update host(_CASSIOPEE_M1bc_out_var)
#pragma acc update host(_CASSIOPEE_PSD_M1out_var)
#pragma acc update host(_CASSIOPEE_PG_location_var)
#pragma acc update host(_CASSIOPEE_PG_var)
#pragma acc update host(_CASSIOPEE_M2_rotation_axis_var)
#pragma acc update host(_CASSIOPEE_M2_var)
#pragma acc update host(_CASSIOPEE_PM_takeoff_var)
#pragma acc update host(_CASSIOPEE_slit_var)
#pragma acc update host(_CASSIOPEE_M4_var)
#pragma acc update host(_CASSIOPEE_PSD_var)
#pragma acc update host(_beamdump_540_var)
#pragma acc update host(_SIRIUS_pos_var)
#pragma acc update host(_SIRIUS_var)
#pragma acc update host(_SIRIUS_source_var)
#pragma acc update host(_SIRIUS_M1_loc_var)
#pragma acc update host(_SIRIUS_M1_rot_var)
#pragma acc update host(_SIRIUS_M1_var)
#pragma acc update host(_SIRIUS_M1_out_var)
#pragma acc update host(_SIRIUS_DCM_location_var)
#pragma acc update host(_SIRIUS_bragg_crystal_var)
#pragma acc update host(_SIRIUS_arm_crystal1_var)
#pragma acc update host(_SIRIUS_bragg_crystal_two_var)
#pragma acc update host(_SIRIUS_arm_crystal2_var)
#pragma acc update host(_SIRIUS_DCM_out_var)
#pragma acc update host(_SIRIUS_DCM_out_div_var)
#pragma acc update host(_SIRIUS_DCM_out_e_var)
#pragma acc update host(_SIRIUS_def_loc_var)
#pragma acc update host(_SIRIUS_def_rot_var)
#pragma acc update host(_SIRIUS_def_mirror_var)
#pragma acc update host(_SIRIUS_def_out_var)
#pragma acc update host(_SIRIUS_sample_stage_var)
#pragma acc update host(_SIRIUS_fluo_var)
#pragma acc update host(_SIRIUS_det_2d_var)
#pragma acc update host(_SIRIUS_det_fluo_var)
#pragma acc update host(_beamdump_565_var)
#pragma acc update host(_LUCIA_pos_var)
#pragma acc update host(_LUCIA_var)
#pragma acc update host(_LUCIA_source_var)
#pragma acc update host(_LUCIA_mon_src_xy_var)
#pragma acc update host(_LUCIA_mon_src_e_var)
#pragma acc update host(_LUCIA_slit_var)
#pragma acc update host(_LUCIA_slit_mon_xy_var)
#pragma acc update host(_LUCIA_DCM_location_var)
#pragma acc update host(_LUCIA_dcm_xtal0_var)
#pragma acc update host(_LUCIA_dcm0_var)
#pragma acc update host(_LUCIA_dcm_xtal1_var)
#pragma acc update host(_LUCIA_dcm1_var)
#pragma acc update host(_LUCIA_mon_dcm_e_var)
#pragma acc update host(_LUCIA_mon_dcm_xy_var)
#pragma acc update host(_LUCIA_diaphragm_var)
#pragma acc update host(_LUCIA_sample_stage_var)
#pragma acc update host(_LUCIA_fluo_rotated_var)
#pragma acc update host(_LUCIA_sample_var)
#pragma acc update host(_LUCIA_transmission_var)
#pragma acc update host(_LUCIA_mon_spl_SDD_var)
#pragma acc update host(_LUCIA_mon_spl_fluo_var)
#pragma acc update host(_beamdump_588_var)
#pragma acc update host(_storage_var)
#pragma acc update host(_hall0_var)
#pragma acc update host(_hall1_var)
#pragma acc update host(_entrance_0_var)
#pragma acc update host(_entrance_1_var)
#pragma acc update host(_ANATOMIX_building_var)
#pragma acc update host(_soleil_label_var)
#pragma acc update host(_instrument_var)

  siminfo_init(NULL);
  save(siminfo_file); /* save data when simulation ends */

  /* Instrument 'SOLEIL' FINALLY */
  SIG_MESSAGE("[SOLEIL] FINALLY [(null):-1]");
  #define splits (instrument->_parameters.splits)
  #define MARS_E0 (instrument->_parameters.MARS_E0)
  #define MARS_reflec_material_M12 (instrument->_parameters.MARS_reflec_material_M12)
  #define MARS_reflections (instrument->_parameters.MARS_reflections)
  #define MARS_dEr (instrument->_parameters.MARS_dEr)
  #define MARS_alpha (instrument->_parameters.MARS_alpha)
  #define PSICHE_E0 (instrument->_parameters.PSICHE_E0)
  #define PSICHE_dE (instrument->_parameters.PSICHE_dE)
  #define PSICHE_DCM_present (instrument->_parameters.PSICHE_DCM_present)
  #define PSICHE_sample_theta (instrument->_parameters.PSICHE_sample_theta)
  #define PSICHE_sample_material (instrument->_parameters.PSICHE_sample_material)
  #define PSICHE_sample_geometry (instrument->_parameters.PSICHE_sample_geometry)
  #define PSICHE_dcm_theta (instrument->_parameters.PSICHE_dcm_theta)
  #define DISCO_grazing_angle_one (instrument->_parameters.DISCO_grazing_angle_one)
  #define DISCO_HFP_shift (instrument->_parameters.DISCO_HFP_shift)
  #define DISCO_VFP_shift (instrument->_parameters.DISCO_VFP_shift)
  #define DISCO_second_HFP_shift (instrument->_parameters.DISCO_second_HFP_shift)
  #define DISCO_x_screw (instrument->_parameters.DISCO_x_screw)
  #define DISCO_scan (instrument->_parameters.DISCO_scan)
  #define PUMA_E0 (instrument->_parameters.PUMA_E0)
  #define PUMA_dE (instrument->_parameters.PUMA_dE)
  #define PUMA_DCM_theta (instrument->_parameters.PUMA_DCM_theta)
  #define PUMA_HFM_angle (instrument->_parameters.PUMA_HFM_angle)
  #define PUMA_HFM_focal (instrument->_parameters.PUMA_HFM_focal)
  #define PUMA_KB_angle (instrument->_parameters.PUMA_KB_angle)
  #define PUMA_KB_coating (instrument->_parameters.PUMA_KB_coating)
  #define PUMA_h (instrument->_parameters.PUMA_h)
  #define PUMA_k (instrument->_parameters.PUMA_k)
  #define PUMA_l (instrument->_parameters.PUMA_l)
  #define CRISTAL_E0 (instrument->_parameters.CRISTAL_E0)
  #define CRISTAL_dE (instrument->_parameters.CRISTAL_dE)
  #define CRISTAL_M1_angle (instrument->_parameters.CRISTAL_M1_angle)
  #define CRISTAL_M2_angle (instrument->_parameters.CRISTAL_M2_angle)
  #define CRISTAL_M1_radius (instrument->_parameters.CRISTAL_M1_radius)
  #define CRISTAL_M2_radius (instrument->_parameters.CRISTAL_M2_radius)
  #define CRISTAL_M_coating (instrument->_parameters.CRISTAL_M_coating)
  #define CRISTAL_reflections (instrument->_parameters.CRISTAL_reflections)
  #define GALAXIES_E0 (instrument->_parameters.GALAXIES_E0)
  #define GALAXIES_dE (instrument->_parameters.GALAXIES_dE)
  #define GALAXIES_hrm (instrument->_parameters.GALAXIES_hrm)
  #define GALAXIES_hrm_ref (instrument->_parameters.GALAXIES_hrm_ref)
  #define GALAXIES_sec_slits (instrument->_parameters.GALAXIES_sec_slits)
  #define GALAXIES_ana_R (instrument->_parameters.GALAXIES_ana_R)
  #define GALAXIES_ana_deg (instrument->_parameters.GALAXIES_ana_deg)
  #define GALAXIES_sample (instrument->_parameters.GALAXIES_sample)
  #define SAMBA_E0 (instrument->_parameters.SAMBA_E0)
  #define SAMBA_dE (instrument->_parameters.SAMBA_dE)
  #define SAMBA_M1_angle (instrument->_parameters.SAMBA_M1_angle)
  #define SAMBA_M2_angle (instrument->_parameters.SAMBA_M2_angle)
  #define SAMBA_sample (instrument->_parameters.SAMBA_sample)
  #define PX1_E0 (instrument->_parameters.PX1_E0)
  #define PX1_dE (instrument->_parameters.PX1_dE)
  #define PX1_K (instrument->_parameters.PX1_K)
  #define PX1_vfm_radius (instrument->_parameters.PX1_vfm_radius)
  #define PX1_hfm_radius (instrument->_parameters.PX1_hfm_radius)
  #define PX1_mirror_grazing_angle (instrument->_parameters.PX1_mirror_grazing_angle)
  #define PX1_det_dist (instrument->_parameters.PX1_det_dist)
  #define PX1_sample (instrument->_parameters.PX1_sample)
  #define PX1_rotX (instrument->_parameters.PX1_rotX)
  #define PX1_rotY (instrument->_parameters.PX1_rotY)
  #define PX1_rotZ (instrument->_parameters.PX1_rotZ)
  #define PX2a_E0 (instrument->_parameters.PX2a_E0)
  #define PX2a_hfm_radius (instrument->_parameters.PX2a_hfm_radius)
  #define PX2a_vfm_radius (instrument->_parameters.PX2a_vfm_radius)
  #define PX2a_mirror_grazing_angle (instrument->_parameters.PX2a_mirror_grazing_angle)
  #define PX2a_sample (instrument->_parameters.PX2a_sample)
  #define PX2a_rotX (instrument->_parameters.PX2a_rotX)
  #define PX2a_rotY (instrument->_parameters.PX2a_rotY)
  #define PX2a_rotZ (instrument->_parameters.PX2a_rotZ)
  #define SWING_E0 (instrument->_parameters.SWING_E0)
  #define SWING_dE (instrument->_parameters.SWING_dE)
  #define SWING_dcm_theta (instrument->_parameters.SWING_dcm_theta)
  #define SWING_hfm_radius (instrument->_parameters.SWING_hfm_radius)
  #define SWING_vfm_radius (instrument->_parameters.SWING_vfm_radius)
  #define SWING_mirror_grazing_angle (instrument->_parameters.SWING_mirror_grazing_angle)
  #define SWING_sample (instrument->_parameters.SWING_sample)
  #define SWING_sample_det (instrument->_parameters.SWING_sample_det)
  #define ROCK_E0 (instrument->_parameters.ROCK_E0)
  #define ROCK_dE (instrument->_parameters.ROCK_dE)
  #define ROCK_scan (instrument->_parameters.ROCK_scan)
  #define ROCK_angle_m2a_m2b (instrument->_parameters.ROCK_angle_m2a_m2b)
  #define ROCK_angle_m1 (instrument->_parameters.ROCK_angle_m1)
  #define ROCK_sample_file (instrument->_parameters.ROCK_sample_file)
  #define ROCK_reflec_material_M1 (instrument->_parameters.ROCK_reflec_material_M1)
  #define ROCK_reflec_material_M2A_M2B (instrument->_parameters.ROCK_reflec_material_M2A_M2B)
  #define ROCK_cc (instrument->_parameters.ROCK_cc)
  #define ANATOMIX_E0 (instrument->_parameters.ANATOMIX_E0)
  #define ANATOMIX_Emono (instrument->_parameters.ANATOMIX_Emono)
  #define ANATOMIX_dE (instrument->_parameters.ANATOMIX_dE)
  #define ANATOMIX_ANGLE (instrument->_parameters.ANATOMIX_ANGLE)
  #define ANATOMIX_sample (instrument->_parameters.ANATOMIX_sample)
  #define NANO_E0 (instrument->_parameters.NANO_E0)
  #define NANO_dE (instrument->_parameters.NANO_dE)
  #define NANO_Emono (instrument->_parameters.NANO_Emono)
  #define NANO_coating_m2 (instrument->_parameters.NANO_coating_m2)
  #define NANO_angle_m1_m2 (instrument->_parameters.NANO_angle_m1_m2)
  #define NANO_angle_kb1 (instrument->_parameters.NANO_angle_kb1)
  #define NANO_angle_kb2 (instrument->_parameters.NANO_angle_kb2)
  #define DIFFABS_E0 (instrument->_parameters.DIFFABS_E0)
  #define DIFFABS_dE (instrument->_parameters.DIFFABS_dE)
  #define DIFFABS_M1_angle (instrument->_parameters.DIFFABS_M1_angle)
  #define DIFFABS_M1_radius (instrument->_parameters.DIFFABS_M1_radius)
  #define DIFFABS_M2_radius (instrument->_parameters.DIFFABS_M2_radius)
  #define DIFFABS_DCM_theta (instrument->_parameters.DIFFABS_DCM_theta)
  #define DIFFABS_sample (instrument->_parameters.DIFFABS_sample)
  #define SIXS_E0 (instrument->_parameters.SIXS_E0)
  #define SIXS_dE (instrument->_parameters.SIXS_dE)
  #define SIXS_dcm_theta (instrument->_parameters.SIXS_dcm_theta)
  #define SIXS_M1_angle (instrument->_parameters.SIXS_M1_angle)
  #define SIXS_M1_radius (instrument->_parameters.SIXS_M1_radius)
  #define SIXS_M2_radius (instrument->_parameters.SIXS_M2_radius)
  #define SIXS_sample_coating (instrument->_parameters.SIXS_sample_coating)
  #define SIXS_sample_bulk (instrument->_parameters.SIXS_sample_bulk)
  #define SIXS_sample_thickness (instrument->_parameters.SIXS_sample_thickness)
  #define SIXS_sample_angle (instrument->_parameters.SIXS_sample_angle)
  #define CASSIOPEE_mirror_material (instrument->_parameters.CASSIOPEE_mirror_material)
  #define CASSIOPEE_undulator_index (instrument->_parameters.CASSIOPEE_undulator_index)
  #define CASSIOPEE_M1_angle (instrument->_parameters.CASSIOPEE_M1_angle)
  #define CASSIOPEE_PG_angle (instrument->_parameters.CASSIOPEE_PG_angle)
  #define CASSIOPEE_PM_angle (instrument->_parameters.CASSIOPEE_PM_angle)
  #define CASSIOPEE_E0 (instrument->_parameters.CASSIOPEE_E0)
  #define CASSIOPEE_dE (instrument->_parameters.CASSIOPEE_dE)
  #define CASSIOPEE_lambda (instrument->_parameters.CASSIOPEE_lambda)
  #define CASSIOPEE_beta_mono (instrument->_parameters.CASSIOPEE_beta_mono)
  #define CASSIOPEE_r_rho (instrument->_parameters.CASSIOPEE_r_rho)
  #define SIRIUS_E0 (instrument->_parameters.SIRIUS_E0)
  #define SIRIUS_dE (instrument->_parameters.SIRIUS_dE)
  #define SIRIUS_M1_angle (instrument->_parameters.SIRIUS_M1_angle)
  #define SIRIUS_M2_angle (instrument->_parameters.SIRIUS_M2_angle)
  #define SIRIUS_def_angle (instrument->_parameters.SIRIUS_def_angle)
  #define SIRIUS_sample_pos (instrument->_parameters.SIRIUS_sample_pos)
  #define SIRIUS_sample (instrument->_parameters.SIRIUS_sample)
  #define LUCIA_E0 (instrument->_parameters.LUCIA_E0)
  #define LUCIA_dE (instrument->_parameters.LUCIA_dE)
  #define LUCIA_dcm_theta (instrument->_parameters.LUCIA_dcm_theta)
  #define LUCIA_sample_material (instrument->_parameters.LUCIA_sample_material)
  #define LUCIA_sample_geometry (instrument->_parameters.LUCIA_sample_geometry)
{

    // If there is a DISCO_scan, calculate the Wavelength(Angstroms) as a function of DISCO_x_screw(mm).
    if(DISCO_scan>=1){ 
#ifdef USE_MPI
      if (mpi_node_rank==0) {
#endif
	    MCDETECTOR DISCO_w_monitor_var = COMP_GETPAR(DISCO_w_monitor,detector); // We have to think in terms of wavelength, the sine drive mechanism was built to linearize the wavelength.
        DISCO_w_monitor_value = DISCO_w_monitor_var.centerX;
        DISCO_x_screw_var = DISCO_x_screw;
        DISCO_w_monitor_error = 0; //Forgot how to get rid of the error bar.  
        //For the error we could have dlambda = lambda*2*DISCO_period*cos(phi)/L*dx_screw/DISCO_x_screw, but we need to have dx_screw. Does it make sense for dx_screw to exist in an exact simulation?
        DISCO_number_events_w_monitor = DISCO_w_monitor_var.events;   
                                                 
#ifdef USE_MPI                  
      }
        //MPI_Barrier(MPI_COMM_WORLD);
#endif  
        //Adding a legend to the graph would be good, need to find out how to do that at a later date. todo            
        // This set of defines is to avoid getting a '.' in the COMPONENT DISCO_name
	    Rotation Rot;
	    rot_set_rotation(Rot,0,0,0);
	mcdetector_out_0D("Wavelength(Ang) as a function of DISCO_x_screw(mm)", DISCO_number_events_w_monitor, DISCO_w_monitor_value, DISCO_w_monitor_error, "Wavelength", coords_set(0,0,0),Rot,9999);

    }

    // If there is a ROCK_scan, calculate the absorption coefficient.
    if(ROCK_scan>=1){ 
#ifdef USE_MPI
      if (mpi_node_rank==0) {
#endif 
        MCDETECTOR e_before_sample = COMP_GETPAR2(ROCK_EnergyMonitor_before_sample,detector);
        MCDETECTOR e_after_sample =  COMP_GETPAR2(ROCK_EnergyMonitor_before_sample,detector);
        ROCK_absorption_coefficient = log(e_before_sample.intensity/e_after_sample.intensity);              
        ROCK_I_err_calc = ((e_before_sample.error/e_before_sample.intensity)+(e_after_sample.error/e_after_sample.intensity));                  
        ROCK_absorption_coefficient_error = ROCK_I_err_calc;  
        ROCK_number_events_after_sample = e_after_sample.events; 

        fprintf(stdout,"*** \n");    
        fprintf(stdout,"Before the sample: I %g I_error %g N %g \n", e_before_sample.intensity, e_before_sample.error, e_before_sample.events);
        fprintf(stdout,"After the sample: I %g I_error %g N %g \n", e_after_sample.intensity, e_after_sample.error, e_after_sample.events); 
        fprintf(stdout,"ROCK_I_err_calc: I %g \n", ROCK_I_err_calc);
        fprintf(stdout,"*** ROCK_n ");  
                                                 
#ifdef USE_MPI                  
       }
        //MPI_Barrier(MPI_COMM_WORLD);
#endif  
                      
        // This set of defines is to avoid getting a '.' in the COMPONENT ROCK_name
        #ifdef NAME_CURRENT_COMP
        #undef NAME_CURRENT_COMP
        #define NAME_CURRENT_COMP "ROCK_absorption_coefficient"
        #endif           
	Coords dummy;
	Rotation Rot;
	rot_set_rotation(Rot,0,0,0);
	mcdetector_out_0D("XANES EXAFS",ROCK_number_events_after_sample, ROCK_absorption_coefficient, ROCK_absorption_coefficient_error,instrument_name,dummy,Rot,9999);  
    }
}
  #undef splits
  #undef MARS_E0
  #undef MARS_reflec_material_M12
  #undef MARS_reflections
  #undef MARS_dEr
  #undef MARS_alpha
  #undef PSICHE_E0
  #undef PSICHE_dE
  #undef PSICHE_DCM_present
  #undef PSICHE_sample_theta
  #undef PSICHE_sample_material
  #undef PSICHE_sample_geometry
  #undef PSICHE_dcm_theta
  #undef DISCO_grazing_angle_one
  #undef DISCO_HFP_shift
  #undef DISCO_VFP_shift
  #undef DISCO_second_HFP_shift
  #undef DISCO_x_screw
  #undef DISCO_scan
  #undef PUMA_E0
  #undef PUMA_dE
  #undef PUMA_DCM_theta
  #undef PUMA_HFM_angle
  #undef PUMA_HFM_focal
  #undef PUMA_KB_angle
  #undef PUMA_KB_coating
  #undef PUMA_h
  #undef PUMA_k
  #undef PUMA_l
  #undef CRISTAL_E0
  #undef CRISTAL_dE
  #undef CRISTAL_M1_angle
  #undef CRISTAL_M2_angle
  #undef CRISTAL_M1_radius
  #undef CRISTAL_M2_radius
  #undef CRISTAL_M_coating
  #undef CRISTAL_reflections
  #undef GALAXIES_E0
  #undef GALAXIES_dE
  #undef GALAXIES_hrm
  #undef GALAXIES_hrm_ref
  #undef GALAXIES_sec_slits
  #undef GALAXIES_ana_R
  #undef GALAXIES_ana_deg
  #undef GALAXIES_sample
  #undef SAMBA_E0
  #undef SAMBA_dE
  #undef SAMBA_M1_angle
  #undef SAMBA_M2_angle
  #undef SAMBA_sample
  #undef PX1_E0
  #undef PX1_dE
  #undef PX1_K
  #undef PX1_vfm_radius
  #undef PX1_hfm_radius
  #undef PX1_mirror_grazing_angle
  #undef PX1_det_dist
  #undef PX1_sample
  #undef PX1_rotX
  #undef PX1_rotY
  #undef PX1_rotZ
  #undef PX2a_E0
  #undef PX2a_hfm_radius
  #undef PX2a_vfm_radius
  #undef PX2a_mirror_grazing_angle
  #undef PX2a_sample
  #undef PX2a_rotX
  #undef PX2a_rotY
  #undef PX2a_rotZ
  #undef SWING_E0
  #undef SWING_dE
  #undef SWING_dcm_theta
  #undef SWING_hfm_radius
  #undef SWING_vfm_radius
  #undef SWING_mirror_grazing_angle
  #undef SWING_sample
  #undef SWING_sample_det
  #undef ROCK_E0
  #undef ROCK_dE
  #undef ROCK_scan
  #undef ROCK_angle_m2a_m2b
  #undef ROCK_angle_m1
  #undef ROCK_sample_file
  #undef ROCK_reflec_material_M1
  #undef ROCK_reflec_material_M2A_M2B
  #undef ROCK_cc
  #undef ANATOMIX_E0
  #undef ANATOMIX_Emono
  #undef ANATOMIX_dE
  #undef ANATOMIX_ANGLE
  #undef ANATOMIX_sample
  #undef NANO_E0
  #undef NANO_dE
  #undef NANO_Emono
  #undef NANO_coating_m2
  #undef NANO_angle_m1_m2
  #undef NANO_angle_kb1
  #undef NANO_angle_kb2
  #undef DIFFABS_E0
  #undef DIFFABS_dE
  #undef DIFFABS_M1_angle
  #undef DIFFABS_M1_radius
  #undef DIFFABS_M2_radius
  #undef DIFFABS_DCM_theta
  #undef DIFFABS_sample
  #undef SIXS_E0
  #undef SIXS_dE
  #undef SIXS_dcm_theta
  #undef SIXS_M1_angle
  #undef SIXS_M1_radius
  #undef SIXS_M2_radius
  #undef SIXS_sample_coating
  #undef SIXS_sample_bulk
  #undef SIXS_sample_thickness
  #undef SIXS_sample_angle
  #undef CASSIOPEE_mirror_material
  #undef CASSIOPEE_undulator_index
  #undef CASSIOPEE_M1_angle
  #undef CASSIOPEE_PG_angle
  #undef CASSIOPEE_PM_angle
  #undef CASSIOPEE_E0
  #undef CASSIOPEE_dE
  #undef CASSIOPEE_lambda
  #undef CASSIOPEE_beta_mono
  #undef CASSIOPEE_r_rho
  #undef SIRIUS_E0
  #undef SIRIUS_dE
  #undef SIRIUS_M1_angle
  #undef SIRIUS_M2_angle
  #undef SIRIUS_def_angle
  #undef SIRIUS_sample_pos
  #undef SIRIUS_sample
  #undef LUCIA_E0
  #undef LUCIA_dE
  #undef LUCIA_dcm_theta
  #undef LUCIA_sample_material
  #undef LUCIA_sample_geometry
  /* call iteratively all components FINALLY */









  class_Monitor_nD_finally(&_MARS_displaySourceLength_var);

  class_PSD_monitor_finally(&_MARS_displaySource_var);














  class_PSD_monitor_finally(&_MARS_displayMono_var);










  class_PSD_monitor_finally(&_MARS_displaySlit2_var);

  class_FluoPowder_finally(&_MARS_Sample_var);

  class_Monitor_nD_finally(&_MARS_detector_diffraction_var);

  class_Monitor_nD_finally(&_MARS_detector_fluo_var);





  class_Monitor_nD_finally(&_PSICHE_mon_src_e_var);

  class_Monitor_nD_finally(&_PSICHE_mon_src_xy_var);






  class_Monitor_nD_finally(&_PSICHE_mon_dcm_e_var);

  class_Monitor_nD_finally(&_PSICHE_mon_dcm_xy_var);



  class_FluoPowder_finally(&_PSICHE_sample_var);


  class_Monitor_nD_finally(&_PSICHE_mon_spl_fluo_var);

  class_Monitor_nD_finally(&_PSICHE_mon_spl_e_var);

  class_Monitor_nD_finally(&_PSICHE_mon_spl_xy_var);





















  class_PSD_monitor_finally(&_DISCO_HFP_var);










  class_PSD_monitor_finally(&_DISCO_VFP_var);












  class_PSD_monitor_finally(&_DISCO_second_HFP_var);






























  class_PSD_monitor_finally(&_DISCO_psd_before_slit_var);


  class_PSD_monitor_finally(&_DISCO_psd_monitor_var);

  class_PSD_monitor_finally(&_DISCO_psd_giant_after_grating_var);

  class_Monitor_nD_finally(&_DISCO_e_monitor_var);

  class_Monitor_nD_finally(&_DISCO_w_monitor_var);










  class_PSD_monitor_finally(&_PUMA_mon_src_xy_var);





  class_PSD_monitor_finally(&_PUMA_mon_HFM_out_xy_var);




  class_PSD_monitor_finally(&_PUMA_mon_DCM_xtal1_only_xy_var);




  class_PSD_monitor_finally(&_PUMA_mon_DCM_out_xy_var);





  class_PSD_monitor_finally(&_PUMA_mon_KB_in_xy_var);




  class_PSD_monitor_finally(&_PUMA_mon_KB_VFM_out_xy_var);





  class_PSD_monitor_finally(&_PUMA_mon_KB_HFM_out_xy_var);


  class_PSD_monitor_finally(&_PUMA_mon_sample_xy_var);





  class_Undulator_finally(&_CRISTAL_Source_var);

















  class_PSD_monitor_finally(&_CRISTAL_psd_slit2_var);


  class_FluoPowder_finally(&_CRISTAL_fluo_var);

  class_Monitor_nD_finally(&_CRISTAL_detector_diffraction_var);

  class_Monitor_nD_finally(&_CRISTAL_detector_fluo_var);





  class_Undulator_finally(&_GALAXIES_Source_U20_var);

  class_Monitor_nD_finally(&_GALAXIES_mon_src_xy_var);

  class_Monitor_nD_finally(&_GALAXIES_mon_src_e_var);




  class_Monitor_nD_finally(&_GALAXIES_mon_prim_xy_var);






  class_Monitor_nD_finally(&_GALAXIES_mon_dcm_e_var);

  class_Monitor_nD_finally(&_GALAXIES_mon_dcm_xy_var);











  class_Monitor_nD_finally(&_GALAXIES_mon_sec_xy_var);












  class_Monitor_nD_finally(&_GALAXIES_mon_sample_xy_kb_var);

  class_Monitor_nD_finally(&_GALAXIES_mon_sample_e_var);


  class_FluoCrystal_finally(&_GALAXIES_sample_var);





  class_Monitor_nD_finally(&_GALAXIES_IXS_det_var);









  class_Monitor_nD_finally(&_SAMBA_M1_out_var);






  class_Monitor_nD_finally(&_SAMBA_DCM_out_var);

  class_Monitor_nD_finally(&_SAMBA_DCM_out_div_var);

  class_Monitor_nD_finally(&_SAMBA_DCM_out_e_var);




  class_Monitor_nD_finally(&_SAMBA_M2_out_var);

  class_Monitor_nD_finally(&_SAMBA_sample_stage_var);

  class_FluoPowder_finally(&_SAMBA_fluo_var);

  class_Monitor_nD_finally(&_SAMBA_det_trans_var);

  class_Monitor_nD_finally(&_SAMBA_det_fluo_var);





  class_Undulator_finally(&_PX1_undulator_var);








  class_Monitor_nD_finally(&_PX1_vfm_location_var);



  class_Monitor_nD_finally(&_PX1_vfm_takeoff_var);

  class_Monitor_nD_finally(&_PX1_hfm_location_var);


  class_Monitor_nD_finally(&_PX1_hfm_takeoff_var);


  class_Monitor_nD_finally(&_PX1_sample_monitor_var);

  class_Single_crystal_finally(&_PX1_sample_var);

  class_PSD_monitor_4PI_finally(&_PX1_psd4pi_var);

  class_PSD_monitor_finally(&_PX1_EigerX16M_var);




  class_Undulator_finally(&_PX2a_undulator_var);











  class_Monitor_nD_finally(&_PX2a_vfm_location_var);



  class_Monitor_nD_finally(&_PX2a_vfm_takeoff_var);

  class_Monitor_nD_finally(&_PX2a_hfm_location_var);


  class_Monitor_nD_finally(&_PX2a_hfm_takeoff_var);


  class_Monitor_nD_finally(&_PX2a_sample_monitor_var);

  class_Single_crystal_finally(&_PX2a_sample_var);

  class_PSD_monitor_4PI_finally(&_PX2a_psd4pi_var);

  class_PSD_monitor_finally(&_PX2a_Eiger9M_var);




  class_Undulator_finally(&_SWING_Source_U20_var);

  class_Monitor_nD_finally(&_SWING_mon_src_xy_var);

  class_Monitor_nD_finally(&_SWING_mon_src_e_var);


  class_Monitor_nD_finally(&_SWING_slit_mon_xy_var);






  class_Monitor_nD_finally(&_SWING_mon_dcm_e_var);

  class_Monitor_nD_finally(&_SWING_mon_dcm_xy_var);

  class_Monitor_nD_finally(&_SWING_vfm_location_var);



  class_Monitor_nD_finally(&_SWING_vfm_takeoff_var);

  class_Monitor_nD_finally(&_SWING_hfm_location_var);


  class_Monitor_nD_finally(&_SWING_hfm_takeoff_var);

  class_Monitor_nD_finally(&_SWING_sample_stage_var);




  class_Monitor_nD_finally(&_SWING_Eiger4M_var);

  class_SAXSQMonitor_finally(&_SWING_QMonitor_var);










  class_PSD_monitor_finally(&_ROCK_slit3_xy_var);

  class_Divergence_monitor_finally(&_ROCK_slit3_div_var);




  class_PSD_monitor_finally(&_ROCK_slit4_in_var);







  class_PSD_monitor_finally(&_ROCK_bragg_crystal_out_var);





  class_Monitor_nD_finally(&_ROCK_EnergyMonitor_before_sample_var);

  class_Monitor_nD_finally(&_ROCK_e_repartition_after_m2b_var);

  class_PSD_monitor_finally(&_ROCK_sample_in_var);

  class_Fluorescence_finally(&_ROCK_absorption_sample_var);

  class_Monitor_nD_finally(&_ROCK_fluo_monitor_var);

  class_Monitor_nD_finally(&_ROCK_EnergyMonitor_after_sample_var);

  class_PSD_monitor_finally(&_ROCK_psd_monitor_var);




  class_Undulator_finally(&_ANATOMIX_source_var);

  class_Monitor_nD_finally(&_ANATOMIX_e_repartition_before_cc_var);

  class_PSD_monitor_finally(&_ANATOMIX_psd_monitor_before_cc_var);





  class_PSD_monitor_finally(&_ANATOMIX_psd_after_cc_var);


  class_PSD_monitor_finally(&_ANATOMIX_psd_repartition_after_cc_var);


  class_Filter_finally(&_ANATOMIX_sample_var);


  class_PSD_monitor_finally(&_ANATOMIX_psd_monitor_after_cc_var);




  class_Undulator_finally(&_NANO_source_var);


  class_PSD_monitor_coh_finally(&_NANO_psd_source_var);











  class_PSD_monitor_finally(&_NANO_PSD_dcm_in_var);










  class_PSD_monitor_finally(&_NANO_psd_ss_in_var);


  class_PSD_monitor_finally(&_NANO_psd_ss_out_var);










  class_PSD_monitor_finally(&_NANO_psd_sample_stage_var);











  class_Monitor_nD_finally(&_DIFFABS_DCM_in_var);

  class_Monitor_nD_finally(&_DIFFABS_DCM_in_div_var);






  class_Monitor_nD_finally(&_DIFFABS_DCM_out_var);

  class_Monitor_nD_finally(&_DIFFABS_DCM_out_div_var);

  class_Monitor_nD_finally(&_DIFFABS_DCM_out_e_var);






  class_Monitor_nD_finally(&_DIFFABS_sample_stage_var);

  class_FluoPowder_finally(&_DIFFABS_fluo_var);

  class_Monitor_nD_finally(&_DIFFABS_fluo_monitor_var);

  class_Monitor_nD_finally(&_DIFFABS_det_angle_var);

  class_Monitor_nD_finally(&_DIFFABS_xpad_var);





  class_Undulator_finally(&_SIXS_Source_U20_var);

  class_Monitor_nD_finally(&_SIXS_mon_src_xy_var);

  class_Monitor_nD_finally(&_SIXS_mon_src_e_var);


  class_Monitor_nD_finally(&_SIXS_slit_mon_xy_var);






  class_Monitor_nD_finally(&_SIXS_mon_dcm_e_var);

  class_Monitor_nD_finally(&_SIXS_mon_dcm_xy_var);









  class_Monitor_nD_finally(&_SIXS_sample_stage_var);

  class_Single_crystal_finally(&_SIXS_sx_layer_var);

  class_Single_crystal_finally(&_SIXS_sx_bulk_var);


  class_Monitor_nD_finally(&_SIXS_det4pi_var);

  class_Monitor_nD_finally(&_SIXS_detector_layer_var);

  class_Monitor_nD_finally(&_SIXS_detector_bulk_var);




  class_Undulator_finally(&_CASSIOPEE_Source_HU60_var);

  class_Undulator_finally(&_CASSIOPEE_Source_HU256_var);







  class_Monitor_nD_finally(&_CASSIOPEE_PSD_M1out_var);



  class_Monitor_nD_finally(&_CASSIOPEE_M2_rotation_axis_var);





  class_Monitor_nD_finally(&_CASSIOPEE_PSD_var);





  class_Monitor_nD_finally(&_SIRIUS_M1_loc_var);




  class_Monitor_nD_finally(&_SIRIUS_DCM_location_var);





  class_Monitor_nD_finally(&_SIRIUS_DCM_out_var);

  class_Monitor_nD_finally(&_SIRIUS_DCM_out_div_var);

  class_Monitor_nD_finally(&_SIRIUS_DCM_out_e_var);

  class_Monitor_nD_finally(&_SIRIUS_def_loc_var);




  class_Monitor_nD_finally(&_SIRIUS_sample_stage_var);

  class_FluoPowder_finally(&_SIRIUS_fluo_var);

  class_Monitor_nD_finally(&_SIRIUS_det_2d_var);

  class_Monitor_nD_finally(&_SIRIUS_det_fluo_var);




  class_Undulator_finally(&_LUCIA_source_var);

  class_Monitor_nD_finally(&_LUCIA_mon_src_xy_var);

  class_Monitor_nD_finally(&_LUCIA_mon_src_e_var);


  class_Monitor_nD_finally(&_LUCIA_slit_mon_xy_var);






  class_Monitor_nD_finally(&_LUCIA_mon_dcm_e_var);

  class_Monitor_nD_finally(&_LUCIA_mon_dcm_xy_var);


  class_Monitor_nD_finally(&_LUCIA_sample_stage_var);


  class_Fluorescence_finally(&_LUCIA_sample_var);

  class_Monitor_nD_finally(&_LUCIA_transmission_var);


  class_Monitor_nD_finally(&_LUCIA_mon_spl_fluo_var);









  siminfo_close(); 

  return(0);
} /* finally */

/* *****************************************************************************
* instrument 'SOLEIL' and components DISPLAY
***************************************************************************** */

  #define magnify     mcdis_magnify
  #define line        mcdis_line
  #define dashed_line mcdis_dashed_line
  #define multiline   mcdis_multiline
  #define rectangle   mcdis_rectangle
  #define box         mcdis_box
  #define circle      mcdis_circle
  #define cylinder    mcdis_cylinder
  #define sphere      mcdis_sphere
  #define cone        mcdis_cone
  #define polygon     mcdis_polygon
  #define polyhedron  mcdis_polyhedron
_class_Arm *class_Arm_display(_class_Arm *_comp
) {
  SIG_MESSAGE("[_origin_display] component origin=Arm() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Arm.comp:69]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  /* A bit ugly; hard-coded dimensions. */

  line (0, 0, 0, 0.2, 0, 0);
  line (0, 0, 0, 0, 0.2, 0);
  line (0, 0, 0, 0, 0, 0.2);

  cone (0.2, 0, 0, 0.01, 0.02, 1, 0, 0);
  cone (0, 0.2, 0, 0.01, 0.02, 0, 1, 0);
  cone (0, 0, 0.2, 0.01, 0.02, 0, 0, 1);
  return(_comp);
} /* class_Arm_display */

_class_Beamstop *class_Beamstop_display(_class_Beamstop *_comp
) {
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  SIG_MESSAGE("[_beamdump_display] component beamdump=Beamstop() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Beamstop.comp:83]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  if (radius != 0)
    circle ("xy", 0, 0, 0, radius);
  else
    multiline (5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0,
               (double)xmin, (double)ymin, 0.0);
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  #undef xwidth
  #undef yheight
  #undef radius
  return(_comp);
} /* class_Beamstop_display */

_class_Text *class_Text_display(_class_Text *_comp
) {
  #define text (_comp->_parameters.text)
  #define size (_comp->_parameters.size)
  #define plane (_comp->_parameters.plane)
  #define pen_thickness (_comp->_parameters.pen_thickness)
  #define pl (_comp->_parameters.pl)
  SIG_MESSAGE("[_ODE_pos_display] component ODE_pos=Text() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Text.comp:133]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
    
  float s   = size / 6.0f;          /* metres per grid unit; glyph height = 6 units */
  float adv = 5.0f;                 /* pen advance in grid units: 4 wide + 1 gap    */
  float u0  = 0.0f;                 /* pen position in grid units                   */

  for (const char *t = text; *t; t++, u0 += adv) {
      int c = toupper((unsigned char)*t);
      if (c < 128 && glyph[c]) {
          float ox=0,oy=0,oz=0;
          const char *p = glyph[c];
          float prevx = 0, prevy = 0, prevz = 0;
          int pen = 0;                      /* pen down? */

          while (*p) {
              if (*p == '|') { pen = 0; p++; continue; }
              while (*p == ' ') p++;
              if (!*p) break;

              /* parse "x,y" (strtol also tolerates future negative coords) */
              char *end;
              long gx = strtol(p, &end, 10); p = end;
              if (*p == ',') p++;
              long gy = strtol(p, &end, 10); p = end;

              float u = (u0 + (float)gx) * s;   /* along text direction   */
              float v = (float)gy * s;          /* along letter height    */

              float x, y, z;
              switch (pl) {
              case 0:  x = ox + u;  y = oy + v;  z = oz;      break;  /* XY */
              case 1:  x = ox;      y = oy + u;  z = oz + v;  break;  /* YZ */
              default: x = ox + v;  y = oy;      z = oz + u;  break;  /* ZX */
              }

              if (pen) {
                  if (pen_thickness > 0) {
                      /* stroke as a cylinder centred on the segment midpoint, axis along it */
                      double dx = x - prevx, dy = y - prevy, dz = z - prevz;
                      double len = sqrt(dx*dx + dy*dy + dz*dz);
                      if (len > 0)
                          cylinder(0.5*(prevx + x), 0.5*(prevy + y), 0.5*(prevz + z),
                                   0.5*size*pen_thickness, len, 0,
                                   dx/len, dy/len, dz/len);
                  } else
                  line(prevx, prevy, prevz, x, y, z);
              }

              /* round joints and stroke ends: sphere at every vertex */
              if (pen_thickness > 0)
                  sphere(x, y, z, 0.5*size*pen_thickness);

              prevx = x; prevy = y; prevz = z;
              pen = 1;
          }
      }
  }
  #undef text
  #undef size
  #undef plane
  #undef pen_thickness
  #undef pl
  return(_comp);
} /* class_Text_display */

_class_Bending_magnet *class_Bending_magnet_display(_class_Bending_magnet *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define lambda0 (_comp->_parameters.lambda0)
  #define dlambda (_comp->_parameters.dlambda)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define gauss_t (_comp->_parameters.gauss_t)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define kc (_comp->_parameters.kc)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define p0 (_comp->_parameters.p0)
  SIG_MESSAGE("[_MARS_Source_display] component MARS_Source=Bending_magnet() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Bending_magnet.comp:230]");

  printf("MCDISPLAY: component %s\n", _comp->_name);


  double radius, D;
  radius = 3.3 * Ee / B;
  ;
  D = 0.1;
  double x0, x1, z0, z1;
  const double phimin = -2.0 * DEG2RAD, phimax = 2.0 * DEG2RAD;
  double phi = phimin, dphi;
  dphi = (phimax - phimin) / 32;
  while (phi < phimax) {
    x0 = radius * (1 - cos (phi));
    x1 = radius * (1 - cos (phi + dphi));
    z0 = radius * sin (phi);
    z1 = radius * sin (phi + dphi);
    line (x0, 0.0, z0, x1, 0.0, z1);
    phi += dphi;
  }

  line (0.0, 0.0, 0.0, D* sin (igamma), 0.0, D);
  line (0.0, 0.0, 0.0, -D* sin (igamma), 0.0, D);
  line (0.0, 0.0, 0.0, 0.0, D* sin (igamma), D);
  line (0.0, 0.0, 0.0, 0.0, -D* sin (igamma), D);

  phi = -igamma;
  dphi = 2.0 * igamma / 32;
  while (phi < igamma) {
    x0 = D * sin (phi);
    x1 = D * sin (phi + dphi);
    z0 = D * cos (phi);
    z1 = D * cos (phi + dphi);
    line (x0, 0.0, z0, x1, 0.0, z1);
    line (0.0, x0, z0, 0.0, x1, z1);
    phi += dphi;
  }
  #undef E0
  #undef dE
  #undef lambda0
  #undef dlambda
  #undef phase
  #undef randomphase
  #undef Ee
  #undef Ie
  #undef B
  #undef sigey
  #undef sigex
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef gauss_t
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef kc
  #undef s1x
  #undef s1y
  #undef p0
  return(_comp);
} /* class_Bending_magnet_display */

_class_Monitor_nD *class_Monitor_nD_display(_class_Monitor_nD *_comp
) {
  #define user0 (_comp->_parameters.user0)
  #define user1 (_comp->_parameters.user1)
  #define user2 (_comp->_parameters.user2)
  #define user3 (_comp->_parameters.user3)
  #define user4 (_comp->_parameters.user4)
  #define user5 (_comp->_parameters.user5)
  #define user6 (_comp->_parameters.user6)
  #define user7 (_comp->_parameters.user7)
  #define user8 (_comp->_parameters.user8)
  #define user9 (_comp->_parameters.user9)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define bins (_comp->_parameters.bins)
  #define min (_comp->_parameters.min)
  #define max (_comp->_parameters.max)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define radius (_comp->_parameters.radius)
  #define options (_comp->_parameters.options)
  #define filename (_comp->_parameters.filename)
  #define geometry (_comp->_parameters.geometry)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define username0 (_comp->_parameters.username0)
  #define username1 (_comp->_parameters.username1)
  #define username2 (_comp->_parameters.username2)
  #define username3 (_comp->_parameters.username3)
  #define username4 (_comp->_parameters.username4)
  #define username5 (_comp->_parameters.username5)
  #define username6 (_comp->_parameters.username6)
  #define username7 (_comp->_parameters.username7)
  #define username8 (_comp->_parameters.username8)
  #define username9 (_comp->_parameters.username9)
  #define DEFS (_comp->_parameters.DEFS)
  #define Vars (_comp->_parameters.Vars)
  #define detector (_comp->_parameters.detector)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_MARS_displaySourceLength_display] component MARS_displaySourceLength=Monitor_nD() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Monitor_nD.comp:606]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  if (geometry && strlen (geometry) && strcmp (geometry, "0") && strcmp (geometry, "NULL")) {
    off_display (offdata);
  } else {
    Monitor_nD_McDisplay (&DEFS, &Vars);
  }
  #undef user0
  #undef user1
  #undef user2
  #undef user3
  #undef user4
  #undef user5
  #undef user6
  #undef user7
  #undef user8
  #undef user9
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef bins
  #undef min
  #undef max
  #undef restore_xray
  #undef radius
  #undef options
  #undef filename
  #undef geometry
  #undef nowritefile
  #undef username0
  #undef username1
  #undef username2
  #undef username3
  #undef username4
  #undef username5
  #undef username6
  #undef username7
  #undef username8
  #undef username9
  #undef DEFS
  #undef Vars
  #undef detector
  #undef offdata
  return(_comp);
} /* class_Monitor_nD_display */

_class_PSD_monitor *class_PSD_monitor_display(_class_PSD_monitor *_comp
) {
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nr (_comp->_parameters.nr)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_displaySource_display] component MARS_displaySource=PSD_monitor() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor.comp:159]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  multiline (5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin,
             (double)ymin, 0.0);
  #undef filename
  #undef xwidth
  #undef yheight
  #undef radius
  #undef restore_xray
  #undef nowritefile
  #undef nx
  #undef ny
  #undef nr
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_display */

_class_Slit *class_Slit_display(_class_Slit *_comp
) {
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define dist (_comp->_parameters.dist)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_x0 (_comp->_parameters.focus_x0)
  #define focus_y0 (_comp->_parameters.focus_y0)
  SIG_MESSAGE("[_MARS_slit1_display] component MARS_slit1=Slit() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Slit.comp:117]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  if (radius == 0) {
    double xw, yh;
    xw = (xmax - xmin) / 2.0;
    yh = (ymax - ymin) / 2.0;
    multiline (3, xmin - xw, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, ymax + yh, 0.0);
    multiline (3, xmax + xw, (double)ymax, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmax, ymax + yh, 0.0);
    multiline (3, xmin - xw, (double)ymin, 0.0, (double)xmin, (double)ymin, 0.0, (double)xmin, ymin - yh, 0.0);
    multiline (3, xmax + xw, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, ymin - yh, 0.0);
  } else {
    circle ("xy", 0, 0, 0, radius);
  }
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  #undef radius
  #undef xwidth
  #undef yheight
  #undef dist
  #undef focus_xw
  #undef focus_yh
  #undef focus_x0
  #undef focus_y0
  return(_comp);
} /* class_Slit_display */

_class_Mirror_curved *class_Mirror_curved_display(_class_Mirror_curved *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define zdepth (_comp->_parameters.zdepth)
  #define yheight (_comp->_parameters.yheight)
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define Z (_comp->_parameters.Z)
  #define At (_comp->_parameters.At)
  #define rho (_comp->_parameters.rho)
  #define T (_comp->_parameters.T)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_MARS_mirror_M1_display] component MARS_mirror_M1=Mirror_curved() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_curved.comp:139]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  double x0, y0, z0, x1, y1, z1, alpha;
  int N = 20;

  y0 = yheight / 2.0;
  y1 = -y0;

  alpha = -(zdepth / 2.0) / fabs (radius);
  x0 = radius * (1 - cos (alpha));
  z0 = radius * sin (alpha);
  line (x0, y0, z0, x0, y1, z0);
  while (alpha < (zdepth / 2.0 / fabs (radius))) {
    alpha += zdepth / N / fabs (radius);
    x1 = radius * (1 - cos (alpha));
    z1 = radius * sin (alpha);
    line (x0, y0, z0, x1, y0, z1);
    line (x0, y1, z0, x1, y1, z1);
    x0 = x1;
    z0 = z1;
    line (x0, y0, z0, x0, y1, z0);
  }
  #undef radius
  #undef R0
  #undef coating
  #undef zdepth
  #undef yheight
  #undef length
  #undef width
  #undef Z
  #undef At
  #undef rho
  #undef T
  #undef re
  return(_comp);
} /* class_Mirror_curved_display */

_class_Bragg_crystal *class_Bragg_crystal_display(_class_Bragg_crystal *_comp
) {
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define V (_comp->_parameters.V)
  #define form_factors (_comp->_parameters.form_factors)
  #define material (_comp->_parameters.material)
  #define alpha (_comp->_parameters.alpha)
  #define R0 (_comp->_parameters.R0)
  #define debye_waller_B (_comp->_parameters.debye_waller_B)
  #define crystal_type (_comp->_parameters.crystal_type)
  #define h (_comp->_parameters.h)
  #define k (_comp->_parameters.k)
  #define l (_comp->_parameters.l)
  #define structure_factor_scale_r (_comp->_parameters.structure_factor_scale_r)
  #define structure_factor_scale_i (_comp->_parameters.structure_factor_scale_i)
  #define Z (_comp->_parameters.Z)
  #define rho (_comp->_parameters.rho)
  #define At (_comp->_parameters.At)
  #define f_rel (_comp->_parameters.f_rel)
  #define f_nt (_comp->_parameters.f_nt)
  #define m_t (_comp->_parameters.m_t)
  #define f0_t (_comp->_parameters.f0_t)
  SIG_MESSAGE("[_MARS_dcm_xtal0_display] component MARS_dcm_xtal0=Bragg_crystal() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Bragg_crystal.comp:288]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  rectangle ("xz", 0, 0, 0, width, length);
  #undef length
  #undef width
  #undef V
  #undef form_factors
  #undef material
  #undef alpha
  #undef R0
  #undef debye_waller_B
  #undef crystal_type
  #undef h
  #undef k
  #undef l
  #undef structure_factor_scale_r
  #undef structure_factor_scale_i
  #undef Z
  #undef rho
  #undef At
  #undef f_rel
  #undef f_nt
  #undef m_t
  #undef f0_t
  return(_comp);
} /* class_Bragg_crystal_display */

_class_E_monitor *class_E_monitor_display(_class_E_monitor *_comp
) {
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_MARS_emon_dcm0_display] component MARS_emon_dcm0=E_monitor() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/E_monitor.comp:121]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  multiline (5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin,
             (double)ymin, 0.0);
  #undef nE
  #undef filename
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef restore_xray
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_E_monitor_display */

_class_FluoPowder *class_FluoPowder_display(_class_FluoPowder *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_powder (_comp->_parameters.flag_powder)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define powder_refl (_comp->_parameters.powder_refl)
  #define powder_format (_comp->_parameters.powder_format)
  #define Vc (_comp->_parameters.Vc)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define DW (_comp->_parameters.DW)
  #define d_phi (_comp->_parameters.d_phi)
  #define nb_atoms (_comp->_parameters.nb_atoms)
  #define barns (_comp->_parameters.barns)
  #define tth_sign (_comp->_parameters.tth_sign)
  #define order (_comp->_parameters.order)
  #define line_info (_comp->_parameters.line_info)
  #define columns (_comp->_parameters.columns)
  #define mat_columns (_comp->_parameters.mat_columns)
  #define offdata (_comp->_parameters.offdata)
  #define tgt_x (_comp->_parameters.tgt_x)
  #define tgt_y (_comp->_parameters.tgt_y)
  #define tgt_z (_comp->_parameters.tgt_z)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_Nq (_comp->_parameters.reuse_Nq)
  #define reuse_my_s_k2_sum (_comp->_parameters.reuse_my_s_k2_sum)
  SIG_MESSAGE("[_MARS_Sample_display] component MARS_Sample=FluoPowder() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:1002]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
    if (shape == 0) { /* cyl */
      circle("xz", 0,  yheight/2.0, 0, radius);
      circle("xz", 0, -yheight/2.0, 0, radius);
      line(-radius, -yheight/2.0, 0, -radius, +yheight/2.0, 0);
      line(+radius, -yheight/2.0, 0, +radius, +yheight/2.0, 0);
      line(0, -yheight/2.0, -radius, 0, +yheight/2.0, -radius);
      line(0, -yheight/2.0, +radius, 0, +yheight/2.0, +radius);
      if (thickness) {
        double radius_i=radius-thickness;
        circle("xz", 0,  yheight/2.0, 0, radius_i);
        circle("xz", 0, -yheight/2.0, 0, radius_i);
        line(-radius_i, -yheight/2.0, 0, -radius_i, +yheight/2.0, 0);
        line(+radius_i, -yheight/2.0, 0, +radius_i, +yheight/2.0, 0);
        line(0, -yheight/2.0, -radius_i, 0, +yheight/2.0, -radius_i);
        line(0, -yheight/2.0, +radius_i, 0, +yheight/2.0, +radius_i);
      }
    } else if (shape == 1) {  /* box */
      double xmin = -0.5*xwidth;
      double xmax =  0.5*xwidth;
      double ymin = -0.5*yheight;
      double ymax =  0.5*yheight;
      double zmin = -0.5*zdepth;
      double zmax =  0.5*zdepth;
      multiline(5, xmin, ymin, zmin,
                   xmax, ymin, zmin,
                   xmax, ymax, zmin,
                   xmin, ymax, zmin,
                   xmin, ymin, zmin);
      multiline(5, xmin, ymin, zmax,
                   xmax, ymin, zmax,
                   xmax, ymax, zmax,
                   xmin, ymax, zmax,
                   xmin, ymin, zmax);
      line(xmin, ymin, zmin, xmin, ymin, zmax);
      line(xmax, ymin, zmin, xmax, ymin, zmax);
      line(xmin, ymax, zmin, xmin, ymax, zmax);
      line(xmax, ymax, zmin, xmax, ymax, zmax);
      if (zdepth) {
        xmin = -0.5*xwidth;
        xmax =  0.5*xwidth;
        ymin = -0.5*yheight;
        ymax =  0.5*yheight;
        zmin = -0.5*zdepth;
        zmax =  0.5*zdepth;
        multiline(5, xmin, ymin, zmin,
                  xmax, ymin, zmin,
                  xmax, ymax, zmin,
                  xmin, ymax, zmin,
                  xmin, ymin, zmin);
        multiline(5, xmin, ymin, zmax,
                  xmax, ymin, zmax,
                  xmax, ymax, zmax,
                  xmin, ymax, zmax,
                  xmin, ymin, zmax);
        line(xmin, ymin, zmin, xmin, ymin, zmax);
        line(xmax, ymin, zmin, xmax, ymin, zmax);
        line(xmin, ymax, zmin, xmin, ymax, zmax);
        line(xmax, ymax, zmin, xmax, ymax, zmax);
      }
    } if (shape == 2) { /* sphere */
      circle("xy",0,0,0,radius);
      circle("xz",0,0,0,radius);
      circle("yz",0,0,0,radius);
    } else if (shape == 3) {        /* OFF file */
      off_display(offdata);
    }
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_powder
  #undef flag_kissel
  #undef powder_refl
  #undef powder_format
  #undef Vc
  #undef delta_d_d
  #undef DW
  #undef d_phi
  #undef nb_atoms
  #undef barns
  #undef tth_sign
  #undef order
  #undef line_info
  #undef columns
  #undef mat_columns
  #undef offdata
  #undef tgt_x
  #undef tgt_y
  #undef tgt_z
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef n_diff
  #undef p_diff
  #undef fluo_rho
  #undef reuse_cum_xs_diffraction
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_Nq
  #undef reuse_my_s_k2_sum
  return(_comp);
} /* class_FluoPowder_display */

_class_Wiggler *class_Wiggler_display(_class_Wiggler *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define lambda0 (_comp->_parameters.lambda0)
  #define dlambda (_comp->_parameters.dlambda)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define length (_comp->_parameters.length)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define gauss_t (_comp->_parameters.gauss_t)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define kc (_comp->_parameters.kc)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define lu (_comp->_parameters.lu)
  #define gap (_comp->_parameters.gap)
  #define p0 (_comp->_parameters.p0)
  SIG_MESSAGE("[_PSICHE_source_display] component PSICHE_source=Wiggler() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Wiggler.comp:254]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  double zz, dz;
  const double xwidth = 1e-2;
  const double D = dist;
  double x0, z0, x1, z1;
  zz = -(length + lu) / 2.0;
  dz = lu / 2.0;

  while (zz <= (length - lu) / 2.0) {
    box (0.0, gap / 2.0 + 5e-4, zz, xwidth, 1e-3, lu / 2.0, 0, 0, 1, 0);
    box (0.0, -gap / 2.0 - 5e-4, zz, xwidth, 1e-3, lu / 2.0, 0, 0, 1, 0);
    zz += dz;
  }

  line (0.0, 0.0, 0.0, K * D * sin (igamma), 0.0, D);
  line (0.0, 0.0, 0.0, -K * D * sin (igamma), 0.0, D);
  line (0.0, 0.0, 0.0, 0.0, D* sin (igamma), D);
  line (0.0, 0.0, 0.0, 0.0, -D* sin (igamma), D);

  double psi, dpsi;
  psi = -igamma;
  dpsi = 2.0 * igamma / 32;
  while (psi < igamma) {
    x0 = D * sin (psi);
    x1 = D * sin (psi + dpsi);
    z0 = D * cos (psi);
    z1 = D * cos (psi + dpsi);
    line (K * x0, 0.0, z0, K * x1, 0.0, z1);
    line (0.0, x0, z0, 0.0, x1, z1);
    psi += dpsi;
  }
  #undef E0
  #undef dE
  #undef lambda0
  #undef dlambda
  #undef phase
  #undef randomphase
  #undef Ee
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef length
  #undef sigey
  #undef sigex
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef gauss_t
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef kc
  #undef s1x
  #undef s1y
  #undef lu
  #undef gap
  #undef p0
  return(_comp);
} /* class_Wiggler_display */

_class_Mask *class_Mask_display(_class_Mask *_comp
) {
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define mask (_comp->_parameters.mask)
  #define invert (_comp->_parameters.invert)
  #define virtual (_comp->_parameters.virtual)
  #define table (_comp->_parameters.table)
  #define ny (_comp->_parameters.ny)
  #define nx (_comp->_parameters.nx)
  #define xmin (_comp->_parameters.xmin)
  #define ymin (_comp->_parameters.ymin)
  #define xmax (_comp->_parameters.xmax)
  #define ymax (_comp->_parameters.ymax)
  #define filter_row (_comp->_parameters.filter_row)
  #define maskval (_comp->_parameters.maskval)
  SIG_MESSAGE("[_DISCO_ColdFinger_display] component DISCO_ColdFinger=Mask() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mask.comp:260]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  rectangle ("xy", 0, 0, 0, xwidth, yheight);
  #undef xwidth
  #undef yheight
  #undef mask
  #undef invert
  #undef virtual
  #undef table
  #undef ny
  #undef nx
  #undef xmin
  #undef ymin
  #undef xmax
  #undef ymax
  #undef filter_row
  #undef maskval
  return(_comp);
} /* class_Mask_display */

_class_Mirror_toroid_pothole *class_Mirror_toroid_pothole_display(_class_Mirror_toroid_pothole *_comp
) {
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define radius (_comp->_parameters.radius)
  #define radius_o (_comp->_parameters.radius_o)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define prms (_comp->_parameters.prms)
  #define reflec_table (_comp->_parameters.reflec_table)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_DISCO_M2_display] component DISCO_M2=Mirror_toroid_pothole() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/Mirror_toroid_pothole.comp:201]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  // See parametric equation used for the 3D view here: https://en.wikipedia.org/wiki/Torus#Geometry or here:https://web.maths.unsw.edu.au/~rsw/Torus/index.php
  // Because the code above doesn't actually reproduce a torus exactly but uses a cylinder and an ellipsoid to construct the toroidal mirror (to avoid solving
  // quartic equations), there's a slight mismatch between the 3D view (exact torus) and the actual toroidal mirror coded above.

  double x0, y0, z0, x1, y1, z1, theta, phi, phi_total, theta_total, theta_beginning, phi_beginning, theta_end, phi_end;
  // int N=50; too many points, makes the 3D matlab viewer bug
  int N = 10;

  phi_total = RAD2DEG * (zdepth / (radius + radius_o)); // degrees
  theta_total = RAD2DEG * (xwidth / radius);

  // fix theta=0 and phi=180 degrees respectively
  theta = 0;
  phi = 180;

  // then start at the beginning of the theta or phi range in order to map the flat surface (xwidth, zdepth) on the torus.
  theta_beginning = theta - (theta_total / 2);
  phi_beginning = phi - (phi_total / 2);

  theta_end = theta + (theta_total / 2);
  phi_end = phi + (phi_total / 2);

  theta = theta_beginning;
  phi = phi_beginning;

  while (theta <= theta_end) {
    phi = 180 - (phi_total / 2);
    x0 = radius * sin (DEG2RAD * theta);
    y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
    z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
    while (phi <= phi_end) {
      x1 = radius * sin (DEG2RAD * theta);
      y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
      z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
      line (x0, y0, z0, x1, y1, z1);
      x0 = x1;
      y0 = y1;
      z0 = z1;
      phi += phi_total / N;
    }
    theta += theta_total / N;
  }

  theta = theta_beginning;
  phi = phi_beginning;

  while (phi <= phi_end) {
    theta = -(theta_total / 2);
    x0 = radius * sin (DEG2RAD * theta);
    y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
    z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
    while (theta <= theta_end) {
      x1 = radius * sin (DEG2RAD * theta);
      y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
      z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
      line (x0, y0, z0, x1, y1, z1);
      x0 = x1;
      y0 = y1;
      z0 = z1;
      theta += theta_total / N;
    }
    phi += phi_total / N;
  }
  #undef zdepth
  #undef xwidth
  #undef radius
  #undef radius_o
  #undef R0
  #undef coating
  #undef prms
  #undef reflec_table
  #undef re
  return(_comp);
} /* class_Mirror_toroid_pothole_display */

_class_Mirror *class_Mirror_display(_class_Mirror *_comp
) {
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define coating (_comp->_parameters.coating)
  #define R0 (_comp->_parameters.R0)
  #define geometry (_comp->_parameters.geometry)
  #define re (_comp->_parameters.re)
  #define offdata (_comp->_parameters.offdata)
  #define shape (_comp->_parameters.shape)
  SIG_MESSAGE("[_DISCO_M4_display] component DISCO_M4=Mirror() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror.comp:161]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  /* A bit ugly; hard-coded dimensions. */
  magnify ("");
  if (shape == ANY) { /* OFF file */
    off_display (offdata);
  } else if (yheight) {
    line (0, -yheight / 2.0, -zdepth / 2.0, 0, yheight / 2.0, -zdepth / 2.0);
    line (0, -yheight / 2.0, zdepth / 2.0, 0, yheight / 2.0, zdepth / 2.0);
    line (0, -yheight / 2.0, -zdepth / 2.0, 0, -yheight / 2.0, zdepth / 2.0);
    line (0, yheight / 2.0, -zdepth / 2.0, 0, yheight / 2.0, zdepth / 2.0);
  } else {
    line (-xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, -zdepth / 2.0);
    line (-xwidth / 2.0, 0, zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
    line (-xwidth / 2.0, 0, -zdepth / 2.0, -xwidth / 2.0, 0, zdepth / 2.0);
    line (xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
  }
  #undef zdepth
  #undef xwidth
  #undef yheight
  #undef coating
  #undef R0
  #undef geometry
  #undef re
  #undef offdata
  #undef shape
  return(_comp);
} /* class_Mirror_display */

_class_Mirror_elliptic *class_Mirror_elliptic_display(_class_Mirror_elliptic *_comp
) {
  #define x_a (_comp->_parameters.x_a)
  #define y_b (_comp->_parameters.y_b)
  #define z_c (_comp->_parameters.z_c)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define R0 (_comp->_parameters.R0)
  #define coating (_comp->_parameters.coating)
  #define length (_comp->_parameters.length)
  #define width (_comp->_parameters.width)
  #define radius (_comp->_parameters.radius)
  #define a2inv (_comp->_parameters.a2inv)
  #define b2inv (_comp->_parameters.b2inv)
  #define c2inv (_comp->_parameters.c2inv)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_DISCO_M51_display] component DISCO_M51=Mirror_elliptic() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_elliptic.comp:195]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  int i, j, N = 12;
  double t, xx, yy, zz, xx0, yy0, zz0;
  double a2, b2, c2;
  a2 = 1.0 / a2inv;
  b2 = 1.0 / b2inv;
  c2 = 1.0 / c2inv;
  if (xwidth && zdepth) {
    for (i = 0; i < N; i++) {
      xx0 = -xwidth / 2.0;
      zz = i * zdepth / (N - 1) - zdepth / 2.0;
      yy0 = -(1) * sqrt (b2 * (1 - xx0 * xx0 / a2 - zz * zz / c2)) + sqrt (b2);
      for (j = 1; j < N; j++) {
        xx = j * xwidth / (N - 1) - xwidth / 2.0;
        yy = -(1) * sqrt (b2 * (1 - xx * xx / a2 - zz * zz / c2)) + sqrt (b2);
        line (xx0, yy0, zz, xx, yy, zz);
        xx0 = xx;
        yy0 = yy;
      }
    }
    for (i = 0; i < N; i++) {
      zz0 = -zdepth / 2.0;
      xx = i * xwidth / (N - 1) - xwidth / 2.0;
      yy0 = -(1) * sqrt (b2 * (1 - xx * xx / a2 - zz0 * zz0 / c2)) + sqrt (b2);
      for (j = 1; j < N; j++) {
        zz = j * zdepth / (N - 1) - zdepth / 2.0;
        yy = -(1) * sqrt (b2 * (1 - xx * xx / a2 - zz * zz / c2)) + sqrt (b2);
        line (xx, yy0, zz0, xx, yy, zz);
        zz0 = zz;
        yy0 = yy;
      }
    }
  }
  #undef x_a
  #undef y_b
  #undef z_c
  #undef zdepth
  #undef xwidth
  #undef R0
  #undef coating
  #undef length
  #undef width
  #undef radius
  #undef a2inv
  #undef b2inv
  #undef c2inv
  #undef re
  return(_comp);
} /* class_Mirror_elliptic_display */

_class_Grating_reflect *class_Grating_reflect_display(_class_Grating_reflect *_comp
) {
  #define d_phi (_comp->_parameters.d_phi)
  #define R0 (_comp->_parameters.R0)
  #define rho_l (_comp->_parameters.rho_l)
  #define order (_comp->_parameters.order)
  #define phi0 (_comp->_parameters.phi0)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define verbose (_comp->_parameters.verbose)
  #define pdir (_comp->_parameters.pdir)
  #define d (_comp->_parameters.d)
  #define b (_comp->_parameters.b)
  #define nslits (_comp->_parameters.nslits)
  SIG_MESSAGE("[_DISCO_reflective_grating_display] component DISCO_reflective_grating=Grating_reflect() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Grating_reflect.comp:206]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  magnify ("");
  line (-xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, -zdepth / 2.0);
  line (-xwidth / 2.0, 0, zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
  line (-xwidth / 2.0, 0, -zdepth / 2.0, -xwidth / 2.0, 0, zdepth / 2.0);
  line (xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
  #undef d_phi
  #undef R0
  #undef rho_l
  #undef order
  #undef phi0
  #undef zdepth
  #undef xwidth
  #undef verbose
  #undef pdir
  #undef d
  #undef b
  #undef nslits
  return(_comp);
} /* class_Grating_reflect_display */

_class_Undulator *class_Undulator_display(_class_Undulator *_comp
) {
  #define E0 (_comp->_parameters.E0)
  #define dE (_comp->_parameters.dE)
  #define phase (_comp->_parameters.phase)
  #define randomphase (_comp->_parameters.randomphase)
  #define Ee (_comp->_parameters.Ee)
  #define dEe (_comp->_parameters.dEe)
  #define Ie (_comp->_parameters.Ie)
  #define B (_comp->_parameters.B)
  #define K (_comp->_parameters.K)
  #define Nper (_comp->_parameters.Nper)
  #define lu (_comp->_parameters.lu)
  #define sigey (_comp->_parameters.sigey)
  #define sigex (_comp->_parameters.sigex)
  #define sigepx (_comp->_parameters.sigepx)
  #define sigepy (_comp->_parameters.sigepy)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define dist (_comp->_parameters.dist)
  #define quick_integ (_comp->_parameters.quick_integ)
  #define E1st (_comp->_parameters.E1st)
  #define verbose (_comp->_parameters.verbose)
  #define Br (_comp->_parameters.Br)
  #define gamma (_comp->_parameters.gamma)
  #define gamma2 (_comp->_parameters.gamma2)
  #define igamma (_comp->_parameters.igamma)
  #define s1x (_comp->_parameters.s1x)
  #define s1y (_comp->_parameters.s1y)
  #define length (_comp->_parameters.length)
  #define kc (_comp->_parameters.kc)
  #define pmul (_comp->_parameters.pmul)
  #define gap (_comp->_parameters.gap)
  #define Bsig (_comp->_parameters.Bsig)
  #define Bpi (_comp->_parameters.Bpi)
  #define gsl_int_ws (_comp->_parameters.gsl_int_ws)
  #define alpha (_comp->_parameters.alpha)
  #define MELE (_comp->_parameters.MELE)
  SIG_MESSAGE("[_CRISTAL_Source_display] component CRISTAL_Source=Undulator() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/sources/Undulator.comp:354]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  double zz, dz;
  const double xwidth = 1e-2;
  const double D = dist;
  double x0, z0, x1, z1;

  zz = -(length + lu) / 2.0;
  dz = lu / 2.0;

  while (zz <= (length - lu) / 2.0) {
    box (0.0, gap / 2.0 + 5e-4, zz, xwidth, 1e-3, lu / 2.0, 0, 0, 1, 0);
    box (0.0, -gap / 2.0 - 5e-4, zz, xwidth, 1e-3, lu / 2.0, 0, 0, 1, 0);
    zz += dz;
  }

  line (0.0, 0.0, 0.0, K * D * sin (igamma), 0.0, D);
  line (0.0, 0.0, 0.0, -K * D * sin (igamma), 0.0, D);
  line (0.0, 0.0, 0.0, 0.0, D* sin (igamma), D);
  line (0.0, 0.0, 0.0, 0.0, -D* sin (igamma), D);

  double phi, dphi;
  phi = -igamma;
  dphi = 2.0 * igamma / 32;
  while (phi < igamma) {
    x0 = D * sin (phi);
    x1 = D * sin (phi + dphi);
    z0 = D * cos (phi);
    z1 = D * cos (phi + dphi);
    line (K * x0, 0.0, z0, K * x1, 0.0, z1);
    line (0.0, x0, z0, 0.0, x1, z1);
    phi += dphi;
  }
  #undef E0
  #undef dE
  #undef phase
  #undef randomphase
  #undef Ee
  #undef dEe
  #undef Ie
  #undef B
  #undef K
  #undef Nper
  #undef lu
  #undef sigey
  #undef sigex
  #undef sigepx
  #undef sigepy
  #undef focus_xw
  #undef focus_yh
  #undef dist
  #undef quick_integ
  #undef E1st
  #undef verbose
  #undef Br
  #undef gamma
  #undef gamma2
  #undef igamma
  #undef s1x
  #undef s1y
  #undef length
  #undef kc
  #undef pmul
  #undef gap
  #undef Bsig
  #undef Bpi
  #undef gsl_int_ws
  #undef alpha
  #undef MELE
  return(_comp);
} /* class_Undulator_display */

_class_Mirror_toroid *class_Mirror_toroid_display(_class_Mirror_toroid *_comp
) {
  #define coating (_comp->_parameters.coating)
  #define zdepth (_comp->_parameters.zdepth)
  #define xwidth (_comp->_parameters.xwidth)
  #define radius (_comp->_parameters.radius)
  #define radius_o (_comp->_parameters.radius_o)
  #define R0 (_comp->_parameters.R0)
  #define re (_comp->_parameters.re)
  SIG_MESSAGE("[_GALAXIES_M2A_display] component GALAXIES_M2A=Mirror_toroid() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Mirror_toroid.comp:135]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  // See parametric equation used for the 3D view here: https://en.wikipedia.org/wiki/Torus#Geometry or here:https://web.maths.unsw.edu.au/~rsw/Torus/index.php
  // Because the code above doesn't actually reproduce a torus exactly but uses a cylinder and an ellipsoid to construct the toroidal mirror (to avoid solving
  // quartic equations), there's a slight mismatch between the 3D view (exact torus) and the actual toroidal mirror coded above.

  double x0, y0, z0, x1, y1, z1, theta, phi, phi_total, theta_total, theta_beginning, phi_beginning, theta_end, phi_end;
  // int N=50; too many points, makes the 3D matlab viewer bug
  int N = 10;

  phi_total = RAD2DEG * (zdepth / (radius + radius_o)); // degrees
  theta_total = RAD2DEG * (xwidth / radius);

  // fix theta=0 and phi=180 degrees respectively
  theta = 0;
  phi = 180;

  // then start at the beginning of the theta or phi range in order to map the flat surface (xwidth, zdepth) on the torus.
  theta_beginning = theta - (theta_total / 2);
  phi_beginning = phi - (phi_total / 2);

  theta_end = theta + (theta_total / 2);
  phi_end = phi + (phi_total / 2);

  theta = theta_beginning;
  phi = phi_beginning;

  while (theta <= theta_end) {
    phi = 180 - (phi_total / 2);
    x0 = radius * sin (DEG2RAD * theta);
    y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
    z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
    while (phi <= phi_end) {
      x1 = radius * sin (DEG2RAD * theta);
      y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
      z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
      line (x0, y0, z0, x1, y1, z1);
      x0 = x1;
      y0 = y1;
      z0 = z1;
      phi += phi_total / N;
    }
    theta += theta_total / N;
  }

  theta = theta_beginning;
  phi = phi_beginning;

  while (phi <= phi_end) {
    theta = -(theta_total / 2);
    x0 = radius * sin (DEG2RAD * theta);
    y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
    z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
    while (theta <= theta_end) {
      x1 = radius * sin (DEG2RAD * theta);
      y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
      z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
      line (x0, y0, z0, x1, y1, z1);
      x0 = x1;
      y0 = y1;
      z0 = z1;
      theta += theta_total / N;
    }
    phi += phi_total / N;
  }
  line (-xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, -zdepth / 2.0);
  line (-xwidth / 2.0, 0, zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
  line (-xwidth / 2.0, 0, -zdepth / 2.0, -xwidth / 2.0, 0, zdepth / 2.0);
  line (xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
  #undef coating
  #undef zdepth
  #undef xwidth
  #undef radius
  #undef radius_o
  #undef R0
  #undef re
  return(_comp);
} /* class_Mirror_toroid_display */

_class_FluoCrystal *class_FluoCrystal_display(_class_FluoCrystal *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define sx_refl (_comp->_parameters.sx_refl)
  #define flag_sx (_comp->_parameters.flag_sx)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define barns (_comp->_parameters.barns)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define order (_comp->_parameters.order)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define n_diff (_comp->_parameters.n_diff)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define p_diff (_comp->_parameters.p_diff)
  #define fluo_rho (_comp->_parameters.fluo_rho)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_cum_xs_diffraction (_comp->_parameters.reuse_cum_xs_diffraction)
  #define reuse_coh_refl (_comp->_parameters.reuse_coh_refl)
  #define reuse_coh_xsect (_comp->_parameters.reuse_coh_xsect)
  #define reuse_tau_count (_comp->_parameters.reuse_tau_count)
  SIG_MESSAGE("[_GALAXIES_sample_display] component GALAXIES_sample=FluoCrystal() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:1002]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
    if (shape == 0) { /* cyl */
      circle("xz", 0,  yheight/2.0, 0, radius);
      circle("xz", 0, -yheight/2.0, 0, radius);
      line(-radius, -yheight/2.0, 0, -radius, +yheight/2.0, 0);
      line(+radius, -yheight/2.0, 0, +radius, +yheight/2.0, 0);
      line(0, -yheight/2.0, -radius, 0, +yheight/2.0, -radius);
      line(0, -yheight/2.0, +radius, 0, +yheight/2.0, +radius);
      if (thickness) {
        double radius_i=radius-thickness;
        circle("xz", 0,  yheight/2.0, 0, radius_i);
        circle("xz", 0, -yheight/2.0, 0, radius_i);
        line(-radius_i, -yheight/2.0, 0, -radius_i, +yheight/2.0, 0);
        line(+radius_i, -yheight/2.0, 0, +radius_i, +yheight/2.0, 0);
        line(0, -yheight/2.0, -radius_i, 0, +yheight/2.0, -radius_i);
        line(0, -yheight/2.0, +radius_i, 0, +yheight/2.0, +radius_i);
      }
    } else if (shape == 1) {  /* box */
      double xmin = -0.5*xwidth;
      double xmax =  0.5*xwidth;
      double ymin = -0.5*yheight;
      double ymax =  0.5*yheight;
      double zmin = -0.5*zdepth;
      double zmax =  0.5*zdepth;
      multiline(5, xmin, ymin, zmin,
                   xmax, ymin, zmin,
                   xmax, ymax, zmin,
                   xmin, ymax, zmin,
                   xmin, ymin, zmin);
      multiline(5, xmin, ymin, zmax,
                   xmax, ymin, zmax,
                   xmax, ymax, zmax,
                   xmin, ymax, zmax,
                   xmin, ymin, zmax);
      line(xmin, ymin, zmin, xmin, ymin, zmax);
      line(xmax, ymin, zmin, xmax, ymin, zmax);
      line(xmin, ymax, zmin, xmin, ymax, zmax);
      line(xmax, ymax, zmin, xmax, ymax, zmax);
      if (zdepth) {
        xmin = -0.5*xwidth;
        xmax =  0.5*xwidth;
        ymin = -0.5*yheight;
        ymax =  0.5*yheight;
        zmin = -0.5*zdepth;
        zmax =  0.5*zdepth;
        multiline(5, xmin, ymin, zmin,
                  xmax, ymin, zmin,
                  xmax, ymax, zmin,
                  xmin, ymax, zmin,
                  xmin, ymin, zmin);
        multiline(5, xmin, ymin, zmax,
                  xmax, ymin, zmax,
                  xmax, ymax, zmax,
                  xmin, ymax, zmax,
                  xmin, ymin, zmax);
        line(xmin, ymin, zmin, xmin, ymin, zmax);
        line(xmax, ymin, zmin, xmax, ymin, zmax);
        line(xmin, ymax, zmin, xmin, ymax, zmax);
        line(xmax, ymax, zmin, xmax, ymax, zmax);
      }
    } if (shape == 2) { /* sphere */
      circle("xy",0,0,0,radius);
      circle("xz",0,0,0,radius);
      circle("yz",0,0,0,radius);
    } else if (shape == 3) {        /* OFF file */
      off_display(offdata);
    }
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef sx_refl
  #undef flag_sx
  #undef delta_d_d
  #undef barns
  #undef recip_cell
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef aa
  #undef bb
  #undef cc
  #undef mosaic_AB
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef order
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef shape
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef n_diff
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef p_diff
  #undef fluo_rho
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_cum_xs_diffraction
  #undef reuse_coh_refl
  #undef reuse_coh_xsect
  #undef reuse_tau_count
  return(_comp);
} /* class_FluoCrystal_display */

_class_Single_crystal *class_Single_crystal_display(_class_Single_crystal *_comp
) {
  #define reflections (_comp->_parameters.reflections)
  #define geometry (_comp->_parameters.geometry)
  #define mosaic_AB (_comp->_parameters.mosaic_AB)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define delta_d_d (_comp->_parameters.delta_d_d)
  #define mosaic (_comp->_parameters.mosaic)
  #define mosaic_a (_comp->_parameters.mosaic_a)
  #define mosaic_b (_comp->_parameters.mosaic_b)
  #define mosaic_c (_comp->_parameters.mosaic_c)
  #define recip_cell (_comp->_parameters.recip_cell)
  #define barns (_comp->_parameters.barns)
  #define ax (_comp->_parameters.ax)
  #define ay (_comp->_parameters.ay)
  #define az (_comp->_parameters.az)
  #define bx (_comp->_parameters.bx)
  #define by (_comp->_parameters.by)
  #define bz (_comp->_parameters.bz)
  #define cx (_comp->_parameters.cx)
  #define cy (_comp->_parameters.cy)
  #define cz (_comp->_parameters.cz)
  #define p_transmit (_comp->_parameters.p_transmit)
  #define sigma_inc (_comp->_parameters.sigma_inc)
  #define aa (_comp->_parameters.aa)
  #define bb (_comp->_parameters.bb)
  #define cc (_comp->_parameters.cc)
  #define order (_comp->_parameters.order)
  #define extra_order (_comp->_parameters.extra_order)
  #define RX (_comp->_parameters.RX)
  #define RY (_comp->_parameters.RY)
  #define powder (_comp->_parameters.powder)
  #define deltak (_comp->_parameters.deltak)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define surf_size (_comp->_parameters.surf_size)
  #define surf_k (_comp->_parameters.surf_k)
  #define surf_FT2 (_comp->_parameters.surf_FT2)
  #define surf_dir (_comp->_parameters.surf_dir)
  #define hkl_info (_comp->_parameters.hkl_info)
  #define offdata (_comp->_parameters.offdata)
  #define hkl_list (_comp->_parameters.hkl_list)
  #define tau_list (_comp->_parameters.tau_list)
  #define abs_info (_comp->_parameters.abs_info)
  SIG_MESSAGE("[_PX1_sample_display] component PX1_sample=Single_crystal() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Single_crystal.comp:1924]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  if (hkl_info.shape == 0) { /* cylinder */
    circle ("xz", 0, yheight / 2.0, 0, radius);
    circle ("xz", 0, -yheight / 2.0, 0, radius);
    line (-radius, -yheight / 2.0, 0, -radius, +yheight / 2.0, 0);
    line (+radius, -yheight / 2.0, 0, +radius, +yheight / 2.0, 0);
    line (0, -yheight / 2.0, -radius, 0, +yheight / 2.0, -radius);
    line (0, -yheight / 2.0, +radius, 0, +yheight / 2.0, +radius);
  } else if (hkl_info.shape == 1) { /* box */
    double xmin = -0.5 * xwidth;
    double xmax = 0.5 * xwidth;
    double ymin = -0.5 * yheight;
    double ymax = 0.5 * yheight;
    double zmin = -0.5 * zdepth;
    double zmax = 0.5 * zdepth;
    multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin);
    multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax);
    line (xmin, ymin, zmin, xmin, ymin, zmax);
    line (xmax, ymin, zmin, xmax, ymin, zmax);
    line (xmin, ymax, zmin, xmin, ymax, zmax);
    line (xmax, ymax, zmin, xmax, ymax, zmax);
  } else if (hkl_info.shape == 2) { /* sphere */
    circle ("xy", 0, 0.0, 0, radius);
    circle ("xz", 0, 0.0, 0, radius);
    circle ("yz", 0, 0.0, 0, radius);
  } else if (hkl_info.shape == 3) { /* OFF file */
    off_display (offdata);
  }
  #undef reflections
  #undef geometry
  #undef mosaic_AB
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef delta_d_d
  #undef mosaic
  #undef mosaic_a
  #undef mosaic_b
  #undef mosaic_c
  #undef recip_cell
  #undef barns
  #undef ax
  #undef ay
  #undef az
  #undef bx
  #undef by
  #undef bz
  #undef cx
  #undef cy
  #undef cz
  #undef p_transmit
  #undef sigma_inc
  #undef aa
  #undef bb
  #undef cc
  #undef order
  #undef extra_order
  #undef RX
  #undef RY
  #undef powder
  #undef deltak
  #undef material_datafile
  #undef surf_size
  #undef surf_k
  #undef surf_FT2
  #undef surf_dir
  #undef hkl_info
  #undef offdata
  #undef hkl_list
  #undef tau_list
  #undef abs_info
  return(_comp);
} /* class_Single_crystal_display */

_class_PSD_monitor_4PI *class_PSD_monitor_4PI_display(_class_PSD_monitor_4PI *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p (_comp->_parameters.PSD_p)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  SIG_MESSAGE("[_PX1_psd4pi_display] component PX1_psd4pi=PSD_monitor_4PI() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_4PI.comp:119]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  circle ("xy", 0, 0, 0, radius);
  circle ("xz", 0, 0, 0, radius);
  circle ("yz", 0, 0, 0, radius);
  #undef radius
  #undef restore_xray
  #undef nx
  #undef ny
  #undef filename
  #undef PSD_N
  #undef PSD_p
  #undef PSD_p2
  return(_comp);
} /* class_PSD_monitor_4PI_display */

_class_Saxs_spheres *class_Saxs_spheres_display(_class_Saxs_spheres *_comp
) {
  #define sphere_mtrl (_comp->_parameters.sphere_mtrl)
  #define R (_comp->_parameters.R)
  #define Phi (_comp->_parameters.Phi)
  #define Delta_rho (_comp->_parameters.Delta_rho)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define target_index (_comp->_parameters.target_index)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define focus_r (_comp->_parameters.focus_r)
  #define mu_c (_comp->_parameters.mu_c)
  #define my_s_pre (_comp->_parameters.my_s_pre)
  #define shape (_comp->_parameters.shape)
  #define Z (_comp->_parameters.Z)
  #define At (_comp->_parameters.At)
  #define rho (_comp->_parameters.rho)
  #define T (_comp->_parameters.T)
  #define mu_ci (_comp->_parameters.mu_ci)
  #define abs_data (_comp->_parameters.abs_data)
  SIG_MESSAGE("[_SWING_sample_test_display] component SWING_sample_test=Saxs_spheres() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Saxs_spheres.comp:201]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  if (shape == 0) { /* cylinder */
    circle ("xz", 0, yheight / 2.0, 0, radius);
    circle ("xz", 0, -yheight / 2.0, 0, radius);
    line (-radius, -yheight / 2.0, 0, -radius, +yheight / 2.0, 0);
    line (+radius, -yheight / 2.0, 0, +radius, +yheight / 2.0, 0);
    line (0, -yheight / 2.0, -radius, 0, +yheight / 2.0, -radius);
    line (0, -yheight / 2.0, +radius, 0, +yheight / 2.0, +radius);
  } else if (shape == 1) { /* box */
    box (0, 0, 0, xwidth, yheight, zdepth, 0, 0, 1, 0);
  } else if (shape == 2) { /* sphere */
    circle ("xy", 0, 0.0, 0, radius);
    circle ("xz", 0, 0.0, 0, radius);
    circle ("yz", 0, 0.0, 0, radius);
  }
  #undef sphere_mtrl
  #undef R
  #undef Phi
  #undef Delta_rho
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef target_x
  #undef target_y
  #undef target_z
  #undef target_index
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef focus_r
  #undef mu_c
  #undef my_s_pre
  #undef shape
  #undef Z
  #undef At
  #undef rho
  #undef T
  #undef mu_ci
  #undef abs_data
  return(_comp);
} /* class_Saxs_spheres_display */

_class_SAXSPDBFast *class_SAXSPDBFast_display(_class_SAXSPDBFast *_comp
) {
  #define RhoSolvent (_comp->_parameters.RhoSolvent)
  #define Concentration (_comp->_parameters.Concentration)
  #define AbsorptionCrosssection (_comp->_parameters.AbsorptionCrosssection)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define SampleToDetectorDistance (_comp->_parameters.SampleToDetectorDistance)
  #define DetectorRadius (_comp->_parameters.DetectorRadius)
  #define qMin (_comp->_parameters.qMin)
  #define qMax (_comp->_parameters.qMax)
  #define NumberOfQBins (_comp->_parameters.NumberOfQBins)
  #define PDBFilepath (_comp->_parameters.PDBFilepath)
  #define Absorption (_comp->_parameters.Absorption)
  #define NumberDensity (_comp->_parameters.NumberDensity)
  #define qArray (_comp->_parameters.qArray)
  #define IArray (_comp->_parameters.IArray)
  SIG_MESSAGE("[_SWING_sample_display] component SWING_sample=SAXSPDBFast() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSPDBFast.comp:538]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  box (0, 0, 0, xwidth, yheight, zdepth, 0, 0, 1, 0);
  #undef RhoSolvent
  #undef Concentration
  #undef AbsorptionCrosssection
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef SampleToDetectorDistance
  #undef DetectorRadius
  #undef qMin
  #undef qMax
  #undef NumberOfQBins
  #undef PDBFilepath
  #undef Absorption
  #undef NumberDensity
  #undef qArray
  #undef IArray
  return(_comp);
} /* class_SAXSPDBFast_display */

_class_SAXSQMonitor *class_SAXSQMonitor_display(_class_SAXSQMonitor *_comp
) {
  #define RFilename (_comp->_parameters.RFilename)
  #define qFilename (_comp->_parameters.qFilename)
  #define NumberOfBins (_comp->_parameters.NumberOfBins)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define RadiusDetector (_comp->_parameters.RadiusDetector)
  #define DistanceFromSample (_comp->_parameters.DistanceFromSample)
  #define LambdaMin (_comp->_parameters.LambdaMin)
  #define Lambda0 (_comp->_parameters.Lambda0)
  #define qMax (_comp->_parameters.qMax)
  #define Nofq (_comp->_parameters.Nofq)
  #define Iofq (_comp->_parameters.Iofq)
  #define IofqSquared (_comp->_parameters.IofqSquared)
  #define NofR (_comp->_parameters.NofR)
  #define IofR (_comp->_parameters.IofR)
  #define IofRSquared (_comp->_parameters.IofRSquared)
  SIG_MESSAGE("[_SWING_QMonitor_display] component SWING_QMonitor=SAXSQMonitor() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/contrib/SAXSQMonitor.comp:194]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  circle ("xy", 0, 0, 0, RadiusDetector);
  #undef RFilename
  #undef qFilename
  #undef NumberOfBins
  #undef restore_xray
  #undef RadiusDetector
  #undef DistanceFromSample
  #undef LambdaMin
  #undef Lambda0
  #undef qMax
  #undef Nofq
  #undef Iofq
  #undef IofqSquared
  #undef NofR
  #undef IofR
  #undef IofRSquared
  return(_comp);
} /* class_SAXSQMonitor_display */

_class_Divergence_monitor *class_Divergence_monitor_display(_class_Divergence_monitor *_comp
) {
  #define nh (_comp->_parameters.nh)
  #define nv (_comp->_parameters.nv)
  #define rad (_comp->_parameters.rad)
  #define filename (_comp->_parameters.filename)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define maxdiv_h (_comp->_parameters.maxdiv_h)
  #define maxdiv_v (_comp->_parameters.maxdiv_v)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define Div_N (_comp->_parameters.Div_N)
  #define Div_p (_comp->_parameters.Div_p)
  #define Div_p2 (_comp->_parameters.Div_p2)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_ROCK_slit3_div_display] component ROCK_slit3_div=Divergence_monitor() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Divergence_monitor.comp:148]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  multiline (5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin,
             (double)ymin, 0.0);
  #undef nh
  #undef nv
  #undef rad
  #undef filename
  #undef xwidth
  #undef yheight
  #undef maxdiv_h
  #undef maxdiv_v
  #undef restore_xray
  #undef nx
  #undef ny
  #undef nz
  #undef nowritefile
  #undef Div_N
  #undef Div_p
  #undef Div_p2
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_Divergence_monitor_display */

_class_Fluorescence *class_Fluorescence_display(_class_Fluorescence *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define thickness (_comp->_parameters.thickness)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define concentric (_comp->_parameters.concentric)
  #define material (_comp->_parameters.material)
  #define packing_factor (_comp->_parameters.packing_factor)
  #define rho (_comp->_parameters.rho)
  #define density (_comp->_parameters.density)
  #define weight (_comp->_parameters.weight)
  #define p_interact (_comp->_parameters.p_interact)
  #define target_x (_comp->_parameters.target_x)
  #define target_y (_comp->_parameters.target_y)
  #define target_z (_comp->_parameters.target_z)
  #define focus_r (_comp->_parameters.focus_r)
  #define focus_xw (_comp->_parameters.focus_xw)
  #define focus_yh (_comp->_parameters.focus_yh)
  #define focus_aw (_comp->_parameters.focus_aw)
  #define focus_ah (_comp->_parameters.focus_ah)
  #define target_index (_comp->_parameters.target_index)
  #define flag_compton (_comp->_parameters.flag_compton)
  #define flag_rayleigh (_comp->_parameters.flag_rayleigh)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define flag_kissel (_comp->_parameters.flag_kissel)
  #define flag_low_z (_comp->_parameters.flag_low_z)
  #define order (_comp->_parameters.order)
  #define compound (_comp->_parameters.compound)
  #define cum_massFractions (_comp->_parameters.cum_massFractions)
  #define cum_xs_fluo (_comp->_parameters.cum_xs_fluo)
  #define cum_xs_Compton (_comp->_parameters.cum_xs_Compton)
  #define cum_xs_Rayleigh (_comp->_parameters.cum_xs_Rayleigh)
  #define xs_fluo (_comp->_parameters.xs_fluo)
  #define xs_Compton (_comp->_parameters.xs_Compton)
  #define xs_Rayleigh (_comp->_parameters.xs_Rayleigh)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define n_fluo (_comp->_parameters.n_fluo)
  #define n_Compton (_comp->_parameters.n_Compton)
  #define n_Rayleigh (_comp->_parameters.n_Rayleigh)
  #define p_fluo (_comp->_parameters.p_fluo)
  #define p_Compton (_comp->_parameters.p_Compton)
  #define p_Rayleigh (_comp->_parameters.p_Rayleigh)
  #define reuse_nb (_comp->_parameters.reuse_nb)
  #define reuse_intersect (_comp->_parameters.reuse_intersect)
  #define reuse_ki (_comp->_parameters.reuse_ki)
  #define reuse_l0 (_comp->_parameters.reuse_l0)
  #define reuse_l1 (_comp->_parameters.reuse_l1)
  #define reuse_l2 (_comp->_parameters.reuse_l2)
  #define reuse_l3 (_comp->_parameters.reuse_l3)
  #define reuse_sigma_barn (_comp->_parameters.reuse_sigma_barn)
  #define reuse_cum_xs_fluo (_comp->_parameters.reuse_cum_xs_fluo)
  #define reuse_cum_xs_Compton (_comp->_parameters.reuse_cum_xs_Compton)
  #define reuse_cum_xs_Rayleigh (_comp->_parameters.reuse_cum_xs_Rayleigh)
  #define reuse_xs_fluo (_comp->_parameters.reuse_xs_fluo)
  #define reuse_xs_Compton (_comp->_parameters.reuse_xs_Compton)
  #define reuse_xs_Rayleigh (_comp->_parameters.reuse_xs_Rayleigh)
  SIG_MESSAGE("[_ROCK_absorption_sample_display] component ROCK_absorption_sample=Fluorescence() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/samples/Fluorescence.comp:1002]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
    if (shape == 0) { /* cyl */
      circle("xz", 0,  yheight/2.0, 0, radius);
      circle("xz", 0, -yheight/2.0, 0, radius);
      line(-radius, -yheight/2.0, 0, -radius, +yheight/2.0, 0);
      line(+radius, -yheight/2.0, 0, +radius, +yheight/2.0, 0);
      line(0, -yheight/2.0, -radius, 0, +yheight/2.0, -radius);
      line(0, -yheight/2.0, +radius, 0, +yheight/2.0, +radius);
      if (thickness) {
        double radius_i=radius-thickness;
        circle("xz", 0,  yheight/2.0, 0, radius_i);
        circle("xz", 0, -yheight/2.0, 0, radius_i);
        line(-radius_i, -yheight/2.0, 0, -radius_i, +yheight/2.0, 0);
        line(+radius_i, -yheight/2.0, 0, +radius_i, +yheight/2.0, 0);
        line(0, -yheight/2.0, -radius_i, 0, +yheight/2.0, -radius_i);
        line(0, -yheight/2.0, +radius_i, 0, +yheight/2.0, +radius_i);
      }
    } else if (shape == 1) {  /* box */
      double xmin = -0.5*xwidth;
      double xmax =  0.5*xwidth;
      double ymin = -0.5*yheight;
      double ymax =  0.5*yheight;
      double zmin = -0.5*zdepth;
      double zmax =  0.5*zdepth;
      multiline(5, xmin, ymin, zmin,
                   xmax, ymin, zmin,
                   xmax, ymax, zmin,
                   xmin, ymax, zmin,
                   xmin, ymin, zmin);
      multiline(5, xmin, ymin, zmax,
                   xmax, ymin, zmax,
                   xmax, ymax, zmax,
                   xmin, ymax, zmax,
                   xmin, ymin, zmax);
      line(xmin, ymin, zmin, xmin, ymin, zmax);
      line(xmax, ymin, zmin, xmax, ymin, zmax);
      line(xmin, ymax, zmin, xmin, ymax, zmax);
      line(xmax, ymax, zmin, xmax, ymax, zmax);
      if (zdepth) {
        xmin = -0.5*xwidth;
        xmax =  0.5*xwidth;
        ymin = -0.5*yheight;
        ymax =  0.5*yheight;
        zmin = -0.5*zdepth;
        zmax =  0.5*zdepth;
        multiline(5, xmin, ymin, zmin,
                  xmax, ymin, zmin,
                  xmax, ymax, zmin,
                  xmin, ymax, zmin,
                  xmin, ymin, zmin);
        multiline(5, xmin, ymin, zmax,
                  xmax, ymin, zmax,
                  xmax, ymax, zmax,
                  xmin, ymax, zmax,
                  xmin, ymin, zmax);
        line(xmin, ymin, zmin, xmin, ymin, zmax);
        line(xmax, ymin, zmin, xmax, ymin, zmax);
        line(xmin, ymax, zmin, xmin, ymax, zmax);
        line(xmax, ymax, zmin, xmax, ymax, zmax);
      }
    } if (shape == 2) { /* sphere */
      circle("xy",0,0,0,radius);
      circle("xz",0,0,0,radius);
      circle("yz",0,0,0,radius);
    } else if (shape == 3) {        /* OFF file */
      off_display(offdata);
    }
  #undef geometry
  #undef radius
  #undef thickness
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef concentric
  #undef material
  #undef packing_factor
  #undef rho
  #undef density
  #undef weight
  #undef p_interact
  #undef target_x
  #undef target_y
  #undef target_z
  #undef focus_r
  #undef focus_xw
  #undef focus_yh
  #undef focus_aw
  #undef focus_ah
  #undef target_index
  #undef flag_compton
  #undef flag_rayleigh
  #undef flag_lorentzian
  #undef flag_kissel
  #undef flag_low_z
  #undef order
  #undef compound
  #undef cum_massFractions
  #undef cum_xs_fluo
  #undef cum_xs_Compton
  #undef cum_xs_Rayleigh
  #undef xs_fluo
  #undef xs_Compton
  #undef xs_Rayleigh
  #undef shape
  #undef offdata
  #undef n_fluo
  #undef n_Compton
  #undef n_Rayleigh
  #undef p_fluo
  #undef p_Compton
  #undef p_Rayleigh
  #undef reuse_nb
  #undef reuse_intersect
  #undef reuse_ki
  #undef reuse_l0
  #undef reuse_l1
  #undef reuse_l2
  #undef reuse_l3
  #undef reuse_sigma_barn
  #undef reuse_cum_xs_fluo
  #undef reuse_cum_xs_Compton
  #undef reuse_cum_xs_Rayleigh
  #undef reuse_xs_fluo
  #undef reuse_xs_Compton
  #undef reuse_xs_Rayleigh
  return(_comp);
} /* class_Fluorescence_display */

_class_Filter *class_Filter_display(_class_Filter *_comp
) {
  #define refraction (_comp->_parameters.refraction)
  #define fixed_delta (_comp->_parameters.fixed_delta)
  #define material_datafile (_comp->_parameters.material_datafile)
  #define geometry (_comp->_parameters.geometry)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define radius (_comp->_parameters.radius)
  #define mu_col (_comp->_parameters.mu_col)
  #define Z (_comp->_parameters.Z)
  #define mu_c (_comp->_parameters.mu_c)
  #define Ar (_comp->_parameters.Ar)
  #define rho (_comp->_parameters.rho)
  #define delta_prefactor (_comp->_parameters.delta_prefactor)
  #define betafact (_comp->_parameters.betafact)
  #define table (_comp->_parameters.table)
  #define shape (_comp->_parameters.shape)
  #define offdata (_comp->_parameters.offdata)
  #define filter_row (_comp->_parameters.filter_row)
  SIG_MESSAGE("[_ANATOMIX_sample_display] component ANATOMIX_sample=Filter() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/optics/Filter.comp:344]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  if (shape == CUBE) {
    box (0, 0, 0, xwidth, yheight, zdepth, 0, 0, 1, 0);
  } else if (shape == CYLINDER) {
    circle ("xz", 0, yheight / 2.0, 0, radius);
    circle ("xz", 0, -yheight / 2.0, 0, radius);
    line (radius, yheight / 2.0, 0, radius, -yheight / 2.0, 0);
    line (-radius, yheight / 2.0, 0, -radius, -yheight / 2.0, 0);
    line (0, yheight / 2.0, radius, 0, -yheight / 2.0, radius);
    line (0, yheight / 2.0, -radius, 0, -yheight / 2.0, -radius);
  } else if (shape == SPHERE) {
    circle ("xy", 0, 0, 0, radius);
    circle ("xz", 0, 0, 0, radius);
    circle ("yz", 0, 0, 0, radius);
  } else if (shape == ANY) { /* OFF file */
    off_display (offdata);
  }
  #undef refraction
  #undef fixed_delta
  #undef material_datafile
  #undef geometry
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef radius
  #undef mu_col
  #undef Z
  #undef mu_c
  #undef Ar
  #undef rho
  #undef delta_prefactor
  #undef betafact
  #undef table
  #undef shape
  #undef offdata
  #undef filter_row
  return(_comp);
} /* class_Filter_display */

_class_PSD_monitor_coh *class_PSD_monitor_coh_display(_class_PSD_monitor_coh *_comp
) {
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define ratio (_comp->_parameters.ratio)
  #define centering (_comp->_parameters.centering)
  #define nowritefile (_comp->_parameters.nowritefile)
  #define PSD_N (_comp->_parameters.PSD_N)
  #define PSD_p2 (_comp->_parameters.PSD_p2)
  #define PSD_phi_real (_comp->_parameters.PSD_phi_real)
  #define PSD_phi_imag (_comp->_parameters.PSD_phi_imag)
  #define xmin (_comp->_parameters.xmin)
  #define xmax (_comp->_parameters.xmax)
  #define ymin (_comp->_parameters.ymin)
  #define ymax (_comp->_parameters.ymax)
  SIG_MESSAGE("[_NANO_psd_source_display] component NANO_psd_source=PSD_monitor_coh() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/PSD_monitor_coh.comp:269]");

  printf("MCDISPLAY: component %s\n", _comp->_name);

  multiline (5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin,
             (double)ymin, 0.0);
  #undef nx
  #undef ny
  #undef filename
  #undef restore_xray
  #undef xwidth
  #undef yheight
  #undef ratio
  #undef centering
  #undef nowritefile
  #undef PSD_N
  #undef PSD_p2
  #undef PSD_phi_real
  #undef PSD_phi_imag
  #undef xmin
  #undef xmax
  #undef ymin
  #undef ymax
  return(_comp);
} /* class_PSD_monitor_coh_display */

_class_Fluo_detector *class_Fluo_detector_display(_class_Fluo_detector *_comp
) {
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define Emin (_comp->_parameters.Emin)
  #define Emax (_comp->_parameters.Emax)
  #define nE (_comp->_parameters.nE)
  #define filename (_comp->_parameters.filename)
  #define restore_xray (_comp->_parameters.restore_xray)
  #define escape_ratio (_comp->_parameters.escape_ratio)
  #define escape_energy (_comp->_parameters.escape_energy)
  #define pileup_ratio (_comp->_parameters.pileup_ratio)
  #define electronic_noise (_comp->_parameters.electronic_noise)
  #define resolution_energy (_comp->_parameters.resolution_energy)
  #define resolution (_comp->_parameters.resolution)
  #define flag_lorentzian (_comp->_parameters.flag_lorentzian)
  #define E_N (_comp->_parameters.E_N)
  #define E_p (_comp->_parameters.E_p)
  #define E_p2 (_comp->_parameters.E_p2)
  #define E_N_pileup (_comp->_parameters.E_N_pileup)
  #define E_p_pileup (_comp->_parameters.E_p_pileup)
  #define E_p2_pileup (_comp->_parameters.E_p2_pileup)
  #define E_N_escape (_comp->_parameters.E_N_escape)
  #define E_p_escape (_comp->_parameters.E_p_escape)
  #define E_p2_escape (_comp->_parameters.E_p2_escape)
  #define shape (_comp->_parameters.shape)
  #define K (_comp->_parameters.K)
  #define p_sum (_comp->_parameters.p_sum)
  #define N_sum (_comp->_parameters.N_sum)
  SIG_MESSAGE("[_LUCIA_mon_spl_SDD_display] component LUCIA_mon_spl_SDD=Fluo_detector() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/monitors/Fluo_detector.comp:270]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  if (shape ==0) {          // disk
    circle("xy",0,0,0,radius);

  } else if (shape == 1) {  // rectangle
    rectangle("xy",0,0,0,xwidth,yheight);

  } else if (shape == 2) {  // sphere
    circle("xy",0,0,0,fabs(radius));
    circle("xz",0,0,0,fabs(radius));
    circle("yz",0,0,0,fabs(radius));
  }
  #undef radius
  #undef xwidth
  #undef yheight
  #undef Emin
  #undef Emax
  #undef nE
  #undef filename
  #undef restore_xray
  #undef escape_ratio
  #undef escape_energy
  #undef pileup_ratio
  #undef electronic_noise
  #undef resolution_energy
  #undef resolution
  #undef flag_lorentzian
  #undef E_N
  #undef E_p
  #undef E_p2
  #undef E_N_pileup
  #undef E_p_pileup
  #undef E_p2_pileup
  #undef E_N_escape
  #undef E_p_escape
  #undef E_p2_escape
  #undef shape
  #undef K
  #undef p_sum
  #undef N_sum
  return(_comp);
} /* class_Fluo_detector_display */

_class_Shape *class_Shape_display(_class_Shape *_comp
) {
  #define geometry (_comp->_parameters.geometry)
  #define radius (_comp->_parameters.radius)
  #define xwidth (_comp->_parameters.xwidth)
  #define yheight (_comp->_parameters.yheight)
  #define zdepth (_comp->_parameters.zdepth)
  #define thickness (_comp->_parameters.thickness)
  #define nx (_comp->_parameters.nx)
  #define ny (_comp->_parameters.ny)
  #define nz (_comp->_parameters.nz)
  #define center (_comp->_parameters.center)
  #define offdata (_comp->_parameters.offdata)
  SIG_MESSAGE("[_storage_display] component storage=Shape() DISPLAY [/u/data/pkwi/WORK/micromamba/envs/mcxtrace-3.x/share/mcxtrace/resources/misc/Shape.comp:93]");

  printf("MCDISPLAY: component %s\n", _comp->_name);
  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) { /* OFF file */
    off_display (offdata);
  } else if (radius > 0 && yheight) { /* cylinder along y*/
    cylinder (0, 0, 0, radius, yheight, thickness, nx, ny, nz);
  } else if (xwidth && yheight) { /* box/rectangle */
    box (0, 0, 0, xwidth, yheight, zdepth, thickness, nx, ny, nz);
  } else if (radius > 0 && !yheight) { /* sphere */
    sphere (0, 0, 0, radius);
  }
  #undef geometry
  #undef radius
  #undef xwidth
  #undef yheight
  #undef zdepth
  #undef thickness
  #undef nx
  #undef ny
  #undef nz
  #undef center
  #undef offdata
  return(_comp);
} /* class_Shape_display */


  #undef magnify
  #undef line
  #undef dashed_line
  #undef multiline
  #undef rectangle
  #undef box
  #undef circle
  #undef cylinder
  #undef sphere
  #undef cone
  #undef polygon
  #undef polyhedron

int display(void) { /* called by mccode_main for SOLEIL:DISPLAY */
  printf("MCDISPLAY: start\n");

  /* call iteratively all components DISPLAY */
  class_Arm_display(&_origin_var);

  class_Arm_display(&_jumper_var);

  class_Beamstop_display(&_beamdump_var);

  class_Text_display(&_ODE_pos_var);

  class_Text_display(&_SMIS_pos_var);

  class_Text_display(&_AILES_pos_var);

  class_Text_display(&_MARS_pos_var);

  class_Arm_display(&_MARS_var);

  class_Bending_magnet_display(&_MARS_Source_var);

  class_Monitor_nD_display(&_MARS_displaySourceLength_var);

  class_PSD_monitor_display(&_MARS_displaySource_var);

  class_Slit_display(&_MARS_slit1_var);

  class_Slit_display(&_MARS_slit2_var);

  class_Arm_display(&_MARS_M1_arm_translation_var);

  class_Arm_display(&_MARS_M1_arm_rotation_1_var);

  class_Mirror_curved_display(&_MARS_mirror_M1_var);

  class_Arm_display(&_MARS_M1_arm_rotation_2_var);

  class_Arm_display(&_MARS_M1_arm_rotation_2_undo_var);

  class_Arm_display(&_MARS_beam_arm_before_crystal_var);

  class_Bragg_crystal_display(&_MARS_dcm_xtal0_var);

  class_Arm_display(&_MARS_dcm0_var);

  class_Bragg_crystal_display(&_MARS_dcm_xtal1_var);

  class_Arm_display(&_MARS_dcm1_var);

  class_E_monitor_display(&_MARS_emon_dcm0_var);

  class_PSD_monitor_display(&_MARS_displayMono_var);

  class_E_monitor_display(&_MARS_displayMonoLength_var);

  class_Arm_display(&_MARS_M2_arm_translation_var);

  class_Arm_display(&_MARS_M2_arm_rotation_1_var);

  class_Mirror_curved_display(&_MARS_mirror_M2_var);

  class_Arm_display(&_MARS_M2_arm_rotation_2_var);

  class_Arm_display(&_MARS_M2_arm_rotation_2_undo_var);

  class_Slit_display(&_MARS_slitSecon1_var);

  class_Slit_display(&_MARS_slitSecon2_var);

  class_E_monitor_display(&_MARS_emon_dcm1_var);

  class_PSD_monitor_display(&_MARS_displaySlit2_var);

  class_FluoPowder_display(&_MARS_Sample_var);

  class_Monitor_nD_display(&_MARS_detector_diffraction_var);

  class_Monitor_nD_display(&_MARS_detector_fluo_var);

  class_Beamstop_display(&_beamdump_40_var);

  class_Text_display(&_PSICHE_pos_var);

  class_Arm_display(&_PSICHE_var);

  class_Wiggler_display(&_PSICHE_source_var);

  class_Monitor_nD_display(&_PSICHE_mon_src_e_var);

  class_Monitor_nD_display(&_PSICHE_mon_src_xy_var);

  class_Arm_display(&_PSICHE_DCM_location_var);

  class_Bragg_crystal_display(&_PSICHE_dcm_xtal0_var);

  class_Arm_display(&_PSICHE_dcm0_var);

  class_Bragg_crystal_display(&_PSICHE_dcm_xtal1_var);

  class_Arm_display(&_PSICHE_dcm1_var);

  class_Monitor_nD_display(&_PSICHE_mon_dcm_e_var);

  class_Monitor_nD_display(&_PSICHE_mon_dcm_xy_var);

  class_Slit_display(&_PSICHE_slit_var);

  class_Arm_display(&_PSICHE_sample_stage_var);

  class_FluoPowder_display(&_PSICHE_sample_var);

  class_Arm_display(&_PSICHE_fluo_holder_var);

  class_Monitor_nD_display(&_PSICHE_mon_spl_fluo_var);

  class_Monitor_nD_display(&_PSICHE_mon_spl_e_var);

  class_Monitor_nD_display(&_PSICHE_mon_spl_xy_var);

  class_Beamstop_display(&_beamdump_61_var);

  class_Text_display(&_PLEIADES_pos_var);

  class_Text_display(&_DISCO_pos_var);

  class_Arm_display(&_DISCO_var);

  class_Bending_magnet_display(&_DISCO_Source_var);

  class_Mask_display(&_DISCO_ColdFinger_var);

  class_Arm_display(&_DISCO_M1_location_var);

  class_Arm_display(&_DISCO_M1_rotated_var);

  class_Arm_display(&_DISCO_M1_x_var);

  class_Mirror_curved_display(&_DISCO_M1_var);

  class_Arm_display(&_DISCO_M1_takeoff_var);

  class_Arm_display(&_DISCO_M1_x_takeoff_var);

  class_Arm_display(&_DISCO_M2_location_var);

  class_Arm_display(&_DISCO_M2_rotated_x_var);

  class_Arm_display(&_DISCO_M2_rotated_var);

  class_Arm_display(&_DISCO_M2_other_side_var);

  class_Mirror_toroid_pothole_display(&_DISCO_M2_var);

  class_Arm_display(&_DISCO_M2_other_side_back_var);

  class_Arm_display(&_DISCO_M2_takeoff_var);

  class_Arm_display(&_DISCO_HFP_location_var);

  class_PSD_monitor_display(&_DISCO_HFP_var);

  class_Arm_display(&_DISCO_M3_arm_var);

  class_Mirror_curved_display(&_DISCO_M3_var);

  class_Arm_display(&_DISCO_M3_takeoff_var);

  class_Arm_display(&_DISCO_M3_yz_var);

  class_Arm_display(&_DISCO_M4_yz_var);

  class_Mirror_display(&_DISCO_M4_var);

  class_Arm_display(&_DISCO_M4_takeoff_var);

  class_Arm_display(&_DISCO_M4_arm_back_var);

  class_Arm_display(&_DISCO_VFP_location_var);

  class_PSD_monitor_display(&_DISCO_VFP_var);

  class_Arm_display(&_DISCO_M51_position_var);

  class_Arm_display(&_DISCO_M51_rotation_var);

  class_Mirror_elliptic_display(&_DISCO_M51_var);

  class_Arm_display(&_DISCO_arm_var);

  class_Arm_display(&_DISCO_M51_arm_back_var);

  class_Arm_display(&_DISCO_M52_position_var);

  class_Arm_display(&_DISCO_M52_x_var);

  class_Mirror_curved_display(&_DISCO_M52_var);

  class_Arm_display(&_DISCO_M52_takeoff_var);

  class_Arm_display(&_DISCO_M52_x_takeoff_var);

  class_Arm_display(&_DISCO_second_HFP_location_var);

  class_PSD_monitor_display(&_DISCO_second_HFP_var);

  class_Arm_display(&_DISCO_M53_location_var);

  class_Arm_display(&_DISCO_M53_rotated_var);

  class_Mirror_toroid_pothole_display(&_DISCO_M53_var);

  class_Arm_display(&_DISCO_M53_takeoff_var);

  class_Arm_display(&_DISCO_M54_location_var);

  class_Arm_display(&_DISCO_M54_rotated_var);

  class_Mirror_toroid_pothole_display(&_DISCO_M54_var);

  class_Arm_display(&_DISCO_M54_takeoff_var);

  class_Arm_display(&_DISCO_Mtoroids_arm_back_var);

  class_Arm_display(&_DISCO_M1_position_var);

  class_Arm_display(&_DISCO_M1_rotation_var);

  class_Mirror_elliptic_display(&_DISCO_mirror_m1_var);

  class_Arm_display(&_DISCO_armm_var);

  class_Arm_display(&_DISCO_M1_arm_back_var);

  class_Arm_display(&_DISCO_Grating_position_var);

  class_Arm_display(&_DISCO_Grating_rotation_var);

  class_Arm_display(&_DISCO_Grating_rotation_lines_grating_var);

  class_Arm_display(&_DISCO_Grating_rotation_nine_degrees_var);

  class_Grating_reflect_display(&_DISCO_reflective_grating_var);

  class_Arm_display(&_DISCO_Grating_rotation_lines_grating_back_var);

  class_Arm_display(&_DISCO_Grating_arm_back_var);

  class_Arm_display(&_DISCO_Grating_arm_back_2_var);

  class_Arm_display(&_DISCO_Grating_arm_back_3_var);

  class_Arm_display(&_DISCO_M22_location_var);

  class_Arm_display(&_DISCO_M22_rotated_var);

  class_Mirror_elliptic_display(&_DISCO_mirror_m2_var);

  class_Arm_display(&_DISCO_arm2_var);

  class_Arm_display(&_DISCO_M44_arm_back_var);

  class_Arm_display(&_DISCO_arm3_var);

  class_PSD_monitor_display(&_DISCO_psd_before_slit_var);

  class_Slit_display(&_DISCO_slit_var);

  class_PSD_monitor_display(&_DISCO_psd_monitor_var);

  class_PSD_monitor_display(&_DISCO_psd_giant_after_grating_var);

  class_Monitor_nD_display(&_DISCO_e_monitor_var);

  class_Monitor_nD_display(&_DISCO_w_monitor_var);

  class_Beamstop_display(&_beamdump_140_var);

  class_Text_display(&_DESIRS_pos_var);

  class_Text_display(&_METRO_pos_var);

  class_Text_display(&_PUMA_pos_var);

  class_Arm_display(&_PUMA_var);

  class_Wiggler_display(&_PUMA_Source_var);

  class_Slit_display(&_PUMA_slit1_var);

  class_Slit_display(&_PUMA_slit2_var);

  class_E_monitor_display(&_PUMA_mon_src_e_var);

  class_PSD_monitor_display(&_PUMA_mon_src_xy_var);

  class_Arm_display(&_PUMA_HFM_location_var);

  class_Arm_display(&_PUMA_HFM_rotated_var);

  class_Mirror_curved_display(&_PUMA_mirror_HFM_var);

  class_Arm_display(&_PUMA_HFM_out_var);

  class_PSD_monitor_display(&_PUMA_mon_HFM_out_xy_var);

  class_Arm_display(&_PUMA_DCM_location_var);

  class_Bragg_crystal_display(&_PUMA_DCM_xtal1_var);

  class_Arm_display(&_PUMA_DCM_xtal1_out_var);

  class_PSD_monitor_display(&_PUMA_mon_DCM_xtal1_only_xy_var);

  class_Bragg_crystal_display(&_PUMA_DCM_xtal2_var);

  class_Arm_display(&_PUMA_DCM_xtal2_out_var);

  class_E_monitor_display(&_PUMA_mon_DCM_out_e_var);

  class_PSD_monitor_display(&_PUMA_mon_DCM_out_xy_var);

  class_Slit_display(&_PUMA_slit3_var);

  class_Slit_display(&_PUMA_slit4_var);

  class_Slit_display(&_PUMA_slit5_var);

  class_Arm_display(&_PUMA_KB_VFM_location_var);

  class_PSD_monitor_display(&_PUMA_mon_KB_in_xy_var);

  class_Arm_display(&_PUMA_KB_VFM_rotated_var);

  class_Mirror_curved_display(&_PUMA_mirror_KB_VFM_var);

  class_Arm_display(&_PUMA_KB_VFM_out_var);

  class_PSD_monitor_display(&_PUMA_mon_KB_VFM_out_xy_var);

  class_Arm_display(&_PUMA_KB_HFM_location_var);

  class_Arm_display(&_PUMA_KB_HFM_rotated_var);

  class_Mirror_curved_display(&_PUMA_mirror_KB_HFM_var);

  class_Arm_display(&_PUMA_KB_HFM_out_var);

  class_PSD_monitor_display(&_PUMA_mon_KB_HFM_out_xy_var);

  class_Arm_display(&_PUMA_sample_location_var);

  class_PSD_monitor_display(&_PUMA_mon_sample_xy_var);

  class_E_monitor_display(&_PUMA_mon_sample_e_var);

  class_Beamstop_display(&_beamdump_181_var);

  class_Text_display(&_CRISTAL_pos_var);

  class_Arm_display(&_CRISTAL_var);

  class_Undulator_display(&_CRISTAL_Source_var);

  class_Slit_display(&_CRISTAL_slit1_var);

  class_Arm_display(&_CRISTAL_dcm_location_var);

  class_Bragg_crystal_display(&_CRISTAL_dcm_xtal0_var);

  class_Arm_display(&_CRISTAL_arm_xtal0_var);

  class_Bragg_crystal_display(&_CRISTAL_dcm_xtal1_var);

  class_Arm_display(&_CRISTAL_arm_xtal1_var);

  class_E_monitor_display(&_CRISTAL_emon_dcm_var);

  class_Arm_display(&_CRISTAL_M1_location_var);

  class_Arm_display(&_CRISTAL_M1_rotated_var);

  class_Mirror_curved_display(&_CRISTAL_M1_var);

  class_Arm_display(&_CRISTAL_M1_out_var);

  class_Arm_display(&_CRISTAL_M2_location_var);

  class_Arm_display(&_CRISTAL_M2_rotated_var);

  class_Mirror_curved_display(&_CRISTAL_M2_var);

  class_Arm_display(&_CRISTAL_M2_out_var);

  class_Slit_display(&_CRISTAL_slit2_var);

  class_PSD_monitor_display(&_CRISTAL_psd_slit2_var);

  class_Arm_display(&_CRISTAL_sample_stage_var);

  class_FluoPowder_display(&_CRISTAL_fluo_var);

  class_Monitor_nD_display(&_CRISTAL_detector_diffraction_var);

  class_Monitor_nD_display(&_CRISTAL_detector_fluo_var);

  class_Beamstop_display(&_beamdump_207_var);

  class_Text_display(&_DEIMOS_pos_var);

  class_Text_display(&_GALAXIES_pos_var);

  class_Arm_display(&_GALAXIES_var);

  class_Undulator_display(&_GALAXIES_Source_U20_var);

  class_Monitor_nD_display(&_GALAXIES_mon_src_xy_var);

  class_Monitor_nD_display(&_GALAXIES_mon_src_e_var);

  class_Slit_display(&_GALAXIES_absorber_var);

  class_Slit_display(&_GALAXIES_diaphragme_var);

  class_Slit_display(&_GALAXIES_fentes_primaires_var);

  class_Monitor_nD_display(&_GALAXIES_mon_prim_xy_var);

  class_Arm_display(&_GALAXIES_DCM_location_var);

  class_Bragg_crystal_display(&_GALAXIES_dcm_xtal0_var);

  class_Arm_display(&_GALAXIES_dcm0_var);

  class_Bragg_crystal_display(&_GALAXIES_dcm_xtal1_var);

  class_Arm_display(&_GALAXIES_dcm1_var);

  class_Monitor_nD_display(&_GALAXIES_mon_dcm_e_var);

  class_Monitor_nD_display(&_GALAXIES_mon_dcm_xy_var);

  class_Arm_display(&_GALAXIES_M1_location_var);

  class_Arm_display(&_GALAXIES_M1_rotated_var);

  class_Mirror_curved_display(&_GALAXIES_M1_var);

  class_Arm_display(&_GALAXIES_M1_out_var);

  class_Slit_display(&_GALAXIES_HRM_gate_in_var);

  class_Arm_display(&_GALAXIES_M2A_location_var);

  class_Arm_display(&_GALAXIES_M2A_rotated_var);

  class_Mirror_toroid_display(&_GALAXIES_M2A_var);

  class_Arm_display(&_GALAXIES_M2A_out_var);

  class_Slit_display(&_GALAXIES_secondary_slits_var);

  class_Monitor_nD_display(&_GALAXIES_mon_sec_xy_var);

  class_Arm_display(&_GALAXIES_M2B_location_var);

  class_Arm_display(&_GALAXIES_M2B_rotated_var);

  class_Mirror_toroid_display(&_GALAXIES_M2B_var);

  class_Arm_display(&_GALAXIES_M2B_out_var);

  class_Arm_display(&_GALAXIES_VFM_location_var);

  class_Arm_display(&_GALAXIES_VFM_rotated_var);

  class_Mirror_curved_display(&_GALAXIES_VFM_var);

  class_Arm_display(&_GALAXIES_VFM_out_var);

  class_Arm_display(&_GALAXIES_HFM_rotated_var);

  class_Mirror_curved_display(&_GALAXIES_HFM_var);

  class_Arm_display(&_GALAXIES_HFM_out_var);

  class_Monitor_nD_display(&_GALAXIES_mon_sample_xy_kb_var);

  class_Monitor_nD_display(&_GALAXIES_mon_sample_e_var);

  class_Arm_display(&_GALAXIES_sample_stage_var);

  class_FluoCrystal_display(&_GALAXIES_sample_var);

  class_Arm_display(&_GALAXIES_sample_out_var);

  class_Arm_display(&_GALAXIES_ana_arm_var);

  class_Bragg_crystal_display(&_GALAXIES_analyzer_var);

  class_Arm_display(&_GALAXIES_ana_out_var);

  class_Monitor_nD_display(&_GALAXIES_IXS_det_var);

  class_Beamstop_display(&_beamdump_257_var);

  class_Text_display(&_TEMPO_pos_var);

  class_Text_display(&_SAMBA_pos_var);

  class_Arm_display(&_SAMBA_var);

  class_Bending_magnet_display(&_SAMBA_BM_source_var);

  class_Arm_display(&_SAMBA_M1_location_var);

  class_Arm_display(&_SAMBA_M1_rotated_var);

  class_Mirror_curved_display(&_SAMBA_M1_var);

  class_Monitor_nD_display(&_SAMBA_M1_out_var);

  class_Arm_display(&_SAMBA_DCM_location_var);

  class_Bragg_crystal_display(&_SAMBA_bragg_crystal_var);

  class_Arm_display(&_SAMBA_arm_crystal1_var);

  class_Bragg_crystal_display(&_SAMBA_bragg_crystal_two_var);

  class_Arm_display(&_SAMBA_arm_crystal2_var);

  class_Monitor_nD_display(&_SAMBA_DCM_out_var);

  class_Monitor_nD_display(&_SAMBA_DCM_out_div_var);

  class_Monitor_nD_display(&_SAMBA_DCM_out_e_var);

  class_Arm_display(&_SAMBA_M2_loc_var);

  class_Arm_display(&_SAMBA_M2_rotated_var);

  class_Mirror_curved_display(&_SAMBA_M2_var);

  class_Monitor_nD_display(&_SAMBA_M2_out_var);

  class_Monitor_nD_display(&_SAMBA_sample_stage_var);

  class_FluoPowder_display(&_SAMBA_fluo_var);

  class_Monitor_nD_display(&_SAMBA_det_trans_var);

  class_Monitor_nD_display(&_SAMBA_det_fluo_var);

  class_Beamstop_display(&_beamdump_283_var);

  class_Text_display(&_HERMES_pos_var);

  class_Text_display(&_PX1_pos_var);

  class_Arm_display(&_PX1_var);

  class_Undulator_display(&_PX1_undulator_var);

  class_Arm_display(&_PX1_bragg_crystal_location_var);

  class_Bragg_crystal_display(&_PX1_bragg_crystal_var);

  class_Arm_display(&_PX1_arm_var);

  class_Bragg_crystal_display(&_PX1_bragg_crystal_two_var);

  class_Arm_display(&_PX1_arm_two_var);

  class_E_monitor_display(&_PX1_bragg_crystal_out_var);

  class_Slit_display(&_PX1_secondary_slits_var);

  class_Monitor_nD_display(&_PX1_vfm_location_var);

  class_Arm_display(&_PX1_vfm_in_xz_plane_var);

  class_Mirror_curved_display(&_PX1_vfm_var);

  class_Monitor_nD_display(&_PX1_vfm_takeoff_var);

  class_Monitor_nD_display(&_PX1_hfm_location_var);

  class_Mirror_curved_display(&_PX1_hfm_var);

  class_Monitor_nD_display(&_PX1_hfm_takeoff_var);

  class_Arm_display(&_PX1_sample_stage_var);

  class_Monitor_nD_display(&_PX1_sample_monitor_var);

  class_Single_crystal_display(&_PX1_sample_var);

  class_PSD_monitor_4PI_display(&_PX1_psd4pi_var);

  class_PSD_monitor_display(&_PX1_EigerX16M_var);

  class_Beamstop_display(&_beamdump_308_var);

  class_Text_display(&_PX2a_pos_var);

  class_Arm_display(&_PX2a_var);

  class_Undulator_display(&_PX2a_undulator_var);

  class_Arm_display(&_PX2a_bragg_crystal_location_var);

  class_Bragg_crystal_display(&_PX2a_bragg_crystal_var);

  class_Arm_display(&_PX2a_arm_var);

  class_Bragg_crystal_display(&_PX2a_bragg_crystal_two_var);

  class_Arm_display(&_PX2a_arm_two_var);

  class_E_monitor_display(&_PX2a_bragg_crystal_out_var);

  class_Arm_display(&_PX2a_hpm_location_var);

  class_Arm_display(&_PX2a_hpm_in_yz_plane_var);

  class_Mirror_toroid_display(&_PX2a_hpm_var);

  class_Arm_display(&_PX2a_hpm_takeoff_var);

  class_Monitor_nD_display(&_PX2a_vfm_location_var);

  class_Arm_display(&_PX2a_vfm_in_xz_plane_var);

  class_Mirror_curved_display(&_PX2a_vfm_var);

  class_Monitor_nD_display(&_PX2a_vfm_takeoff_var);

  class_Monitor_nD_display(&_PX2a_hfm_location_var);

  class_Mirror_curved_display(&_PX2a_hfm_var);

  class_Monitor_nD_display(&_PX2a_hfm_takeoff_var);

  class_Arm_display(&_PX2a_sample_stage_var);

  class_Monitor_nD_display(&_PX2a_sample_monitor_var);

  class_Single_crystal_display(&_PX2a_sample_var);

  class_PSD_monitor_4PI_display(&_PX2a_psd4pi_var);

  class_PSD_monitor_display(&_PX2a_Eiger9M_var);

  class_Beamstop_display(&_beamdump_335_var);

  class_Text_display(&_SWING_pos_var);

  class_Arm_display(&_SWING_var);

  class_Undulator_display(&_SWING_Source_U20_var);

  class_Monitor_nD_display(&_SWING_mon_src_xy_var);

  class_Monitor_nD_display(&_SWING_mon_src_e_var);

  class_Slit_display(&_SWING_slit_var);

  class_Monitor_nD_display(&_SWING_slit_mon_xy_var);

  class_Arm_display(&_SWING_DCM_location_var);

  class_Bragg_crystal_display(&_SWING_dcm_xtal0_var);

  class_Arm_display(&_SWING_dcm0_var);

  class_Bragg_crystal_display(&_SWING_dcm_xtal1_var);

  class_Arm_display(&_SWING_dcm1_var);

  class_Monitor_nD_display(&_SWING_mon_dcm_e_var);

  class_Monitor_nD_display(&_SWING_mon_dcm_xy_var);

  class_Monitor_nD_display(&_SWING_vfm_location_var);

  class_Arm_display(&_SWING_vfm_in_xz_plane_var);

  class_Mirror_curved_display(&_SWING_vfm_var);

  class_Monitor_nD_display(&_SWING_vfm_takeoff_var);

  class_Monitor_nD_display(&_SWING_hfm_location_var);

  class_Mirror_curved_display(&_SWING_hfm_var);

  class_Monitor_nD_display(&_SWING_hfm_takeoff_var);

  class_Monitor_nD_display(&_SWING_sample_stage_var);

  class_Saxs_spheres_display(&_SWING_sample_test_var);

  class_SAXSPDBFast_display(&_SWING_sample_var);

  class_Arm_display(&_SWING_sample_out_var);

  class_Monitor_nD_display(&_SWING_Eiger4M_var);

  class_SAXSQMonitor_display(&_SWING_QMonitor_var);

  class_Beamstop_display(&_beamdump_364_var);

  class_Text_display(&_ANTARES_pos_var);

  class_Text_display(&_ROCK_pos_var);

  class_Arm_display(&_ROCK_var);

  class_Bending_magnet_display(&_ROCK_Source_var);

  class_Slit_display(&_ROCK_slit1_var);

  class_Slit_display(&_ROCK_slit2_var);

  class_Mirror_toroid_pothole_display(&_ROCK_mirror_m1_var);

  class_Arm_display(&_ROCK_mirror_m1_out_var);

  class_PSD_monitor_display(&_ROCK_slit3_xy_var);

  class_Divergence_monitor_display(&_ROCK_slit3_div_var);

  class_Slit_display(&_ROCK_slit3_var);

  class_Mirror_display(&_ROCK_mirror_m2a_var);

  class_Arm_display(&_ROCK_mirror_m2a_out_var);

  class_PSD_monitor_display(&_ROCK_slit4_in_var);

  class_Slit_display(&_ROCK_slit4_var);

  class_Arm_display(&_ROCK_arm_crystal0_var);

  class_Bragg_crystal_display(&_ROCK_bragg_crystal_var);

  class_Arm_display(&_ROCK_arm_crystal1_var);

  class_Bragg_crystal_display(&_ROCK_bragg_crystal_two_var);

  class_Arm_display(&_ROCK_arm_crystal2_var);

  class_PSD_monitor_display(&_ROCK_bragg_crystal_out_var);

  class_Slit_display(&_ROCK_slit5_var);

  class_Slit_display(&_ROCK_slit6_var);

  class_Mirror_curved_display(&_ROCK_mirror_m2b_var);

  class_Arm_display(&_ROCK_mirror_m2b_out_var);

  class_Monitor_nD_display(&_ROCK_EnergyMonitor_before_sample_var);

  class_Monitor_nD_display(&_ROCK_e_repartition_after_m2b_var);

  class_PSD_monitor_display(&_ROCK_sample_in_var);

  class_Fluorescence_display(&_ROCK_absorption_sample_var);

  class_Monitor_nD_display(&_ROCK_fluo_monitor_var);

  class_Monitor_nD_display(&_ROCK_EnergyMonitor_after_sample_var);

  class_PSD_monitor_display(&_ROCK_psd_monitor_var);

  class_Beamstop_display(&_beamdump_398_var);

  class_Text_display(&_ANATOMIX_pos_var);

  class_Arm_display(&_ANATOMIX_var);

  class_Undulator_display(&_ANATOMIX_source_var);

  class_Monitor_nD_display(&_ANATOMIX_e_repartition_before_cc_var);

  class_PSD_monitor_display(&_ANATOMIX_psd_monitor_before_cc_var);

  class_Bragg_crystal_display(&_ANATOMIX_bragg_crystal_var);

  class_Arm_display(&_ANATOMIX_arm_var);

  class_Bragg_crystal_display(&_ANATOMIX_bragg_crystal_two_var);

  class_Arm_display(&_ANATOMIX_arm_two_var);

  class_PSD_monitor_display(&_ANATOMIX_psd_after_cc_var);

  class_E_monitor_display(&_ANATOMIX_e_monitor_before_sample_var);

  class_PSD_monitor_display(&_ANATOMIX_psd_repartition_after_cc_var);

  class_Arm_display(&_ANATOMIX_sample_rotation_stage_var);

  class_Filter_display(&_ANATOMIX_sample_var);

  class_E_monitor_display(&_ANATOMIX_e_monitor_after_sample_var);

  class_PSD_monitor_display(&_ANATOMIX_psd_monitor_after_cc_var);

  class_Beamstop_display(&_beamdump_416_var);

  class_Text_display(&_NANOSCOPIUM_pos_var);

  class_Arm_display(&_NANOSCOPIUM_var);

  class_Undulator_display(&_NANO_source_var);

  class_E_monitor_display(&_NANO_e_monitor_source_var);

  class_PSD_monitor_coh_display(&_NANO_psd_source_var);

  class_Slit_display(&_NANO_slit_1_var);

  class_Arm_display(&_NANO_m1_in_var);

  class_Arm_display(&_NANO_m1_roll_var);

  class_Mirror_curved_display(&_NANO_mirror_m1_var);

  class_Arm_display(&_NANO_beam_deviation_var);

  class_Arm_display(&_NANO_m2_in_var);

  class_Mirror_curved_display(&_NANO_mirror_m2_var);

  class_Arm_display(&_NANO_mirror_m2_out_var);

  class_Slit_display(&_NANO_slit_2_var);

  class_Arm_display(&_NANO_dcm_in_var);

  class_PSD_monitor_display(&_NANO_PSD_dcm_in_var);

  class_Arm_display(&_NANO_bragg_roll_var);

  class_Bragg_crystal_display(&_NANO_bragg_crystal_1_var);

  class_Arm_display(&_NANO_dcm2_rot_var);

  class_Arm_display(&_NANO_dcm_transl_var);

  class_Bragg_crystal_display(&_NANO_bragg_crystal_2_var);

  class_Arm_display(&_NANO_bragg2_out_var);

  class_Arm_display(&_NANO_dcm_out_var);

  class_E_monitor_display(&_NANO_e_dcm_out_var);

  class_Arm_display(&_NANO_secondary_source_slits_var);

  class_PSD_monitor_display(&_NANO_psd_ss_in_var);

  class_Slit_display(&_NANO_slit_3_var);

  class_PSD_monitor_display(&_NANO_psd_ss_out_var);

  class_Arm_display(&_NANO_jjxray2_slits_var);

  class_Slit_display(&_NANO_slit_5_var);

  class_Arm_display(&_NANO_kb_in_var);

  class_Mirror_curved_display(&_NANO_kb_1_var);

  class_Arm_display(&_NANO_kb_beam_deviation_var);

  class_Arm_display(&_NANO_kb1_out_var);

  class_Mirror_curved_display(&_NANO_kb2_var);

  class_Arm_display(&_NANO_kb_out_var);

  class_Slit_display(&_NANO_slit_var);

  class_PSD_monitor_display(&_NANO_psd_sample_stage_var);

  class_Beamstop_display(&_beamdump_456_var);

  class_Text_display(&_DIFFABS_pos_var);

  class_Arm_display(&_DIFFABS_var);

  class_Bending_magnet_display(&_DIFFABS_BM_D13_1_var);

  class_Slit_display(&_DIFFABS_primary_slit_var);

  class_Arm_display(&_DIFFABS_M1_location_var);

  class_Arm_display(&_DIFFABS_M1_rotated_var);

  class_Mirror_curved_display(&_DIFFABS_M1_var);

  class_Arm_display(&_DIFFABS_M1_out_var);

  class_Slit_display(&_DIFFABS_DCM_slit_in_var);

  class_Monitor_nD_display(&_DIFFABS_DCM_in_var);

  class_Monitor_nD_display(&_DIFFABS_DCM_in_div_var);

  class_Arm_display(&_DIFFABS_DCM_location_var);

  class_Bragg_crystal_display(&_DIFFABS_bragg_crystal_var);

  class_Arm_display(&_DIFFABS_arm_crystal1_var);

  class_Bragg_crystal_display(&_DIFFABS_bragg_crystal_two_var);

  class_Arm_display(&_DIFFABS_arm_crystal2_var);

  class_Monitor_nD_display(&_DIFFABS_DCM_out_var);

  class_Monitor_nD_display(&_DIFFABS_DCM_out_div_var);

  class_Monitor_nD_display(&_DIFFABS_DCM_out_e_var);

  class_Slit_display(&_DIFFABS_DCM_slit_out_var);

  class_Arm_display(&_DIFFABS_M2_location_var);

  class_Arm_display(&_DIFFABS_M2_rotated_var);

  class_Mirror_curved_display(&_DIFFABS_M2_var);

  class_Arm_display(&_DIFFABS_M2_out_var);

  class_Monitor_nD_display(&_DIFFABS_sample_stage_var);

  class_FluoPowder_display(&_DIFFABS_fluo_var);

  class_Monitor_nD_display(&_DIFFABS_fluo_monitor_var);

  class_Monitor_nD_display(&_DIFFABS_det_angle_var);

  class_Monitor_nD_display(&_DIFFABS_xpad_var);

  class_Beamstop_display(&_beamdump_487_var);

  class_Text_display(&_SEXTANTS_var);

  class_Text_display(&_SIXS_pos_var);

  class_Arm_display(&_SIXS_var);

  class_Undulator_display(&_SIXS_Source_U20_var);

  class_Monitor_nD_display(&_SIXS_mon_src_xy_var);

  class_Monitor_nD_display(&_SIXS_mon_src_e_var);

  class_Slit_display(&_SIXS_slit_var);

  class_Monitor_nD_display(&_SIXS_slit_mon_xy_var);

  class_Arm_display(&_SIXS_DCM_location_var);

  class_Bragg_crystal_display(&_SIXS_dcm_xtal0_var);

  class_Arm_display(&_SIXS_dcm0_var);

  class_Bragg_crystal_display(&_SIXS_dcm_xtal1_var);

  class_Arm_display(&_SIXS_dcm1_var);

  class_Monitor_nD_display(&_SIXS_mon_dcm_e_var);

  class_Monitor_nD_display(&_SIXS_mon_dcm_xy_var);

  class_Arm_display(&_SIXS_M1_location_var);

  class_Arm_display(&_SIXS_M1_rotated_var);

  class_Mirror_curved_display(&_SIXS_M1_var);

  class_Arm_display(&_SIXS_M1_out_var);

  class_Arm_display(&_SIXS_M2_location_var);

  class_Arm_display(&_SIXS_M2_rotated_var);

  class_Mirror_curved_display(&_SIXS_M2_var);

  class_Arm_display(&_SIXS_M2_out_var);

  class_Monitor_nD_display(&_SIXS_sample_stage_var);

  class_Single_crystal_display(&_SIXS_sx_layer_var);

  class_Single_crystal_display(&_SIXS_sx_bulk_var);

  class_Arm_display(&_SIXS_sample_out_var);

  class_Monitor_nD_display(&_SIXS_det4pi_var);

  class_Monitor_nD_display(&_SIXS_detector_layer_var);

  class_Monitor_nD_display(&_SIXS_detector_bulk_var);

  class_Beamstop_display(&_beamdump_519_var);

  class_Text_display(&_CASSIOPEE_pos_var);

  class_Arm_display(&_CASSIOPEE_var);

  class_Undulator_display(&_CASSIOPEE_Source_HU60_var);

  class_Undulator_display(&_CASSIOPEE_Source_HU256_var);

  class_Arm_display(&_CASSIOPEE_M1a_location_var);

  class_Mirror_curved_display(&_CASSIOPEE_M1a_var);

  class_Arm_display(&_CASSIOPEE_M1a_out_var);

  class_Mirror_curved_display(&_CASSIOPEE_M1b_var);

  class_Mirror_curved_display(&_CASSIOPEE_M1c_var);

  class_Arm_display(&_CASSIOPEE_M1bc_out_var);

  class_Monitor_nD_display(&_CASSIOPEE_PSD_M1out_var);

  class_Arm_display(&_CASSIOPEE_PG_location_var);

  class_Grating_reflect_display(&_CASSIOPEE_PG_var);

  class_Monitor_nD_display(&_CASSIOPEE_M2_rotation_axis_var);

  class_Mirror_display(&_CASSIOPEE_M2_var);

  class_Arm_display(&_CASSIOPEE_PM_takeoff_var);

  class_Slit_display(&_CASSIOPEE_slit_var);

  class_Mirror_curved_display(&_CASSIOPEE_M4_var);

  class_Monitor_nD_display(&_CASSIOPEE_PSD_var);

  class_Beamstop_display(&_beamdump_540_var);

  class_Text_display(&_SIRIUS_pos_var);

  class_Arm_display(&_SIRIUS_var);

  class_Bending_magnet_display(&_SIRIUS_source_var);

  class_Monitor_nD_display(&_SIRIUS_M1_loc_var);

  class_Arm_display(&_SIRIUS_M1_rot_var);

  class_Mirror_curved_display(&_SIRIUS_M1_var);

  class_Arm_display(&_SIRIUS_M1_out_var);

  class_Monitor_nD_display(&_SIRIUS_DCM_location_var);

  class_Bragg_crystal_display(&_SIRIUS_bragg_crystal_var);

  class_Arm_display(&_SIRIUS_arm_crystal1_var);

  class_Bragg_crystal_display(&_SIRIUS_bragg_crystal_two_var);

  class_Arm_display(&_SIRIUS_arm_crystal2_var);

  class_Monitor_nD_display(&_SIRIUS_DCM_out_var);

  class_Monitor_nD_display(&_SIRIUS_DCM_out_div_var);

  class_Monitor_nD_display(&_SIRIUS_DCM_out_e_var);

  class_Monitor_nD_display(&_SIRIUS_def_loc_var);

  class_Arm_display(&_SIRIUS_def_rot_var);

  class_Mirror_display(&_SIRIUS_def_mirror_var);

  class_Arm_display(&_SIRIUS_def_out_var);

  class_Monitor_nD_display(&_SIRIUS_sample_stage_var);

  class_FluoPowder_display(&_SIRIUS_fluo_var);

  class_Monitor_nD_display(&_SIRIUS_det_2d_var);

  class_Monitor_nD_display(&_SIRIUS_det_fluo_var);

  class_Beamstop_display(&_beamdump_565_var);

  class_Text_display(&_LUCIA_pos_var);

  class_Arm_display(&_LUCIA_var);

  class_Undulator_display(&_LUCIA_source_var);

  class_Monitor_nD_display(&_LUCIA_mon_src_xy_var);

  class_Monitor_nD_display(&_LUCIA_mon_src_e_var);

  class_Slit_display(&_LUCIA_slit_var);

  class_Monitor_nD_display(&_LUCIA_slit_mon_xy_var);

  class_Arm_display(&_LUCIA_DCM_location_var);

  class_Bragg_crystal_display(&_LUCIA_dcm_xtal0_var);

  class_Arm_display(&_LUCIA_dcm0_var);

  class_Bragg_crystal_display(&_LUCIA_dcm_xtal1_var);

  class_Arm_display(&_LUCIA_dcm1_var);

  class_Monitor_nD_display(&_LUCIA_mon_dcm_e_var);

  class_Monitor_nD_display(&_LUCIA_mon_dcm_xy_var);

  class_Slit_display(&_LUCIA_diaphragm_var);

  class_Monitor_nD_display(&_LUCIA_sample_stage_var);

  class_Arm_display(&_LUCIA_fluo_rotated_var);

  class_Fluorescence_display(&_LUCIA_sample_var);

  class_Monitor_nD_display(&_LUCIA_transmission_var);

  class_Fluo_detector_display(&_LUCIA_mon_spl_SDD_var);

  class_Monitor_nD_display(&_LUCIA_mon_spl_fluo_var);

  class_Beamstop_display(&_beamdump_588_var);

  class_Shape_display(&_storage_var);

  class_Shape_display(&_hall0_var);

  class_Shape_display(&_hall1_var);

  class_Arm_display(&_entrance_0_var);

  class_Shape_display(&_entrance_1_var);

  class_Shape_display(&_ANATOMIX_building_var);

  class_Text_display(&_soleil_label_var);

  printf("MCDISPLAY: end\n");

  return(0);
} /* display */

void* _getvar_parameters(char* compname)
/* enables settings parameters based use of the GETPAR macro */
{
  #ifdef OPENACC
    #define strcmp(a,b) str_comp(a,b)
  #endif
  if (!strcmp(compname, "origin")) return (void *) &(_origin_var._parameters);
  if (!strcmp(compname, "jumper")) return (void *) &(_jumper_var._parameters);
  if (!strcmp(compname, "beamdump")) return (void *) &(_beamdump_var._parameters);
  if (!strcmp(compname, "ODE_pos")) return (void *) &(_ODE_pos_var._parameters);
  if (!strcmp(compname, "SMIS_pos")) return (void *) &(_SMIS_pos_var._parameters);
  if (!strcmp(compname, "AILES_pos")) return (void *) &(_AILES_pos_var._parameters);
  if (!strcmp(compname, "MARS_pos")) return (void *) &(_MARS_pos_var._parameters);
  if (!strcmp(compname, "MARS")) return (void *) &(_MARS_var._parameters);
  if (!strcmp(compname, "MARS_Source")) return (void *) &(_MARS_Source_var._parameters);
  if (!strcmp(compname, "MARS_displaySourceLength")) return (void *) &(_MARS_displaySourceLength_var._parameters);
  if (!strcmp(compname, "MARS_displaySource")) return (void *) &(_MARS_displaySource_var._parameters);
  if (!strcmp(compname, "MARS_slit1")) return (void *) &(_MARS_slit1_var._parameters);
  if (!strcmp(compname, "MARS_slit2")) return (void *) &(_MARS_slit2_var._parameters);
  if (!strcmp(compname, "MARS_M1_arm_translation")) return (void *) &(_MARS_M1_arm_translation_var._parameters);
  if (!strcmp(compname, "MARS_M1_arm_rotation_1")) return (void *) &(_MARS_M1_arm_rotation_1_var._parameters);
  if (!strcmp(compname, "MARS_mirror_M1")) return (void *) &(_MARS_mirror_M1_var._parameters);
  if (!strcmp(compname, "MARS_M1_arm_rotation_2")) return (void *) &(_MARS_M1_arm_rotation_2_var._parameters);
  if (!strcmp(compname, "MARS_M1_arm_rotation_2_undo")) return (void *) &(_MARS_M1_arm_rotation_2_undo_var._parameters);
  if (!strcmp(compname, "MARS_beam_arm_before_crystal")) return (void *) &(_MARS_beam_arm_before_crystal_var._parameters);
  if (!strcmp(compname, "MARS_dcm_xtal0")) return (void *) &(_MARS_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "MARS_dcm0")) return (void *) &(_MARS_dcm0_var._parameters);
  if (!strcmp(compname, "MARS_dcm_xtal1")) return (void *) &(_MARS_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "MARS_dcm1")) return (void *) &(_MARS_dcm1_var._parameters);
  if (!strcmp(compname, "MARS_emon_dcm0")) return (void *) &(_MARS_emon_dcm0_var._parameters);
  if (!strcmp(compname, "MARS_displayMono")) return (void *) &(_MARS_displayMono_var._parameters);
  if (!strcmp(compname, "MARS_displayMonoLength")) return (void *) &(_MARS_displayMonoLength_var._parameters);
  if (!strcmp(compname, "MARS_M2_arm_translation")) return (void *) &(_MARS_M2_arm_translation_var._parameters);
  if (!strcmp(compname, "MARS_M2_arm_rotation_1")) return (void *) &(_MARS_M2_arm_rotation_1_var._parameters);
  if (!strcmp(compname, "MARS_mirror_M2")) return (void *) &(_MARS_mirror_M2_var._parameters);
  if (!strcmp(compname, "MARS_M2_arm_rotation_2")) return (void *) &(_MARS_M2_arm_rotation_2_var._parameters);
  if (!strcmp(compname, "MARS_M2_arm_rotation_2_undo")) return (void *) &(_MARS_M2_arm_rotation_2_undo_var._parameters);
  if (!strcmp(compname, "MARS_slitSecon1")) return (void *) &(_MARS_slitSecon1_var._parameters);
  if (!strcmp(compname, "MARS_slitSecon2")) return (void *) &(_MARS_slitSecon2_var._parameters);
  if (!strcmp(compname, "MARS_emon_dcm1")) return (void *) &(_MARS_emon_dcm1_var._parameters);
  if (!strcmp(compname, "MARS_displaySlit2")) return (void *) &(_MARS_displaySlit2_var._parameters);
  if (!strcmp(compname, "MARS_Sample")) return (void *) &(_MARS_Sample_var._parameters);
  if (!strcmp(compname, "MARS_detector_diffraction")) return (void *) &(_MARS_detector_diffraction_var._parameters);
  if (!strcmp(compname, "MARS_detector_fluo")) return (void *) &(_MARS_detector_fluo_var._parameters);
  if (!strcmp(compname, "beamdump_40")) return (void *) &(_beamdump_40_var._parameters);
  if (!strcmp(compname, "PSICHE_pos")) return (void *) &(_PSICHE_pos_var._parameters);
  if (!strcmp(compname, "PSICHE")) return (void *) &(_PSICHE_var._parameters);
  if (!strcmp(compname, "PSICHE_source")) return (void *) &(_PSICHE_source_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_src_e")) return (void *) &(_PSICHE_mon_src_e_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_src_xy")) return (void *) &(_PSICHE_mon_src_xy_var._parameters);
  if (!strcmp(compname, "PSICHE_DCM_location")) return (void *) &(_PSICHE_DCM_location_var._parameters);
  if (!strcmp(compname, "PSICHE_dcm_xtal0")) return (void *) &(_PSICHE_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "PSICHE_dcm0")) return (void *) &(_PSICHE_dcm0_var._parameters);
  if (!strcmp(compname, "PSICHE_dcm_xtal1")) return (void *) &(_PSICHE_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "PSICHE_dcm1")) return (void *) &(_PSICHE_dcm1_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_dcm_e")) return (void *) &(_PSICHE_mon_dcm_e_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_dcm_xy")) return (void *) &(_PSICHE_mon_dcm_xy_var._parameters);
  if (!strcmp(compname, "PSICHE_slit")) return (void *) &(_PSICHE_slit_var._parameters);
  if (!strcmp(compname, "PSICHE_sample_stage")) return (void *) &(_PSICHE_sample_stage_var._parameters);
  if (!strcmp(compname, "PSICHE_sample")) return (void *) &(_PSICHE_sample_var._parameters);
  if (!strcmp(compname, "PSICHE_fluo_holder")) return (void *) &(_PSICHE_fluo_holder_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_spl_fluo")) return (void *) &(_PSICHE_mon_spl_fluo_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_spl_e")) return (void *) &(_PSICHE_mon_spl_e_var._parameters);
  if (!strcmp(compname, "PSICHE_mon_spl_xy")) return (void *) &(_PSICHE_mon_spl_xy_var._parameters);
  if (!strcmp(compname, "beamdump_61")) return (void *) &(_beamdump_61_var._parameters);
  if (!strcmp(compname, "PLEIADES_pos")) return (void *) &(_PLEIADES_pos_var._parameters);
  if (!strcmp(compname, "DISCO_pos")) return (void *) &(_DISCO_pos_var._parameters);
  if (!strcmp(compname, "DISCO")) return (void *) &(_DISCO_var._parameters);
  if (!strcmp(compname, "DISCO_Source")) return (void *) &(_DISCO_Source_var._parameters);
  if (!strcmp(compname, "DISCO_ColdFinger")) return (void *) &(_DISCO_ColdFinger_var._parameters);
  if (!strcmp(compname, "DISCO_M1_location")) return (void *) &(_DISCO_M1_location_var._parameters);
  if (!strcmp(compname, "DISCO_M1_rotated")) return (void *) &(_DISCO_M1_rotated_var._parameters);
  if (!strcmp(compname, "DISCO_M1_x")) return (void *) &(_DISCO_M1_x_var._parameters);
  if (!strcmp(compname, "DISCO_M1")) return (void *) &(_DISCO_M1_var._parameters);
  if (!strcmp(compname, "DISCO_M1_takeoff")) return (void *) &(_DISCO_M1_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_M1_x_takeoff")) return (void *) &(_DISCO_M1_x_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_M2_location")) return (void *) &(_DISCO_M2_location_var._parameters);
  if (!strcmp(compname, "DISCO_M2_rotated_x")) return (void *) &(_DISCO_M2_rotated_x_var._parameters);
  if (!strcmp(compname, "DISCO_M2_rotated")) return (void *) &(_DISCO_M2_rotated_var._parameters);
  if (!strcmp(compname, "DISCO_M2_other_side")) return (void *) &(_DISCO_M2_other_side_var._parameters);
  if (!strcmp(compname, "DISCO_M2")) return (void *) &(_DISCO_M2_var._parameters);
  if (!strcmp(compname, "DISCO_M2_other_side_back")) return (void *) &(_DISCO_M2_other_side_back_var._parameters);
  if (!strcmp(compname, "DISCO_M2_takeoff")) return (void *) &(_DISCO_M2_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_HFP_location")) return (void *) &(_DISCO_HFP_location_var._parameters);
  if (!strcmp(compname, "DISCO_HFP")) return (void *) &(_DISCO_HFP_var._parameters);
  if (!strcmp(compname, "DISCO_M3_arm")) return (void *) &(_DISCO_M3_arm_var._parameters);
  if (!strcmp(compname, "DISCO_M3")) return (void *) &(_DISCO_M3_var._parameters);
  if (!strcmp(compname, "DISCO_M3_takeoff")) return (void *) &(_DISCO_M3_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_M3_yz")) return (void *) &(_DISCO_M3_yz_var._parameters);
  if (!strcmp(compname, "DISCO_M4_yz")) return (void *) &(_DISCO_M4_yz_var._parameters);
  if (!strcmp(compname, "DISCO_M4")) return (void *) &(_DISCO_M4_var._parameters);
  if (!strcmp(compname, "DISCO_M4_takeoff")) return (void *) &(_DISCO_M4_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_M4_arm_back")) return (void *) &(_DISCO_M4_arm_back_var._parameters);
  if (!strcmp(compname, "DISCO_VFP_location")) return (void *) &(_DISCO_VFP_location_var._parameters);
  if (!strcmp(compname, "DISCO_VFP")) return (void *) &(_DISCO_VFP_var._parameters);
  if (!strcmp(compname, "DISCO_M51_position")) return (void *) &(_DISCO_M51_position_var._parameters);
  if (!strcmp(compname, "DISCO_M51_rotation")) return (void *) &(_DISCO_M51_rotation_var._parameters);
  if (!strcmp(compname, "DISCO_M51")) return (void *) &(_DISCO_M51_var._parameters);
  if (!strcmp(compname, "DISCO_arm")) return (void *) &(_DISCO_arm_var._parameters);
  if (!strcmp(compname, "DISCO_M51_arm_back")) return (void *) &(_DISCO_M51_arm_back_var._parameters);
  if (!strcmp(compname, "DISCO_M52_position")) return (void *) &(_DISCO_M52_position_var._parameters);
  if (!strcmp(compname, "DISCO_M52_x")) return (void *) &(_DISCO_M52_x_var._parameters);
  if (!strcmp(compname, "DISCO_M52")) return (void *) &(_DISCO_M52_var._parameters);
  if (!strcmp(compname, "DISCO_M52_takeoff")) return (void *) &(_DISCO_M52_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_M52_x_takeoff")) return (void *) &(_DISCO_M52_x_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_second_HFP_location")) return (void *) &(_DISCO_second_HFP_location_var._parameters);
  if (!strcmp(compname, "DISCO_second_HFP")) return (void *) &(_DISCO_second_HFP_var._parameters);
  if (!strcmp(compname, "DISCO_M53_location")) return (void *) &(_DISCO_M53_location_var._parameters);
  if (!strcmp(compname, "DISCO_M53_rotated")) return (void *) &(_DISCO_M53_rotated_var._parameters);
  if (!strcmp(compname, "DISCO_M53")) return (void *) &(_DISCO_M53_var._parameters);
  if (!strcmp(compname, "DISCO_M53_takeoff")) return (void *) &(_DISCO_M53_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_M54_location")) return (void *) &(_DISCO_M54_location_var._parameters);
  if (!strcmp(compname, "DISCO_M54_rotated")) return (void *) &(_DISCO_M54_rotated_var._parameters);
  if (!strcmp(compname, "DISCO_M54")) return (void *) &(_DISCO_M54_var._parameters);
  if (!strcmp(compname, "DISCO_M54_takeoff")) return (void *) &(_DISCO_M54_takeoff_var._parameters);
  if (!strcmp(compname, "DISCO_Mtoroids_arm_back")) return (void *) &(_DISCO_Mtoroids_arm_back_var._parameters);
  if (!strcmp(compname, "DISCO_M1_position")) return (void *) &(_DISCO_M1_position_var._parameters);
  if (!strcmp(compname, "DISCO_M1_rotation")) return (void *) &(_DISCO_M1_rotation_var._parameters);
  if (!strcmp(compname, "DISCO_mirror_m1")) return (void *) &(_DISCO_mirror_m1_var._parameters);
  if (!strcmp(compname, "DISCO_armm")) return (void *) &(_DISCO_armm_var._parameters);
  if (!strcmp(compname, "DISCO_M1_arm_back")) return (void *) &(_DISCO_M1_arm_back_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_position")) return (void *) &(_DISCO_Grating_position_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_rotation")) return (void *) &(_DISCO_Grating_rotation_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_rotation_lines_grating")) return (void *) &(_DISCO_Grating_rotation_lines_grating_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_rotation_nine_degrees")) return (void *) &(_DISCO_Grating_rotation_nine_degrees_var._parameters);
  if (!strcmp(compname, "DISCO_reflective_grating")) return (void *) &(_DISCO_reflective_grating_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_rotation_lines_grating_back")) return (void *) &(_DISCO_Grating_rotation_lines_grating_back_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_arm_back")) return (void *) &(_DISCO_Grating_arm_back_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_arm_back_2")) return (void *) &(_DISCO_Grating_arm_back_2_var._parameters);
  if (!strcmp(compname, "DISCO_Grating_arm_back_3")) return (void *) &(_DISCO_Grating_arm_back_3_var._parameters);
  if (!strcmp(compname, "DISCO_M22_location")) return (void *) &(_DISCO_M22_location_var._parameters);
  if (!strcmp(compname, "DISCO_M22_rotated")) return (void *) &(_DISCO_M22_rotated_var._parameters);
  if (!strcmp(compname, "DISCO_mirror_m2")) return (void *) &(_DISCO_mirror_m2_var._parameters);
  if (!strcmp(compname, "DISCO_arm2")) return (void *) &(_DISCO_arm2_var._parameters);
  if (!strcmp(compname, "DISCO_M44_arm_back")) return (void *) &(_DISCO_M44_arm_back_var._parameters);
  if (!strcmp(compname, "DISCO_arm3")) return (void *) &(_DISCO_arm3_var._parameters);
  if (!strcmp(compname, "DISCO_psd_before_slit")) return (void *) &(_DISCO_psd_before_slit_var._parameters);
  if (!strcmp(compname, "DISCO_slit")) return (void *) &(_DISCO_slit_var._parameters);
  if (!strcmp(compname, "DISCO_psd_monitor")) return (void *) &(_DISCO_psd_monitor_var._parameters);
  if (!strcmp(compname, "DISCO_psd_giant_after_grating")) return (void *) &(_DISCO_psd_giant_after_grating_var._parameters);
  if (!strcmp(compname, "DISCO_e_monitor")) return (void *) &(_DISCO_e_monitor_var._parameters);
  if (!strcmp(compname, "DISCO_w_monitor")) return (void *) &(_DISCO_w_monitor_var._parameters);
  if (!strcmp(compname, "beamdump_140")) return (void *) &(_beamdump_140_var._parameters);
  if (!strcmp(compname, "DESIRS_pos")) return (void *) &(_DESIRS_pos_var._parameters);
  if (!strcmp(compname, "METRO_pos")) return (void *) &(_METRO_pos_var._parameters);
  if (!strcmp(compname, "PUMA_pos")) return (void *) &(_PUMA_pos_var._parameters);
  if (!strcmp(compname, "PUMA")) return (void *) &(_PUMA_var._parameters);
  if (!strcmp(compname, "PUMA_Source")) return (void *) &(_PUMA_Source_var._parameters);
  if (!strcmp(compname, "PUMA_slit1")) return (void *) &(_PUMA_slit1_var._parameters);
  if (!strcmp(compname, "PUMA_slit2")) return (void *) &(_PUMA_slit2_var._parameters);
  if (!strcmp(compname, "PUMA_mon_src_e")) return (void *) &(_PUMA_mon_src_e_var._parameters);
  if (!strcmp(compname, "PUMA_mon_src_xy")) return (void *) &(_PUMA_mon_src_xy_var._parameters);
  if (!strcmp(compname, "PUMA_HFM_location")) return (void *) &(_PUMA_HFM_location_var._parameters);
  if (!strcmp(compname, "PUMA_HFM_rotated")) return (void *) &(_PUMA_HFM_rotated_var._parameters);
  if (!strcmp(compname, "PUMA_mirror_HFM")) return (void *) &(_PUMA_mirror_HFM_var._parameters);
  if (!strcmp(compname, "PUMA_HFM_out")) return (void *) &(_PUMA_HFM_out_var._parameters);
  if (!strcmp(compname, "PUMA_mon_HFM_out_xy")) return (void *) &(_PUMA_mon_HFM_out_xy_var._parameters);
  if (!strcmp(compname, "PUMA_DCM_location")) return (void *) &(_PUMA_DCM_location_var._parameters);
  if (!strcmp(compname, "PUMA_DCM_xtal1")) return (void *) &(_PUMA_DCM_xtal1_var._parameters);
  if (!strcmp(compname, "PUMA_DCM_xtal1_out")) return (void *) &(_PUMA_DCM_xtal1_out_var._parameters);
  if (!strcmp(compname, "PUMA_mon_DCM_xtal1_only_xy")) return (void *) &(_PUMA_mon_DCM_xtal1_only_xy_var._parameters);
  if (!strcmp(compname, "PUMA_DCM_xtal2")) return (void *) &(_PUMA_DCM_xtal2_var._parameters);
  if (!strcmp(compname, "PUMA_DCM_xtal2_out")) return (void *) &(_PUMA_DCM_xtal2_out_var._parameters);
  if (!strcmp(compname, "PUMA_mon_DCM_out_e")) return (void *) &(_PUMA_mon_DCM_out_e_var._parameters);
  if (!strcmp(compname, "PUMA_mon_DCM_out_xy")) return (void *) &(_PUMA_mon_DCM_out_xy_var._parameters);
  if (!strcmp(compname, "PUMA_slit3")) return (void *) &(_PUMA_slit3_var._parameters);
  if (!strcmp(compname, "PUMA_slit4")) return (void *) &(_PUMA_slit4_var._parameters);
  if (!strcmp(compname, "PUMA_slit5")) return (void *) &(_PUMA_slit5_var._parameters);
  if (!strcmp(compname, "PUMA_KB_VFM_location")) return (void *) &(_PUMA_KB_VFM_location_var._parameters);
  if (!strcmp(compname, "PUMA_mon_KB_in_xy")) return (void *) &(_PUMA_mon_KB_in_xy_var._parameters);
  if (!strcmp(compname, "PUMA_KB_VFM_rotated")) return (void *) &(_PUMA_KB_VFM_rotated_var._parameters);
  if (!strcmp(compname, "PUMA_mirror_KB_VFM")) return (void *) &(_PUMA_mirror_KB_VFM_var._parameters);
  if (!strcmp(compname, "PUMA_KB_VFM_out")) return (void *) &(_PUMA_KB_VFM_out_var._parameters);
  if (!strcmp(compname, "PUMA_mon_KB_VFM_out_xy")) return (void *) &(_PUMA_mon_KB_VFM_out_xy_var._parameters);
  if (!strcmp(compname, "PUMA_KB_HFM_location")) return (void *) &(_PUMA_KB_HFM_location_var._parameters);
  if (!strcmp(compname, "PUMA_KB_HFM_rotated")) return (void *) &(_PUMA_KB_HFM_rotated_var._parameters);
  if (!strcmp(compname, "PUMA_mirror_KB_HFM")) return (void *) &(_PUMA_mirror_KB_HFM_var._parameters);
  if (!strcmp(compname, "PUMA_KB_HFM_out")) return (void *) &(_PUMA_KB_HFM_out_var._parameters);
  if (!strcmp(compname, "PUMA_mon_KB_HFM_out_xy")) return (void *) &(_PUMA_mon_KB_HFM_out_xy_var._parameters);
  if (!strcmp(compname, "PUMA_sample_location")) return (void *) &(_PUMA_sample_location_var._parameters);
  if (!strcmp(compname, "PUMA_mon_sample_xy")) return (void *) &(_PUMA_mon_sample_xy_var._parameters);
  if (!strcmp(compname, "PUMA_mon_sample_e")) return (void *) &(_PUMA_mon_sample_e_var._parameters);
  if (!strcmp(compname, "beamdump_181")) return (void *) &(_beamdump_181_var._parameters);
  if (!strcmp(compname, "CRISTAL_pos")) return (void *) &(_CRISTAL_pos_var._parameters);
  if (!strcmp(compname, "CRISTAL")) return (void *) &(_CRISTAL_var._parameters);
  if (!strcmp(compname, "CRISTAL_Source")) return (void *) &(_CRISTAL_Source_var._parameters);
  if (!strcmp(compname, "CRISTAL_slit1")) return (void *) &(_CRISTAL_slit1_var._parameters);
  if (!strcmp(compname, "CRISTAL_dcm_location")) return (void *) &(_CRISTAL_dcm_location_var._parameters);
  if (!strcmp(compname, "CRISTAL_dcm_xtal0")) return (void *) &(_CRISTAL_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "CRISTAL_arm_xtal0")) return (void *) &(_CRISTAL_arm_xtal0_var._parameters);
  if (!strcmp(compname, "CRISTAL_dcm_xtal1")) return (void *) &(_CRISTAL_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "CRISTAL_arm_xtal1")) return (void *) &(_CRISTAL_arm_xtal1_var._parameters);
  if (!strcmp(compname, "CRISTAL_emon_dcm")) return (void *) &(_CRISTAL_emon_dcm_var._parameters);
  if (!strcmp(compname, "CRISTAL_M1_location")) return (void *) &(_CRISTAL_M1_location_var._parameters);
  if (!strcmp(compname, "CRISTAL_M1_rotated")) return (void *) &(_CRISTAL_M1_rotated_var._parameters);
  if (!strcmp(compname, "CRISTAL_M1")) return (void *) &(_CRISTAL_M1_var._parameters);
  if (!strcmp(compname, "CRISTAL_M1_out")) return (void *) &(_CRISTAL_M1_out_var._parameters);
  if (!strcmp(compname, "CRISTAL_M2_location")) return (void *) &(_CRISTAL_M2_location_var._parameters);
  if (!strcmp(compname, "CRISTAL_M2_rotated")) return (void *) &(_CRISTAL_M2_rotated_var._parameters);
  if (!strcmp(compname, "CRISTAL_M2")) return (void *) &(_CRISTAL_M2_var._parameters);
  if (!strcmp(compname, "CRISTAL_M2_out")) return (void *) &(_CRISTAL_M2_out_var._parameters);
  if (!strcmp(compname, "CRISTAL_slit2")) return (void *) &(_CRISTAL_slit2_var._parameters);
  if (!strcmp(compname, "CRISTAL_psd_slit2")) return (void *) &(_CRISTAL_psd_slit2_var._parameters);
  if (!strcmp(compname, "CRISTAL_sample_stage")) return (void *) &(_CRISTAL_sample_stage_var._parameters);
  if (!strcmp(compname, "CRISTAL_fluo")) return (void *) &(_CRISTAL_fluo_var._parameters);
  if (!strcmp(compname, "CRISTAL_detector_diffraction")) return (void *) &(_CRISTAL_detector_diffraction_var._parameters);
  if (!strcmp(compname, "CRISTAL_detector_fluo")) return (void *) &(_CRISTAL_detector_fluo_var._parameters);
  if (!strcmp(compname, "beamdump_207")) return (void *) &(_beamdump_207_var._parameters);
  if (!strcmp(compname, "DEIMOS_pos")) return (void *) &(_DEIMOS_pos_var._parameters);
  if (!strcmp(compname, "GALAXIES_pos")) return (void *) &(_GALAXIES_pos_var._parameters);
  if (!strcmp(compname, "GALAXIES")) return (void *) &(_GALAXIES_var._parameters);
  if (!strcmp(compname, "GALAXIES_Source_U20")) return (void *) &(_GALAXIES_Source_U20_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_src_xy")) return (void *) &(_GALAXIES_mon_src_xy_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_src_e")) return (void *) &(_GALAXIES_mon_src_e_var._parameters);
  if (!strcmp(compname, "GALAXIES_absorber")) return (void *) &(_GALAXIES_absorber_var._parameters);
  if (!strcmp(compname, "GALAXIES_diaphragme")) return (void *) &(_GALAXIES_diaphragme_var._parameters);
  if (!strcmp(compname, "GALAXIES_fentes_primaires")) return (void *) &(_GALAXIES_fentes_primaires_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_prim_xy")) return (void *) &(_GALAXIES_mon_prim_xy_var._parameters);
  if (!strcmp(compname, "GALAXIES_DCM_location")) return (void *) &(_GALAXIES_DCM_location_var._parameters);
  if (!strcmp(compname, "GALAXIES_dcm_xtal0")) return (void *) &(_GALAXIES_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "GALAXIES_dcm0")) return (void *) &(_GALAXIES_dcm0_var._parameters);
  if (!strcmp(compname, "GALAXIES_dcm_xtal1")) return (void *) &(_GALAXIES_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "GALAXIES_dcm1")) return (void *) &(_GALAXIES_dcm1_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_dcm_e")) return (void *) &(_GALAXIES_mon_dcm_e_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_dcm_xy")) return (void *) &(_GALAXIES_mon_dcm_xy_var._parameters);
  if (!strcmp(compname, "GALAXIES_M1_location")) return (void *) &(_GALAXIES_M1_location_var._parameters);
  if (!strcmp(compname, "GALAXIES_M1_rotated")) return (void *) &(_GALAXIES_M1_rotated_var._parameters);
  if (!strcmp(compname, "GALAXIES_M1")) return (void *) &(_GALAXIES_M1_var._parameters);
  if (!strcmp(compname, "GALAXIES_M1_out")) return (void *) &(_GALAXIES_M1_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_HRM_gate_in")) return (void *) &(_GALAXIES_HRM_gate_in_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2A_location")) return (void *) &(_GALAXIES_M2A_location_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2A_rotated")) return (void *) &(_GALAXIES_M2A_rotated_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2A")) return (void *) &(_GALAXIES_M2A_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2A_out")) return (void *) &(_GALAXIES_M2A_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_secondary_slits")) return (void *) &(_GALAXIES_secondary_slits_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_sec_xy")) return (void *) &(_GALAXIES_mon_sec_xy_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2B_location")) return (void *) &(_GALAXIES_M2B_location_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2B_rotated")) return (void *) &(_GALAXIES_M2B_rotated_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2B")) return (void *) &(_GALAXIES_M2B_var._parameters);
  if (!strcmp(compname, "GALAXIES_M2B_out")) return (void *) &(_GALAXIES_M2B_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_VFM_location")) return (void *) &(_GALAXIES_VFM_location_var._parameters);
  if (!strcmp(compname, "GALAXIES_VFM_rotated")) return (void *) &(_GALAXIES_VFM_rotated_var._parameters);
  if (!strcmp(compname, "GALAXIES_VFM")) return (void *) &(_GALAXIES_VFM_var._parameters);
  if (!strcmp(compname, "GALAXIES_VFM_out")) return (void *) &(_GALAXIES_VFM_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_HFM_rotated")) return (void *) &(_GALAXIES_HFM_rotated_var._parameters);
  if (!strcmp(compname, "GALAXIES_HFM")) return (void *) &(_GALAXIES_HFM_var._parameters);
  if (!strcmp(compname, "GALAXIES_HFM_out")) return (void *) &(_GALAXIES_HFM_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_sample_xy_kb")) return (void *) &(_GALAXIES_mon_sample_xy_kb_var._parameters);
  if (!strcmp(compname, "GALAXIES_mon_sample_e")) return (void *) &(_GALAXIES_mon_sample_e_var._parameters);
  if (!strcmp(compname, "GALAXIES_sample_stage")) return (void *) &(_GALAXIES_sample_stage_var._parameters);
  if (!strcmp(compname, "GALAXIES_sample")) return (void *) &(_GALAXIES_sample_var._parameters);
  if (!strcmp(compname, "GALAXIES_sample_out")) return (void *) &(_GALAXIES_sample_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_ana_arm")) return (void *) &(_GALAXIES_ana_arm_var._parameters);
  if (!strcmp(compname, "GALAXIES_analyzer")) return (void *) &(_GALAXIES_analyzer_var._parameters);
  if (!strcmp(compname, "GALAXIES_ana_out")) return (void *) &(_GALAXIES_ana_out_var._parameters);
  if (!strcmp(compname, "GALAXIES_IXS_det")) return (void *) &(_GALAXIES_IXS_det_var._parameters);
  if (!strcmp(compname, "beamdump_257")) return (void *) &(_beamdump_257_var._parameters);
  if (!strcmp(compname, "TEMPO_pos")) return (void *) &(_TEMPO_pos_var._parameters);
  if (!strcmp(compname, "SAMBA_pos")) return (void *) &(_SAMBA_pos_var._parameters);
  if (!strcmp(compname, "SAMBA")) return (void *) &(_SAMBA_var._parameters);
  if (!strcmp(compname, "SAMBA_BM_source")) return (void *) &(_SAMBA_BM_source_var._parameters);
  if (!strcmp(compname, "SAMBA_M1_location")) return (void *) &(_SAMBA_M1_location_var._parameters);
  if (!strcmp(compname, "SAMBA_M1_rotated")) return (void *) &(_SAMBA_M1_rotated_var._parameters);
  if (!strcmp(compname, "SAMBA_M1")) return (void *) &(_SAMBA_M1_var._parameters);
  if (!strcmp(compname, "SAMBA_M1_out")) return (void *) &(_SAMBA_M1_out_var._parameters);
  if (!strcmp(compname, "SAMBA_DCM_location")) return (void *) &(_SAMBA_DCM_location_var._parameters);
  if (!strcmp(compname, "SAMBA_bragg_crystal")) return (void *) &(_SAMBA_bragg_crystal_var._parameters);
  if (!strcmp(compname, "SAMBA_arm_crystal1")) return (void *) &(_SAMBA_arm_crystal1_var._parameters);
  if (!strcmp(compname, "SAMBA_bragg_crystal_two")) return (void *) &(_SAMBA_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "SAMBA_arm_crystal2")) return (void *) &(_SAMBA_arm_crystal2_var._parameters);
  if (!strcmp(compname, "SAMBA_DCM_out")) return (void *) &(_SAMBA_DCM_out_var._parameters);
  if (!strcmp(compname, "SAMBA_DCM_out_div")) return (void *) &(_SAMBA_DCM_out_div_var._parameters);
  if (!strcmp(compname, "SAMBA_DCM_out_e")) return (void *) &(_SAMBA_DCM_out_e_var._parameters);
  if (!strcmp(compname, "SAMBA_M2_loc")) return (void *) &(_SAMBA_M2_loc_var._parameters);
  if (!strcmp(compname, "SAMBA_M2_rotated")) return (void *) &(_SAMBA_M2_rotated_var._parameters);
  if (!strcmp(compname, "SAMBA_M2")) return (void *) &(_SAMBA_M2_var._parameters);
  if (!strcmp(compname, "SAMBA_M2_out")) return (void *) &(_SAMBA_M2_out_var._parameters);
  if (!strcmp(compname, "SAMBA_sample_stage")) return (void *) &(_SAMBA_sample_stage_var._parameters);
  if (!strcmp(compname, "SAMBA_fluo")) return (void *) &(_SAMBA_fluo_var._parameters);
  if (!strcmp(compname, "SAMBA_det_trans")) return (void *) &(_SAMBA_det_trans_var._parameters);
  if (!strcmp(compname, "SAMBA_det_fluo")) return (void *) &(_SAMBA_det_fluo_var._parameters);
  if (!strcmp(compname, "beamdump_283")) return (void *) &(_beamdump_283_var._parameters);
  if (!strcmp(compname, "HERMES_pos")) return (void *) &(_HERMES_pos_var._parameters);
  if (!strcmp(compname, "PX1_pos")) return (void *) &(_PX1_pos_var._parameters);
  if (!strcmp(compname, "PX1")) return (void *) &(_PX1_var._parameters);
  if (!strcmp(compname, "PX1_undulator")) return (void *) &(_PX1_undulator_var._parameters);
  if (!strcmp(compname, "PX1_bragg_crystal_location")) return (void *) &(_PX1_bragg_crystal_location_var._parameters);
  if (!strcmp(compname, "PX1_bragg_crystal")) return (void *) &(_PX1_bragg_crystal_var._parameters);
  if (!strcmp(compname, "PX1_arm")) return (void *) &(_PX1_arm_var._parameters);
  if (!strcmp(compname, "PX1_bragg_crystal_two")) return (void *) &(_PX1_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "PX1_arm_two")) return (void *) &(_PX1_arm_two_var._parameters);
  if (!strcmp(compname, "PX1_bragg_crystal_out")) return (void *) &(_PX1_bragg_crystal_out_var._parameters);
  if (!strcmp(compname, "PX1_secondary_slits")) return (void *) &(_PX1_secondary_slits_var._parameters);
  if (!strcmp(compname, "PX1_vfm_location")) return (void *) &(_PX1_vfm_location_var._parameters);
  if (!strcmp(compname, "PX1_vfm_in_xz_plane")) return (void *) &(_PX1_vfm_in_xz_plane_var._parameters);
  if (!strcmp(compname, "PX1_vfm")) return (void *) &(_PX1_vfm_var._parameters);
  if (!strcmp(compname, "PX1_vfm_takeoff")) return (void *) &(_PX1_vfm_takeoff_var._parameters);
  if (!strcmp(compname, "PX1_hfm_location")) return (void *) &(_PX1_hfm_location_var._parameters);
  if (!strcmp(compname, "PX1_hfm")) return (void *) &(_PX1_hfm_var._parameters);
  if (!strcmp(compname, "PX1_hfm_takeoff")) return (void *) &(_PX1_hfm_takeoff_var._parameters);
  if (!strcmp(compname, "PX1_sample_stage")) return (void *) &(_PX1_sample_stage_var._parameters);
  if (!strcmp(compname, "PX1_sample_monitor")) return (void *) &(_PX1_sample_monitor_var._parameters);
  if (!strcmp(compname, "PX1_sample")) return (void *) &(_PX1_sample_var._parameters);
  if (!strcmp(compname, "PX1_psd4pi")) return (void *) &(_PX1_psd4pi_var._parameters);
  if (!strcmp(compname, "PX1_EigerX16M")) return (void *) &(_PX1_EigerX16M_var._parameters);
  if (!strcmp(compname, "beamdump_308")) return (void *) &(_beamdump_308_var._parameters);
  if (!strcmp(compname, "PX2a_pos")) return (void *) &(_PX2a_pos_var._parameters);
  if (!strcmp(compname, "PX2a")) return (void *) &(_PX2a_var._parameters);
  if (!strcmp(compname, "PX2a_undulator")) return (void *) &(_PX2a_undulator_var._parameters);
  if (!strcmp(compname, "PX2a_bragg_crystal_location")) return (void *) &(_PX2a_bragg_crystal_location_var._parameters);
  if (!strcmp(compname, "PX2a_bragg_crystal")) return (void *) &(_PX2a_bragg_crystal_var._parameters);
  if (!strcmp(compname, "PX2a_arm")) return (void *) &(_PX2a_arm_var._parameters);
  if (!strcmp(compname, "PX2a_bragg_crystal_two")) return (void *) &(_PX2a_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "PX2a_arm_two")) return (void *) &(_PX2a_arm_two_var._parameters);
  if (!strcmp(compname, "PX2a_bragg_crystal_out")) return (void *) &(_PX2a_bragg_crystal_out_var._parameters);
  if (!strcmp(compname, "PX2a_hpm_location")) return (void *) &(_PX2a_hpm_location_var._parameters);
  if (!strcmp(compname, "PX2a_hpm_in_yz_plane")) return (void *) &(_PX2a_hpm_in_yz_plane_var._parameters);
  if (!strcmp(compname, "PX2a_hpm")) return (void *) &(_PX2a_hpm_var._parameters);
  if (!strcmp(compname, "PX2a_hpm_takeoff")) return (void *) &(_PX2a_hpm_takeoff_var._parameters);
  if (!strcmp(compname, "PX2a_vfm_location")) return (void *) &(_PX2a_vfm_location_var._parameters);
  if (!strcmp(compname, "PX2a_vfm_in_xz_plane")) return (void *) &(_PX2a_vfm_in_xz_plane_var._parameters);
  if (!strcmp(compname, "PX2a_vfm")) return (void *) &(_PX2a_vfm_var._parameters);
  if (!strcmp(compname, "PX2a_vfm_takeoff")) return (void *) &(_PX2a_vfm_takeoff_var._parameters);
  if (!strcmp(compname, "PX2a_hfm_location")) return (void *) &(_PX2a_hfm_location_var._parameters);
  if (!strcmp(compname, "PX2a_hfm")) return (void *) &(_PX2a_hfm_var._parameters);
  if (!strcmp(compname, "PX2a_hfm_takeoff")) return (void *) &(_PX2a_hfm_takeoff_var._parameters);
  if (!strcmp(compname, "PX2a_sample_stage")) return (void *) &(_PX2a_sample_stage_var._parameters);
  if (!strcmp(compname, "PX2a_sample_monitor")) return (void *) &(_PX2a_sample_monitor_var._parameters);
  if (!strcmp(compname, "PX2a_sample")) return (void *) &(_PX2a_sample_var._parameters);
  if (!strcmp(compname, "PX2a_psd4pi")) return (void *) &(_PX2a_psd4pi_var._parameters);
  if (!strcmp(compname, "PX2a_Eiger9M")) return (void *) &(_PX2a_Eiger9M_var._parameters);
  if (!strcmp(compname, "beamdump_335")) return (void *) &(_beamdump_335_var._parameters);
  if (!strcmp(compname, "SWING_pos")) return (void *) &(_SWING_pos_var._parameters);
  if (!strcmp(compname, "SWING")) return (void *) &(_SWING_var._parameters);
  if (!strcmp(compname, "SWING_Source_U20")) return (void *) &(_SWING_Source_U20_var._parameters);
  if (!strcmp(compname, "SWING_mon_src_xy")) return (void *) &(_SWING_mon_src_xy_var._parameters);
  if (!strcmp(compname, "SWING_mon_src_e")) return (void *) &(_SWING_mon_src_e_var._parameters);
  if (!strcmp(compname, "SWING_slit")) return (void *) &(_SWING_slit_var._parameters);
  if (!strcmp(compname, "SWING_slit_mon_xy")) return (void *) &(_SWING_slit_mon_xy_var._parameters);
  if (!strcmp(compname, "SWING_DCM_location")) return (void *) &(_SWING_DCM_location_var._parameters);
  if (!strcmp(compname, "SWING_dcm_xtal0")) return (void *) &(_SWING_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "SWING_dcm0")) return (void *) &(_SWING_dcm0_var._parameters);
  if (!strcmp(compname, "SWING_dcm_xtal1")) return (void *) &(_SWING_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "SWING_dcm1")) return (void *) &(_SWING_dcm1_var._parameters);
  if (!strcmp(compname, "SWING_mon_dcm_e")) return (void *) &(_SWING_mon_dcm_e_var._parameters);
  if (!strcmp(compname, "SWING_mon_dcm_xy")) return (void *) &(_SWING_mon_dcm_xy_var._parameters);
  if (!strcmp(compname, "SWING_vfm_location")) return (void *) &(_SWING_vfm_location_var._parameters);
  if (!strcmp(compname, "SWING_vfm_in_xz_plane")) return (void *) &(_SWING_vfm_in_xz_plane_var._parameters);
  if (!strcmp(compname, "SWING_vfm")) return (void *) &(_SWING_vfm_var._parameters);
  if (!strcmp(compname, "SWING_vfm_takeoff")) return (void *) &(_SWING_vfm_takeoff_var._parameters);
  if (!strcmp(compname, "SWING_hfm_location")) return (void *) &(_SWING_hfm_location_var._parameters);
  if (!strcmp(compname, "SWING_hfm")) return (void *) &(_SWING_hfm_var._parameters);
  if (!strcmp(compname, "SWING_hfm_takeoff")) return (void *) &(_SWING_hfm_takeoff_var._parameters);
  if (!strcmp(compname, "SWING_sample_stage")) return (void *) &(_SWING_sample_stage_var._parameters);
  if (!strcmp(compname, "SWING_sample_test")) return (void *) &(_SWING_sample_test_var._parameters);
  if (!strcmp(compname, "SWING_sample")) return (void *) &(_SWING_sample_var._parameters);
  if (!strcmp(compname, "SWING_sample_out")) return (void *) &(_SWING_sample_out_var._parameters);
  if (!strcmp(compname, "SWING_Eiger4M")) return (void *) &(_SWING_Eiger4M_var._parameters);
  if (!strcmp(compname, "SWING_QMonitor")) return (void *) &(_SWING_QMonitor_var._parameters);
  if (!strcmp(compname, "beamdump_364")) return (void *) &(_beamdump_364_var._parameters);
  if (!strcmp(compname, "ANTARES_pos")) return (void *) &(_ANTARES_pos_var._parameters);
  if (!strcmp(compname, "ROCK_pos")) return (void *) &(_ROCK_pos_var._parameters);
  if (!strcmp(compname, "ROCK")) return (void *) &(_ROCK_var._parameters);
  if (!strcmp(compname, "ROCK_Source")) return (void *) &(_ROCK_Source_var._parameters);
  if (!strcmp(compname, "ROCK_slit1")) return (void *) &(_ROCK_slit1_var._parameters);
  if (!strcmp(compname, "ROCK_slit2")) return (void *) &(_ROCK_slit2_var._parameters);
  if (!strcmp(compname, "ROCK_mirror_m1")) return (void *) &(_ROCK_mirror_m1_var._parameters);
  if (!strcmp(compname, "ROCK_mirror_m1_out")) return (void *) &(_ROCK_mirror_m1_out_var._parameters);
  if (!strcmp(compname, "ROCK_slit3_xy")) return (void *) &(_ROCK_slit3_xy_var._parameters);
  if (!strcmp(compname, "ROCK_slit3_div")) return (void *) &(_ROCK_slit3_div_var._parameters);
  if (!strcmp(compname, "ROCK_slit3")) return (void *) &(_ROCK_slit3_var._parameters);
  if (!strcmp(compname, "ROCK_mirror_m2a")) return (void *) &(_ROCK_mirror_m2a_var._parameters);
  if (!strcmp(compname, "ROCK_mirror_m2a_out")) return (void *) &(_ROCK_mirror_m2a_out_var._parameters);
  if (!strcmp(compname, "ROCK_slit4_in")) return (void *) &(_ROCK_slit4_in_var._parameters);
  if (!strcmp(compname, "ROCK_slit4")) return (void *) &(_ROCK_slit4_var._parameters);
  if (!strcmp(compname, "ROCK_arm_crystal0")) return (void *) &(_ROCK_arm_crystal0_var._parameters);
  if (!strcmp(compname, "ROCK_bragg_crystal")) return (void *) &(_ROCK_bragg_crystal_var._parameters);
  if (!strcmp(compname, "ROCK_arm_crystal1")) return (void *) &(_ROCK_arm_crystal1_var._parameters);
  if (!strcmp(compname, "ROCK_bragg_crystal_two")) return (void *) &(_ROCK_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "ROCK_arm_crystal2")) return (void *) &(_ROCK_arm_crystal2_var._parameters);
  if (!strcmp(compname, "ROCK_bragg_crystal_out")) return (void *) &(_ROCK_bragg_crystal_out_var._parameters);
  if (!strcmp(compname, "ROCK_slit5")) return (void *) &(_ROCK_slit5_var._parameters);
  if (!strcmp(compname, "ROCK_slit6")) return (void *) &(_ROCK_slit6_var._parameters);
  if (!strcmp(compname, "ROCK_mirror_m2b")) return (void *) &(_ROCK_mirror_m2b_var._parameters);
  if (!strcmp(compname, "ROCK_mirror_m2b_out")) return (void *) &(_ROCK_mirror_m2b_out_var._parameters);
  if (!strcmp(compname, "ROCK_EnergyMonitor_before_sample")) return (void *) &(_ROCK_EnergyMonitor_before_sample_var._parameters);
  if (!strcmp(compname, "ROCK_e_repartition_after_m2b")) return (void *) &(_ROCK_e_repartition_after_m2b_var._parameters);
  if (!strcmp(compname, "ROCK_sample_in")) return (void *) &(_ROCK_sample_in_var._parameters);
  if (!strcmp(compname, "ROCK_absorption_sample")) return (void *) &(_ROCK_absorption_sample_var._parameters);
  if (!strcmp(compname, "ROCK_fluo_monitor")) return (void *) &(_ROCK_fluo_monitor_var._parameters);
  if (!strcmp(compname, "ROCK_EnergyMonitor_after_sample")) return (void *) &(_ROCK_EnergyMonitor_after_sample_var._parameters);
  if (!strcmp(compname, "ROCK_psd_monitor")) return (void *) &(_ROCK_psd_monitor_var._parameters);
  if (!strcmp(compname, "beamdump_398")) return (void *) &(_beamdump_398_var._parameters);
  if (!strcmp(compname, "ANATOMIX_pos")) return (void *) &(_ANATOMIX_pos_var._parameters);
  if (!strcmp(compname, "ANATOMIX")) return (void *) &(_ANATOMIX_var._parameters);
  if (!strcmp(compname, "ANATOMIX_source")) return (void *) &(_ANATOMIX_source_var._parameters);
  if (!strcmp(compname, "ANATOMIX_e_repartition_before_cc")) return (void *) &(_ANATOMIX_e_repartition_before_cc_var._parameters);
  if (!strcmp(compname, "ANATOMIX_psd_monitor_before_cc")) return (void *) &(_ANATOMIX_psd_monitor_before_cc_var._parameters);
  if (!strcmp(compname, "ANATOMIX_bragg_crystal")) return (void *) &(_ANATOMIX_bragg_crystal_var._parameters);
  if (!strcmp(compname, "ANATOMIX_arm")) return (void *) &(_ANATOMIX_arm_var._parameters);
  if (!strcmp(compname, "ANATOMIX_bragg_crystal_two")) return (void *) &(_ANATOMIX_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "ANATOMIX_arm_two")) return (void *) &(_ANATOMIX_arm_two_var._parameters);
  if (!strcmp(compname, "ANATOMIX_psd_after_cc")) return (void *) &(_ANATOMIX_psd_after_cc_var._parameters);
  if (!strcmp(compname, "ANATOMIX_e_monitor_before_sample")) return (void *) &(_ANATOMIX_e_monitor_before_sample_var._parameters);
  if (!strcmp(compname, "ANATOMIX_psd_repartition_after_cc")) return (void *) &(_ANATOMIX_psd_repartition_after_cc_var._parameters);
  if (!strcmp(compname, "ANATOMIX_sample_rotation_stage")) return (void *) &(_ANATOMIX_sample_rotation_stage_var._parameters);
  if (!strcmp(compname, "ANATOMIX_sample")) return (void *) &(_ANATOMIX_sample_var._parameters);
  if (!strcmp(compname, "ANATOMIX_e_monitor_after_sample")) return (void *) &(_ANATOMIX_e_monitor_after_sample_var._parameters);
  if (!strcmp(compname, "ANATOMIX_psd_monitor_after_cc")) return (void *) &(_ANATOMIX_psd_monitor_after_cc_var._parameters);
  if (!strcmp(compname, "beamdump_416")) return (void *) &(_beamdump_416_var._parameters);
  if (!strcmp(compname, "NANOSCOPIUM_pos")) return (void *) &(_NANOSCOPIUM_pos_var._parameters);
  if (!strcmp(compname, "NANOSCOPIUM")) return (void *) &(_NANOSCOPIUM_var._parameters);
  if (!strcmp(compname, "NANO_source")) return (void *) &(_NANO_source_var._parameters);
  if (!strcmp(compname, "NANO_e_monitor_source")) return (void *) &(_NANO_e_monitor_source_var._parameters);
  if (!strcmp(compname, "NANO_psd_source")) return (void *) &(_NANO_psd_source_var._parameters);
  if (!strcmp(compname, "NANO_slit_1")) return (void *) &(_NANO_slit_1_var._parameters);
  if (!strcmp(compname, "NANO_m1_in")) return (void *) &(_NANO_m1_in_var._parameters);
  if (!strcmp(compname, "NANO_m1_roll")) return (void *) &(_NANO_m1_roll_var._parameters);
  if (!strcmp(compname, "NANO_mirror_m1")) return (void *) &(_NANO_mirror_m1_var._parameters);
  if (!strcmp(compname, "NANO_beam_deviation")) return (void *) &(_NANO_beam_deviation_var._parameters);
  if (!strcmp(compname, "NANO_m2_in")) return (void *) &(_NANO_m2_in_var._parameters);
  if (!strcmp(compname, "NANO_mirror_m2")) return (void *) &(_NANO_mirror_m2_var._parameters);
  if (!strcmp(compname, "NANO_mirror_m2_out")) return (void *) &(_NANO_mirror_m2_out_var._parameters);
  if (!strcmp(compname, "NANO_slit_2")) return (void *) &(_NANO_slit_2_var._parameters);
  if (!strcmp(compname, "NANO_dcm_in")) return (void *) &(_NANO_dcm_in_var._parameters);
  if (!strcmp(compname, "NANO_PSD_dcm_in")) return (void *) &(_NANO_PSD_dcm_in_var._parameters);
  if (!strcmp(compname, "NANO_bragg_roll")) return (void *) &(_NANO_bragg_roll_var._parameters);
  if (!strcmp(compname, "NANO_bragg_crystal_1")) return (void *) &(_NANO_bragg_crystal_1_var._parameters);
  if (!strcmp(compname, "NANO_dcm2_rot")) return (void *) &(_NANO_dcm2_rot_var._parameters);
  if (!strcmp(compname, "NANO_dcm_transl")) return (void *) &(_NANO_dcm_transl_var._parameters);
  if (!strcmp(compname, "NANO_bragg_crystal_2")) return (void *) &(_NANO_bragg_crystal_2_var._parameters);
  if (!strcmp(compname, "NANO_bragg2_out")) return (void *) &(_NANO_bragg2_out_var._parameters);
  if (!strcmp(compname, "NANO_dcm_out")) return (void *) &(_NANO_dcm_out_var._parameters);
  if (!strcmp(compname, "NANO_e_dcm_out")) return (void *) &(_NANO_e_dcm_out_var._parameters);
  if (!strcmp(compname, "NANO_secondary_source_slits")) return (void *) &(_NANO_secondary_source_slits_var._parameters);
  if (!strcmp(compname, "NANO_psd_ss_in")) return (void *) &(_NANO_psd_ss_in_var._parameters);
  if (!strcmp(compname, "NANO_slit_3")) return (void *) &(_NANO_slit_3_var._parameters);
  if (!strcmp(compname, "NANO_psd_ss_out")) return (void *) &(_NANO_psd_ss_out_var._parameters);
  if (!strcmp(compname, "NANO_jjxray2_slits")) return (void *) &(_NANO_jjxray2_slits_var._parameters);
  if (!strcmp(compname, "NANO_slit_5")) return (void *) &(_NANO_slit_5_var._parameters);
  if (!strcmp(compname, "NANO_kb_in")) return (void *) &(_NANO_kb_in_var._parameters);
  if (!strcmp(compname, "NANO_kb_1")) return (void *) &(_NANO_kb_1_var._parameters);
  if (!strcmp(compname, "NANO_kb_beam_deviation")) return (void *) &(_NANO_kb_beam_deviation_var._parameters);
  if (!strcmp(compname, "NANO_kb1_out")) return (void *) &(_NANO_kb1_out_var._parameters);
  if (!strcmp(compname, "NANO_kb2")) return (void *) &(_NANO_kb2_var._parameters);
  if (!strcmp(compname, "NANO_kb_out")) return (void *) &(_NANO_kb_out_var._parameters);
  if (!strcmp(compname, "NANO_slit")) return (void *) &(_NANO_slit_var._parameters);
  if (!strcmp(compname, "NANO_psd_sample_stage")) return (void *) &(_NANO_psd_sample_stage_var._parameters);
  if (!strcmp(compname, "beamdump_456")) return (void *) &(_beamdump_456_var._parameters);
  if (!strcmp(compname, "DIFFABS_pos")) return (void *) &(_DIFFABS_pos_var._parameters);
  if (!strcmp(compname, "DIFFABS")) return (void *) &(_DIFFABS_var._parameters);
  if (!strcmp(compname, "DIFFABS_BM_D13_1")) return (void *) &(_DIFFABS_BM_D13_1_var._parameters);
  if (!strcmp(compname, "DIFFABS_primary_slit")) return (void *) &(_DIFFABS_primary_slit_var._parameters);
  if (!strcmp(compname, "DIFFABS_M1_location")) return (void *) &(_DIFFABS_M1_location_var._parameters);
  if (!strcmp(compname, "DIFFABS_M1_rotated")) return (void *) &(_DIFFABS_M1_rotated_var._parameters);
  if (!strcmp(compname, "DIFFABS_M1")) return (void *) &(_DIFFABS_M1_var._parameters);
  if (!strcmp(compname, "DIFFABS_M1_out")) return (void *) &(_DIFFABS_M1_out_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_slit_in")) return (void *) &(_DIFFABS_DCM_slit_in_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_in")) return (void *) &(_DIFFABS_DCM_in_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_in_div")) return (void *) &(_DIFFABS_DCM_in_div_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_location")) return (void *) &(_DIFFABS_DCM_location_var._parameters);
  if (!strcmp(compname, "DIFFABS_bragg_crystal")) return (void *) &(_DIFFABS_bragg_crystal_var._parameters);
  if (!strcmp(compname, "DIFFABS_arm_crystal1")) return (void *) &(_DIFFABS_arm_crystal1_var._parameters);
  if (!strcmp(compname, "DIFFABS_bragg_crystal_two")) return (void *) &(_DIFFABS_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "DIFFABS_arm_crystal2")) return (void *) &(_DIFFABS_arm_crystal2_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_out")) return (void *) &(_DIFFABS_DCM_out_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_out_div")) return (void *) &(_DIFFABS_DCM_out_div_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_out_e")) return (void *) &(_DIFFABS_DCM_out_e_var._parameters);
  if (!strcmp(compname, "DIFFABS_DCM_slit_out")) return (void *) &(_DIFFABS_DCM_slit_out_var._parameters);
  if (!strcmp(compname, "DIFFABS_M2_location")) return (void *) &(_DIFFABS_M2_location_var._parameters);
  if (!strcmp(compname, "DIFFABS_M2_rotated")) return (void *) &(_DIFFABS_M2_rotated_var._parameters);
  if (!strcmp(compname, "DIFFABS_M2")) return (void *) &(_DIFFABS_M2_var._parameters);
  if (!strcmp(compname, "DIFFABS_M2_out")) return (void *) &(_DIFFABS_M2_out_var._parameters);
  if (!strcmp(compname, "DIFFABS_sample_stage")) return (void *) &(_DIFFABS_sample_stage_var._parameters);
  if (!strcmp(compname, "DIFFABS_fluo")) return (void *) &(_DIFFABS_fluo_var._parameters);
  if (!strcmp(compname, "DIFFABS_fluo_monitor")) return (void *) &(_DIFFABS_fluo_monitor_var._parameters);
  if (!strcmp(compname, "DIFFABS_det_angle")) return (void *) &(_DIFFABS_det_angle_var._parameters);
  if (!strcmp(compname, "DIFFABS_xpad")) return (void *) &(_DIFFABS_xpad_var._parameters);
  if (!strcmp(compname, "beamdump_487")) return (void *) &(_beamdump_487_var._parameters);
  if (!strcmp(compname, "SEXTANTS")) return (void *) &(_SEXTANTS_var._parameters);
  if (!strcmp(compname, "SIXS_pos")) return (void *) &(_SIXS_pos_var._parameters);
  if (!strcmp(compname, "SIXS")) return (void *) &(_SIXS_var._parameters);
  if (!strcmp(compname, "SIXS_Source_U20")) return (void *) &(_SIXS_Source_U20_var._parameters);
  if (!strcmp(compname, "SIXS_mon_src_xy")) return (void *) &(_SIXS_mon_src_xy_var._parameters);
  if (!strcmp(compname, "SIXS_mon_src_e")) return (void *) &(_SIXS_mon_src_e_var._parameters);
  if (!strcmp(compname, "SIXS_slit")) return (void *) &(_SIXS_slit_var._parameters);
  if (!strcmp(compname, "SIXS_slit_mon_xy")) return (void *) &(_SIXS_slit_mon_xy_var._parameters);
  if (!strcmp(compname, "SIXS_DCM_location")) return (void *) &(_SIXS_DCM_location_var._parameters);
  if (!strcmp(compname, "SIXS_dcm_xtal0")) return (void *) &(_SIXS_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "SIXS_dcm0")) return (void *) &(_SIXS_dcm0_var._parameters);
  if (!strcmp(compname, "SIXS_dcm_xtal1")) return (void *) &(_SIXS_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "SIXS_dcm1")) return (void *) &(_SIXS_dcm1_var._parameters);
  if (!strcmp(compname, "SIXS_mon_dcm_e")) return (void *) &(_SIXS_mon_dcm_e_var._parameters);
  if (!strcmp(compname, "SIXS_mon_dcm_xy")) return (void *) &(_SIXS_mon_dcm_xy_var._parameters);
  if (!strcmp(compname, "SIXS_M1_location")) return (void *) &(_SIXS_M1_location_var._parameters);
  if (!strcmp(compname, "SIXS_M1_rotated")) return (void *) &(_SIXS_M1_rotated_var._parameters);
  if (!strcmp(compname, "SIXS_M1")) return (void *) &(_SIXS_M1_var._parameters);
  if (!strcmp(compname, "SIXS_M1_out")) return (void *) &(_SIXS_M1_out_var._parameters);
  if (!strcmp(compname, "SIXS_M2_location")) return (void *) &(_SIXS_M2_location_var._parameters);
  if (!strcmp(compname, "SIXS_M2_rotated")) return (void *) &(_SIXS_M2_rotated_var._parameters);
  if (!strcmp(compname, "SIXS_M2")) return (void *) &(_SIXS_M2_var._parameters);
  if (!strcmp(compname, "SIXS_M2_out")) return (void *) &(_SIXS_M2_out_var._parameters);
  if (!strcmp(compname, "SIXS_sample_stage")) return (void *) &(_SIXS_sample_stage_var._parameters);
  if (!strcmp(compname, "SIXS_sx_layer")) return (void *) &(_SIXS_sx_layer_var._parameters);
  if (!strcmp(compname, "SIXS_sx_bulk")) return (void *) &(_SIXS_sx_bulk_var._parameters);
  if (!strcmp(compname, "SIXS_sample_out")) return (void *) &(_SIXS_sample_out_var._parameters);
  if (!strcmp(compname, "SIXS_det4pi")) return (void *) &(_SIXS_det4pi_var._parameters);
  if (!strcmp(compname, "SIXS_detector_layer")) return (void *) &(_SIXS_detector_layer_var._parameters);
  if (!strcmp(compname, "SIXS_detector_bulk")) return (void *) &(_SIXS_detector_bulk_var._parameters);
  if (!strcmp(compname, "beamdump_519")) return (void *) &(_beamdump_519_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_pos")) return (void *) &(_CASSIOPEE_pos_var._parameters);
  if (!strcmp(compname, "CASSIOPEE")) return (void *) &(_CASSIOPEE_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_Source_HU60")) return (void *) &(_CASSIOPEE_Source_HU60_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_Source_HU256")) return (void *) &(_CASSIOPEE_Source_HU256_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M1a_location")) return (void *) &(_CASSIOPEE_M1a_location_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M1a")) return (void *) &(_CASSIOPEE_M1a_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M1a_out")) return (void *) &(_CASSIOPEE_M1a_out_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M1b")) return (void *) &(_CASSIOPEE_M1b_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M1c")) return (void *) &(_CASSIOPEE_M1c_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M1bc_out")) return (void *) &(_CASSIOPEE_M1bc_out_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_PSD_M1out")) return (void *) &(_CASSIOPEE_PSD_M1out_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_PG_location")) return (void *) &(_CASSIOPEE_PG_location_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_PG")) return (void *) &(_CASSIOPEE_PG_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M2_rotation_axis")) return (void *) &(_CASSIOPEE_M2_rotation_axis_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M2")) return (void *) &(_CASSIOPEE_M2_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_PM_takeoff")) return (void *) &(_CASSIOPEE_PM_takeoff_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_slit")) return (void *) &(_CASSIOPEE_slit_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_M4")) return (void *) &(_CASSIOPEE_M4_var._parameters);
  if (!strcmp(compname, "CASSIOPEE_PSD")) return (void *) &(_CASSIOPEE_PSD_var._parameters);
  if (!strcmp(compname, "beamdump_540")) return (void *) &(_beamdump_540_var._parameters);
  if (!strcmp(compname, "SIRIUS_pos")) return (void *) &(_SIRIUS_pos_var._parameters);
  if (!strcmp(compname, "SIRIUS")) return (void *) &(_SIRIUS_var._parameters);
  if (!strcmp(compname, "SIRIUS_source")) return (void *) &(_SIRIUS_source_var._parameters);
  if (!strcmp(compname, "SIRIUS_M1_loc")) return (void *) &(_SIRIUS_M1_loc_var._parameters);
  if (!strcmp(compname, "SIRIUS_M1_rot")) return (void *) &(_SIRIUS_M1_rot_var._parameters);
  if (!strcmp(compname, "SIRIUS_M1")) return (void *) &(_SIRIUS_M1_var._parameters);
  if (!strcmp(compname, "SIRIUS_M1_out")) return (void *) &(_SIRIUS_M1_out_var._parameters);
  if (!strcmp(compname, "SIRIUS_DCM_location")) return (void *) &(_SIRIUS_DCM_location_var._parameters);
  if (!strcmp(compname, "SIRIUS_bragg_crystal")) return (void *) &(_SIRIUS_bragg_crystal_var._parameters);
  if (!strcmp(compname, "SIRIUS_arm_crystal1")) return (void *) &(_SIRIUS_arm_crystal1_var._parameters);
  if (!strcmp(compname, "SIRIUS_bragg_crystal_two")) return (void *) &(_SIRIUS_bragg_crystal_two_var._parameters);
  if (!strcmp(compname, "SIRIUS_arm_crystal2")) return (void *) &(_SIRIUS_arm_crystal2_var._parameters);
  if (!strcmp(compname, "SIRIUS_DCM_out")) return (void *) &(_SIRIUS_DCM_out_var._parameters);
  if (!strcmp(compname, "SIRIUS_DCM_out_div")) return (void *) &(_SIRIUS_DCM_out_div_var._parameters);
  if (!strcmp(compname, "SIRIUS_DCM_out_e")) return (void *) &(_SIRIUS_DCM_out_e_var._parameters);
  if (!strcmp(compname, "SIRIUS_def_loc")) return (void *) &(_SIRIUS_def_loc_var._parameters);
  if (!strcmp(compname, "SIRIUS_def_rot")) return (void *) &(_SIRIUS_def_rot_var._parameters);
  if (!strcmp(compname, "SIRIUS_def_mirror")) return (void *) &(_SIRIUS_def_mirror_var._parameters);
  if (!strcmp(compname, "SIRIUS_def_out")) return (void *) &(_SIRIUS_def_out_var._parameters);
  if (!strcmp(compname, "SIRIUS_sample_stage")) return (void *) &(_SIRIUS_sample_stage_var._parameters);
  if (!strcmp(compname, "SIRIUS_fluo")) return (void *) &(_SIRIUS_fluo_var._parameters);
  if (!strcmp(compname, "SIRIUS_det_2d")) return (void *) &(_SIRIUS_det_2d_var._parameters);
  if (!strcmp(compname, "SIRIUS_det_fluo")) return (void *) &(_SIRIUS_det_fluo_var._parameters);
  if (!strcmp(compname, "beamdump_565")) return (void *) &(_beamdump_565_var._parameters);
  if (!strcmp(compname, "LUCIA_pos")) return (void *) &(_LUCIA_pos_var._parameters);
  if (!strcmp(compname, "LUCIA")) return (void *) &(_LUCIA_var._parameters);
  if (!strcmp(compname, "LUCIA_source")) return (void *) &(_LUCIA_source_var._parameters);
  if (!strcmp(compname, "LUCIA_mon_src_xy")) return (void *) &(_LUCIA_mon_src_xy_var._parameters);
  if (!strcmp(compname, "LUCIA_mon_src_e")) return (void *) &(_LUCIA_mon_src_e_var._parameters);
  if (!strcmp(compname, "LUCIA_slit")) return (void *) &(_LUCIA_slit_var._parameters);
  if (!strcmp(compname, "LUCIA_slit_mon_xy")) return (void *) &(_LUCIA_slit_mon_xy_var._parameters);
  if (!strcmp(compname, "LUCIA_DCM_location")) return (void *) &(_LUCIA_DCM_location_var._parameters);
  if (!strcmp(compname, "LUCIA_dcm_xtal0")) return (void *) &(_LUCIA_dcm_xtal0_var._parameters);
  if (!strcmp(compname, "LUCIA_dcm0")) return (void *) &(_LUCIA_dcm0_var._parameters);
  if (!strcmp(compname, "LUCIA_dcm_xtal1")) return (void *) &(_LUCIA_dcm_xtal1_var._parameters);
  if (!strcmp(compname, "LUCIA_dcm1")) return (void *) &(_LUCIA_dcm1_var._parameters);
  if (!strcmp(compname, "LUCIA_mon_dcm_e")) return (void *) &(_LUCIA_mon_dcm_e_var._parameters);
  if (!strcmp(compname, "LUCIA_mon_dcm_xy")) return (void *) &(_LUCIA_mon_dcm_xy_var._parameters);
  if (!strcmp(compname, "LUCIA_diaphragm")) return (void *) &(_LUCIA_diaphragm_var._parameters);
  if (!strcmp(compname, "LUCIA_sample_stage")) return (void *) &(_LUCIA_sample_stage_var._parameters);
  if (!strcmp(compname, "LUCIA_fluo_rotated")) return (void *) &(_LUCIA_fluo_rotated_var._parameters);
  if (!strcmp(compname, "LUCIA_sample")) return (void *) &(_LUCIA_sample_var._parameters);
  if (!strcmp(compname, "LUCIA_transmission")) return (void *) &(_LUCIA_transmission_var._parameters);
  if (!strcmp(compname, "LUCIA_mon_spl_SDD")) return (void *) &(_LUCIA_mon_spl_SDD_var._parameters);
  if (!strcmp(compname, "LUCIA_mon_spl_fluo")) return (void *) &(_LUCIA_mon_spl_fluo_var._parameters);
  if (!strcmp(compname, "beamdump_588")) return (void *) &(_beamdump_588_var._parameters);
  if (!strcmp(compname, "storage")) return (void *) &(_storage_var._parameters);
  if (!strcmp(compname, "hall0")) return (void *) &(_hall0_var._parameters);
  if (!strcmp(compname, "hall1")) return (void *) &(_hall1_var._parameters);
  if (!strcmp(compname, "entrance_0")) return (void *) &(_entrance_0_var._parameters);
  if (!strcmp(compname, "entrance_1")) return (void *) &(_entrance_1_var._parameters);
  if (!strcmp(compname, "ANATOMIX_building")) return (void *) &(_ANATOMIX_building_var._parameters);
  if (!strcmp(compname, "soleil_label")) return (void *) &(_soleil_label_var._parameters);
  return 0;
}

void* _get_particle_var(char *token, _class_particle *p)
/* enables setpars based use of GET_PARTICLE_DVAR macro and similar */
{
  if (!strcmp(token, "PUMA_scat_before_VFM")) return (void *) &(p->PUMA_scat_before_VFM);
  if (!strcmp(token, "flag_scatt")) return (void *) &(p->flag_scatt);
  if (!strcmp(token, "flag_hfm")) return (void *) &(p->flag_hfm);
  if (!strcmp(token, "flag_vfm")) return (void *) &(p->flag_vfm);
  if (!strcmp(token, "PX2a_flag_hfm")) return (void *) &(p->PX2a_flag_hfm);
  if (!strcmp(token, "PX2a_flag_vfm")) return (void *) &(p->PX2a_flag_vfm);
  if (!strcmp(token, "SWING_flag_hfm")) return (void *) &(p->SWING_flag_hfm);
  if (!strcmp(token, "SWING_flag_vfm")) return (void *) &(p->SWING_flag_vfm);
  if (!strcmp(token, "SIXS_flag_scatt")) return (void *) &(p->SIXS_flag_scatt);
  if (!strcmp(token, "beamline")) return (void *) &(p->beamline);
  return 0;
}

int _getcomp_index(char* compname)
/* Enables retrieving the component position & rotation when the index is not known.
 * Component indexing into MACROS, e.g., POS_A_COMP_INDEX, are 1-based! */
{
  if (!strcmp(compname, "origin")) return 1;
  if (!strcmp(compname, "jumper")) return 2;
  if (!strcmp(compname, "beamdump")) return 3;
  if (!strcmp(compname, "ODE_pos")) return 4;
  if (!strcmp(compname, "SMIS_pos")) return 5;
  if (!strcmp(compname, "AILES_pos")) return 6;
  if (!strcmp(compname, "MARS_pos")) return 7;
  if (!strcmp(compname, "MARS")) return 8;
  if (!strcmp(compname, "MARS_Source")) return 9;
  if (!strcmp(compname, "MARS_displaySourceLength")) return 10;
  if (!strcmp(compname, "MARS_displaySource")) return 11;
  if (!strcmp(compname, "MARS_slit1")) return 12;
  if (!strcmp(compname, "MARS_slit2")) return 13;
  if (!strcmp(compname, "MARS_M1_arm_translation")) return 14;
  if (!strcmp(compname, "MARS_M1_arm_rotation_1")) return 15;
  if (!strcmp(compname, "MARS_mirror_M1")) return 16;
  if (!strcmp(compname, "MARS_M1_arm_rotation_2")) return 17;
  if (!strcmp(compname, "MARS_M1_arm_rotation_2_undo")) return 18;
  if (!strcmp(compname, "MARS_beam_arm_before_crystal")) return 19;
  if (!strcmp(compname, "MARS_dcm_xtal0")) return 20;
  if (!strcmp(compname, "MARS_dcm0")) return 21;
  if (!strcmp(compname, "MARS_dcm_xtal1")) return 22;
  if (!strcmp(compname, "MARS_dcm1")) return 23;
  if (!strcmp(compname, "MARS_emon_dcm0")) return 24;
  if (!strcmp(compname, "MARS_displayMono")) return 25;
  if (!strcmp(compname, "MARS_displayMonoLength")) return 26;
  if (!strcmp(compname, "MARS_M2_arm_translation")) return 27;
  if (!strcmp(compname, "MARS_M2_arm_rotation_1")) return 28;
  if (!strcmp(compname, "MARS_mirror_M2")) return 29;
  if (!strcmp(compname, "MARS_M2_arm_rotation_2")) return 30;
  if (!strcmp(compname, "MARS_M2_arm_rotation_2_undo")) return 31;
  if (!strcmp(compname, "MARS_slitSecon1")) return 32;
  if (!strcmp(compname, "MARS_slitSecon2")) return 33;
  if (!strcmp(compname, "MARS_emon_dcm1")) return 34;
  if (!strcmp(compname, "MARS_displaySlit2")) return 35;
  if (!strcmp(compname, "MARS_Sample")) return 36;
  if (!strcmp(compname, "MARS_detector_diffraction")) return 37;
  if (!strcmp(compname, "MARS_detector_fluo")) return 38;
  if (!strcmp(compname, "beamdump_40")) return 39;
  if (!strcmp(compname, "PSICHE_pos")) return 40;
  if (!strcmp(compname, "PSICHE")) return 41;
  if (!strcmp(compname, "PSICHE_source")) return 42;
  if (!strcmp(compname, "PSICHE_mon_src_e")) return 43;
  if (!strcmp(compname, "PSICHE_mon_src_xy")) return 44;
  if (!strcmp(compname, "PSICHE_DCM_location")) return 45;
  if (!strcmp(compname, "PSICHE_dcm_xtal0")) return 46;
  if (!strcmp(compname, "PSICHE_dcm0")) return 47;
  if (!strcmp(compname, "PSICHE_dcm_xtal1")) return 48;
  if (!strcmp(compname, "PSICHE_dcm1")) return 49;
  if (!strcmp(compname, "PSICHE_mon_dcm_e")) return 50;
  if (!strcmp(compname, "PSICHE_mon_dcm_xy")) return 51;
  if (!strcmp(compname, "PSICHE_slit")) return 52;
  if (!strcmp(compname, "PSICHE_sample_stage")) return 53;
  if (!strcmp(compname, "PSICHE_sample")) return 54;
  if (!strcmp(compname, "PSICHE_fluo_holder")) return 55;
  if (!strcmp(compname, "PSICHE_mon_spl_fluo")) return 56;
  if (!strcmp(compname, "PSICHE_mon_spl_e")) return 57;
  if (!strcmp(compname, "PSICHE_mon_spl_xy")) return 58;
  if (!strcmp(compname, "beamdump_61")) return 59;
  if (!strcmp(compname, "PLEIADES_pos")) return 60;
  if (!strcmp(compname, "DISCO_pos")) return 61;
  if (!strcmp(compname, "DISCO")) return 62;
  if (!strcmp(compname, "DISCO_Source")) return 63;
  if (!strcmp(compname, "DISCO_ColdFinger")) return 64;
  if (!strcmp(compname, "DISCO_M1_location")) return 65;
  if (!strcmp(compname, "DISCO_M1_rotated")) return 66;
  if (!strcmp(compname, "DISCO_M1_x")) return 67;
  if (!strcmp(compname, "DISCO_M1")) return 68;
  if (!strcmp(compname, "DISCO_M1_takeoff")) return 69;
  if (!strcmp(compname, "DISCO_M1_x_takeoff")) return 70;
  if (!strcmp(compname, "DISCO_M2_location")) return 71;
  if (!strcmp(compname, "DISCO_M2_rotated_x")) return 72;
  if (!strcmp(compname, "DISCO_M2_rotated")) return 73;
  if (!strcmp(compname, "DISCO_M2_other_side")) return 74;
  if (!strcmp(compname, "DISCO_M2")) return 75;
  if (!strcmp(compname, "DISCO_M2_other_side_back")) return 76;
  if (!strcmp(compname, "DISCO_M2_takeoff")) return 77;
  if (!strcmp(compname, "DISCO_HFP_location")) return 78;
  if (!strcmp(compname, "DISCO_HFP")) return 79;
  if (!strcmp(compname, "DISCO_M3_arm")) return 80;
  if (!strcmp(compname, "DISCO_M3")) return 81;
  if (!strcmp(compname, "DISCO_M3_takeoff")) return 82;
  if (!strcmp(compname, "DISCO_M3_yz")) return 83;
  if (!strcmp(compname, "DISCO_M4_yz")) return 84;
  if (!strcmp(compname, "DISCO_M4")) return 85;
  if (!strcmp(compname, "DISCO_M4_takeoff")) return 86;
  if (!strcmp(compname, "DISCO_M4_arm_back")) return 87;
  if (!strcmp(compname, "DISCO_VFP_location")) return 88;
  if (!strcmp(compname, "DISCO_VFP")) return 89;
  if (!strcmp(compname, "DISCO_M51_position")) return 90;
  if (!strcmp(compname, "DISCO_M51_rotation")) return 91;
  if (!strcmp(compname, "DISCO_M51")) return 92;
  if (!strcmp(compname, "DISCO_arm")) return 93;
  if (!strcmp(compname, "DISCO_M51_arm_back")) return 94;
  if (!strcmp(compname, "DISCO_M52_position")) return 95;
  if (!strcmp(compname, "DISCO_M52_x")) return 96;
  if (!strcmp(compname, "DISCO_M52")) return 97;
  if (!strcmp(compname, "DISCO_M52_takeoff")) return 98;
  if (!strcmp(compname, "DISCO_M52_x_takeoff")) return 99;
  if (!strcmp(compname, "DISCO_second_HFP_location")) return 100;
  if (!strcmp(compname, "DISCO_second_HFP")) return 101;
  if (!strcmp(compname, "DISCO_M53_location")) return 102;
  if (!strcmp(compname, "DISCO_M53_rotated")) return 103;
  if (!strcmp(compname, "DISCO_M53")) return 104;
  if (!strcmp(compname, "DISCO_M53_takeoff")) return 105;
  if (!strcmp(compname, "DISCO_M54_location")) return 106;
  if (!strcmp(compname, "DISCO_M54_rotated")) return 107;
  if (!strcmp(compname, "DISCO_M54")) return 108;
  if (!strcmp(compname, "DISCO_M54_takeoff")) return 109;
  if (!strcmp(compname, "DISCO_Mtoroids_arm_back")) return 110;
  if (!strcmp(compname, "DISCO_M1_position")) return 111;
  if (!strcmp(compname, "DISCO_M1_rotation")) return 112;
  if (!strcmp(compname, "DISCO_mirror_m1")) return 113;
  if (!strcmp(compname, "DISCO_armm")) return 114;
  if (!strcmp(compname, "DISCO_M1_arm_back")) return 115;
  if (!strcmp(compname, "DISCO_Grating_position")) return 116;
  if (!strcmp(compname, "DISCO_Grating_rotation")) return 117;
  if (!strcmp(compname, "DISCO_Grating_rotation_lines_grating")) return 118;
  if (!strcmp(compname, "DISCO_Grating_rotation_nine_degrees")) return 119;
  if (!strcmp(compname, "DISCO_reflective_grating")) return 120;
  if (!strcmp(compname, "DISCO_Grating_rotation_lines_grating_back")) return 121;
  if (!strcmp(compname, "DISCO_Grating_arm_back")) return 122;
  if (!strcmp(compname, "DISCO_Grating_arm_back_2")) return 123;
  if (!strcmp(compname, "DISCO_Grating_arm_back_3")) return 124;
  if (!strcmp(compname, "DISCO_M22_location")) return 125;
  if (!strcmp(compname, "DISCO_M22_rotated")) return 126;
  if (!strcmp(compname, "DISCO_mirror_m2")) return 127;
  if (!strcmp(compname, "DISCO_arm2")) return 128;
  if (!strcmp(compname, "DISCO_M44_arm_back")) return 129;
  if (!strcmp(compname, "DISCO_arm3")) return 130;
  if (!strcmp(compname, "DISCO_psd_before_slit")) return 131;
  if (!strcmp(compname, "DISCO_slit")) return 132;
  if (!strcmp(compname, "DISCO_psd_monitor")) return 133;
  if (!strcmp(compname, "DISCO_psd_giant_after_grating")) return 134;
  if (!strcmp(compname, "DISCO_e_monitor")) return 135;
  if (!strcmp(compname, "DISCO_w_monitor")) return 136;
  if (!strcmp(compname, "beamdump_140")) return 137;
  if (!strcmp(compname, "DESIRS_pos")) return 138;
  if (!strcmp(compname, "METRO_pos")) return 139;
  if (!strcmp(compname, "PUMA_pos")) return 140;
  if (!strcmp(compname, "PUMA")) return 141;
  if (!strcmp(compname, "PUMA_Source")) return 142;
  if (!strcmp(compname, "PUMA_slit1")) return 143;
  if (!strcmp(compname, "PUMA_slit2")) return 144;
  if (!strcmp(compname, "PUMA_mon_src_e")) return 145;
  if (!strcmp(compname, "PUMA_mon_src_xy")) return 146;
  if (!strcmp(compname, "PUMA_HFM_location")) return 147;
  if (!strcmp(compname, "PUMA_HFM_rotated")) return 148;
  if (!strcmp(compname, "PUMA_mirror_HFM")) return 149;
  if (!strcmp(compname, "PUMA_HFM_out")) return 150;
  if (!strcmp(compname, "PUMA_mon_HFM_out_xy")) return 151;
  if (!strcmp(compname, "PUMA_DCM_location")) return 152;
  if (!strcmp(compname, "PUMA_DCM_xtal1")) return 153;
  if (!strcmp(compname, "PUMA_DCM_xtal1_out")) return 154;
  if (!strcmp(compname, "PUMA_mon_DCM_xtal1_only_xy")) return 155;
  if (!strcmp(compname, "PUMA_DCM_xtal2")) return 156;
  if (!strcmp(compname, "PUMA_DCM_xtal2_out")) return 157;
  if (!strcmp(compname, "PUMA_mon_DCM_out_e")) return 158;
  if (!strcmp(compname, "PUMA_mon_DCM_out_xy")) return 159;
  if (!strcmp(compname, "PUMA_slit3")) return 160;
  if (!strcmp(compname, "PUMA_slit4")) return 161;
  if (!strcmp(compname, "PUMA_slit5")) return 162;
  if (!strcmp(compname, "PUMA_KB_VFM_location")) return 163;
  if (!strcmp(compname, "PUMA_mon_KB_in_xy")) return 164;
  if (!strcmp(compname, "PUMA_KB_VFM_rotated")) return 165;
  if (!strcmp(compname, "PUMA_mirror_KB_VFM")) return 166;
  if (!strcmp(compname, "PUMA_KB_VFM_out")) return 167;
  if (!strcmp(compname, "PUMA_mon_KB_VFM_out_xy")) return 168;
  if (!strcmp(compname, "PUMA_KB_HFM_location")) return 169;
  if (!strcmp(compname, "PUMA_KB_HFM_rotated")) return 170;
  if (!strcmp(compname, "PUMA_mirror_KB_HFM")) return 171;
  if (!strcmp(compname, "PUMA_KB_HFM_out")) return 172;
  if (!strcmp(compname, "PUMA_mon_KB_HFM_out_xy")) return 173;
  if (!strcmp(compname, "PUMA_sample_location")) return 174;
  if (!strcmp(compname, "PUMA_mon_sample_xy")) return 175;
  if (!strcmp(compname, "PUMA_mon_sample_e")) return 176;
  if (!strcmp(compname, "beamdump_181")) return 177;
  if (!strcmp(compname, "CRISTAL_pos")) return 178;
  if (!strcmp(compname, "CRISTAL")) return 179;
  if (!strcmp(compname, "CRISTAL_Source")) return 180;
  if (!strcmp(compname, "CRISTAL_slit1")) return 181;
  if (!strcmp(compname, "CRISTAL_dcm_location")) return 182;
  if (!strcmp(compname, "CRISTAL_dcm_xtal0")) return 183;
  if (!strcmp(compname, "CRISTAL_arm_xtal0")) return 184;
  if (!strcmp(compname, "CRISTAL_dcm_xtal1")) return 185;
  if (!strcmp(compname, "CRISTAL_arm_xtal1")) return 186;
  if (!strcmp(compname, "CRISTAL_emon_dcm")) return 187;
  if (!strcmp(compname, "CRISTAL_M1_location")) return 188;
  if (!strcmp(compname, "CRISTAL_M1_rotated")) return 189;
  if (!strcmp(compname, "CRISTAL_M1")) return 190;
  if (!strcmp(compname, "CRISTAL_M1_out")) return 191;
  if (!strcmp(compname, "CRISTAL_M2_location")) return 192;
  if (!strcmp(compname, "CRISTAL_M2_rotated")) return 193;
  if (!strcmp(compname, "CRISTAL_M2")) return 194;
  if (!strcmp(compname, "CRISTAL_M2_out")) return 195;
  if (!strcmp(compname, "CRISTAL_slit2")) return 196;
  if (!strcmp(compname, "CRISTAL_psd_slit2")) return 197;
  if (!strcmp(compname, "CRISTAL_sample_stage")) return 198;
  if (!strcmp(compname, "CRISTAL_fluo")) return 199;
  if (!strcmp(compname, "CRISTAL_detector_diffraction")) return 200;
  if (!strcmp(compname, "CRISTAL_detector_fluo")) return 201;
  if (!strcmp(compname, "beamdump_207")) return 202;
  if (!strcmp(compname, "DEIMOS_pos")) return 203;
  if (!strcmp(compname, "GALAXIES_pos")) return 204;
  if (!strcmp(compname, "GALAXIES")) return 205;
  if (!strcmp(compname, "GALAXIES_Source_U20")) return 206;
  if (!strcmp(compname, "GALAXIES_mon_src_xy")) return 207;
  if (!strcmp(compname, "GALAXIES_mon_src_e")) return 208;
  if (!strcmp(compname, "GALAXIES_absorber")) return 209;
  if (!strcmp(compname, "GALAXIES_diaphragme")) return 210;
  if (!strcmp(compname, "GALAXIES_fentes_primaires")) return 211;
  if (!strcmp(compname, "GALAXIES_mon_prim_xy")) return 212;
  if (!strcmp(compname, "GALAXIES_DCM_location")) return 213;
  if (!strcmp(compname, "GALAXIES_dcm_xtal0")) return 214;
  if (!strcmp(compname, "GALAXIES_dcm0")) return 215;
  if (!strcmp(compname, "GALAXIES_dcm_xtal1")) return 216;
  if (!strcmp(compname, "GALAXIES_dcm1")) return 217;
  if (!strcmp(compname, "GALAXIES_mon_dcm_e")) return 218;
  if (!strcmp(compname, "GALAXIES_mon_dcm_xy")) return 219;
  if (!strcmp(compname, "GALAXIES_M1_location")) return 220;
  if (!strcmp(compname, "GALAXIES_M1_rotated")) return 221;
  if (!strcmp(compname, "GALAXIES_M1")) return 222;
  if (!strcmp(compname, "GALAXIES_M1_out")) return 223;
  if (!strcmp(compname, "GALAXIES_HRM_gate_in")) return 224;
  if (!strcmp(compname, "GALAXIES_M2A_location")) return 225;
  if (!strcmp(compname, "GALAXIES_M2A_rotated")) return 226;
  if (!strcmp(compname, "GALAXIES_M2A")) return 227;
  if (!strcmp(compname, "GALAXIES_M2A_out")) return 228;
  if (!strcmp(compname, "GALAXIES_secondary_slits")) return 229;
  if (!strcmp(compname, "GALAXIES_mon_sec_xy")) return 230;
  if (!strcmp(compname, "GALAXIES_M2B_location")) return 231;
  if (!strcmp(compname, "GALAXIES_M2B_rotated")) return 232;
  if (!strcmp(compname, "GALAXIES_M2B")) return 233;
  if (!strcmp(compname, "GALAXIES_M2B_out")) return 234;
  if (!strcmp(compname, "GALAXIES_VFM_location")) return 235;
  if (!strcmp(compname, "GALAXIES_VFM_rotated")) return 236;
  if (!strcmp(compname, "GALAXIES_VFM")) return 237;
  if (!strcmp(compname, "GALAXIES_VFM_out")) return 238;
  if (!strcmp(compname, "GALAXIES_HFM_rotated")) return 239;
  if (!strcmp(compname, "GALAXIES_HFM")) return 240;
  if (!strcmp(compname, "GALAXIES_HFM_out")) return 241;
  if (!strcmp(compname, "GALAXIES_mon_sample_xy_kb")) return 242;
  if (!strcmp(compname, "GALAXIES_mon_sample_e")) return 243;
  if (!strcmp(compname, "GALAXIES_sample_stage")) return 244;
  if (!strcmp(compname, "GALAXIES_sample")) return 245;
  if (!strcmp(compname, "GALAXIES_sample_out")) return 246;
  if (!strcmp(compname, "GALAXIES_ana_arm")) return 247;
  if (!strcmp(compname, "GALAXIES_analyzer")) return 248;
  if (!strcmp(compname, "GALAXIES_ana_out")) return 249;
  if (!strcmp(compname, "GALAXIES_IXS_det")) return 250;
  if (!strcmp(compname, "beamdump_257")) return 251;
  if (!strcmp(compname, "TEMPO_pos")) return 252;
  if (!strcmp(compname, "SAMBA_pos")) return 253;
  if (!strcmp(compname, "SAMBA")) return 254;
  if (!strcmp(compname, "SAMBA_BM_source")) return 255;
  if (!strcmp(compname, "SAMBA_M1_location")) return 256;
  if (!strcmp(compname, "SAMBA_M1_rotated")) return 257;
  if (!strcmp(compname, "SAMBA_M1")) return 258;
  if (!strcmp(compname, "SAMBA_M1_out")) return 259;
  if (!strcmp(compname, "SAMBA_DCM_location")) return 260;
  if (!strcmp(compname, "SAMBA_bragg_crystal")) return 261;
  if (!strcmp(compname, "SAMBA_arm_crystal1")) return 262;
  if (!strcmp(compname, "SAMBA_bragg_crystal_two")) return 263;
  if (!strcmp(compname, "SAMBA_arm_crystal2")) return 264;
  if (!strcmp(compname, "SAMBA_DCM_out")) return 265;
  if (!strcmp(compname, "SAMBA_DCM_out_div")) return 266;
  if (!strcmp(compname, "SAMBA_DCM_out_e")) return 267;
  if (!strcmp(compname, "SAMBA_M2_loc")) return 268;
  if (!strcmp(compname, "SAMBA_M2_rotated")) return 269;
  if (!strcmp(compname, "SAMBA_M2")) return 270;
  if (!strcmp(compname, "SAMBA_M2_out")) return 271;
  if (!strcmp(compname, "SAMBA_sample_stage")) return 272;
  if (!strcmp(compname, "SAMBA_fluo")) return 273;
  if (!strcmp(compname, "SAMBA_det_trans")) return 274;
  if (!strcmp(compname, "SAMBA_det_fluo")) return 275;
  if (!strcmp(compname, "beamdump_283")) return 276;
  if (!strcmp(compname, "HERMES_pos")) return 277;
  if (!strcmp(compname, "PX1_pos")) return 278;
  if (!strcmp(compname, "PX1")) return 279;
  if (!strcmp(compname, "PX1_undulator")) return 280;
  if (!strcmp(compname, "PX1_bragg_crystal_location")) return 281;
  if (!strcmp(compname, "PX1_bragg_crystal")) return 282;
  if (!strcmp(compname, "PX1_arm")) return 283;
  if (!strcmp(compname, "PX1_bragg_crystal_two")) return 284;
  if (!strcmp(compname, "PX1_arm_two")) return 285;
  if (!strcmp(compname, "PX1_bragg_crystal_out")) return 286;
  if (!strcmp(compname, "PX1_secondary_slits")) return 287;
  if (!strcmp(compname, "PX1_vfm_location")) return 288;
  if (!strcmp(compname, "PX1_vfm_in_xz_plane")) return 289;
  if (!strcmp(compname, "PX1_vfm")) return 290;
  if (!strcmp(compname, "PX1_vfm_takeoff")) return 291;
  if (!strcmp(compname, "PX1_hfm_location")) return 292;
  if (!strcmp(compname, "PX1_hfm")) return 293;
  if (!strcmp(compname, "PX1_hfm_takeoff")) return 294;
  if (!strcmp(compname, "PX1_sample_stage")) return 295;
  if (!strcmp(compname, "PX1_sample_monitor")) return 296;
  if (!strcmp(compname, "PX1_sample")) return 297;
  if (!strcmp(compname, "PX1_psd4pi")) return 298;
  if (!strcmp(compname, "PX1_EigerX16M")) return 299;
  if (!strcmp(compname, "beamdump_308")) return 300;
  if (!strcmp(compname, "PX2a_pos")) return 301;
  if (!strcmp(compname, "PX2a")) return 302;
  if (!strcmp(compname, "PX2a_undulator")) return 303;
  if (!strcmp(compname, "PX2a_bragg_crystal_location")) return 304;
  if (!strcmp(compname, "PX2a_bragg_crystal")) return 305;
  if (!strcmp(compname, "PX2a_arm")) return 306;
  if (!strcmp(compname, "PX2a_bragg_crystal_two")) return 307;
  if (!strcmp(compname, "PX2a_arm_two")) return 308;
  if (!strcmp(compname, "PX2a_bragg_crystal_out")) return 309;
  if (!strcmp(compname, "PX2a_hpm_location")) return 310;
  if (!strcmp(compname, "PX2a_hpm_in_yz_plane")) return 311;
  if (!strcmp(compname, "PX2a_hpm")) return 312;
  if (!strcmp(compname, "PX2a_hpm_takeoff")) return 313;
  if (!strcmp(compname, "PX2a_vfm_location")) return 314;
  if (!strcmp(compname, "PX2a_vfm_in_xz_plane")) return 315;
  if (!strcmp(compname, "PX2a_vfm")) return 316;
  if (!strcmp(compname, "PX2a_vfm_takeoff")) return 317;
  if (!strcmp(compname, "PX2a_hfm_location")) return 318;
  if (!strcmp(compname, "PX2a_hfm")) return 319;
  if (!strcmp(compname, "PX2a_hfm_takeoff")) return 320;
  if (!strcmp(compname, "PX2a_sample_stage")) return 321;
  if (!strcmp(compname, "PX2a_sample_monitor")) return 322;
  if (!strcmp(compname, "PX2a_sample")) return 323;
  if (!strcmp(compname, "PX2a_psd4pi")) return 324;
  if (!strcmp(compname, "PX2a_Eiger9M")) return 325;
  if (!strcmp(compname, "beamdump_335")) return 326;
  if (!strcmp(compname, "SWING_pos")) return 327;
  if (!strcmp(compname, "SWING")) return 328;
  if (!strcmp(compname, "SWING_Source_U20")) return 329;
  if (!strcmp(compname, "SWING_mon_src_xy")) return 330;
  if (!strcmp(compname, "SWING_mon_src_e")) return 331;
  if (!strcmp(compname, "SWING_slit")) return 332;
  if (!strcmp(compname, "SWING_slit_mon_xy")) return 333;
  if (!strcmp(compname, "SWING_DCM_location")) return 334;
  if (!strcmp(compname, "SWING_dcm_xtal0")) return 335;
  if (!strcmp(compname, "SWING_dcm0")) return 336;
  if (!strcmp(compname, "SWING_dcm_xtal1")) return 337;
  if (!strcmp(compname, "SWING_dcm1")) return 338;
  if (!strcmp(compname, "SWING_mon_dcm_e")) return 339;
  if (!strcmp(compname, "SWING_mon_dcm_xy")) return 340;
  if (!strcmp(compname, "SWING_vfm_location")) return 341;
  if (!strcmp(compname, "SWING_vfm_in_xz_plane")) return 342;
  if (!strcmp(compname, "SWING_vfm")) return 343;
  if (!strcmp(compname, "SWING_vfm_takeoff")) return 344;
  if (!strcmp(compname, "SWING_hfm_location")) return 345;
  if (!strcmp(compname, "SWING_hfm")) return 346;
  if (!strcmp(compname, "SWING_hfm_takeoff")) return 347;
  if (!strcmp(compname, "SWING_sample_stage")) return 348;
  if (!strcmp(compname, "SWING_sample_test")) return 349;
  if (!strcmp(compname, "SWING_sample")) return 350;
  if (!strcmp(compname, "SWING_sample_out")) return 351;
  if (!strcmp(compname, "SWING_Eiger4M")) return 352;
  if (!strcmp(compname, "SWING_QMonitor")) return 353;
  if (!strcmp(compname, "beamdump_364")) return 354;
  if (!strcmp(compname, "ANTARES_pos")) return 355;
  if (!strcmp(compname, "ROCK_pos")) return 356;
  if (!strcmp(compname, "ROCK")) return 357;
  if (!strcmp(compname, "ROCK_Source")) return 358;
  if (!strcmp(compname, "ROCK_slit1")) return 359;
  if (!strcmp(compname, "ROCK_slit2")) return 360;
  if (!strcmp(compname, "ROCK_mirror_m1")) return 361;
  if (!strcmp(compname, "ROCK_mirror_m1_out")) return 362;
  if (!strcmp(compname, "ROCK_slit3_xy")) return 363;
  if (!strcmp(compname, "ROCK_slit3_div")) return 364;
  if (!strcmp(compname, "ROCK_slit3")) return 365;
  if (!strcmp(compname, "ROCK_mirror_m2a")) return 366;
  if (!strcmp(compname, "ROCK_mirror_m2a_out")) return 367;
  if (!strcmp(compname, "ROCK_slit4_in")) return 368;
  if (!strcmp(compname, "ROCK_slit4")) return 369;
  if (!strcmp(compname, "ROCK_arm_crystal0")) return 370;
  if (!strcmp(compname, "ROCK_bragg_crystal")) return 371;
  if (!strcmp(compname, "ROCK_arm_crystal1")) return 372;
  if (!strcmp(compname, "ROCK_bragg_crystal_two")) return 373;
  if (!strcmp(compname, "ROCK_arm_crystal2")) return 374;
  if (!strcmp(compname, "ROCK_bragg_crystal_out")) return 375;
  if (!strcmp(compname, "ROCK_slit5")) return 376;
  if (!strcmp(compname, "ROCK_slit6")) return 377;
  if (!strcmp(compname, "ROCK_mirror_m2b")) return 378;
  if (!strcmp(compname, "ROCK_mirror_m2b_out")) return 379;
  if (!strcmp(compname, "ROCK_EnergyMonitor_before_sample")) return 380;
  if (!strcmp(compname, "ROCK_e_repartition_after_m2b")) return 381;
  if (!strcmp(compname, "ROCK_sample_in")) return 382;
  if (!strcmp(compname, "ROCK_absorption_sample")) return 383;
  if (!strcmp(compname, "ROCK_fluo_monitor")) return 384;
  if (!strcmp(compname, "ROCK_EnergyMonitor_after_sample")) return 385;
  if (!strcmp(compname, "ROCK_psd_monitor")) return 386;
  if (!strcmp(compname, "beamdump_398")) return 387;
  if (!strcmp(compname, "ANATOMIX_pos")) return 388;
  if (!strcmp(compname, "ANATOMIX")) return 389;
  if (!strcmp(compname, "ANATOMIX_source")) return 390;
  if (!strcmp(compname, "ANATOMIX_e_repartition_before_cc")) return 391;
  if (!strcmp(compname, "ANATOMIX_psd_monitor_before_cc")) return 392;
  if (!strcmp(compname, "ANATOMIX_bragg_crystal")) return 393;
  if (!strcmp(compname, "ANATOMIX_arm")) return 394;
  if (!strcmp(compname, "ANATOMIX_bragg_crystal_two")) return 395;
  if (!strcmp(compname, "ANATOMIX_arm_two")) return 396;
  if (!strcmp(compname, "ANATOMIX_psd_after_cc")) return 397;
  if (!strcmp(compname, "ANATOMIX_e_monitor_before_sample")) return 398;
  if (!strcmp(compname, "ANATOMIX_psd_repartition_after_cc")) return 399;
  if (!strcmp(compname, "ANATOMIX_sample_rotation_stage")) return 400;
  if (!strcmp(compname, "ANATOMIX_sample")) return 401;
  if (!strcmp(compname, "ANATOMIX_e_monitor_after_sample")) return 402;
  if (!strcmp(compname, "ANATOMIX_psd_monitor_after_cc")) return 403;
  if (!strcmp(compname, "beamdump_416")) return 404;
  if (!strcmp(compname, "NANOSCOPIUM_pos")) return 405;
  if (!strcmp(compname, "NANOSCOPIUM")) return 406;
  if (!strcmp(compname, "NANO_source")) return 407;
  if (!strcmp(compname, "NANO_e_monitor_source")) return 408;
  if (!strcmp(compname, "NANO_psd_source")) return 409;
  if (!strcmp(compname, "NANO_slit_1")) return 410;
  if (!strcmp(compname, "NANO_m1_in")) return 411;
  if (!strcmp(compname, "NANO_m1_roll")) return 412;
  if (!strcmp(compname, "NANO_mirror_m1")) return 413;
  if (!strcmp(compname, "NANO_beam_deviation")) return 414;
  if (!strcmp(compname, "NANO_m2_in")) return 415;
  if (!strcmp(compname, "NANO_mirror_m2")) return 416;
  if (!strcmp(compname, "NANO_mirror_m2_out")) return 417;
  if (!strcmp(compname, "NANO_slit_2")) return 418;
  if (!strcmp(compname, "NANO_dcm_in")) return 419;
  if (!strcmp(compname, "NANO_PSD_dcm_in")) return 420;
  if (!strcmp(compname, "NANO_bragg_roll")) return 421;
  if (!strcmp(compname, "NANO_bragg_crystal_1")) return 422;
  if (!strcmp(compname, "NANO_dcm2_rot")) return 423;
  if (!strcmp(compname, "NANO_dcm_transl")) return 424;
  if (!strcmp(compname, "NANO_bragg_crystal_2")) return 425;
  if (!strcmp(compname, "NANO_bragg2_out")) return 426;
  if (!strcmp(compname, "NANO_dcm_out")) return 427;
  if (!strcmp(compname, "NANO_e_dcm_out")) return 428;
  if (!strcmp(compname, "NANO_secondary_source_slits")) return 429;
  if (!strcmp(compname, "NANO_psd_ss_in")) return 430;
  if (!strcmp(compname, "NANO_slit_3")) return 431;
  if (!strcmp(compname, "NANO_psd_ss_out")) return 432;
  if (!strcmp(compname, "NANO_jjxray2_slits")) return 433;
  if (!strcmp(compname, "NANO_slit_5")) return 434;
  if (!strcmp(compname, "NANO_kb_in")) return 435;
  if (!strcmp(compname, "NANO_kb_1")) return 436;
  if (!strcmp(compname, "NANO_kb_beam_deviation")) return 437;
  if (!strcmp(compname, "NANO_kb1_out")) return 438;
  if (!strcmp(compname, "NANO_kb2")) return 439;
  if (!strcmp(compname, "NANO_kb_out")) return 440;
  if (!strcmp(compname, "NANO_slit")) return 441;
  if (!strcmp(compname, "NANO_psd_sample_stage")) return 442;
  if (!strcmp(compname, "beamdump_456")) return 443;
  if (!strcmp(compname, "DIFFABS_pos")) return 444;
  if (!strcmp(compname, "DIFFABS")) return 445;
  if (!strcmp(compname, "DIFFABS_BM_D13_1")) return 446;
  if (!strcmp(compname, "DIFFABS_primary_slit")) return 447;
  if (!strcmp(compname, "DIFFABS_M1_location")) return 448;
  if (!strcmp(compname, "DIFFABS_M1_rotated")) return 449;
  if (!strcmp(compname, "DIFFABS_M1")) return 450;
  if (!strcmp(compname, "DIFFABS_M1_out")) return 451;
  if (!strcmp(compname, "DIFFABS_DCM_slit_in")) return 452;
  if (!strcmp(compname, "DIFFABS_DCM_in")) return 453;
  if (!strcmp(compname, "DIFFABS_DCM_in_div")) return 454;
  if (!strcmp(compname, "DIFFABS_DCM_location")) return 455;
  if (!strcmp(compname, "DIFFABS_bragg_crystal")) return 456;
  if (!strcmp(compname, "DIFFABS_arm_crystal1")) return 457;
  if (!strcmp(compname, "DIFFABS_bragg_crystal_two")) return 458;
  if (!strcmp(compname, "DIFFABS_arm_crystal2")) return 459;
  if (!strcmp(compname, "DIFFABS_DCM_out")) return 460;
  if (!strcmp(compname, "DIFFABS_DCM_out_div")) return 461;
  if (!strcmp(compname, "DIFFABS_DCM_out_e")) return 462;
  if (!strcmp(compname, "DIFFABS_DCM_slit_out")) return 463;
  if (!strcmp(compname, "DIFFABS_M2_location")) return 464;
  if (!strcmp(compname, "DIFFABS_M2_rotated")) return 465;
  if (!strcmp(compname, "DIFFABS_M2")) return 466;
  if (!strcmp(compname, "DIFFABS_M2_out")) return 467;
  if (!strcmp(compname, "DIFFABS_sample_stage")) return 468;
  if (!strcmp(compname, "DIFFABS_fluo")) return 469;
  if (!strcmp(compname, "DIFFABS_fluo_monitor")) return 470;
  if (!strcmp(compname, "DIFFABS_det_angle")) return 471;
  if (!strcmp(compname, "DIFFABS_xpad")) return 472;
  if (!strcmp(compname, "beamdump_487")) return 473;
  if (!strcmp(compname, "SEXTANTS")) return 474;
  if (!strcmp(compname, "SIXS_pos")) return 475;
  if (!strcmp(compname, "SIXS")) return 476;
  if (!strcmp(compname, "SIXS_Source_U20")) return 477;
  if (!strcmp(compname, "SIXS_mon_src_xy")) return 478;
  if (!strcmp(compname, "SIXS_mon_src_e")) return 479;
  if (!strcmp(compname, "SIXS_slit")) return 480;
  if (!strcmp(compname, "SIXS_slit_mon_xy")) return 481;
  if (!strcmp(compname, "SIXS_DCM_location")) return 482;
  if (!strcmp(compname, "SIXS_dcm_xtal0")) return 483;
  if (!strcmp(compname, "SIXS_dcm0")) return 484;
  if (!strcmp(compname, "SIXS_dcm_xtal1")) return 485;
  if (!strcmp(compname, "SIXS_dcm1")) return 486;
  if (!strcmp(compname, "SIXS_mon_dcm_e")) return 487;
  if (!strcmp(compname, "SIXS_mon_dcm_xy")) return 488;
  if (!strcmp(compname, "SIXS_M1_location")) return 489;
  if (!strcmp(compname, "SIXS_M1_rotated")) return 490;
  if (!strcmp(compname, "SIXS_M1")) return 491;
  if (!strcmp(compname, "SIXS_M1_out")) return 492;
  if (!strcmp(compname, "SIXS_M2_location")) return 493;
  if (!strcmp(compname, "SIXS_M2_rotated")) return 494;
  if (!strcmp(compname, "SIXS_M2")) return 495;
  if (!strcmp(compname, "SIXS_M2_out")) return 496;
  if (!strcmp(compname, "SIXS_sample_stage")) return 497;
  if (!strcmp(compname, "SIXS_sx_layer")) return 498;
  if (!strcmp(compname, "SIXS_sx_bulk")) return 499;
  if (!strcmp(compname, "SIXS_sample_out")) return 500;
  if (!strcmp(compname, "SIXS_det4pi")) return 501;
  if (!strcmp(compname, "SIXS_detector_layer")) return 502;
  if (!strcmp(compname, "SIXS_detector_bulk")) return 503;
  if (!strcmp(compname, "beamdump_519")) return 504;
  if (!strcmp(compname, "CASSIOPEE_pos")) return 505;
  if (!strcmp(compname, "CASSIOPEE")) return 506;
  if (!strcmp(compname, "CASSIOPEE_Source_HU60")) return 507;
  if (!strcmp(compname, "CASSIOPEE_Source_HU256")) return 508;
  if (!strcmp(compname, "CASSIOPEE_M1a_location")) return 509;
  if (!strcmp(compname, "CASSIOPEE_M1a")) return 510;
  if (!strcmp(compname, "CASSIOPEE_M1a_out")) return 511;
  if (!strcmp(compname, "CASSIOPEE_M1b")) return 512;
  if (!strcmp(compname, "CASSIOPEE_M1c")) return 513;
  if (!strcmp(compname, "CASSIOPEE_M1bc_out")) return 514;
  if (!strcmp(compname, "CASSIOPEE_PSD_M1out")) return 515;
  if (!strcmp(compname, "CASSIOPEE_PG_location")) return 516;
  if (!strcmp(compname, "CASSIOPEE_PG")) return 517;
  if (!strcmp(compname, "CASSIOPEE_M2_rotation_axis")) return 518;
  if (!strcmp(compname, "CASSIOPEE_M2")) return 519;
  if (!strcmp(compname, "CASSIOPEE_PM_takeoff")) return 520;
  if (!strcmp(compname, "CASSIOPEE_slit")) return 521;
  if (!strcmp(compname, "CASSIOPEE_M4")) return 522;
  if (!strcmp(compname, "CASSIOPEE_PSD")) return 523;
  if (!strcmp(compname, "beamdump_540")) return 524;
  if (!strcmp(compname, "SIRIUS_pos")) return 525;
  if (!strcmp(compname, "SIRIUS")) return 526;
  if (!strcmp(compname, "SIRIUS_source")) return 527;
  if (!strcmp(compname, "SIRIUS_M1_loc")) return 528;
  if (!strcmp(compname, "SIRIUS_M1_rot")) return 529;
  if (!strcmp(compname, "SIRIUS_M1")) return 530;
  if (!strcmp(compname, "SIRIUS_M1_out")) return 531;
  if (!strcmp(compname, "SIRIUS_DCM_location")) return 532;
  if (!strcmp(compname, "SIRIUS_bragg_crystal")) return 533;
  if (!strcmp(compname, "SIRIUS_arm_crystal1")) return 534;
  if (!strcmp(compname, "SIRIUS_bragg_crystal_two")) return 535;
  if (!strcmp(compname, "SIRIUS_arm_crystal2")) return 536;
  if (!strcmp(compname, "SIRIUS_DCM_out")) return 537;
  if (!strcmp(compname, "SIRIUS_DCM_out_div")) return 538;
  if (!strcmp(compname, "SIRIUS_DCM_out_e")) return 539;
  if (!strcmp(compname, "SIRIUS_def_loc")) return 540;
  if (!strcmp(compname, "SIRIUS_def_rot")) return 541;
  if (!strcmp(compname, "SIRIUS_def_mirror")) return 542;
  if (!strcmp(compname, "SIRIUS_def_out")) return 543;
  if (!strcmp(compname, "SIRIUS_sample_stage")) return 544;
  if (!strcmp(compname, "SIRIUS_fluo")) return 545;
  if (!strcmp(compname, "SIRIUS_det_2d")) return 546;
  if (!strcmp(compname, "SIRIUS_det_fluo")) return 547;
  if (!strcmp(compname, "beamdump_565")) return 548;
  if (!strcmp(compname, "LUCIA_pos")) return 549;
  if (!strcmp(compname, "LUCIA")) return 550;
  if (!strcmp(compname, "LUCIA_source")) return 551;
  if (!strcmp(compname, "LUCIA_mon_src_xy")) return 552;
  if (!strcmp(compname, "LUCIA_mon_src_e")) return 553;
  if (!strcmp(compname, "LUCIA_slit")) return 554;
  if (!strcmp(compname, "LUCIA_slit_mon_xy")) return 555;
  if (!strcmp(compname, "LUCIA_DCM_location")) return 556;
  if (!strcmp(compname, "LUCIA_dcm_xtal0")) return 557;
  if (!strcmp(compname, "LUCIA_dcm0")) return 558;
  if (!strcmp(compname, "LUCIA_dcm_xtal1")) return 559;
  if (!strcmp(compname, "LUCIA_dcm1")) return 560;
  if (!strcmp(compname, "LUCIA_mon_dcm_e")) return 561;
  if (!strcmp(compname, "LUCIA_mon_dcm_xy")) return 562;
  if (!strcmp(compname, "LUCIA_diaphragm")) return 563;
  if (!strcmp(compname, "LUCIA_sample_stage")) return 564;
  if (!strcmp(compname, "LUCIA_fluo_rotated")) return 565;
  if (!strcmp(compname, "LUCIA_sample")) return 566;
  if (!strcmp(compname, "LUCIA_transmission")) return 567;
  if (!strcmp(compname, "LUCIA_mon_spl_SDD")) return 568;
  if (!strcmp(compname, "LUCIA_mon_spl_fluo")) return 569;
  if (!strcmp(compname, "beamdump_588")) return 570;
  if (!strcmp(compname, "storage")) return 571;
  if (!strcmp(compname, "hall0")) return 572;
  if (!strcmp(compname, "hall1")) return 573;
  if (!strcmp(compname, "entrance_0")) return 574;
  if (!strcmp(compname, "entrance_1")) return 575;
  if (!strcmp(compname, "ANATOMIX_building")) return 576;
  if (!strcmp(compname, "soleil_label")) return 577;
  return -1;
}

/* embedding file "metadata-r.c" */

/** --- Contents of  metadata-r.c ---------------------------------------------------------------------------------- */
// Created by Gregory Tucker, Data Management Software Centre, European Spallation Source ERIC on 07/07/23.
#ifndef MCCODE_NAME
#include "metadata-r.h"
#endif

char * metadata_table_key_component(char* key){
  if (strlen(key) == 0) return NULL;
  char sep[2] = ":\0"; // matches any number of repeated colons
  // look for the separator in the provided key; strtok is allowed to modify the string, so copy it
  char * tok = malloc((strlen(key) + 1) * sizeof(char));
  if (!tok) {
    fprintf(stderr,"Error allocating token\n");
    exit(-1);
  }
  strcpy(tok, key);
  char * pch = strtok(tok, sep); // this *is* the component name (if provided) -- but we need to move the pointer
  char * comp = malloc((1 + strlen(pch)) * sizeof(char));
  if (!comp) {
    fprintf(stderr,"Error allocating comp\n");
    exit(-1);
  }
  strcpy(comp, pch);
  if (tok) free(tok);
  return comp;
}
char * metadata_table_key_literal(char * key){
  if (strlen(key) == 0) return NULL;
  char sep[3] = ":\0";
  char * tok = malloc((strlen(key) + 1 ) * sizeof(char));
  if (!tok) {
    fprintf(stderr,"Error allocating token\n");
    exit(-1);
  }
  strcpy(tok, key);
  char * pch = strtok(tok, sep); // this *is* the component name (if provided)
  if (pch) pch = strtok(NULL, sep); // either NULL or the literal name
  char * name = NULL;
  if (pch) {
    name = malloc((1 + strlen(pch)) * sizeof(char));
    if (!name) {
      fprintf(stderr,"Error allocating name\n");
	exit(-1);
    }
    strcpy(name, pch);
  }
  if (tok) free(tok);
  return name;
}
int metadata_table_defined(int no, metadata_table_t * tab, char * key){
  if (strlen(key) == 0){
    /* This is 0 instead of `no` independent of any wildcard-matching logic
     * because a caller _already_ knows `no` and can verify
     * that `key` is not "" at call-time. So returning `no` is useless.
     */
    return 0;
  }
  char * comp = metadata_table_key_component(key);
  char * name = metadata_table_key_literal(key);
  // look through the table for the matching component and literal names
  int number = 0;
  for (int i=0; i<no; ++i){
    if (!strcmp(comp, tab[i].source)){
      if (name == NULL || !strcmp(name, tab[i].name)) ++number;
    }
  }
  if (comp) free(comp);
  if (name) free(name);
  return number;
}

char * metadata_table_name(int no, metadata_table_t * tab, char *key){
    if (strlen(key) == 0){
        return NULL;
    }
    char * comp = metadata_table_key_component(key);
    char * name = metadata_table_key_literal(key);
    if (name == NULL) {
        for (int i=0; i<no; ++i){
            if (!strcmp(comp, tab[i].source)){
                name = malloc((strlen(tab[i].name) + 1) * sizeof(char));
		if (!name) {
		  fprintf(stderr,"Error allocating metadata_table_name\n");
		  exit(-1);
		}
                strcpy(name, tab[i].name);
                break;
            }
        }
    } else {
        int found=0;
        for (int i=0; i<no; ++i){
            if (!strcmp(comp, tab[i].source) && !strcmp(name, tab[i].name)) {
                found = 1;
                break;
            }
        }
        if (!found) free(name);
    }
    free(comp);
    return name;
}

char * metadata_table_type(int no, metadata_table_t * tab, char * key){
  if (strlen(key) == 0) {
    fprintf(stderr, "Unable to check type of non-existent key\n");
    exit(1);
  }
  char * comp = metadata_table_key_component(key);
  char * name = metadata_table_key_literal(key);
  if (name == NULL){
    fprintf(stderr, "Unable to check type of literal for component %s without its name\n", comp);
    free(comp);
    exit(1);
  }
  char * type = NULL;
  for (int i=0; i<no; ++i){
    if (!strcmp(comp, tab[i].source) && !strcmp(name, tab[i].name)) type = tab[i].type;
  }
  if (comp) free(comp);
  if (name) free(name);
  return type;
}

char * metadata_table_literal(int no, metadata_table_t * tab, char * key){
  if (strlen(key) == 0) {
    fprintf(stderr, "Unable to retrieve literal for non-existent key\n");
    exit(1);
  }
  char * comp = metadata_table_key_component(key);
  char * name = metadata_table_key_literal(key);
  if (name == NULL){
    fprintf(stderr, "Unable to retrieve literal for component %s without its name\n", comp);
    free(comp);
    exit(1);
  }
  char * type = NULL;
  for (int i=0; i<no; ++i){
    if (!strcmp(comp, tab[i].source) && !strcmp(name, tab[i].name)) type = tab[i].value;
  }
  if (comp) free(comp);
  if (name) free(name);
  return type;
}
void metadata_table_print_all_keys(int no, metadata_table_t * tab){
  for (int i=0; i<no; ++i){
    printf("%s::%s ", tab[i].source, tab[i].name);
  }
  printf("\n");
}
int metadata_table_print_all_components(int no, metadata_table_t * tab){
  int count = 0;
  char ** known = malloc(no * sizeof(char*));
  if (!known) {
    fprintf(stderr,"Error allocating table of known metadata\n");
    exit(-1);
  }
  for (int i=0; i<no; ++i){
    int unknown = 1;
    for (int j=0; j<count; ++j) if (!strcmp(tab[i].source, known[j])) unknown = 0;
    if (unknown) known[count++] = tab[i].source;
  }
  size_t nchar = 0;
  for (int i=0; i<count; ++i) nchar += strlen(known[i]) + 1;
  char * line = malloc((nchar + 1) * sizeof(char));
  char * linetmp = malloc((nchar + 1) * sizeof(char));
  if (!line || !linetmp) {
    fprintf(stderr,"Error allocating metadata print arrays\n");
    exit(-1);
  }
  line[0] = '\0';
  for (int i=0; i<count; ++i) sprintf(linetmp, "%s%s ", line, known[i]);
  line=linetmp;
  line[strlen(line)] = '\0'; // eat the trailing space
  printf("%s\n", line);
  free(line);
  free(linetmp);
  free(known);
  return count;
}
int metadata_table_print_component_keys(int no, metadata_table_t * tab, char * key){
  char * comp = metadata_table_key_component(key);
  char * name = metadata_table_key_literal(key);
  int count = 0;
  for (int i=0; i<no; ++i) if (!strcmp(tab[i].source, comp) && (name == NULL || !strcmp(tab[i].name, name))) {
    if (name == NULL) printf("%s ", tab[i].name);
    ++count;
  }
  if (name != NULL) printf("%d", count); // replace count by strlen(tab[i].value)?
  printf("\n");
  return count;
}
/* -------------------------------------------------------------------------------------Contents of  metadata-r.c --- */
/* End of file "metadata-r.c". */

/* embedding file "mccode_main.c" */

/*******************************************************************************
* mccode_main: McCode main() function.
*******************************************************************************/
int mccode_main(int argc, char *argv[])
{
  /*  double run_num = 0; */
  time_t  t;
  clock_t ct;

#ifdef USE_MPI
  char mpi_node_name[MPI_MAX_PROCESSOR_NAME];
  int  mpi_node_name_len;
#endif /* USE_MPI */

#ifdef MAC
  argc = ccommand(&argv);
#endif

#ifdef USE_MPI
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD, &mpi_node_count); /* get number of nodes */
  MPI_Comm_rank(MPI_COMM_WORLD, &mpi_node_rank);
  /* PW 2026100 - workaround for issue on macOS arm64 with openmpi=5:
    https://github.com/open-mpi/ompi/issues/14558
    MPI_Comm_set_name(MPI_COMM_WORLD, instrument_name); */
  MPI_Get_processor_name(mpi_node_name, &mpi_node_name_len);
#endif /* USE_MPI */

  ct = clock();

  // device and host functional RNG seed
  struct timeval tm;
  gettimeofday(&tm, NULL);
  mcseed = (long) tm.tv_sec*1000000 + tm.tv_usec;
  mcstartdate = (long)tm.tv_sec;  /* set start date before parsing options and creating sim file */
  // init global _particle.randstate for random number use
  // during init(), finally() and display(). NOTE: during trace, a local
  // "_particle" variable is present and thus used instead.
  //
  // PW: srandom deferred until init() since we did not read seed input from commandline
  //srandom(_hash(mcseed-1));

#ifdef USE_MPI
  /* *** print number of nodes *********************************************** */
  if (mpi_node_count > 1) {
    MPI_MASTER(
    printf("Simulation '%s' (%s): running on %i nodes (master is '%s', MPI version %i.%i).\n",
      instrument_name, instrument_source, mpi_node_count, mpi_node_name, MPI_VERSION, MPI_SUBVERSION);
    );
    /* share the same seed, then adapt random seed for each node */
    MPI_Bcast(&mcseed, 1, MPI_LONG, 0, MPI_COMM_WORLD); /* root sends its seed to slaves */
    mcseed += mpi_node_rank; /* make sure we use different seeds per noe */
  }
#endif /* USE_MPI */

#ifdef OPENACC
#ifdef USE_MPI
  int num_devices = acc_get_num_devices(acc_device_nvidia);
  if(num_devices>0){
    int my_device = mpi_node_rank % num_devices;
    acc_set_device_num( my_device, acc_device_nvidia );
    printf("Have found %d GPU devices on rank %d. Will use device %d.\n", num_devices, mpi_node_rank, my_device);
  }else{
    printf("There was an issue probing acc_get_num_devices, fallback to host\n");
    acc_set_device_type( acc_device_host );
  }
#endif
#endif

  /* *** parse options ******************************************************* */
  SIG_MESSAGE("[" __FILE__ "] main START");
  mcformat = getenv(FLAVOR_UPPER "_FORMAT") ?
             getenv(FLAVOR_UPPER "_FORMAT") : FLAVOR_UPPER;
  instrument_exe = argv[0]; /* store the executable path */
  /* read simulation parameters and options */
  mcparseoptions(argc, argv); /* sets output dir and format */


#ifdef USE_MPI
  if (mpi_node_count > 1) {
    /* share the same seed, then adapt random seed for each node */
    MPI_Bcast(&mcseed, 1, MPI_LONG, 0, MPI_COMM_WORLD); /* root sends its seed to slaves */
    mcseed += mpi_node_rank; /* make sure we use different seeds per node */
  }
#endif


/* *** install sig handler, but only once !! after parameters parsing ******* */
#ifndef NOSIGNALS
#ifdef SIGQUIT
  if (signal( SIGQUIT ,sighandler) == SIG_IGN)
    signal( SIGQUIT,SIG_IGN);   /* quit (ASCII FS) */
#endif
#ifdef SIGABRT
  if (signal( SIGABRT ,sighandler) == SIG_IGN)
    signal( SIGABRT,SIG_IGN);   /* used by abort, replace SIGIOT in the future */
#endif
#ifdef SIGTERM
  if (signal( SIGTERM ,sighandler) == SIG_IGN)
    signal( SIGTERM,SIG_IGN);   /* software termination signal from kill */
#endif
#ifdef SIGUSR1
  if (signal( SIGUSR1 ,sighandler) == SIG_IGN)
    signal( SIGUSR1,SIG_IGN);   /* display simulation status */
#endif
#ifdef SIGUSR2
  if (signal( SIGUSR2 ,sighandler) == SIG_IGN)
    signal( SIGUSR2,SIG_IGN);
#endif
#ifdef SIGHUP
  if (signal( SIGHUP ,sighandler) == SIG_IGN)
    signal( SIGHUP,SIG_IGN);
#endif
#ifdef SIGILL
  if (signal( SIGILL ,sighandler) == SIG_IGN)
    signal( SIGILL,SIG_IGN);    /* illegal instruction (not reset when caught) */
#endif
#ifdef SIGFPE
  if (signal( SIGFPE ,sighandler) == SIG_IGN)
    signal( SIGSEGV,SIG_IGN);    /* floating point exception */
#endif
#ifdef SIGBUS
  if (signal( SIGBUS ,sighandler) == SIG_IGN)
    signal( SIGSEGV,SIG_IGN);    /* bus error */
#endif
#ifdef SIGSEGV
  if (signal( SIGSEGV ,sighandler) == SIG_IGN)
    signal( SIGSEGV,SIG_IGN);   /* segmentation violation */
#endif
#endif /* !NOSIGNALS */


  // init executed by master/host
  siminfo_init(NULL); /* open SIM */
  SIG_MESSAGE("[" __FILE__ "] main INITIALISE");
  init();

#ifdef USE_NEXUS
  /* store component SETTING parameter values as present at end of INITIALISE */
  MPI_MASTER(
    if (nxhandle && !mcdotrace && mcformat && strcasestr(mcformat, "NeXus"))
      mccomp_param_runtime_nexus_all(nxhandle);
  );
#endif


#ifndef NOSIGNALS
#ifdef SIGINT
  if (signal( SIGINT ,sighandler) == SIG_IGN)
    signal( SIGINT,SIG_IGN);    /* interrupt (rubout) only after INIT */
#endif
#endif /* !NOSIGNALS */

/* ================ main particle generation/propagation loop ================ */
#ifdef USE_MPI
  /* sliced Ncount on each MPI node */
  mcncount = mpi_node_count > 1 ?
    floor(mcncount / mpi_node_count) :
    mcncount; /* number of rays per node */
#endif

// MT specific init, note that per-ray init is empty
#if RNG_ALG == 1
  mt_srandom(mcseed);
#endif


// main raytrace work loop
#ifndef FUNNEL
  // legacy version
  raytrace_all(mcncount, mcseed);
#else
  MPI_MASTER(
  // "funneled" version in which propagation is more parallelizable
  printf("\nNOTE: CPU COMPONENT grammar activated:\n 1) \"FUNNEL\" raytrace algorithm enabled.\n 2) Any SPLIT's are dynamically allocated based on available buffer size. \n");
	     );
  raytrace_all_funnel(mcncount, mcseed);
#endif


#ifdef USE_MPI
 /* merge run_num from MPI nodes */
  if (mpi_node_count > 1) {
  double mcrun_num_double = (double)mcrun_num;
  mc_MPI_Sum(&mcrun_num_double, 1);
  mcrun_num = (unsigned long long)mcrun_num_double;
  }
#endif


  // save/finally executed by master node/thread/host
  // All MPI nodes reach this final save together: collective output (e.g.
  // gathering event lists on the master) is only allowed from here on.
  mcsave_final = 1;
  finally();


#ifdef USE_MPI
  MPI_Finalize();
#endif /* USE_MPI */


  return 0;
} /* mccode_main */
/* End of file "mccode_main.c". */

/* end of generated C code ./SOLEIL.c */
