/*******************************************************************************
*
* McStas, the neutron ray-tracing package: Guide_four_side_inlay.comp
*
* Component: Guide_four_side_2_shells
*
* %I
* Written by: Tobias Panzner
* Date: 02/12/2009
* Version: $Revision: 1.0 $
* Release: McStas 1.12b
* Origin: PSI
*
* %D
*  This component models a multichannel guide with a core and two outer shells.
*  As user you can controll the properties of every wall of the core and the shells 
*  separatly. All togther you have
*  24 walls: From the core 4 inner walls and four outer walls and from each outer
*  shells 4 inner and 4 outer walls. Neutrons outside the outer channel will pass by. 
* 
*  Every single wall can have a elliptic, parabolic or straight shape.
*  All four sides of the guide are independent from each other.
*  In the elliptic case the side wall shape follows the equation x^2/b^2+(z+z0)^2/a^2=1
*  (the center of the ellipse is located at (0,-z0)).
*  In the parabolic case the side wall shape follows the equation z=b-ax^2;mc
*  In the straight case the side wall shape follows the equation z=l/(w2-w1)*x-w1.
*
*  The shape selection is done by the focal points. The focal points are located at the 
*  z-axis and are defined by their distance to the entrance or exit window of the guide
*  (in the following called 'focal length').
*
*  If both focal lengths for one wall are zero it will be a straight wall (entrance and 
*  exit width have to be given in the beginning).
*
*  If one of the focal lengths is not zero the shape will be parabolic (only the entrance width 
*  given in the beginning is recognized; exit width will be calculated). If the the entrance 
*  focal length is zero the guide will be a focusing devise.
*  If the exit focal length is zero it will be defocusing devise.
*
*  If both focals are non zero the shape of the wall will be elliptic (only the entrance width 
*  given in the beginning is recognized; exit width will be calculated). 
*
*  Notice: 1.)The focal points are in general located outside the guide (positive focal lengths).
*             Focal points inside the guide need to have negative focal lengths.
*          2.)The exit width parameters (w2r, w2l, h2u,h2d) are only taken into account if the 
*             walls have a linear shape. In the ellitic or parabolic case they will be ignored.
*
*  For the inner channel: the outer side of each wall is calculated by the component in depentence 
*  of the wallthickness and the shape of the inner side.
*
*  Each of the 24 walls can have a own indepenting reflecting layer defined by a file or it can 
*  be a absorber or it can be transparent.
*
*  The reflectivity properties can be given by an input file (Format [q(Angs-1) R(0-1)]) or by 
*  parameters (Qc, alpha, m, W).
*
* %BUGS
* This component does not work with gravitation on.
*
* This component does not work correctly in GROUP-modus.
*
* %P
* INPUT PARAMETERS:
*
* GENERAL PARAMETERS (VALID FOR ALL 12 SIDES):
*
* l:       [m]    length of guide (DEFAULT = 0)
*
* R0:      [1]    Low-angle reflectivity (DEFAULT = 0.99)
*
* THE INNER WALLS OF THE INLAY ARE DEFINED BY:
*
* w1r:     [m]    Width at the right guide entry   (negative x-axis)
*                 (DEFAULT = 0)
*
* w2r:     [m]    Width at the right guide exit    (negative x-axis)
*                 (DEFAULT = 0)
*
* w1l:     [m]    Width at the left guide entry    (positive x-axis)
*                 (DEFAULT = 0)
*
* w2l:     [m]    Width at the left guide exit     (positive x-axis)
*                 (DEFAULT = 0)
*
* h1d:     [m]    Height at the bottom guide entry (negative y-axis)
*                 (DEFAULT = 0)
*
* h2d:     [m]    Height at the bottom guide entry (negative y-axis)
*                 (DEFAULT = 0)
*
* h1u:     [m]    Height at the top guide entry    (positive y-axis)
*                 (DEFAULT = 0)
*
* h2u:     [m]    Height at the top guide entry    (positive y-axis)
*                 (DEFAULT = 0)
*
* linwr     [m]   right horizontal wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0)
*
* loutwr   [m]    right horizontal wall: distance of 2nd focal point
*                 and guide exit (DEFAULT = 0)
*
* linwl    [m]    left horizontal wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0)
*
* loutwl   [m]    left horizontal wall: distance of 2nd focal point
*                 and guide exit  (DEFAULT = 0)
*
* linhd    [m]    lower vertical wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0)
*
* louthd   [m]    lower vertical wall: distance of 2nd focal point
*                 and guide exit (DEFAULT = 0)
*
* linhu    [m]    upper vertical wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0) 
*
* louthu   [m]    upper vertical wall: distance of 2nd focal point
*                 and guide exit (DEFAULT = 0)
*
* RIreflect: (str)  Name of relfectivity file for the right inner wall.
*                   Format [q(Angs-1) R(0-1)]  (DEFAULT : no file)
*
* LIreflect: (str)  Name of relfectivity file for the left inner wall.
*                   Format [q(Angs-1) R(0-1)]   (DEFAULT : no file)
* 
* DIreflect: (str)  Name of relfectivity file for the bottom inner wall.
*                   Format [q(Angs-1) R(0-1)] (DEFAULT : no file)
*
* UIreflect: (str)  Name of relfectivity file for the top inner wall. 
*                   Format [q(Angs-1) R(0-1)]    (DEFAULT : no file)
*
* Qcxr:    [AA-1] Critical scattering vector for right vertical
*                 inner wall (DEFAULT = 0.0217)
*
* Qcxl:    [AA-1] Critical scattering vector for left vertical
*                 inner wall (DEFAULT = 0.0217)
*
* Qcyd:    [AA-1] Critical scattering vector for bottom inner wall
*                 (DEFAULT = 0.0217)
*
* Qcyu:    [AA-1] Critical scattering vector for top inner wall
*                 (DEFAULT = 0.0217)
*
* alphaxr: [AA]   Slope of reflectivity for right vertical
*                 inner wall (DEFAULT = 6.07)
*
* alphaxl: [AA]   Slope of reflectivity for left vertical
*                 inner wall (DEFAULT = 6.07)
*
* alphayd: [AA]   Slope of reflectivity for bottom inner wall
*                 (DEFAULT = 6.07)
*
* alphayu: [AA]   Slope of reflectivity for top inner wall
*                 (DEFAULT = 6.07)
*
* mxr:     [1]    m-value of material for right vertical inner wall.
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = 3.6)
*
* mxl:     [1]    m-value of material for left vertical inner wall.
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = 3.6)
*
* myd:     [1]    m-value of material for bottom inner wall
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = 3.6)
*
* myu:     [1]    m-value of material for top inner wall
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = 3.6)
*
* Wxr:       [AA-1] Width of supermirror cut-off for right inner wall
*                   (DEFAULT = 0.003)
*
* Wxl:       [AA-1] Width of supermirror cut-off for left inner wall
*                   (DEFAULT = 0.003)
*
* Wyu:       [AA-1] Width of supermirror cut-off for top inner wall
*                   (DEFAULT = 0.003)
*
* Wyd:       [AA-1] Width of supermirror cut-off for bottom inner wall
*                   (DEFAULT = 0.003)
*
* rwallthick: [m]   thickness of the right wall (DEFAULT = 0.001 m)
*
* lwallthick: [m]   thickness of the left wall  (DEFAULT = 0.001 m)
*
* uwallthick: [m]   thickness of the top wall   (DEFAULT = 0.001 m)
*
* dwallthick: [m]   thickness of the bottom wall(DEFAULT = 0.001 m)
*
*   THE OUTER WALLS OF THE INLAY ARE DEFINED BY: 
*
* ROreflect: (str)  Name of relfectivity file for the right outer wall.
*                   Format [q(Angs-1) R(0-1)]  (DEFAULT : no file)
*
* LOreflect: (str)  Name of relfectivity file for the left outer wall.
*                   Format [q(Angs-1) R(0-1)]   (DEFAULT : no file)
* 
* DOreflect: (str)  Name of relfectivity file for the bottom outer wall.
*                   Format [q(Angs-1) R(0-1)] (DEFAULT : no file)
*
* UOreflect: (str)  Name of relfectivity file for the top outer wall.
*                   Format [q(Angs-1) R(0-1)]    (DEFAULT : no file)
*
* QcxrOW:    [AA-1] Critical scattering vector for right vertical
*                   outer wall (DEFAULT = 0.0217)
*
* QcxlOW:    [AA-1] Critical scattering vector for left vertical
*                   outer wall (DEFAULT = 0.0217)
*
* QcydOW:    [AA-1] Critical scattering vector for bottom outer wall
*                   (DEFAULT = 0.0217)
*
* QcyuOW:    [AA-1] Critical scattering vector for top outer wall
*                   (DEFAULT = 0.0217)
*
* alphaxrOW: [AA]   Slope of reflectivity for right vertical
*                   outer wall (DEFAULT = 6.07)
*
* alphaxlOW: [AA]   Slope of reflectivity for left vertical
*                   outer wall (DEFAULT = 6.07)
*
* alphaydOW: [AA]   Slope of reflectivity for bottom outer wall
*                   (DEFAULT = 6.07)
*
* alphayuOW: [AA]   Slope of reflectivity for top outer wall
*                   (DEFAULT = 6.07)
*
* mxrOW:     [1]   m-value of material for right vertical outer wall
*                  0 means the wall is absorbing. (DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = 0)
*
* mxlOW:     [1]   m-value of material for left vertical outer wall
*                  0 means the wall is absorbing.(DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = 0)
*
* mydOW:     [1]   m-value of material for bottom outer wall
*                  0 means the wall is absorbing. (DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = 0)
*
* myuOW:     [1]   m-value of material for top outer wall
*                  0 means the wall is absorbing. (DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = 0)
*
* WxrOW:       [AA-1] Width of supermirror cut-off for right outer wall
*                     (DEFAULT = 0.003)
*
* WxlOW:       [AA-1] Width of supermirror cut-off for left outer wall
*                     (DEFAULT = 0.003)
*
* WyuOW:       [AA-1] Width of supermirror cut-off for top outer wall
*                     (DEFAULT = 0.003)
*
* WydOW:       [AA-1] Width of supermirror cut-off for bottom outer wall
*                     (DEFAULT = 0.003)
*
* THE INNER WALLS OF THE OUTER CHANNEL @ ARE DEFINED BY:	
*
* w1r@:     [m]    Width at the right guide entry   (negative x-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* w2r@:     [m]    Width at the right guide exit    (negative x-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* w1l@:     [m]    Width at the left guide entry    (positive x-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* w2l@:     [m]    Width at the left guide exit     (positive x-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* h1d@:     [m]    Height at the bottom guide entry (negative y-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* h2d@:     [m]    Height at the bottom guide entry (negative y-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* h1u@:     [m]    Height at the top guide entry    (positive y-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* h2u@:     [m]    Height at the top guide entry    (positive y-axis)
*                 (DEFAULT = 2.00 + 2*@)
*
* linwr@     [m]   right horizontal wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0)
*
* loutwr@   [m]    right horizontal wall: distance of 2nd focal point
*                 and guide exit (DEFAULT = 0)
*
* linwl@    [m]    left horizontal wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0)
*
* loutwl@   [m]    left horizontal wall: distance of 2nd focal point
*                 and guide exit  (DEFAULT = 0)
*
* linhd@    [m]    lower vertical wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0)
*
* louthd@   [m]    lower vertical wall: distance of 2nd focal point
*                 and guide exit (DEFAULT = 0)
*
* linhu@    [m]    upper vertical wall: distance of 1st focal point
*                 and guide entry (DEFAULT = 0) 
*
* louthu@   [m]    upper vertical wall: distance of 2nd focal point
*                 and guide exit (DEFAULT = 0)
*
* aRIreflect@: (str)  Name of relfectivity file for the right inner wall.
*                   Format [q(Angs-1) R(0-1)]  (DEFAULT : no file)
*
* aLIreflect@: (str)  Name of relfectivity file for the left inner wall.
*                   Format [q(Angs-1) R(0-1)]   (DEFAULT : no file)
* 
* aDIreflect@: (str)  Name of relfectivity file for the bottom inner wall.
*                   Format [q(Angs-1) R(0-1)] (DEFAULT : no file)
*
* aUIreflect@: (str)  Name of relfectivity file for the top inner wall. 
*                   Format [q(Angs-1) R(0-1)]    (DEFAULT : no file)
*
* Qcxr@:    [AA-1] Critical scattering vector for right vertical
*                 inner wall (DEFAULT = 0.0217)
*
* Qcxl@:    [AA-1] Critical scattering vector for left vertical
*                 inner wall (DEFAULT = 0.0217)
*
* Qcyd@:    [AA-1] Critical scattering vector for bottom inner wall
*                 (DEFAULT = 0.0217)
*
* Qcyu@:    [AA-1] Critical scattering vector for top inner wall
*                 (DEFAULT = 0.0217)
*
* alphaxr@: [AA]   Slope of reflectivity for right vertical
*                 inner wall (DEFAULT = 6.07)
*
* alphaxl@: [AA]   Slope of reflectivity for left vertical
*                 inner wall (DEFAULT = 6.07)
*
* alphayd@: [AA]   Slope of reflectivity for bottom inner wall
*                 (DEFAULT = 6.07)
*
* alphayu@: [AA]   Slope of reflectivity for top inner wall
*                 (DEFAULT = 6.07)
*
* mxr@:     [1]    m-value of material for right vertical inner wall.
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = -1)
*
* mxl@:     [1]    m-value of material for left vertical inner wall.
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = -1)
*
* myd@:     [1]    m-value of material for bottom inner wall
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = -1)
*
* myu@:     [1]    m-value of material for top inner wall
*                  0 means the wall is absorbing.
*		  -1 means the wall is transparent.
*                 (DEFAULT = -1)
*
* Wxr@:       [AA-1] Width of supermirror cut-off for right inner wall
*                   (DEFAULT = 0.003)
*
* Wxl@:       [AA-1] Width of supermirror cut-off for left inner wall
*                   (DEFAULT = 0.003)
*
* Wyu@:       [AA-1] Width of supermirror cut-off for top inner wall
*                   (DEFAULT = 0.003)
*
* Wyd@:       [AA-1] Width of supermirror cut-off for bottom inner wall
*                   (DEFAULT = 0.003)
*
* rwallthick@: [m]   thickness of the right wall (DEFAULT = 0.001 m)
*
* lwallthick@: [m]   thickness of the left wall  (DEFAULT = 0.001 m)
*
* uwallthick@: [m]   thickness of the top wall   (DEFAULT = 0.001 m)
*
* dwallthick@: [m]   thickness of the bottom wall(DEFAULT = 0.001 m)
*
*   THE OUTER WALLS OF THE OUTER CHANNEL @ ARE DEFINED BY: 
*
* ROreflect@: (str)  Name of relfectivity file for the right outer wall.
*                   Format [q(Angs-1) R(0-1)]  (DEFAULT : no file)
*
* LOreflect@: (str)  Name of relfectivity file for the left outer wall.
*                   Format [q(Angs-1) R(0-1)]   (DEFAULT : no file)
* 
* DOreflect@: (str)  Name of relfectivity file for the bottom outer wall.
*                   Format [q(Angs-1) R(0-1)] (DEFAULT : no file)
*
* UOreflect@: (str)  Name of relfectivity file for the top outer wall.
*                   Format [q(Angs-1) R(0-1)]    (DEFAULT : no file)
*
* QcxrOW@:    [AA-1] Critical scattering vector for right vertical
*                   outer wall (DEFAULT = 0.0217)
*
* QcxlOW@:    [AA-1] Critical scattering vector for left vertical
*                   outer wall (DEFAULT = 0.0217)
*
* QcydOW@:    [AA-1] Critical scattering vector for bottom outer wall
*                   (DEFAULT = 0.0217)
*
* QcyuOW@:    [AA-1] Critical scattering vector for top outer wall
*                   (DEFAULT = 0.0217)
*
* alphaxrOW@: [AA]   Slope of reflectivity for right vertical
*                   outer wall (DEFAULT = 6.07)
*
* alphaxlOW@: [AA]   Slope of reflectivity for left vertical
*                   outer wall (DEFAULT = 6.07)
*
* alphaydOW@: [AA]   Slope of reflectivity for bottom outer wall
*                   (DEFAULT = 6.07)
*
* alphayuOW@: [AA]   Slope of reflectivity for top outer wall
*                   (DEFAULT = 6.07)
*
* mxrOW@:     [1]   m-value of material for right vertical outer wall
*                  0 means the wall is absorbing. (DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = -1)
*
* mxlOW@:     [1]   m-value of material for left vertical outer wall
*                  0 means the wall is absorbing.(DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = -1)
*
* mydOW@:     [1]   m-value of material for bottom outer wall
*                  0 means the wall is absorbing. (DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = -1)
*
* myuOW@:     [1]   m-value of material for top outer wall
*                  0 means the wall is absorbing. (DEFAULT)
*		  -1 means the wall is transparent.
*                  (DEFAULT = -1)
*
* WxrOW@:       [AA-1] Width of supermirror cut-off for right outer wall
*                     (DEFAULT = 0.003)
*
* WxlOW@:       [AA-1] Width of supermirror cut-off for left outer wall
*                     (DEFAULT = 0.003)
*
* WyuOW@:       [AA-1] Width of supermirror cut-off for top outer wall
*                     (DEFAULT = 0.003)
*
* WydOW@:       [AA-1] Width of supermirror cut-off for bottom outer wall
*                     (DEFAULT = 0.003)
*
*
* %End
*
******************************************************************************/

DEFINE COMPONENT Guide_four_side_2_shells
DEFINITION PARAMETERS(string RIreflect=0, LIreflect=0, UIreflect=0, DIreflect=0, ROreflect=0, LOreflect=0, UOreflect=0, DOreflect=0, RIreflect1=0, LIreflect1=0, UIreflect1=0, DIreflect1=0, ROreflect1=0, LOreflect1=0, UOreflect1=0, DOreflect1=0,RIreflect2=0, LIreflect2=0, UIreflect2=0, DIreflect2=0, ROreflect2=0, LOreflect2=0, UOreflect2=0, DOreflect2=0)
SETTING PARAMETERS (w1l=0,w2l=0,linwl=0,loutwl=0,
                    w1r=0,w2r=0,linwr=0,loutwr=0,
                    h1u=0,h2u=0,linhu=0,louthu=0,
                    h1d=0,h2d=0,linhd=0,louthd=0,
                    l=0, R0=0.99,
                    Qcxl=0.0217,Qcxr=0.0217,Qcyu=0.0217, Qcyd=0.0217,
                    alphaxl=6.07, alphaxr=6.07, alphayu=6.07, alphayd=6.07,
                    Wxr=0.003,Wxl=0.003,Wyu=0.003,Wyd=0.003,
                    mxr=3.6, mxl=3.6, myu=3.6, myd=3.6,
                    QcxrOW=0.0217,QcxlOW=0.0217,QcyuOW=0.0217, QcydOW=0.0217,
                    alphaxlOW=6.07, alphaxrOW=6.07, alphayuOW=6.07, alphaydOW=6.07,
                    WxrOW=0.003,WxlOW=0.003,WyuOW=0.003,WydOW=0.003,
                    mxrOW=0, mxlOW=0, myuOW=0, mydOW=0,
		    rwallthick=0.001,lwallthick=0.001,uwallthick=0.001,dwallthick=0.001,

                    w1l1=2.002,w2l1=2.002,linwl1=0,loutwl1=0,
                    w1r1=2.002,w2r1=2.002,linwr1=0,loutwr1=0,
                    h1u1=2.002,h2u1=2.002,linhu1=0,louthu1=0,
                    h1d1=2.002,h2d1=2.002,linhd1=0,louthd1=0,
                    Qcxl1=0.0217,Qcxr1=0.0217,Qcyu1=0.0217, Qcyd1=0.0217,
                    alphaxl1=6.07, alphaxr1=6.07, alphayu1=6.07, alphayd1=6.07,
                    Wxr1=0.003,Wxl1=0.003,Wyu1=0.003,Wyd1=0.003,
                    mxr1=-1, mxl1=-1, myu1=-1, myd1=-1,
                    QcxrOW1=0.0217,QcxlOW1=0.0217,QcyuOW1=0.0217, QcydOW1=0.0217,
                    alphaxlOW1=6.07, alphaxrOW1=6.07, alphayuOW1=6.07, alphaydOW1=6.07,
                    WxrOW1=0.003,WxlOW1=0.003,WyuOW1=0.003,WydOW1=0.003,
                    mxrOW1=-1, mxlOW1=-1, myuOW1=-1, mydOW1=-1,
		    rwallthick1=0.001,lwallthick1=0.001,uwallthick1=0.001,dwallthick1=0.001,

                    w1l2=2.004,w2l2=2.004,linwl2=0,loutwl2=0,
                    w1r2=2.004,w2r2=2.004,linwr2=0,loutwr2=0,
                    h1u2=2.004,h2u2=2.004,linhu2=0,louthu2=0,
                    h1d2=2.004,h2d2=2.004,linhd2=0,louthd2=0,
                    Qcxl2=0.0217,Qcxr2=0.0217,Qcyu2=0.0217, Qcyd2=0.0217,
                    alphaxl2=6.07, alphaxr2=6.07, alphayu2=6.07, alphayd2=6.07,
                    Wxr2=0.003,Wxl2=0.003,Wyu2=0.003,Wyd2=0.003,
                    mxr2=-1, mxl2=-1, myu2=-1, myd2=-1,
                    QcxrOW2=0.0217,QcxlOW2=0.0217,QcyuOW2=0.0217, QcydOW2=0.0217,
                    alphaxlOW2=6.07, alphaxrOW2=6.07, alphayuOW2=6.07, alphaydOW2=6.07,
                    WxrOW2=0.003,WxlOW2=0.003,WyuOW2=0.003,WydOW2=0.003,
                    mxrOW2=-1, mxlOW2=-1, myuOW2=-1, mydOW2=-1,
		    rwallthick2=0.001,lwallthick2=0.001,uwallthick2=0.001,dwallthick2=0.001)

OUTPUT PARAMETERS(w1rwt,w1lwt,h1uwt,h1dwt,w2rwt,w2lwt,h2uwt,h2dwt,
                  pawr,pawl,pbwr,pbwl,pahu,pahd,pbhu,pbhd,
                  awl,bwl,awr,bwr,ahu,bhu,ahd,bhd,
                  awlwt,bwlwt,awrwt,bwrwt,ahuwt,bhuwt,ahdwt,bhdwt,
                  pawrwt,pawlwt,pbwrwt,pbwlwt,pahuwt,pahdwt,pbhuwt,pbhdwt,
                  t1,t2w1r,t2w2r,t2w1l,t2w2l,t2h1u,t2h2u,t2h1d,t2h2d,
                  t2w1rwt,t2w2rwt,t2w1lwt,t2w2lwt,t2h1uwt,t2h2uwt,t2h1dwt,t2h2dwt,

		  a2wlwt,b2wlwt,a2wrwt,b2wrwt,a2huwt,b2huwt,a2hdwt,b2hdwt,
                  a2wl,b2wl,a2wr,b2wr,a2hu,b2hu,a2hd,b2hd,
                  mru1,mru2,nru1,nru2,mrd1,mrd2,nrd1,nrd2,mlu1,mlu2,nlu1,nlu2,mld1,mld2,nld1,nld2,
                  z0wr,z0wl,z0hu,z0hd,
		
		  lbwl,lbwr,lbhu,lbhd,
                  p2parawr,p2parawl,p2parahu,p2parahd,
                  u1wl,u2wl,u1wr,u2wr,u1hu,u2hu,u1hd,u2hd,
                  DIV1wl,DIV1wr,DIV1hu,DIV1hd,
                  p2parawrwt,p2parawlwt,p2parahuwt,p2parahdwt,
                  DIV1wlwt,DIV1wrwt,DIV1huwt,DIV1hdwt,
                  u1wrwt,u2wrwt,u1wlwt,u2wlwt,u1huwt,u2huwt,u1hdwt,u2hdwt,
                  dxwr,dzwr,dxwl,dzwl,dyhu,dzhu,dyhd,dzhd,

                  zw1r,zw2r,zw1l,zw2l,zh1u,zh2u,zh1d,zh2d,m,n,
                  pwr,qwr,pwl,qwl,phu,qhu,phd,qhd,
                  nz,nx,ny,n2,
                  pf,
                  vxin,vyin,vzin,
                  q,
                  xintersecwr,xintersecwl,yintersechd,yintersechu,
                  xlimitr,xlimitrwt,xlimitl,xlimitlwt,ylimitd,ylimitdwt,ylimitu,ylimituwt,
                  xtest,ytest,
                  pwrwt,qwrwt,pwlwt,qwlwt,phuwt,qhuwt,phdwt,qhdwt,
                  zw1rwt,zw2rwt,zw1lwt,zw2lwt,zh1uwt,zh2uwt,zh1dwt,zh2dwt,
                  xintersecwrwt,xintersecwlwt,yintersechdwt,yintersechuwt,

                  riTable, liTable, uiTable, diTable,
                  roTable, loTable, uoTable, doTable,



		  w1rwt1,w1lwt1,h1uwt1,h1dwt1,w2rwt1,w2lwt1,h2uwt1,h2dwt1,
                  pawr1,pawl1,pbwr1,pbwl1,pahu1,pahd1,pbhu1,pbhd1,
                  awl1,bwl1,awr1,bwr1,ahu1,bhu1,ahd1,bhd1,
                  awlwt1,bwlwt1,awrwt1,bwrwt1,ahuwt1,bhuwt1,ahdwt1,bhdwt1,
                  pawrwt1,pawlwt1,pbwrwt1,pbwlwt1,pahuwt1,pahdwt1,pbhuwt1,pbhdwt1,
                  t2w1r1,t2w2r1,t2w1l1,t2w2l1,t2h1u1,t2h2u1,t2h1d1,t2h2d1,
                  t2w1rwt1,t2w2rwt1,t2w1lwt1,t2w2lwt1,t2h1uwt1,t2h2uwt1,t2h1dwt1,t2h2dwt1,

                  a2wlwt1,b2wlwt1,a2wrwt1,b2wrwt1,a2huwt1,b2huwt1,a2hdwt1,b2hdwt1,
                  a2wl1,b2wl1,a2wr1,b2wr1,a2hu1,b2hu1,a2hd1,b2hd1,
                  mru11,mru21,nru11,nru21,mrd11,mrd21,nrd11,nrd21,mlu11,mlu21,nlu11,nlu21,mld11,mld21,nld11,nld21,
                  z0wr1,z0wl1,z0hu1,z0hd1,

                  lbwl1,lbwr1,lbhu1,lbhd1,
                  p2parawr1,p2parawl1,p2parahu1,p2parahd1,
                  u1wl1,u2wl1,u1wr1,u2wr1,u1hu1,u2hu1,u1hd1,u2hd1,
                  DIV1wl1,DIV1wr1,DIV1hu1,DIV1hd1,
                  p2parawrwt1,p2parawlwt1,p2parahuwt1,p2parahdwt1,
                  DIV1wlwt1,DIV1wrwt1,DIV1huwt1,DIV1hdwt1,
                  u1wrwt1,u2wrwt1,u1wlwt1,u2wlwt1,u1huwt1,u2huwt1,u1hdwt1,u2hdwt1,
                  dxwr1,dzwr1,dxwl1,dzwl1,dyhu1,dzhu1,dyhd1,dzhd1,


                  zw1r1,zw2r1,zw1l1,zw2l1,zh1u1,zh2u1,zh1d1,zh2d1,
                  pwr1,qwr1,pwl1,qwl1,phu1,qhu1,phd1,qhd1,
                  xintersecwr1,xintersecwl1,yintersechd1,yintersechu1,
                  pwrwt1,qwrwt1,pwlwt1,qwlwt1,phuwt1,qhuwt1,phdwt1,qhdwt1,
                  zw1rwt1,zw2rwt1,zw1lwt1,zw2lwt1,zh1uwt1,zh2uwt1,zh1dwt1,zh2dwt1,
                  xintersecwrwt1,xintersecwlwt1,yintersechdwt1,yintersechuwt1,

                  riTable1, liTable1, uiTable1, diTable1,
                  roTable1, loTable1, uoTable1, doTable1,

                  w1rwt2,w1lwt2,h1uwt2,h1dwt2,w2rwt2,w2lwt2,h2uwt2,h2dwt2,
                  pawr2,pawl2,pbwr2,pbwl2,pahu2,pahd2,pbhu2,pbhd2,
                  awl2,bwl2,awr2,bwr2,ahu2,bhu2,ahd2,bhd2,
                  awlwt2,bwlwt2,awrwt2,bwrwt2,ahuwt2,bhuwt2,ahdwt2,bhdwt2,
                  pawrwt2,pawlwt2,pbwrwt2,pbwlwt2,pahuwt2,pahdwt2,pbhuwt2,pbhdwt2,
                  t2w1r2,t2w2r2,t2w1l2,t2w2l2,t2h1u2,t2h2u2,t2h1d2,t2h2d2,
                  t2w1rwt2,t2w2rwt2,t2w1lwt2,t2w2lwt2,t2h1uwt2,t2h2uwt2,t2h1dwt2,t2h2dwt2,

                  a2wlwt2,b2wlwt2,a2wrwt2,b2wrwt2,a2huwt2,b2huwt2,a2hdwt2,b2hdwt2,
                  a2wl2,b2wl2,a2wr2,b2wr2,a2hu2,b2hu2,a2hd2,b2hd2,
                  mru12,mru22,nru12,nru22,mrd12,mrd22,nrd12,nrd22,mlu12,mlu22,nlu12,nlu22,mld12,mld22,nld12,nld22,
                  z0wr2,z0wl2,z0hu2,z0hd2,

                  lbwl2,lbwr2,lbhu2,lbhd2,
                  p2parawr2,p2parawl2,p2parahu2,p2parahd2,
                  u1wl2,u2wl2,u1wr2,u2wr2,u1hu2,u2hu2,u1hd2,u2hd2,
                  DIV1wl2,DIV1wr2,DIV1hu2,DIV1hd2,
                  p2parawrwt2,p2parawlwt2,p2parahuwt2,p2parahdwt2,
                  DIV1wlwt2,DIV1wrwt2,DIV1huwt2,DIV1hdwt2,
                  u1wrwt2,u2wrwt2,u1wlwt2,u2wlwt2,u1huwt2,u2huwt2,u1hdwt2,u2hdwt2,
                  dxwr2,dzwr2,dxwl2,dzwl2,dyhu2,dzhu2,dyhd2,dzhd2,


                  zw1r2,zw2r2,zw1l2,zw2l2,zh1u2,zh2u2,zh1d2,zh2d2,
                  pwr2,qwr2,pwl2,qwl2,phu2,qhu2,phd2,qhd2,
                  xintersecwr2,xintersecwl2,yintersechd2,yintersechu2,
                  pwrwt2,qwrwt2,pwlwt2,qwlwt2,phuwt2,qhuwt2,phdwt2,qhdwt2,
                  zw1rwt2,zw2rwt2,zw1lwt2,zw2lwt2,zh1uwt2,zh2uwt2,zh1dwt2,zh2dwt2,
                  xintersecwrwt2,xintersecwlwt2,yintersechdwt2,yintersechuwt2,

                  riTable2, liTable2, uiTable2, diTable2,
                  roTable2, loTable2, uoTable2, doTable2)

STATE PARAMETERS (x,y,z,vx,vy,vz,t,sx,sy,p)

SHARE
%{
%include "read_table-lib"
%}


DECLARE
%{
  double w1rwt,w1lwt,h1uwt,h1dwt,w2rwt,w2lwt,h2uwt,h2dwt;					/* entrance and exit width for th OUTER walls of the guide*/
  double pawr,pawl,pbwr,pbwl,pahu,pahd,pbhu,pbhd;						/* parameter a and b of the parabolic curves (INNER walls)*/
  double awl,bwl,awr,bwr,ahu,bhu,ahd,bhd;							/* long and short axis a and b auf the ellipses (INNER walls)*/
  double awlwt,bwlwt,awrwt,bwrwt,ahuwt,bhuwt,ahdwt,bhdwt;					/* long and short axis a and b auf the ellipses (OUTER walls)*/
  double pawrwt,pawlwt,pbwrwt,pbwlwt,pahuwt,pahdwt,pbhuwt,pbhdwt;				/* parameter a and b of the parabolic curves for the OUTER wall*/
  double t1,t2w1r,t2w2r,t2w1l,t2w2l,t2h1u,t2h2u,t2h1d,t2h2d;					/* time variables (INNER walls)*/
  double t2w1rwt,t2w2rwt,t2w1lwt,t2w2lwt,t2h1uwt,t2h2uwt,t2h1dwt,t2h2dwt;			/* time variables (OUTER walls)*/


  double a2wlwt,b2wlwt,a2wrwt,b2wrwt,a2huwt,b2huwt,a2hdwt,b2hdwt;				/* square of long and short axis a and b auf the ellipses (OUTER walls) */
  double a2wl,b2wl,a2wr,b2wr,a2hu,b2hu,a2hd,b2hd;						/* square of long and short axis a and b auf the ellipses (INNER walls)*/
  double mru1,mru2,nru1,nru2,mrd1,mrd2,nrd1,nrd2,mlu1,mlu2,nlu1,nlu2,mld1,mld2,nld1,nld2;	/* variables the calculated the guide geometrie in the entrance and exit plane (absorbing mask given by the walls)*/
  double z0wr,z0wl,z0hu,z0hd;									/* z-component of the center of the ellipse (x-component is allways zero) */

 double lbwl,lbwr,lbhu,lbhd;								/* length between focal points , needed for elliptic case */
 double p2parawr,p2parawl,p2parahu,p2parahd;						/* help variables to calculate the parabolic curve parameters a and b (INNER walls)*/
 double u1wl,u2wl,u1wr,u2wr,u1hu,u2hu,u1hd,u2hd;					/* help variables to calculate the long axis a of the ellipse (INNER walls)*/
 double DIV1wl,DIV1wr,DIV1hu,DIV1hd;							/* help variables (INNER walls)*/
 double p2parawrwt,p2parawlwt,p2parahuwt,p2parahdwt;					/* help variables to calculate the parabolic curve parameters a and b for (OUTER wall)*/
 double DIV1wlwt,DIV1wrwt,DIV1huwt,DIV1hdwt;						/* help variables (OUTER wall) */
 double u1wrwt,u2wrwt,u1wlwt,u2wlwt,u1huwt,u2huwt,u1hdwt,u2hdwt;			/* help variables to calculate the long axis a of the ellipse (OUTER walls)*/
 double dxwr,dzwr,dxwl,dzwl,dyhu,dzhu,dyhd,dzhd;					/* help variables to calculate the entrance and exit witdh of the OUTER walls*/


  double zw1r,zw2r,zw1l,zw2l,zh1u,zh2u,zh1d,zh2d,m,n;							/* zcomponent of the intersection point of the neutron trajectory and the ellipse (INNER walls)*/
  double pwr,qwr,pwl,qwl,phu,qhu,phd,qhd;								/* parameters for the quadratic equations for the intersection points or the intersection time (INNER walls)*/
  double nz,nx,ny,n2;											/* component and length of the surfaces normal vector at the intersection point */
  double pf;												/* prefactor to calculate the velocity vector after the interaction */
  double vxin,vyin,vzin;										/* velocity vector components before the interaction*/
  double q;												/* q-vector for the interaction */
  double xintersecwr,xintersecwl,yintersechd,yintersechu;						/* intersection point crosscheck variables (INNER walls) */
  double xlimitr,xlimitrwt,xlimitl,xlimitlwt,ylimitd,ylimitdwt,ylimitu,ylimituwt;			/* limit variables to determine the interaction position given by the time relative to the guide walls*/
  double xtest,ytest;											/* interaction position of the neutron given by the interaction time; crosscheck with limit variables*/
  double pwrwt,qwrwt,pwlwt,qwlwt,phuwt,qhuwt,phdwt,qhdwt;						/* parameters for the quadratic equations for the intersection points or the intersection time (OUTER walls)*/
  double zw1rwt,zw2rwt,zw1lwt,zw2lwt,zh1uwt,zh2uwt,zh1dwt,zh2dwt;					/* zcomponent of the intersection point of the neutron trajectory and the ellipse (OUTER walls)*/
  double xintersecwrwt,xintersecwlwt,yintersechdwt,yintersechuwt;					/* intersection point crosscheck variables (OUTER walls) */


  t_Table riTable,liTable,uiTable,diTable;
  t_Table roTable,loTable,uoTable,doTable;

  double w1rwt1,w1lwt1,h1uwt1,h1dwt1,w2rwt1,w2lwt1,h2uwt1,h2dwt1;
  double pawr1,pawl1,pbwr1,pbwl1,pahu1,pahd1,pbhu1,pbhd1;
  double awl1,bwl1,awr1,bwr1,ahu1,bhu1,ahd1,bhd1;
  double awlwt1,bwlwt1,awrwt1,bwrwt1,ahuwt1,bhuwt1,ahdwt1,bhdwt1;
  double pawrwt1,pawlwt1,pbwrwt1,pbwlwt1,pahuwt1,pahdwt1,pbhuwt1,pbhdwt1;
  double t2w1r1,t2w2r1,t2w1l1,t2w2l1,t2h1u1,t2h2u1,t2h1d1,t2h2d1;
  double t2w1rwt1,t2w2rwt1,t2w1lwt1,t2w2lwt1,t2h1uwt1,t2h2uwt1,t2h1dwt1,t2h2dwt1;

  double a2wlwt1,b2wlwt1,a2wrwt1,b2wrwt1,a2huwt1,b2huwt1,a2hdwt1,b2hdwt1;
  double a2wl1,b2wl1,a2wr1,b2wr1,a2hu1,b2hu1,a2hd1,b2hd1;
  double mru11,mru21,nru11,nru21,mrd11,mrd21,nrd11,nrd21,mlu11,mlu21,nlu11,nlu21,mld11,mld21,nld11,nld21;
  double z0wr1,z0wl1,z0hu1,z0hd1;

  double lbwl1,lbwr1,lbhu1,lbhd1;
  double p2parawr1,p2parawl1,p2parahu1,p2parahd1;
  double u1wl1,u2wl1,u1wr1,u2wr1,u1hu1,u2hu1,u1hd1,u2hd1;
  double DIV1wl1,DIV1wr1,DIV1hu1,DIV1hd1;
  double p2parawrwt1,p2parawlwt1,p2parahuwt1,p2parahdwt1;
  double DIV1wlwt1,DIV1wrwt1,DIV1huwt1,DIV1hdwt1;
  double u1wrwt1,u2wrwt1,u1wlwt1,u2wlwt1,u1huwt1,u2huwt1,u1hdwt1,u2hdwt1;
  double dxwr1,dzwr1,dxwl1,dzwl1,dyhu1,dzhu1,dyhd1,dzhd1;


  double zw1r1,zw2r1,zw1l1,zw2l1,zh1u1,zh2u1,zh1d1,zh2d1;
  double pwr1,qwr1,pwl1,qwl1,phu1,qhu1,phd1,qhd1;
  double xintersecwr1,xintersecwl1,yintersechd1,yintersechu1;
  double pwrwt1,qwrwt1,pwlwt1,qwlwt1,phuwt1,qhuwt1,phdwt1,qhdwt1;
  double zw1rwt1,zw2rwt1,zw1lwt1,zw2lwt1,zh1uwt1,zh2uwt1,zh1dwt1,zh2dwt1;
  double xintersecwrwt1,xintersecwlwt1,yintersechdwt1,yintersechuwt1;

  t_Table riTable1,liTable1,uiTable1,diTable1;
  t_Table roTable1,loTable1,uoTable1,doTable1;

  double w1rwt2,w1lwt2,h1uwt2,h1dwt2,w2rwt2,w2lwt2,h2uwt2,h2dwt2;
  double pawr2,pawl2,pbwr2,pbwl2,pahu2,pahd2,pbhu2,pbhd2;
  double awl2,bwl2,awr2,bwr2,ahu2,bhu2,ahd2,bhd2;
  double awlwt2,bwlwt2,awrwt2,bwrwt2,ahuwt2,bhuwt2,ahdwt2,bhdwt2;
  double pawrwt2,pawlwt2,pbwrwt2,pbwlwt2,pahuwt2,pahdwt2,pbhuwt2,pbhdwt2;
  double t2w1r2,t2w2r2,t2w1l2,t2w2l2,t2h1u2,t2h2u2,t2h1d2,t2h2d2;
  double t2w1rwt2,t2w2rwt2,t2w1lwt2,t2w2lwt2,t2h1uwt2,t2h2uwt2,t2h1dwt2,t2h2dwt2;

  double a2wlwt2,b2wlwt2,a2wrwt2,b2wrwt2,a2huwt2,b2huwt2,a2hdwt2,b2hdwt2;
  double a2wl2,b2wl2,a2wr2,b2wr2,a2hu2,b2hu2,a2hd2,b2hd2;
  double mru12,mru22,nru12,nru22,mrd12,mrd22,nrd12,nrd22,mlu12,mlu22,nlu12,nlu22,mld12,mld22,nld12,nld22;
  double z0wr2,z0wl2,z0hu2,z0hd2;

  double lbwl2,lbwr2,lbhu2,lbhd2;
  double p2parawr2,p2parawl2,p2parahu2,p2parahd2;
  double u1wl2,u2wl2,u1wr2,u2wr2,u1hu2,u2hu2,u1hd2,u2hd2;
  double DIV1wl2,DIV1wr2,DIV1hu2,DIV1hd2;
  double p2parawrwt2,p2parawlwt2,p2parahuwt2,p2parahdwt2;
  double DIV1wlwt2,DIV1wrwt2,DIV1huwt2,DIV1hdwt2;
  double u1wrwt2,u2wrwt2,u1wlwt2,u2wlwt2,u1huwt2,u2huwt2,u1hdwt2,u2hdwt2;
  double dxwr2,dzwr2,dxwl2,dzwl2,dyhu2,dzhu2,dyhd2,dzhd2;


  double zw1r2,zw2r2,zw1l2,zw2l2,zh1u2,zh2u2,zh1d2,zh2d2;
  double pwr2,qwr2,pwl2,qwl2,phu2,qhu2,phd2,qhd2;
  double xintersecwr2,xintersecwl2,yintersechd2,yintersechu2;
  double pwrwt2,qwrwt2,pwlwt2,qwlwt2,phuwt2,qhuwt2,phdwt2,qhdwt2;
  double zw1rwt2,zw2rwt2,zw1lwt2,zw2lwt2,zh1uwt2,zh2uwt2,zh1dwt2,zh2dwt2;
  double xintersecwrwt2,xintersecwlwt2,yintersechdwt2,yintersechuwt2;

  t_Table riTable2, liTable2, uiTable2, diTable2;
  t_Table roTable2, loTable2, uoTable2, doTable2;
%}


INITIALIZE
%{

 int i;

if (RIreflect && strlen(RIreflect)) {
    if (Table_Read(&riTable, RIreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"right inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, RIreflect));
  }

if (LIreflect && strlen(LIreflect)) {
    if (Table_Read(&liTable, LIreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"left inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, LIreflect));
  }

if (UIreflect && strlen(UIreflect)) {
    if (Table_Read(&uiTable, UIreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"top inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, UIreflect));
  }

if (DIreflect && strlen(DIreflect)) {
    if (Table_Read(&diTable, DIreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"botton inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, DIreflect));
  }

if (ROreflect && strlen(ROreflect)) {
    if (Table_Read(&roTable, ROreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"right outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, ROreflect));
  }

if (LOreflect && strlen(LOreflect)) {
    if (Table_Read(&loTable, LOreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"left outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, LOreflect));
  }

if (UOreflect && strlen(UOreflect)) {
    if (Table_Read(&uoTable, UOreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"top outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, UOreflect));
  }

if (DOreflect && strlen(DOreflect)) {
    if (Table_Read(&doTable, DOreflect, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"botton outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, DOreflect));
  }

if (w1r < 0)											/* Ceckup for the input variables */
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w1r should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w1l < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w1l should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h1u < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h1u should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h1d < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h1d should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w2r < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w2r should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w2l < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w2l should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h2u < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h2u should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h2d < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h2d should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (mxrOW !=-1 && mxrOW < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxrOW must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mxlOW !=-1 && mxlOW<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxlOW must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myuOW !=-1 && myuOW<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myuOW must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mydOW !=-1 && mydOW<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mydOW must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (Qcxl < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcxl can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcxr < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcxr can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcyu < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcyu can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcyd < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcyd can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphaxl < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphaxl can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphaxr < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphaxr can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphayu < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphayu can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphayd < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphayd can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (rwallthick < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) rwallthick can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (lwallthick < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) lwallthick can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }
if (uwallthick < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) uwallthick can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (dwallthick < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) dwallthick can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (mxr < 0 && mxr!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxr must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mxl < 0 && mxl!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxl must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myu < 0 && myu!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myu must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myd < 0 && myd!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myd must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (Wxr <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wxr must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wxl <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wxl must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wyu <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wyu must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wyd <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wyd must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (RIreflect1 && strlen(RIreflect1)) {
    if (Table_Read(&riTable1, RIreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"right inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, RIreflect1));
  }

if (LIreflect1 && strlen(LIreflect1)) {
    if (Table_Read(&liTable1, LIreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"left inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, LIreflect1));
  }

if (UIreflect1 && strlen(UIreflect1)) {
    if (Table_Read(&uiTable1, UIreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"top inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, UIreflect1));
  }

if (DIreflect1 && strlen(DIreflect1)) {
    if (Table_Read(&diTable1, DIreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"botton inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, DIreflect1));
  }

if (ROreflect1 && strlen(ROreflect1)) {
    if (Table_Read(&roTable1, ROreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"right outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, ROreflect1));
  }

if (LOreflect1 && strlen(LOreflect1)) {
    if (Table_Read(&loTable1, LOreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"left outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, LOreflect1));
  }

if (UOreflect1 && strlen(UOreflect1)) {
    if (Table_Read(&uoTable1, UOreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"top outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, UOreflect1));
  }

if (DOreflect1 && strlen(DOreflect1)) {
    if (Table_Read(&doTable1, DOreflect1, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"botton outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, DOreflect1));
  }


if (w1r1 < 0)											/* Ceckup for the input variables */
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w1r1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w1l1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w1l1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h1u1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h1u1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h1d1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h1d1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w2r1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w2r1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w2l1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w2l1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h2u1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h2u1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h2d1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h2d1 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (mxrOW1 !=-1 && mxrOW1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxrOW1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mxlOW1 !=-1 && mxlOW1<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxlOW1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myuOW1 !=-1 && myuOW1<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myuOW1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mydOW1 !=-1 && mydOW1<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mydOW1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (Qcxl1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcxl1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcxr1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcxr1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcyu1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcyu1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcyd1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcyd1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphaxl1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphaxl1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphaxr1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphaxr1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphayu1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphayu1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphayd1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphayd1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (rwallthick1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) rwallthick1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (lwallthick1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) lwallthick1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }
if (uwallthick1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) uwallthick1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (dwallthick1 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) dwallthick1 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (mxr1 < 0 && mxr1!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxr1 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mxl1 < 0 && mxl1!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxl1 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myu1 < 0 && myu1!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myu1 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myd1 < 0 && myd1!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myd1 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (Wxr1 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wxr1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wxl1 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wxl1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wyu1 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wyu1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wyd1 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wyd1 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }


if (RIreflect2 && strlen(RIreflect2)) {
    if (Table_Read(&riTable2, RIreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"right inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, RIreflect2));
  }

if (LIreflect2 && strlen(LIreflect2)) {
    if (Table_Read(&liTable2, LIreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"left inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, LIreflect2));
  }

if (UIreflect2 && strlen(UIreflect2)) {
    if (Table_Read(&uiTable2, UIreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"top inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, UIreflect2));
  }

if (DIreflect2 && strlen(DIreflect2)) {
    if (Table_Read(&diTable2, DIreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"botton inner Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, DIreflect2));
  }

if (ROreflect2 && strlen(ROreflect2)) {
    if (Table_Read(&roTable2, ROreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"right outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, ROreflect2));
  }

if (LOreflect2 && strlen(LOreflect2)) {
    if (Table_Read(&loTable2, LOreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"left outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, LOreflect2));
  }

if (UOreflect2 && strlen(UOreflect2)) {
    if (Table_Read(&uoTable2, UOreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"top outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, UOreflect2));
  }

if (DOreflect2 && strlen(DOreflect2)) {
    if (Table_Read(&doTable2, DOreflect2, 1) <= 0) 							/* read 1st block data from file into pTable */
      exit(fprintf(stderr,"botton outer Wall: %s: can not read file %s\n", NAME_CURRENT_COMP, DOreflect2));
  }


if (w1r2 < 0)											/* Ceckup for the input variables */
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w1r2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w1l2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w1l2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h1u2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h1u2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h1d2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h1d2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w2r2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w2r2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (w2l2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) w2l2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h2u2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h2u2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (h2d2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) h2d2 should  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    fprintf(stderr,"           (for negative values use the global guide position !) \n");
    exit(-1);
  }

if (mxrOW2 !=-1 && mxrOW2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxrOW2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mxlOW2 !=-1 && mxlOW2<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxlOW2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myuOW2 !=-1 && myuOW2<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myuOW2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mydOW2 !=-1 && mydOW2<0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mydOW2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (Qcxl2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcxl2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcxr2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcxr2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcyu2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcyu2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (Qcyd2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Qcyd2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphaxl2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphaxl2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphaxr2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphaxr2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphayu2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphayu2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (alphayd2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) alphayd2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (rwallthick2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) rwallthick2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (lwallthick2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) lwallthick2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }
if (uwallthick2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) uwallthick2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (dwallthick2 < 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) dwallthick2 can  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           NOT be negative \n");
    exit(-1);
  }

if (mxr2 < 0 && mxr2!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxr2 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (mxl2 < 0 && mxl2!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) mxl2 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myu2 < 0 && myu2!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myu2 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (myd2 < 0 && myd2!=-1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) myd2 must  \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be -1 (transperent) or \n");
    fprintf(stderr,"           be  0 (absorbing) or \n");
    fprintf(stderr,"           be  > 0 (reflecting) \n");
    exit(-1);
  }

if (Wxr2 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wxr2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wxl2 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wxl2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wyu2 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wyu2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }

if (Wyd2 <=0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) Wyd2 must \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           be positive\n");
    exit(-1);
  }




if (l <= 0)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) real guide length \n",
    NAME_CURRENT_COMP);
    fprintf(stderr,"           is <= ZERO ! \n");
    exit(-1);
  }

if (mcgravitation) fprintf(stderr,"WARNING: Guide_four_side: %s: "
    "This component produces wrong results with gravitation !\n"
    "Use Guide_gravity.\n",
    NAME_CURRENT_COMP);


													/* Calculation of curve-parameters for the right side wall - negative x-axis */

													/* elliptic right side wall */

lbwr=linwr+l+loutwr;											/* lenght between the two focal points for the right wall */
z0wr=(linwr-l-loutwr)/2.0;										/* calculation of the z-component of the center of the ellipse for the right wall (with opposite sign)*/

if(loutwr!=0 && linwr!=0)										/* ? elliptic shape ? */
  { 
    u1wr=sqrt((linwr*linwr)+(w1r*w1r));									/* length between entrance focal point and starting point of the elliptic wall (INNER wall)*/
    u2wr=sqrt((w1r*w1r)+((l+loutwr)*(l+loutwr)));							/* length between exit focal point and end point of the elliptic wall (INNER wall) */
    awr=(u1wr+u2wr)/2.0;										/* long half axis a of the ellipse (INNER  wall)*/
    a2wr=awr*awr;											/* square of the long axis a (INNER wall)*/
    bwr=sqrt(a2wr-(lbwr*lbwr/4.0));									/* short half axis b of the ellipse  (INNER wall)*/
    b2wr=bwr*bwr;											/* square of short half axis b of the ellipse  (INNER wall)*/
    DIV1wr=sqrt(1.0-((lbwr/2.0-loutwr)*(lbwr/2.0-loutwr)/a2wr));					/* help variable to calculated the exit width (INNER wall)*/
    w2r=bwr*DIV1wr;											/* exit width (INNER wall)*/
    if(l<lbwr/2-loutwr){										/* if the maximum opening of  the guide is smaller than the small half axis b, the OUTER wall is defined by: */
        dxwr=rwallthick*sin(atan(a2wr*w1r/(b2wr*z0wr)));						/* help variable dx; needed because the wall is not paralell to the z-axis or the wallthickness is not perpendicular to z*/
        dzwr=rwallthick*cos(atan(a2wr*w1r/(b2wr*z0wr)));						/* help variable dz; needed because the wall is not paralell to the z-axis or the wallthickness is not perpendicular to z*/
    	u1wrwt=sqrt(((linwr+dzwr)*(linwr+dzwr))+((w1r+dxwr)*(w1r+dxwr)));				/* length between entrance focal point and starting point of the elliptic wall (OUTER wall)*/
    	u2wrwt=sqrt(((w1r+dxwr)*(w1r+dxwr))+((l+loutwr-dzwr)*(l+loutwr-dzwr)));				/* length between exit focal point and end point of the elliptic wall (OUTER wall) */
    	awrwt=(u1wrwt+u2wrwt)/2.0;									/* long half axis a of the ellipse  (OUTER wall)*/
    	a2wrwt=awrwt*awrwt;										/* square of the long axis a (OUTER wall)*/
    	bwrwt=sqrt(a2wrwt-(lbwr*lbwr/4.0));								/* short half axis b of the ellipse  (OUTER wall)*/
    	b2wrwt=bwrwt*bwrwt;										/* square of short half axis b of the ellipse  (OUTER wall)*/
    	w2rwt=bwrwt*sqrt(1.0-((lbwr/2.0-loutwr)*(lbwr/2.0-loutwr)/a2wrwt));				/* exit width for OUTER right elliptic wall */
        w1rwt=bwrwt*sqrt(1.0-((lbwr/2.0-loutwr-l)*(lbwr/2.0-loutwr-l)/a2wrwt));				/* entrance width for OUTER right elliptic wall */
    }else{												/* if the maximum opening of  the guide is the small half axis bthe OUTER wall is defined by:*/
	bwrwt=bwr+rwallthick;										/* short half axis b of the ellipse  (OUTER wall)*/
        b2wrwt=bwrwt*bwrwt;										/* square of the long axis a (OUTER wall)*/
        awrwt=sqrt(b2wrwt+(lbwr*lbwr/4.0));								/* long half axis a of the ellipse  (OUTER  wall)*/
        a2wrwt=b2wrwt+(lbwr*lbwr/4.0);									/* square of short half axis b of the ellipse  (OUTER wall)*/
        w2rwt=bwrwt*sqrt(1.0-((lbwr/2.0-loutwr)*(lbwr/2.0-loutwr)/a2wrwt));				/* exit width for OUTER right elliptic wall */
        w1rwt=bwrwt*sqrt(1.0-((lbwr/2.0-linwr)*(lbwr/2.0-linwr)/a2wrwt));				/* entrance width for OUTER right elliptic wall */
    }
   }

													/* parabolic focusing right side wall */

if(linwr==0 && loutwr!=0){										/* ? parabolic focusing shape ? */
    DIV1wr=(l+loutwr)*(l+loutwr);									/* help variable to calculate the curve parameters (INNER wall) */
    p2parawr=2.0*(sqrt(DIV1wr+(w1r*w1r))-sqrt(DIV1wr));							/* help variable to calculate the curve parameters (INNER wall) */
    w2r=sqrt(p2parawr*(loutwr+p2parawr/4.0));								/* exit width for right focusing parabolic wall (INNER wall) */
    pbwr=l+loutwr+p2parawr/4.0;										/* parameter b for parabolic equation to define the wall (INNER wall)*/
    pawr=1.0/p2parawr;											/* parameter a for parabolic equation to define the wall (INNER wall)*/
    dxwr=rwallthick*sin(atan(w1r*2*pawr));								/* help variable dx; needed because the wall is not paralell to the z-axis or the wallthickness is not perpendicular to z*/
    dzwr=rwallthick*cos(atan(w1r*2*pawr));								/* help variable dz; needed because the wall is not paralell to the z-axis or the wallthickness is not perpendicular to z*/
    DIV1wrwt=(l+loutwr-dzwr)*(l+loutwl-dzwr);								/* help variable to calculate the curve parameters (OUTER wall) */
    p2parawrwt=2.0*(sqrt(DIV1wrwt+((w1r+dxwr)*(w1r+dxwr)))-sqrt(DIV1wrwt));				/* help variable to calculate the curve parameters (OUTER wall) */
    pbwrwt=l+loutwr+p2parawrwt/4.0;									/* parameter b for parabolic equation to define the wall (OUTER wall)*/
    pawrwt=1.0/p2parawrwt;										/* parameter a for parabolic equation to define the wall (OUTER wall)*/
    w2rwt=sqrt(p2parawrwt*(loutwr+p2parawrwt/4.0));							/* exit width for right focusing parabolic wall (OUTER wall) */
    w1rwt=sqrt(p2parawrwt*(loutwr+l+p2parawrwt/4.0));							/* entrance width for right focusing parabolic wall (OUTER wall) */
   }

													/* parabolic defocusing right side wall */

if (linwr!=0 && loutwr==0)										/* ? parabolic defocusing shape ? */
    {
      DIV1wr=linwr*linwr;										/* help variable to calculate the curve parameters (INNER wall) */
      p2parawr=2.0*(sqrt(DIV1wr+(w1r*w1r))-sqrt(DIV1wr));						/* help variable to calculate the curve parameters (INNER wall) */
      w2r=sqrt(p2parawr*(l+linwr+p2parawr/4.0));							/* exit width for right focusing parabolic wall (INNER wall) */
      pbwr=-(linwr+p2parawr/4.0);									/* parameter b for parabolic equation to define the wall (INNER wall)*/
      pawr=-1.0/p2parawr;										/* parameter a for parabolic equation to define the wall (INNER wall)*/
      dxwr=rwallthick*sin(atan(-w2r*2*pawr));								/* help variable dx; needed because the wall is not paralell to the z-axis or the wallthickness is not perpendicular to z*/
      dzwr=rwallthick*cos(atan(-w2r*2*pawr));								/* help variable dz; needed because the wall is not paralell to the z-axis or the wallthickness is not perpendicular to z*/
      DIV1wrwt=(linwr+l-dzwr)*(linwr+l-dzwr);								/* help variable to calculate the curve parameters (OUTER wall) */
      p2parawrwt=2.0*(sqrt(DIV1wrwt+((w2r+dxwr)*(w2r+dxwr)))-sqrt(DIV1wrwt));				/* help variable to calculate the curve parameters (OUTER wall) */
      w1rwt=sqrt(p2parawrwt*(linwr+p2parawrwt/4.0));							/* entrance width for right focusing parabolic wall (OUTER wall) */
      w2rwt=sqrt(p2parawrwt*(linwr+l+p2parawrwt/4.0));							/* exit width for right focusing parabolic wall (OUTER wall) */
      pbwrwt=-(linwr+p2parawrwt/4.0);									/* parameter b for parabolic equation to define the wall (OUTER wall)*/
      pawrwt=-1.0/p2parawrwt;										/* parameter a for parabolic equation to define the wall (OUTER wall)*/
    }

													/* straight right side wall */

if(linwr==0 && loutwr==0){										/* ? linear shape ? */
    w1rwt=w1r+rwallthick/(cos(atan((w1r-w2r)/l)));							/* entrance width for right focusing parabolic wall (OUTER wall) */
    w2rwt=w2r+rwallthick/(cos(atan((w1r-w2r)/l)));							/* exit width for right focusing parabolic wall (OUTER wall) */
    }


													/* Calculation of curve-parameters for the left side wall - positive x-axis - analog to right side*/

lbwl=linwl+l+loutwl;
z0wl=(linwl-l-loutwl)/2.0;

if((linwl!=0) && (loutwl!=0) ) 										/* elleptic left side wall */
  { 
    u1wl=sqrt((linwl*linwl)+(w1l*w1l));
    u2wl=sqrt((w1l*w1l)+((l+loutwl)*(l+loutwl)));
    awl=(u1wl+u2wl)/2.0;
    a2wl=awl*awl;
    bwl=sqrt(a2wl-(lbwl*lbwl/4.0));
    b2wl=bwl*bwl;
    DIV1wl=sqrt(1.0-((lbwl/2.0-loutwl)*(lbwl/2.0-loutwl)/a2wl));
    w2l=bwl*DIV1wl;
    if(l<lbwl/2-loutwl){
        dxwl=lwallthick*sin(atan(a2wl*w1l/(b2wl*z0wl)));
        dzwl=lwallthick*cos(atan(a2wl*w1l/(b2wl*z0wl)));
    	u1wlwt=sqrt(((linwl+dzwl)*(linwl+dzwl))+((w1l+dxwl)*(w1l+dxwl)));								
    	u2wlwt=sqrt(((w1l+dxwl)*(w1l+dxwl))+((l+loutwl-dzwl)*(l+loutwl-dzwl)));	
    	awlwt=(u1wlwt+u2wlwt)/2.0;
    	a2wlwt=awlwt*awlwt;
    	bwlwt=sqrt(a2wlwt-(lbwl*lbwl/4.0));
    	b2wlwt=bwlwt*bwlwt;
    	w2lwt=bwlwt*sqrt(1.0-((lbwl/2.0-loutwl)*(lbwl/2.0-loutwl)/a2wlwt));
        w1lwt=bwlwt*sqrt(1.0-((lbwl/2.0-loutwl-l)*(lbwl/2.0-loutwl-l)/a2wlwt));
    }else{
	bwlwt=bwl+lwallthick;
        b2wlwt=bwlwt*bwlwt;
        awlwt=sqrt(b2wlwt+(lbwl*lbwl/4.0));
        a2wlwt=b2wlwt+(lbwl*lbwl/4.0);
        w2lwt=bwlwt*sqrt(1.0-((lbwl/2.0-loutwl)*(lbwl/2.0-loutwl)/a2wlwt));
        w1lwt=bwlwt*sqrt(1.0-((lbwl/2.0-linwl)*(lbwl/2.0-linwl)/a2wlwt));
    }
   }


if(linwl==0 && loutwl!=0)										/* parabolic focusing left side wall */
   {
    DIV1wl=(l+loutwl)*(l+loutwl);
    p2parawl=2.0*(sqrt(DIV1wl+(w1l*w1l))-sqrt(DIV1wl));
    w2l=sqrt(p2parawl*(loutwl+p2parawl/4.0));
    pbwl=l+loutwl+p2parawl/4.0;
    pawl=1.0/p2parawl;
    dxwl=lwallthick*sin(atan(w1l*2*pawl));
    dzwl=lwallthick*cos(atan(w1l*2*pawl));
    DIV1wlwt=(l+loutwl-dzwl)*(l+loutwl-dzwl);
    p2parawlwt=2.0*(sqrt(DIV1wlwt+((w1l+dxwl)*(w1l+dxwl)))-sqrt(DIV1wlwt));
    pbwlwt=l+loutwl+p2parawlwt/4.0;
    pawlwt=1.0/p2parawlwt;
    w2lwt=sqrt(p2parawlwt*(loutwl+p2parawlwt/4.0));
    w1lwt=sqrt(p2parawlwt*(loutwl+l+p2parawlwt/4.0));
   }

if (linwl!=0 && loutwl==0)										/* parabolic defocusing left side wall */
    {
      DIV1wl=linwl*linwl;
      p2parawl=2.0*(sqrt(DIV1wl+(w1l*w1l))-sqrt(DIV1wl));
      w2l=sqrt(p2parawl*(l+linwl+p2parawl/4.0));
      pbwl=-(linwl+p2parawl/4.0);
      pawl=-1.0/p2parawl;
      dxwl=lwallthick*sin(atan(-w2l*2*pawl));
      dzwl=lwallthick*cos(atan(-w2l*2*pawl));
      DIV1wlwt=(linwl+l-dzwl)*(linwl+l-dzwl);
      p2parawlwt=2.0*(sqrt(DIV1wlwt+((w2l+dxwl)*(w2l+dxwl)))-sqrt(DIV1wlwt));
      w1lwt=sqrt(p2parawlwt*(linwl+p2parawlwt/4.0));
      w2lwt=sqrt(p2parawlwt*(linwl+l+p2parawlwt/4.0));
      pbwlwt=-(linwl+p2parawlwt/4.0);
      pawlwt=-1.0/p2parawlwt;
    }

if(linwl==0 && loutwl==0){
    w1lwt=w1l+lwallthick/(cos(atan((w2l-w1l)/l)));
    w2lwt=w2l+lwallthick/(cos(atan((w2l-w1l)/l)));
    }


													/* Calculation of curve-parameters for the top wall - positive y-axis - analog  right wall*/

lbhu=linhu+l+louthu;
z0hu=lbhu/2.0-l-louthu;	

if (linhu != 0 && louthu !=0)										/* elliptic top wall */
   {
    u1hu=sqrt((linhu*linhu)+(h1u*h1u));
    u2hu=sqrt((h1u*h1u)+((l+louthu)*(l+louthu)));
    ahu=(u1hu+u2hu)/2.0;
    bhu=sqrt(ahu*ahu-(lbhu*lbhu/4.0));
    a2hu=ahu*ahu;
    b2hu=bhu*bhu;
    DIV1hu=sqrt(1.0-((lbhu/2.0-louthu)*(lbhu/2.0-louthu)/a2hu));
    h2u=bhu*DIV1hu;
    if(l<lbhu/2-louthu){
        dyhu=uwallthick*sin(atan(a2hu*h1u/(b2hu*z0hu)));
        dzhu=uwallthick*cos(atan(a2hu*h1u/(b2hu*z0hu)));
    	u1huwt=sqrt(((linhu+dzhu)*(linhu+dzhu))+((h1u+dyhu)*(h1u+dyhu)));								
    	u2huwt=sqrt(((h1u+dyhu)*(h1u+dyhu))+((l+louthu-dzhu)*(l+louthu-dzhu)));	
    	ahuwt=(u1huwt+u2huwt)/2.0;
    	a2huwt=ahuwt*ahuwt;
    	bhuwt=sqrt(a2huwt-(lbhu*lbhu/4.0));
    	b2huwt=bhuwt*bhuwt;
    	h2uwt=bhuwt*sqrt(1.0-((lbhu/2.0-louthu)*(lbhu/2.0-louthu)/a2huwt));
        h1uwt=bhuwt*sqrt(1.0-((lbhu/2.0-louthu-l)*(lbhu/2.0-louthu-l)/a2huwt));
    }else{
	bhuwt=bhu+uwallthick;
        b2huwt=bhuwt*bhuwt;
        ahuwt=sqrt(b2huwt+(lbhu*lbhu/4.0));
        a2huwt=b2huwt+(lbhu*lbhu/4.0);
        h2uwt=bhuwt*sqrt(1.0-((lbhu/2.0-louthu)*(lbhu/2.0-louthu)/a2huwt));
        h1uwt=bhuwt*sqrt(1.0-((lbhu/2.0-linhu)*(lbhu/2.0-linhu)/a2huwt));
    }
  }

if(linhu==0 && louthu!=0)										/* parabolic focusing top wall */
   { 	
    DIV1hu=(l+louthu)*(l+louthu);
    p2parahu=2.0*(sqrt(DIV1hu+(h1u*h1u))-sqrt(DIV1hu));
    h2u=sqrt(p2parahu*(louthu+p2parahu/4.0));
    pbhu=l+louthu+p2parahu/4.0;
    pahu=1.0/p2parahu;
    dyhu=uwallthick*sin(atan(h1u*2*pahu));
    dzhu=uwallthick*cos(atan(h1u*2*pahu));
    DIV1huwt=(l+louthu-dzhu)*(l+louthu-dzhu);
    p2parahuwt=2.0*(sqrt(DIV1huwt+((h1u+dyhu)*(h1u+dyhu)))-sqrt(DIV1huwt));
    pbhuwt=l+louthu+p2parahuwt/4.0;
    pahuwt=1.0/p2parahuwt;
    h2uwt=sqrt(p2parahuwt*(louthu+p2parahuwt/4.0));
    h1uwt=sqrt(p2parahuwt*(louthu+l+p2parahuwt/4.0));
   } 

if (linhu!=0 && louthu==0)										/* parabolic defocusing top wall */
    {
      DIV1hu=linhu*linhu;
      p2parahu=2.0*(sqrt(DIV1hu+(h1u*h1u))-sqrt(DIV1hu));
      h2u=sqrt(p2parahu*(l+linhu+p2parahu/4.0));
      pbhu=-(linhu+p2parahu/4.0);
      pahu=-1.0/p2parahu;
      dyhu=uwallthick*sin(atan(-h2u*2*pahu));
      dzhu=uwallthick*cos(atan(-h2u*2*pahu));
      DIV1huwt=(linhu+l-dzhu)*(linhu+l-dzhu);
      p2parahuwt=2.0*(sqrt(DIV1huwt+((h2u+dyhu)*(h2u+dyhu)))-sqrt(DIV1huwt));
      h1uwt=sqrt(p2parahuwt*(linhu+p2parahuwt/4.0));
      h2uwt=sqrt(p2parahuwt*(linhu+l+p2parahuwt/4.0));
      pbhuwt=-(linhu+p2parahuwt/4.0);
      pahuwt=-1.0/p2parahuwt;
    }

if(linhu==0 && louthu==0){
    h1uwt=h1u+uwallthick/(cos(atan((h2u-h1u)/l)));
    h2uwt=h2u+uwallthick/(cos(atan((h2u-h1u)/l)));
    }


													/* Calculation of curve-parameters for the bottom wall - negative y-axis - analog right wall */
lbhd=linhd+l+louthd;
z0hd=lbhd/2.0-l-louthd;

if (linhd != 0 && louthd !=0)										/* elliptic bottom wall */
   {
    u1hd=sqrt((linhd*linhd)+(h1d*h1d));
    u2hd=sqrt((h1d*h1d)+((l+louthd)*(l+louthd)));
    ahd=(u1hd+u2hd)/2.0;
    bhd=sqrt(ahd*ahd-(lbhd*lbhd/4.0));
    a2hd=ahd*ahd;
    b2hd=bhd*bhd;
    DIV1hd=sqrt(1.0-((lbhd/2.0-louthd)*(lbhd/2.0-louthd)/a2hd));
    h2d=bhd*DIV1hd;
    if(l<lbhd/2-louthd){
        dyhd=dwallthick*sin(atan(a2hd*h1d/(b2hd*z0hd)));
        dzhd=dwallthick*cos(atan(a2hd*h1d/(b2hd*z0hd)));
    	u1hdwt=sqrt(((linhd+dzhd)*(linhd+dzhd))+((h1d+dyhd)*(h1d+dyhd)));	
    	u2hdwt=sqrt(((h1d+dyhd)*(h1d+dyhd))+((l+louthd-dzhd)*(l+louthd-dzhd)));
    	ahdwt=(u1hdwt+u2hdwt)/2.0;
    	a2hdwt=ahdwt*ahdwt;
    	bhdwt=sqrt(a2hdwt-(lbhd*lbhd/4.0));
    	b2hdwt=bhdwt*bhdwt;
    	h2dwt=bhdwt*sqrt(1.0-((lbhd/2.0-louthd)*(lbhd/2.0-louthd)/a2hdwt));
        h1dwt=bhdwt*sqrt(1.0-((lbhd/2.0-louthd-l)*(lbhd/2.0-louthd-l)/a2hdwt));
    }else{
	bhdwt=bhd+dwallthick;
        b2hdwt=bhdwt*bhdwt;
        ahdwt=sqrt(b2hdwt+(lbhd*lbhd/4.0));
        a2hdwt=b2hdwt+(lbhd*lbhd/4.0);
        h2dwt=bhdwt*sqrt(1.0-((lbhd/2.0-louthd)*(lbhd/2.0-louthd)/a2hdwt));
        h1dwt=bhdwt*sqrt(1.0-((lbhd/2.0-linhd)*(lbhd/2.0-linhd)/a2hdwt));
    }
  }

if(linhd==0 && louthd!=0)										/* parabolic focusing bottom wall */
   {	
    DIV1hd=(l+louthd)*(l+louthd);
    p2parahd=2.0*(sqrt(DIV1hd+(h1d*h1d))-sqrt(DIV1hd));
    h2d=sqrt(p2parahd*(louthd+p2parahd/4.0));
    pbhd=l+louthd+p2parahd/4.0;
    pahd=1.0/p2parahd;
    dyhd=dwallthick*sin(atan(h1d*2*pahd));
    dzhd=dwallthick*cos(atan(h1d*2*pahd));
    DIV1hdwt=(l+louthd-dzhd)*(l+louthd-dzhd);
    p2parahdwt=2.0*(sqrt(DIV1hdwt+((h1d+dyhd)*(h1d+dyhd)))-sqrt(DIV1hdwt));
    pbhdwt=l+louthd+p2parahdwt/4.0;
    pahdwt=1.0/p2parahdwt;
    h2dwt=sqrt(p2parahdwt*(louthd+p2parahdwt/4.0));
    h1dwt=sqrt(p2parahdwt*(louthd+l+p2parahdwt/4.0));
   }

if (linhd!=0 && louthd==0)										/* parabolic defocusing bottom wall */
    {
      DIV1hd=linhd*linhd;
      p2parahd=2.0*(sqrt(DIV1hd+(h1d*h1d))-sqrt(DIV1hd));
      h2d=sqrt(p2parahd*(l+linhd+p2parahd/4.0));
      pbhd=-(linhd+p2parahd/4.0);
      pahd=-1.0/p2parahd;
      dyhd=dwallthick*sin(atan(-h2d*2*pahd));
      dzhd=dwallthick*cos(atan(-h2d*2*pahd));
      DIV1hdwt=(linhd+l-dzhd)*(linhd+l-dzhd);
      p2parahdwt=2.0*(sqrt(DIV1hdwt+((h2d+dyhd)*(h2d+dyhd)))-sqrt(DIV1hdwt));
      h1dwt=sqrt(p2parahdwt*(linhd+p2parahdwt/4.0));
      h2dwt=sqrt(p2parahdwt*(linhd+l+p2parahdwt/4.0));
      pbhdwt=-(linhd+p2parahdwt/4.0);
      pahdwt=-1.0/p2parahdwt;
    }

if(linhd==0 && louthd==0){
    h1dwt=h1d+dwallthick/(cos(atan((h2d-h1d)/l)));
    h2dwt=h2d+dwallthick/(cos(atan((h2d-h1d)/l)));
    }



mru1=(h1uwt-h1u)/(w1r-w1rwt);										/* calculation for entrance and exit absorbing mask for the right upper corner*/
nru1=h1u-mru1*(-w1r);
mru2=(h2uwt-h2u)/(w2r-w2rwt);
nru2=h2u-mru2*(-w2r);

mrd1=(-h1dwt+h1d)/(w1r-w1rwt);										/* calculation for entrance and exit absorbing mask for the right lower corner*/
nrd1=-h1d-mrd1*(-w1r);
mrd2=(-h2dwt+h2d)/(w2r-w2rwt);
nrd2=-h2d-mrd2*(-w2r);

mlu1=(h1uwt-h1u)/(-w1l+w1lwt);										/* calculation for entrance and exit absorbing mask for the left upper corner*/
nlu1=h1u-mlu1*w1l;
mlu2=(h2uwt-h2u)/(-w2l+w2lwt);
nlu2=h2u-mlu2*w2l;

mld1=(-h1dwt+h1d)/(-w1l+w1lwt);										/* calculation for entrance and exit absorbing mask for the left lower corner*/
nld1=-h1d-mld1*w1l;
mld2=(-h2dwt+h2d)/(-w2l+w2lwt);
nld2=-h2d-mld2*w2l;

                                       /*          FIRST SHELL      */

lbwr1=linwr1+l+loutwr1;
z0wr1=(linwr1-l-loutwr1)/2.0;

if(loutwr1!=0 && linwr1!=0)
  { 
    u1wr1=sqrt((linwr1*linwr1)+(w1r1*w1r1));
    u2wr1=sqrt((w1r1*w1r1)+((l+loutwr1)*(l+loutwr1)));
    awr1=(u1wr1+u2wr1)/2.0;
    a2wr1=awr1*awr1;
    bwr1=sqrt(a2wr1-(lbwr1*lbwr1/4.0));
    b2wr1=bwr1*bwr1;
    DIV1wr1=sqrt(1.0-((lbwr1/2.0-loutwr1)*(lbwr1/2.0-loutwr1)/a2wr1));
    w2r1=bwr1*DIV1wr1;
    if(l<lbwr1/2-loutwr1){
        dxwr1=rwallthick1*sin(atan(a2wr1*w1r1/(b2wr1*z0wr1)));
        dzwr1=rwallthick1*cos(atan(a2wr1*w1r1/(b2wr1*z0wr1)));
    	u1wrwt1=sqrt(((linwr1+dzwr1)*(linwr1+dzwr1))+((w1r1+dxwr1)*(w1r1+dxwr1)));
    	u2wrwt1=sqrt(((w1r1+dxwr1)*(w1r1+dxwr1))+((l+loutwr1-dzwr1)*(l+loutwr1-dzwr1)));
    	awrwt1=(u1wrwt1+u2wrwt1)/2.0;
    	a2wrwt1=awrwt1*awrwt1;
    	bwrwt1=sqrt(a2wrwt1-(lbwr1*lbwr1/4.0));
    	b2wrwt1=bwrwt1*bwrwt1;
    	w2rwt1=bwrwt1*sqrt(1.0-((lbwr1/2.0-loutwr1)*(lbwr1/2.0-loutwr1)/a2wrwt1));
        w1rwt1=bwrwt1*sqrt(1.0-((lbwr1/2.0-loutwr1-l)*(lbwr1/2.0-loutwr1-l)/a2wrwt1));
    }else{
	bwrwt1=bwr1+rwallthick1;
        b2wrwt1=bwrwt1*bwrwt1;
        awrwt1=sqrt(b2wrwt1+(lbwr1*lbwr1/4.0));
        a2wrwt1=b2wrwt1+(lbwr1*lbwr1/4.0);
        w2rwt1=bwrwt1*sqrt(1.0-((lbwr1/2.0-loutwr1)*(lbwr1/2.0-loutwr1)/a2wrwt1));
        w1rwt1=bwrwt1*sqrt(1.0-((lbwr1/2.0-linwr1)*(lbwr1/2.0-linwr1)/a2wrwt1));
    }
   }



if(linwr1==0 && loutwr1!=0){
    DIV1wr1=(l+loutwr1)*(l+loutwr1);
    p2parawr1=2.0*(sqrt(DIV1wr1+(w1r1*w1r1))-sqrt(DIV1wr1));
    w2r1=sqrt(p2parawr1*(loutwr1+p2parawr1/4.0));
    pbwr1=l+loutwr1+p2parawr1/4.0;
    pawr1=1.0/p2parawr1;
    dxwr1=rwallthick1*sin(atan(w1r1*2*pawr1));
    dzwr1=rwallthick1*cos(atan(w1r1*2*pawr1));
    DIV1wrwt1=(l+loutwr1-dzwr1)*(l+loutwl1-dzwr1);
    p2parawrwt1=2.0*(sqrt(DIV1wrwt1+((w1r1+dxwr1)*(w1r1+dxwr1)))-sqrt(DIV1wrwt1));
    pbwrwt1=l+loutwr1+p2parawrwt1/4.0;
    pawrwt1=1.0/p2parawrwt1;
    w2rwt1=sqrt(p2parawrwt1*(loutwr1+p2parawrwt1/4.0));
    w1rwt1=sqrt(p2parawrwt1*(loutwr1+l+p2parawrwt1/4.0));
   }



if (linwr1!=0 && loutwr1==0)
    {
      DIV1wr1=linwr1*linwr1;
      p2parawr1=2.0*(sqrt(DIV1wr1+(w1r1*w1r1))-sqrt(DIV1wr1));
      w2r1=sqrt(p2parawr1*(l+linwr1+p2parawr1/4.0));
      pbwr1=-(linwr1+p2parawr1/4.0);
      pawr1=-1.0/p2parawr1;
      dxwr1=rwallthick1*sin(atan(-w2r1*2*pawr1));
      dzwr1=rwallthick1*cos(atan(-w2r1*2*pawr1));
      DIV1wrwt1=(linwr1+l-dzwr1)*(linwr1+l-dzwr1);
      p2parawrwt1=2.0*(sqrt(DIV1wrwt1+((w2r1+dxwr1)*(w2r1+dxwr1)))-sqrt(DIV1wrwt1));
      w1rwt1=sqrt(p2parawrwt1*(linwr1+p2parawrwt1/4.0));
      w2rwt1=sqrt(p2parawrwt1*(linwr1+l+p2parawrwt1/4.0));
      pbwrwt1=-(linwr1+p2parawrwt1/4.0);
      pawrwt1=-1.0/p2parawrwt1;
    }


if(linwr1==0 && loutwr1==0){
    w1rwt1=w1r1+rwallthick1/(cos(atan((w1r1-w2r1)/l)));
    w2rwt1=w2r1+rwallthick1/(cos(atan((w1r1-w2r1)/l)));
    }

lbwl1=linwl1+l+loutwl1;
z0wl1=(linwl1-l-loutwl1)/2.0;

if((linwl1!=0) && (loutwl1!=0) ) 
  { 
    u1wl1=sqrt((linwl1*linwl1)+(w1l1*w1l1));
    u2wl1=sqrt((w1l1*w1l1)+((l+loutwl1)*(l+loutwl1)));
    awl1=(u1wl1+u2wl1)/2.0;
    a2wl1=awl1*awl1;
    bwl1=sqrt(a2wl1-(lbwl1*lbwl1/4.0));
    b2wl1=bwl1*bwl1;
    DIV1wl1=sqrt(1.0-((lbwl1/2.0-loutwl1)*(lbwl1/2.0-loutwl1)/a2wl1));
    w2l1=bwl1*DIV1wl1;
    if(l<lbwl1/2-loutwl1){
        dxwl1=lwallthick1*sin(atan(a2wl1*w1l1/(b2wl1*z0wl1)));
        dzwl1=lwallthick1*cos(atan(a2wl1*w1l1/(b2wl1*z0wl1)));
    	u1wlwt1=sqrt(((linwl1+dzwl1)*(linwl1+dzwl1))+((w1l1+dxwl1)*(w1l1+dxwl1)));								
    	u2wlwt1=sqrt(((w1l1+dxwl1)*(w1l1+dxwl1))+((l+loutwl1-dzwl1)*(l+loutwl1-dzwl1)));	
    	awlwt1=(u1wlwt1+u2wlwt1)/2.0;
    	a2wlwt1=awlwt1*awlwt1;
    	bwlwt1=sqrt(a2wlwt1-(lbwl1*lbwl1/4.0));
    	b2wlwt1=bwlwt1*bwlwt1;
    	w2lwt1=bwlwt1*sqrt(1.0-((lbwl1/2.0-loutwl1)*(lbwl1/2.0-loutwl1)/a2wlwt1));
        w1lwt1=bwlwt1*sqrt(1.0-((lbwl1/2.0-loutwl1-l)*(lbwl1/2.0-loutwl1-l)/a2wlwt1));
    }else{
	bwlwt1=bwl1+lwallthick1;
        b2wlwt1=bwlwt1*bwlwt1;
        awlwt1=sqrt(b2wlwt1+(lbwl1*lbwl1/4.0));
        a2wlwt1=b2wlwt1+(lbwl1*lbwl1/4.0);
        w2lwt1=bwlwt1*sqrt(1.0-((lbwl1/2.0-loutwl1)*(lbwl1/2.0-loutwl1)/a2wlwt1));
        w1lwt1=bwlwt1*sqrt(1.0-((lbwl1/2.0-linwl1)*(lbwl1/2.0-linwl1)/a2wlwt1));
    }
   }


if(linwl1==0 && loutwl1!=0)
   {
    DIV1wl1=(l+loutwl1)*(l+loutwl1);
    p2parawl1=2.0*(sqrt(DIV1wl1+(w1l1*w1l1))-sqrt(DIV1wl1));
    w2l1=sqrt(p2parawl1*(loutwl1+p2parawl1/4.0));
    pbwl1=l+loutwl1+p2parawl1/4.0;
    pawl1=1.0/p2parawl1;
    dxwl1=lwallthick1*sin(atan(w1l1*2*pawl1));
    dzwl1=lwallthick1*cos(atan(w1l1*2*pawl1));
    DIV1wlwt1=(l+loutwl1-dzwl1)*(l+loutwl1-dzwl1);
    p2parawlwt1=2.0*(sqrt(DIV1wlwt1+((w1l1+dxwl1)*(w1l1+dxwl1)))-sqrt(DIV1wlwt1));
    pbwlwt1=l+loutwl1+p2parawlwt1/4.0;
    pawlwt1=1.0/p2parawlwt1;
    w2lwt1=sqrt(p2parawlwt1*(loutwl1+p2parawlwt1/4.0));
    w1lwt1=sqrt(p2parawlwt1*(loutwl1+l+p2parawlwt1/4.0));
   }

if (linwl1!=0 && loutwl1==0)
    {
      DIV1wl1=linwl1*linwl1;
      p2parawl1=2.0*(sqrt(DIV1wl1+(w1l1*w1l1))-sqrt(DIV1wl1));
      w2l1=sqrt(p2parawl1*(l+linwl1+p2parawl1/4.0));
      pbwl1=-(linwl1+p2parawl1/4.0);
      pawl1=-1.0/p2parawl1;
      dxwl1=lwallthick1*sin(atan(-w2l1*2*pawl1));
      dzwl1=lwallthick1*cos(atan(-w2l1*2*pawl1));
      DIV1wlwt1=(linwl1+l-dzwl1)*(linwl1+l-dzwl1);
      p2parawlwt1=2.0*(sqrt(DIV1wlwt1+((w2l1+dxwl1)*(w2l1+dxwl1)))-sqrt(DIV1wlwt1));
      w1lwt1=sqrt(p2parawlwt1*(linwl1+p2parawlwt1/4.0));
      w2lwt1=sqrt(p2parawlwt1*(linwl1+l+p2parawlwt1/4.0));
      pbwlwt1=-(linwl1+p2parawlwt1/4.0);
      pawlwt1=-1.0/p2parawlwt1;
    }

if(linwl1==0 && loutwl1==0){
    w1lwt1=w1l1+lwallthick1/(cos(atan((w2l1-w1l1)/l)));
    w2lwt1=w2l1+lwallthick1/(cos(atan((w2l1-w1l1)/l)));
    }


lbhu1=linhu1+l+louthu1;
z0hu1=lbhu1/2.0-l-louthu1;	

if (linhu1 != 0 && louthu1 !=0)
   {
    u1hu1=sqrt((linhu1*linhu1)+(h1u1*h1u1));
    u2hu1=sqrt((h1u1*h1u1)+((l+louthu1)*(l+louthu1)));
    ahu1=(u1hu1+u2hu1)/2.0;
    bhu1=sqrt(ahu1*ahu1-(lbhu1*lbhu1/4.0));
    a2hu1=ahu1*ahu1;
    b2hu1=bhu1*bhu1;
    DIV1hu1=sqrt(1.0-((lbhu1/2.0-louthu1)*(lbhu1/2.0-louthu1)/a2hu1));
    h2u1=bhu1*DIV1hu1;
    if(l<lbhu1/2-louthu1){
        dyhu1=uwallthick1*sin(atan(a2hu1*h1u1/(b2hu1*z0hu1)));
        dzhu1=uwallthick1*cos(atan(a2hu1*h1u1/(b2hu1*z0hu1)));
    	u1huwt1=sqrt(((linhu1+dzhu1)*(linhu1+dzhu1))+((h1u1+dyhu1)*(h1u1+dyhu1)));								
    	u2huwt1=sqrt(((h1u1+dyhu1)*(h1u1+dyhu1))+((l+louthu1-dzhu1)*(l+louthu1-dzhu1)));	
    	ahuwt1=(u1huwt1+u2huwt1)/2.0;
    	a2huwt1=ahuwt1*ahuwt1;
    	bhuwt1=sqrt(a2huwt1-(lbhu1*lbhu1/4.0));
    	b2huwt1=bhuwt1*bhuwt1;
    	h2uwt1=bhuwt1*sqrt(1.0-((lbhu1/2.0-louthu1)*(lbhu1/2.0-louthu1)/a2huwt1));
        h1uwt1=bhuwt1*sqrt(1.0-((lbhu1/2.0-louthu1-l)*(lbhu1/2.0-louthu1-l)/a2huwt1));
    }else{
	bhuwt1=bhu1+uwallthick1;
        b2huwt1=bhuwt1*bhuwt1;
        ahuwt1=sqrt(b2huwt1+(lbhu1*lbhu1/4.0));
        a2huwt1=b2huwt1+(lbhu1*lbhu1/4.0);
        h2uwt1=bhuwt1*sqrt(1.0-((lbhu1/2.0-louthu1)*(lbhu1/2.0-louthu1)/a2huwt1));
        h1uwt1=bhuwt1*sqrt(1.0-((lbhu1/2.0-linhu1)*(lbhu1/2.0-linhu1)/a2huwt1));
    }
  }

if(linhu1==0 && louthu1!=0)
   { 	
    DIV1hu1=(l+louthu1)*(l+louthu1);
    p2parahu1=2.0*(sqrt(DIV1hu1+(h1u1*h1u1))-sqrt(DIV1hu1));
    h2u1=sqrt(p2parahu1*(louthu1+p2parahu1/4.0));
    pbhu1=l+louthu1+p2parahu1/4.0;
    pahu1=1.0/p2parahu1;
    dyhu1=uwallthick1*sin(atan(h1u1*2*pahu1));
    dzhu1=uwallthick1*cos(atan(h1u1*2*pahu1));
    DIV1huwt1=(l+louthu1-dzhu1)*(l+louthu1-dzhu1);
    p2parahuwt1=2.0*(sqrt(DIV1huwt1+((h1u1+dyhu1)*(h1u1+dyhu1)))-sqrt(DIV1huwt1));
    pbhuwt1=l+louthu1+p2parahuwt1/4.0;
    pahuwt1=1.0/p2parahuwt1;
    h2uwt1=sqrt(p2parahuwt1*(louthu1+p2parahuwt1/4.0));
    h1uwt1=sqrt(p2parahuwt1*(louthu1+l+p2parahuwt1/4.0));
   } 

if (linhu1!=0 && louthu1==0)
    {
      DIV1hu1=linhu1*linhu1;
      p2parahu1=2.0*(sqrt(DIV1hu1+(h1u1*h1u1))-sqrt(DIV1hu1));
      h2u1=sqrt(p2parahu1*(l+linhu1+p2parahu1/4.0));
      pbhu1=-(linhu1+p2parahu1/4.0);
      pahu1=-1.0/p2parahu1;
      dyhu1=uwallthick1*sin(atan(-h2u1*2*pahu1));
      dzhu1=uwallthick1*cos(atan(-h2u1*2*pahu1));
      DIV1huwt1=(linhu1+l-dzhu1)*(linhu1+l-dzhu1);
      p2parahuwt1=2.0*(sqrt(DIV1huwt1+((h2u1+dyhu1)*(h2u1+dyhu1)))-sqrt(DIV1huwt1));
      h1uwt1=sqrt(p2parahuwt1*(linhu1+p2parahuwt1/4.0));
      h2uwt1=sqrt(p2parahuwt1*(linhu1+l+p2parahuwt1/4.0));
      pbhuwt1=-(linhu1+p2parahuwt1/4.0);
      pahuwt1=-1.0/p2parahuwt1;
    }

if(linhu1==0 && louthu1==0){
    h1uwt1=h1u1+uwallthick1/(cos(atan((h2u1-h1u1)/l)));
    h2uwt1=h2u1+uwallthick1/(cos(atan((h2u1-h1u1)/l)));
    }


lbhd1=linhd1+l+louthd1;
z0hd1=lbhd1/2.0-l-louthd1;

if (linhd1 != 0 && louthd1 !=0)
   {
    u1hd1=sqrt((linhd1*linhd1)+(h1d1*h1d1));
    u2hd1=sqrt((h1d1*h1d1)+((l+louthd1)*(l+louthd1)));
    ahd1=(u1hd1+u2hd1)/2.0;
    bhd1=sqrt(ahd1*ahd1-(lbhd1*lbhd1/4.0));
    a2hd1=ahd1*ahd1;
    b2hd1=bhd1*bhd1;
    DIV1hd1=sqrt(1.0-((lbhd1/2.0-louthd1)*(lbhd1/2.0-louthd1)/a2hd1));
    h2d1=bhd1*DIV1hd1;
    if(l<lbhd/21-louthd1){
        dyhd1=dwallthick1*sin(atan(a2hd1*h1d1/(b2hd1*z0hd1)));
        dzhd1=dwallthick1*cos(atan(a2hd1*h1d1/(b2hd1*z0hd1)));
    	u1hdwt1=sqrt(((linhd1+dzhd1)*(linhd1+dzhd1))+((h1d1+dyhd1)*(h1d1+dyhd1)));	
    	u2hdwt1=sqrt(((h1d1+dyhd1)*(h1d1+dyhd1))+((l+louthd1-dzhd1)*(l+louthd1-dzhd1)));
    	ahdwt1=(u1hdwt1+u2hdwt1)/2.0;
    	a2hdwt1=ahdwt1*ahdwt1;
    	bhdwt1=sqrt(a2hdwt1-(lbhd1*lbhd1/4.0));
    	b2hdwt1=bhdwt1*bhdwt1;
    	h2dwt1=bhdwt1*sqrt(1.0-((lbhd1/2.0-louthd1)*(lbhd1/2.0-louthd1)/a2hdwt1));
        h1dwt1=bhdwt1*sqrt(1.0-((lbhd1/2.0-louthd1-l)*(lbhd1/2.0-louthd1-l)/a2hdwt1));
    }else{
	bhdwt1=bhd1+dwallthick1;
        b2hdwt1=bhdwt1*bhdwt1;
        ahdwt1=sqrt(b2hdwt1+(lbhd1*lbhd1/4.0));
        a2hdwt1=b2hdwt1+(lbhd1*lbhd1/4.0);
        h2dwt1=bhdwt1*sqrt(1.0-((lbhd1/2.0-louthd1)*(lbhd1/2.0-louthd1)/a2hdwt1));
        h1dwt1=bhdwt1*sqrt(1.0-((lbhd1/2.0-linhd1)*(lbhd1/2.0-linhd1)/a2hdwt1));
    }
  }

if(linhd1==0 && louthd1!=0)
   {	
    DIV1hd1=(l+louthd1)*(l+louthd1);
    p2parahd1=2.0*(sqrt(DIV1hd1+(h1d1*h1d1))-sqrt(DIV1hd1));
    h2d1=sqrt(p2parahd1*(louthd1+p2parahd1/4.0));
    pbhd1=l+louthd1+p2parahd1/4.0;
    pahd1=1.0/p2parahd1;
    dyhd1=dwallthick1*sin(atan(h1d1*2*pahd1));
    dzhd1=dwallthick1*cos(atan(h1d1*2*pahd1));
    DIV1hdwt1=(l+louthd1-dzhd1)*(l+louthd1-dzhd1);
    p2parahdwt1=2.0*(sqrt(DIV1hdwt1+((h1d1+dyhd1)*(h1d1+dyhd1)))-sqrt(DIV1hdwt1));
    pbhdwt1=l+louthd1+p2parahdwt1/4.0;
    pahdwt1=1.0/p2parahdwt1;
    h2dwt1=sqrt(p2parahdwt1*(louthd1+p2parahdwt1/4.0));
    h1dwt1=sqrt(p2parahdwt1*(louthd1+l+p2parahdwt1/4.0));
   }

if (linhd1!=0 && louthd1==0)
    {
      DIV1hd1=linhd1*linhd1;
      p2parahd1=2.0*(sqrt(DIV1hd1+(h1d1*h1d1))-sqrt(DIV1hd1));
      h2d1=sqrt(p2parahd1*(l+linhd1+p2parahd1/4.0));
      pbhd1=-(linhd1+p2parahd1/4.0);
      pahd1=-1.0/p2parahd1;
      dyhd1=dwallthick1*sin(atan(-h2d1*2*pahd1));
      dzhd1=dwallthick1*cos(atan(-h2d1*2*pahd1));
      DIV1hdwt1=(linhd1+l-dzhd1)*(linhd1+l-dzhd1);
      p2parahdwt1=2.0*(sqrt(DIV1hdwt1+((h2d1+dyhd1)*(h2d1+dyhd1)))-sqrt(DIV1hdwt1));
      h1dwt1=sqrt(p2parahdwt1*(linhd1+p2parahdwt1/4.0));
      h2dwt1=sqrt(p2parahdwt1*(linhd1+l+p2parahdwt1/4.0));
      pbhdwt1=-(linhd1+p2parahdwt1/4.0);
      pahdwt1=-1.0/p2parahdwt1;
    }

if(linhd1==0 && louthd1==0){
    h1dwt1=h1d1+dwallthick1/(cos(atan((h2d1-h1d1)/l)));
    h2dwt1=h2d1+dwallthick1/(cos(atan((h2d1-h1d1)/l)));
    }



mru11=(h1uwt1-h1u1)/(w1r1-w1rwt1);
nru11=h1u1-mru11*(-w1r1);
mru21=(h2uwt1-h2u1)/(w2r1-w2rwt1);
nru21=h2u1-mru21*(-w2r1);

mrd11=(-h1dwt1+h1d1)/(w1r1-w1rwt1);
nrd11=-h1d1-mrd11*(-w1r1);
mrd21=(-h2dwt1+h2d1)/(w2r1-w2rwt1);
nrd21=-h2d1-mrd21*(-w2r1);

mlu11=(h1uwt1-h1u1)/(-w1l1+w1lwt1);
nlu11=h1u1-mlu11*w1l1;
mlu21=(h2uwt1-h2u1)/(-w2l1+w2lwt1);
nlu21=h2u1-mlu21*w2l1;

mld11=(-h1dwt1+h1d1)/(-w1l1+w1lwt1);
nld11=-h1d1-mld11*w1l1;
mld21=(-h2dwt1+h2d1)/(-w2l1+w2lwt1);
nld21=-h2d1-mld21*w2l1;



if (w1r1 < w1rwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w1r1 have to be bigger or equal w1rwt  \n");
    printf(" w1r1= %f \n",w1r1 );
    printf(" w1rwt = %f \n",w1rwt  );
    fprintf(stderr,"           check input and wallthicknesses! \n");
    exit(-1);
  }

if (w1l1 < w1lwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w1l1 have to be bigger or equal w1lwt  \n");
    printf(" w1l1= %f \n",w1l1 );
    printf(" w1lwt = %f \n",w1lwt  );
    fprintf(stderr,"           check input parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h1u1 < h1uwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h1u1 have to be bigger or equal h1uwt  \n");
    printf(" h1u1= %f \n",h1u1 );
    printf(" h1uwt = %f \n",h1uwt  );
    fprintf(stderr,"           check input parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h1d1 < h1dwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h1d1 have to be bigger or equal h1dwt  \n");
    printf(" h1d1= %f \n",h1d1 );
    printf(" h1dwt = %f \n",h1dwt  );
    fprintf(stderr,"           check curve parameter and walltchicknesses! \n");
    exit(-1);
  }


if (w2r1 < w2rwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w2r1 have to be bigger or equal w2rwt  \n");
    printf(" w2r1= %f \n",w2r1 );
    printf(" w2rwt = %f \n",w2rwt  );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

if (w2l1 < w2lwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w2l1 have to be bigger or equal w2lwt  \n");
    printf(" w2l1= %f \n",w2l1 );
    printf(" w2lwt = %f \n",w2lwt  );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h2u1 < h2uwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h2u1 have to be bigger or equal h2uwt  \n");
    printf(" h2u1= %f \n",h2u1 );
    printf(" h2uwt = %f \n",h2uwt  );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h2d1 < h2dwt )
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h2d1 have to be bigger or equal h2dwt  \n");
    printf(" h2d1= %f \n",h2d1 );
    printf(" h2dwt = %f \n",h2dwt  );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

lbwr2=linwr2+l+loutwr2;
z0wr2=(linwr2-l-loutwr2)/2.0;

if(loutwr2!=0 && linwr2!=0)
  { 
    u1wr2=sqrt((linwr2*linwr2)+(w1r2*w1r2));
    u2wr2=sqrt((w1r2*w1r2)+((l+loutwr2)*(l+loutwr2)));
    awr2=(u1wr2+u2wr2)/2.0;
    a2wr2=awr2*awr2;
    bwr2=sqrt(a2wr2-(lbwr2*lbwr2/4.0));
    b2wr2=bwr2*bwr2;
    DIV1wr2=sqrt(1.0-((lbwr2/2.0-loutwr2)*(lbwr2/2.0-loutwr2)/a2wr2));
    w2r2=bwr2*DIV1wr2;
    if(l<lbwr2/2-loutwr2){
        dxwr2=rwallthick2*sin(atan(a2wr2*w1r2/(b2wr2*z0wr2)));
        dzwr2=rwallthick2*cos(atan(a2wr2*w1r2/(b2wr2*z0wr2)));
    	u1wrwt2=sqrt(((linwr2+dzwr2)*(linwr2+dzwr2))+((w1r2+dxwr2)*(w1r2+dxwr2)));
    	u2wrwt2=sqrt(((w1r2+dxwr2)*(w1r2+dxwr2))+((l+loutwr2-dzwr2)*(l+loutwr2-dzwr2)));
    	awrwt2=(u1wrwt2+u2wrwt2)/2.0;
    	a2wrwt2=awrwt2*awrwt2;
    	bwrwt2=sqrt(a2wrwt2-(lbwr2*lbwr2/4.0));
    	b2wrwt2=bwrwt2*bwrwt2;
    	w2rwt2=bwrwt2*sqrt(1.0-((lbwr2/2.0-loutwr2)*(lbwr2/2.0-loutwr2)/a2wrwt2));
        w1rwt2=bwrwt2*sqrt(1.0-((lbwr2/2.0-loutwr2-l)*(lbwr2/2.0-loutwr2-l)/a2wrwt2));
    }else{
	bwrwt2=bwr2+rwallthick2;
        b2wrwt2=bwrwt2*bwrwt2;
        awrwt2=sqrt(b2wrwt2+(lbwr2*lbwr2/4.0));
        a2wrwt2=b2wrwt2+(lbwr2*lbwr2/4.0);
        w2rwt2=bwrwt2*sqrt(1.0-((lbwr2/2.0-loutwr2)*(lbwr2/2.0-loutwr2)/a2wrwt2));
        w1rwt2=bwrwt2*sqrt(1.0-((lbwr2/2.0-linwr2)*(lbwr2/2.0-linwr2)/a2wrwt2));
    }
   }



if(linwr2==0 && loutwr2!=0){
    DIV1wr2=(l+loutwr2)*(l+loutwr2);
    p2parawr2=2.0*(sqrt(DIV1wr2+(w1r2*w1r2))-sqrt(DIV1wr2));
    w2r2=sqrt(p2parawr2*(loutwr2+p2parawr2/4.0));
    pbwr2=l+loutwr2+p2parawr2/4.0;
    pawr2=1.0/p2parawr2;
    dxwr2=rwallthick2*sin(atan(w1r2*2*pawr2));
    dzwr2=rwallthick2*cos(atan(w1r2*2*pawr2));
    DIV1wrwt2=(l+loutwr2-dzwr2)*(l+loutwl2-dzwr2);
    p2parawrwt2=2.0*(sqrt(DIV1wrwt2+((w1r2+dxwr2)*(w1r2+dxwr2)))-sqrt(DIV1wrwt2));
    pbwrwt2=l+loutwr2+p2parawrwt2/4.0;
    pawrwt2=1.0/p2parawrwt2;
    w2rwt2=sqrt(p2parawrwt2*(loutwr2+p2parawrwt2/4.0));
    w1rwt2=sqrt(p2parawrwt2*(loutwr2+l+p2parawrwt2/4.0));
   }



if (linwr2!=0 && loutwr2==0)
    {
      DIV1wr2=linwr2*linwr2;
      p2parawr2=2.0*(sqrt(DIV1wr2+(w1r2*w1r2))-sqrt(DIV1wr2));
      w2r2=sqrt(p2parawr2*(l+linwr2+p2parawr2/4.0));
      pbwr2=-(linwr2+p2parawr2/4.0);
      pawr2=-1.0/p2parawr2;
      dxwr2=rwallthick2*sin(atan(-w2r2*2*pawr2));
      dzwr2=rwallthick2*cos(atan(-w2r2*2*pawr2));
      DIV1wrwt2=(linwr2+l-dzwr2)*(linwr2+l-dzwr2);
      p2parawrwt2=2.0*(sqrt(DIV1wrwt2+((w2r2+dxwr2)*(w2r2+dxwr2)))-sqrt(DIV1wrwt2));
      w1rwt2=sqrt(p2parawrwt2*(linwr2+p2parawrwt2/4.0));
      w2rwt2=sqrt(p2parawrwt2*(linwr2+l+p2parawrwt2/4.0));
      pbwrwt2=-(linwr2+p2parawrwt2/4.0);
      pawrwt2=-1.0/p2parawrwt2;
    }


if(linwr2==0 && loutwr2==0){
    w1rwt2=w1r2+rwallthick2/(cos(atan((w1r2-w2r2)/l)));
    w2rwt2=w2r2+rwallthick2/(cos(atan((w1r2-w2r2)/l)));
    }

lbwl2=linwl2+l+loutwl2;
z0wl2=(linwl2-l-loutwl2)/2.0;

if((linwl2!=0) && (loutwl2!=0) ) 
  { 
    u1wl2=sqrt((linwl2*linwl2)+(w1l2*w1l2));
    u2wl2=sqrt((w1l2*w1l2)+((l+loutwl2)*(l+loutwl2)));
    awl2=(u1wl2+u2wl2)/2.0;
    a2wl2=awl2*awl2;
    bwl2=sqrt(a2wl2-(lbwl2*lbwl2/4.0));
    b2wl2=bwl2*bwl2;
    DIV1wl2=sqrt(1.0-((lbwl2/2.0-loutwl2)*(lbwl2/2.0-loutwl2)/a2wl2));
    w2l2=bwl2*DIV1wl2;
    if(l<lbwl2/2-loutwl2){
        dxwl2=lwallthick2*sin(atan(a2wl2*w1l2/(b2wl2*z0wl2)));
        dzwl2=lwallthick2*cos(atan(a2wl2*w1l2/(b2wl2*z0wl2)));
    	u1wlwt2=sqrt(((linwl2+dzwl2)*(linwl2+dzwl2))+((w1l2+dxwl2)*(w1l2+dxwl2)));								
    	u2wlwt2=sqrt(((w1l2+dxwl2)*(w1l2+dxwl2))+((l+loutwl2-dzwl2)*(l+loutwl2-dzwl2)));	
    	awlwt2=(u1wlwt2+u2wlwt2)/2.0;
    	a2wlwt2=awlwt2*awlwt2;
    	bwlwt2=sqrt(a2wlwt2-(lbwl2*lbwl2/4.0));
    	b2wlwt2=bwlwt2*bwlwt2;
    	w2lwt2=bwlwt2*sqrt(1.0-((lbwl2/2.0-loutwl2)*(lbwl2/2.0-loutwl2)/a2wlwt2));
        w1lwt2=bwlwt2*sqrt(1.0-((lbwl2/2.0-loutwl2-l)*(lbwl2/2.0-loutwl2-l)/a2wlwt2));
    }else{
	bwlwt2=bwl2+lwallthick2;
        b2wlwt2=bwlwt2*bwlwt2;
        awlwt2=sqrt(b2wlwt2+(lbwl2*lbwl2/4.0));
        a2wlwt2=b2wlwt2+(lbwl2*lbwl2/4.0);
        w2lwt2=bwlwt2*sqrt(1.0-((lbwl2/2.0-loutwl2)*(lbwl2/2.0-loutwl2)/a2wlwt2));
        w1lwt2=bwlwt2*sqrt(1.0-((lbwl2/2.0-linwl2)*(lbwl2/2.0-linwl2)/a2wlwt2));
    }
   }


if(linwl2==0 && loutwl2!=0)
   {
    DIV1wl2=(l+loutwl2)*(l+loutwl2);
    p2parawl2=2.0*(sqrt(DIV1wl2+(w1l2*w1l2))-sqrt(DIV1wl2));
    w2l2=sqrt(p2parawl2*(loutwl2+p2parawl2/4.0));
    pbwl2=l+loutwl2+p2parawl2/4.0;
    pawl2=1.0/p2parawl2;
    dxwl2=lwallthick2*sin(atan(w1l2*2*pawl2));
    dzwl2=lwallthick2*cos(atan(w1l2*2*pawl2));
    DIV1wlwt2=(l+loutwl2-dzwl2)*(l+loutwl2-dzwl2);
    p2parawlwt2=2.0*(sqrt(DIV1wlwt2+((w1l2+dxwl2)*(w1l2+dxwl2)))-sqrt(DIV1wlwt2));
    pbwlwt2=l+loutwl2+p2parawlwt2/4.0;
    pawlwt2=1.0/p2parawlwt2;
    w2lwt2=sqrt(p2parawlwt2*(loutwl2+p2parawlwt2/4.0));
    w1lwt2=sqrt(p2parawlwt2*(loutwl2+l+p2parawlwt2/4.0));
   }

if (linwl2!=0 && loutwl2==0)
    {
      DIV1wl2=linwl2*linwl2;
      p2parawl2=2.0*(sqrt(DIV1wl2+(w1l2*w1l2))-sqrt(DIV1wl2));
      w2l2=sqrt(p2parawl2*(l+linwl2+p2parawl2/4.0));
      pbwl2=-(linwl2+p2parawl2/4.0);
      pawl2=-1.0/p2parawl2;
      dxwl2=lwallthick2*sin(atan(-w2l2*2*pawl2));
      dzwl2=lwallthick2*cos(atan(-w2l2*2*pawl2));
      DIV1wlwt2=(linwl2+l-dzwl2)*(linwl2+l-dzwl2);
      p2parawlwt2=2.0*(sqrt(DIV1wlwt2+((w2l2+dxwl2)*(w2l2+dxwl2)))-sqrt(DIV1wlwt2));
      w1lwt2=sqrt(p2parawlwt2*(linwl2+p2parawlwt2/4.0));
      w2lwt2=sqrt(p2parawlwt2*(linwl2+l+p2parawlwt2/4.0));
      pbwlwt2=-(linwl2+p2parawlwt2/4.0);
      pawlwt2=-1.0/p2parawlwt2;
    }

if(linwl2==0 && loutwl2==0){
    w1lwt2=w1l2+lwallthick2/(cos(atan((w2l2-w1l2)/l)));
    w2lwt2=w2l2+lwallthick2/(cos(atan((w2l2-w1l2)/l)));
    }


lbhu2=linhu2+l+louthu2;
z0hu2=lbhu2/2.0-l-louthu2;	

if (linhu2 != 0 && louthu2 !=0)
   {
    u1hu2=sqrt((linhu2*linhu2)+(h1u2*h1u2));
    u2hu2=sqrt((h1u2*h1u2)+((l+louthu2)*(l+louthu2)));
    ahu2=(u1hu2+u2hu2)/2.0;
    bhu2=sqrt(ahu2*ahu2-(lbhu2*lbhu2/4.0));
    a2hu2=ahu2*ahu2;
    b2hu2=bhu2*bhu2;
    DIV1hu2=sqrt(1.0-((lbhu2/2.0-louthu2)*(lbhu2/2.0-louthu2)/a2hu2));
    h2u2=bhu2*DIV1hu2;
    if(l<lbhu2/2-louthu2){
        dyhu2=uwallthick2*sin(atan(a2hu2*h1u2/(b2hu2*z0hu2)));
        dzhu2=uwallthick2*cos(atan(a2hu2*h1u2/(b2hu2*z0hu2)));
    	u1huwt2=sqrt(((linhu2+dzhu2)*(linhu2+dzhu2))+((h1u2+dyhu2)*(h1u2+dyhu2)));								
    	u2huwt2=sqrt(((h1u2+dyhu2)*(h1u2+dyhu2))+((l+louthu2-dzhu2)*(l+louthu2-dzhu2)));	
    	ahuwt2=(u1huwt2+u2huwt2)/2.0;
    	a2huwt2=ahuwt2*ahuwt2;
    	bhuwt2=sqrt(a2huwt2-(lbhu2*lbhu2/4.0));
    	b2huwt2=bhuwt2*bhuwt2;
    	h2uwt2=bhuwt2*sqrt(1.0-((lbhu2/2.0-louthu2)*(lbhu2/2.0-louthu2)/a2huwt2));
        h1uwt2=bhuwt2*sqrt(1.0-((lbhu2/2.0-louthu2-l)*(lbhu2/2.0-louthu2-l)/a2huwt2));
    }else{
	bhuwt2=bhu2+uwallthick2;
        b2huwt2=bhuwt2*bhuwt2;
        ahuwt2=sqrt(b2huwt2+(lbhu2*lbhu2/4.0));
        a2huwt2=b2huwt2+(lbhu2*lbhu2/4.0);
        h2uwt2=bhuwt2*sqrt(1.0-((lbhu2/2.0-louthu2)*(lbhu2/2.0-louthu2)/a2huwt2));
        h1uwt2=bhuwt2*sqrt(1.0-((lbhu2/2.0-linhu2)*(lbhu2/2.0-linhu2)/a2huwt2));
    }
  }

if(linhu2==0 && louthu2!=0)
   { 	
    DIV1hu2=(l+louthu2)*(l+louthu2);
    p2parahu2=2.0*(sqrt(DIV1hu2+(h1u2*h1u2))-sqrt(DIV1hu2));
    h2u2=sqrt(p2parahu2*(louthu2+p2parahu2/4.0));
    pbhu2=l+louthu2+p2parahu2/4.0;
    pahu2=1.0/p2parahu2;
    dyhu2=uwallthick2*sin(atan(h1u2*2*pahu2));
    dzhu2=uwallthick2*cos(atan(h1u2*2*pahu2));
    DIV1huwt2=(l+louthu2-dzhu2)*(l+louthu2-dzhu2);
    p2parahuwt2=2.0*(sqrt(DIV1huwt2+((h1u2+dyhu2)*(h1u2+dyhu2)))-sqrt(DIV1huwt2));
    pbhuwt2=l+louthu2+p2parahuwt2/4.0;
    pahuwt2=1.0/p2parahuwt2;
    h2uwt2=sqrt(p2parahuwt2*(louthu2+p2parahuwt2/4.0));
    h1uwt2=sqrt(p2parahuwt2*(louthu2+l+p2parahuwt2/4.0));
   } 

if (linhu2!=0 && louthu2==0)
    {
      DIV1hu2=linhu2*linhu2;
      p2parahu2=2.0*(sqrt(DIV1hu2+(h1u2*h1u2))-sqrt(DIV1hu2));
      h2u2=sqrt(p2parahu2*(l+linhu2+p2parahu2/4.0));
      pbhu2=-(linhu2+p2parahu2/4.0);
      pahu2=-1.0/p2parahu2;
      dyhu2=uwallthick2*sin(atan(-h2u2*2*pahu2));
      dzhu2=uwallthick2*cos(atan(-h2u2*2*pahu2));
      DIV1huwt2=(linhu2+l-dzhu2)*(linhu2+l-dzhu2);
      p2parahuwt2=2.0*(sqrt(DIV1huwt2+((h2u2+dyhu2)*(h2u2+dyhu2)))-sqrt(DIV1huwt2));
      h1uwt2=sqrt(p2parahuwt2*(linhu2+p2parahuwt2/4.0));
      h2uwt2=sqrt(p2parahuwt2*(linhu2+l+p2parahuwt2/4.0));
      pbhuwt2=-(linhu2+p2parahuwt2/4.0);
      pahuwt2=-1.0/p2parahuwt2;
    }

if(linhu2==0 && louthu2==0){
    h1uwt2=h1u2+uwallthick2/(cos(atan((h2u2-h1u2)/l)));
    h2uwt2=h2u2+uwallthick2/(cos(atan((h2u2-h1u2)/l)));
    }


lbhd2=linhd2+l+louthd2;
z0hd2=lbhd2/2.0-l-louthd2;

if (linhd2 != 0 && louthd2 !=0)
   {
    u1hd2=sqrt((linhd2*linhd2)+(h1d2*h1d2));
    u2hd2=sqrt((h1d2*h1d2)+((l+louthd2)*(l+louthd2)));
    ahd2=(u1hd2+u2hd2)/2.0;
    bhd2=sqrt(ahd2*ahd2-(lbhd2*lbhd2/4.0));
    a2hd2=ahd2*ahd2;
    b2hd2=bhd2*bhd2;
    DIV1hd2=sqrt(1.0-((lbhd2/2.0-louthd2)*(lbhd2/2.0-louthd2)/a2hd2));
    h2d2=bhd2*DIV1hd2;
    if(l<lbhd2/21-louthd2){
        dyhd2=dwallthick2*sin(atan(a2hd2*h1d2/(b2hd2*z0hd2)));
        dzhd2=dwallthick2*cos(atan(a2hd2*h1d2/(b2hd2*z0hd2)));
    	u1hdwt2=sqrt(((linhd2+dzhd2)*(linhd2+dzhd2))+((h1d2+dyhd2)*(h1d2+dyhd2)));	
    	u2hdwt2=sqrt(((h1d2+dyhd2)*(h1d2+dyhd2))+((l+louthd2-dzhd2)*(l+louthd2-dzhd2)));
    	ahdwt2=(u1hdwt2+u2hdwt2)/2.0;
    	a2hdwt2=ahdwt2*ahdwt2;
    	bhdwt2=sqrt(a2hdwt2-(lbhd2*lbhd2/4.0));
    	b2hdwt2=bhdwt2*bhdwt2;
    	h2dwt2=bhdwt2*sqrt(1.0-((lbhd2/2.0-louthd2)*(lbhd2/2.0-louthd2)/a2hdwt2));
        h1dwt2=bhdwt2*sqrt(1.0-((lbhd2/2.0-louthd2-l)*(lbhd2/2.0-louthd2-l)/a2hdwt2));
    }else{
	bhdwt2=bhd2+dwallthick2;
        b2hdwt2=bhdwt2*bhdwt2;
        ahdwt2=sqrt(b2hdwt2+(lbhd2*lbhd2/4.0));
        a2hdwt2=b2hdwt2+(lbhd2*lbhd2/4.0);
        h2dwt2=bhdwt2*sqrt(1.0-((lbhd2/2.0-louthd2)*(lbhd2/2.0-louthd2)/a2hdwt2));
        h1dwt2=bhdwt2*sqrt(1.0-((lbhd2/2.0-linhd2)*(lbhd2/2.0-linhd2)/a2hdwt2));
    }
  }

if(linhd2==0 && louthd2!=0)
   {	
    DIV1hd2=(l+louthd2)*(l+louthd2);
    p2parahd2=2.0*(sqrt(DIV1hd2+(h1d2*h1d2))-sqrt(DIV1hd2));
    h2d2=sqrt(p2parahd2*(louthd2+p2parahd2/4.0));
    pbhd2=l+louthd2+p2parahd2/4.0;
    pahd2=1.0/p2parahd2;
    dyhd2=dwallthick2*sin(atan(h1d2*2*pahd2));
    dzhd2=dwallthick2*cos(atan(h1d2*2*pahd2));
    DIV1hdwt2=(l+louthd2-dzhd2)*(l+louthd2-dzhd2);
    p2parahdwt2=2.0*(sqrt(DIV1hdwt2+((h1d2+dyhd2)*(h1d2+dyhd2)))-sqrt(DIV1hdwt2));
    pbhdwt2=l+louthd2+p2parahdwt2/4.0;
    pahdwt2=1.0/p2parahdwt2;
    h2dwt2=sqrt(p2parahdwt2*(louthd2+p2parahdwt2/4.0));
    h1dwt2=sqrt(p2parahdwt2*(louthd2+l+p2parahdwt2/4.0));
   }

if (linhd2!=0 && louthd2==0)
    {
      DIV1hd2=linhd2*linhd2;
      p2parahd2=2.0*(sqrt(DIV1hd2+(h1d2*h1d2))-sqrt(DIV1hd2));
      h2d2=sqrt(p2parahd2*(l+linhd2+p2parahd2/4.0));
      pbhd2=-(linhd2+p2parahd2/4.0);
      pahd2=-1.0/p2parahd2;
      dyhd2=dwallthick2*sin(atan(-h2d2*2*pahd2));
      dzhd2=dwallthick2*cos(atan(-h2d2*2*pahd2));
      DIV1hdwt2=(linhd2+l-dzhd2)*(linhd2+l-dzhd2);
      p2parahdwt2=2.0*(sqrt(DIV1hdwt2+((h2d2+dyhd2)*(h2d2+dyhd2)))-sqrt(DIV1hdwt2));
      h1dwt2=sqrt(p2parahdwt2*(linhd2+p2parahdwt2/4.0));
      h2dwt2=sqrt(p2parahdwt2*(linhd2+l+p2parahdwt2/4.0));
      pbhdwt2=-(linhd2+p2parahdwt2/4.0);
      pahdwt2=-1.0/p2parahdwt2;
    }

if(linhd2==0 && louthd2==0){
    h1dwt2=h1d2+dwallthick2/(cos(atan((h2d2-h1d2)/l)));
    h2dwt2=h2d2+dwallthick2/(cos(atan((h2d2-h1d2)/l)));
    }



mru12=(h1uwt2-h1u2)/(w1r2-w1rwt2);
nru12=h1u2-mru12*(-w1r2);
mru22=(h2uwt2-h2u2)/(w2r2-w2rwt2);
nru22=h2u2-mru22*(-w2r2);

mrd12=(-h1dwt2+h1d2)/(w1r2-w1rwt2);
nrd12=-h1d2-mrd12*(-w1r2);
mrd22=(-h2dwt2+h2d2)/(w2r2-w2rwt2);
nrd22=-h2d2-mrd22*(-w2r2);

mlu12=(h1uwt2-h1u2)/(-w1l2+w1lwt2);
nlu12=h1u2-mlu12*w1l2;
mlu22=(h2uwt2-h2u2)/(-w2l2+w2lwt2);
nlu22=h2u2-mlu22*w2l2;

mld12=(-h1dwt2+h1d2)/(-w1l2+w1lwt2);
nld12=-h1d2-mld12*w1l2;
mld22=(-h2dwt2+h2d2)/(-w2l2+w2lwt2);
nld22=-h2d2-mld22*w2l2;



if (w1r2 < w1rwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w1r2 have to be bigger or equal w1rwt1 \n");
    printf(" w1r2= %f \n",w1r2 );
    printf(" w1rwt1= %f \n",w1rwt1 );
    fprintf(stderr,"           check input and wallthicknesses! \n");
    exit(-1);
  }

if (w1l2 < w1lwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w1l2 have to be bigger or equal w1lwt1 \n");
    printf(" w1l2= %f \n",w1l2 );
    printf(" w1lwt1= %f \n",w1lwt1 );
    fprintf(stderr,"           check input parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h1u2 < h1uwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h1u2 have to be bigger or equal h1uwt1 \n");
    printf(" h1u2= %f \n",h1u2 );
    printf(" h1uwt1= %f \n",h1uwt1 );
    fprintf(stderr,"           check input parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h1d2 < h1dwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h1d2 have to be bigger or equal h1dwt1 \n");
    printf(" h1d2= %f \n",h1d2 );
    printf(" h1dwt1= %f \n",h1dwt1 );
    fprintf(stderr,"           check curve parameter and walltchicknesses! \n");
    exit(-1);
  }


if (w2r2 < w2rwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w2r2 have to be bigger or equal w2rwt1 \n");
    printf(" w2r2= %f \n",w2r2 );
    printf(" w2rwt1= %f \n",w2rwt1 );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

if (w2l2 < w2lwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           w2l2 have to be bigger or equal w2lwt1 \n");
    printf(" w2l2= %f \n",w2l2 );
    printf(" w2lwt1= %f \n",w2lwt1 );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h2u2 < h2uwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h2u2 have to be bigger or equal h2uwt1 \n");
    printf(" h2u2= %f \n",h2u2 );
    printf(" h2uwt1= %f \n",h2uwt1 );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }

if (h2d2 < h2dwt1)
  {
    fprintf(stderr,"Component: %s (Guide_four_side) \n", NAME_CURRENT_COMP);
    fprintf(stderr,"           h2d2 have to be bigger or equal h2dwt1 \n");
    printf(" h2d2= %f \n",h2d2 );
    printf(" h2dwt1= %f \n",h2dwt1 );
    fprintf(stderr,"           check curve parameter and wallthicknesses! \n");
    exit(-1);
  }



%}



TRACE
%{

  int i;

  PROP_Z0;												/* Propagate neutron to guide entrance. */ 


  if(x <= -w1r && x >= -w1rwt && y <= mru1*x+nru1 && y>= mrd1*x+nrd1 && mxr!=-1 && mxrOW!=-1)		/* absorbing the neutron if it hit the RIGHT entrance wall and the wall is not transparent*/
      ABSORB;
  if(x >= w1l && x <=  w1lwt && y <= mlu1*x+nlu1 && y>= mld1*x+nld1 && mxl!=-1 && mxlOW!=-1 ) 		/* absorbing the neutron if it hit the LEFT entrance wall and the wall is not transparent*/
      ABSORB;
  if(y<=-h1d && y >=-h1dwt && x <= (y-nld1)/mld1 && x>= (y-nrd1)/mrd1 && myd!=-1 && mydOW!=-1)		/* absorbing the neutron if it hit the BOTTOM entrance wall and the wall is not transparent*/
      ABSORB;
  if(y>=h1u && y <= h1uwt && x <= (y-nlu1)/mlu1 && x>= (y-nru1)/mru1 && myu!=-1 && myuOW!=-1)		/* absorbing the neutron if it hit the TOP entrance wall and the wall is not transparent*/
    ABSORB; 

  if(x <= -w1r1 && x >= -w1rwt1 && y <= mru11*x+nru11 && y>= mrd11*x+nrd11 && mxr1!=-1 && mxrOW1!=-1)
      ABSORB;
  if(x >= w1l1 && x <=  w1lwt1 && y <= mlu11*x+nlu11 && y>= mld11*x+nld11 && mxl1!=-1 && mxlOW1!=-1 )
      ABSORB;
  if(y<=-h1d1 && y >=-h1dwt1 && x <= (y-nld11)/mld11 && x>= (y-nrd11)/mrd11 && myd1!=-1 && mydOW1!=-1)
      ABSORB;
  if(y>=h1u1 && y <= h1uwt1 && x <= (y-nlu11)/mlu11 && x>= (y-nru11)/mru11 && myu1!=-1 && myuOW1!=-1)
    ABSORB; 

  if(x <= -w1r2 && x >= -w1rwt2 && y <= mru12*x+nru12 && y>= mrd12*x+nrd12 && mxr2!=-1 && mxrOW2!=-1)
      ABSORB;
  if(x >= w1l2 && x <=  w1lwt2 && y <= mlu12*x+nlu12 && y>= mld12*x+nld12 && mxl2!=-1 && mxlOW2!=-1 )
      ABSORB;
  if(y<=-h1d2 && y >=-h1dwt2 && x <= (y-nld12)/mld12 && x>= (y-nrd12)/mrd12 && myd2!=-1 && mydOW2!=-1)
      ABSORB;
  if(y>=h1u2 && y <= h1uwt2 && x <= (y-nlu12)/mlu12 && x>= (y-nru12)/mru12 && myu2!=-1 && myuOW2!=-1)
    ABSORB; 


do{										/* start the propagation loop inside the guide */
  t1=(l-z)/vz;									/* needed time to pass the guide (or rest of the guide without any interaction)*/

  if(loutwr==0 && linwr==0)							/* for a straight right wall */
  {
  m=(-w2r+w1r)/l;
  t2w1r=(m*z+(-w1r)-x)/(vx-m*vz);						/* time untill next interaction with this wall (INNER wall)*/
  t2w1rwt=(m*z+(-w1rwt)-x)/(vx-m*vz);						/* time untill next interaction with this wall (OUTER wall)*/
  if(t2w1r<1e-15)								/* solving the precision problem for the intersection times given by double variable type, to small times (<1e-15) gives scattering events */
    t2w1r=t1+2.0;								/* at the same postion again (time is set to zero). this results in a sign change in the velocity components, which results in a wall tunneling.*/
  if(t2w1rwt<1e-15)								/* see comments above*/
    t2w1rwt=t1+2.0; 
  }


  if(loutwr!=0 && linwr!=0)							/* for a elliptic right wall */
  { 										/* solving the elliptic equation in respect to z and the straight neutron trajectoty, only two z values possible! */
    m=vx/vz;									/* m parameter of the neutron trajectory*/
    n=-m*z+x;									/* n parameter of the neutron trajectory */
    pwr=2.0*(a2wr*m*n+b2wr*z0wr)/(a2wr*m*m+b2wr);				/* p parameter of quadratic equation for calulation the z component of the intersection point with respect to the neutron trajectory (INNER wall)*/
    qwr=(a2wr*n*n+b2wr*z0wr*z0wr-a2wr*b2wr)/(a2wr*m*m+b2wr);			/* q parameter of quadratic equation for calulation the z component of the intersection point with respect to the neutron trajectory (INNER wall)*/ 
    if ((pwr*pwr/4.0)-qwr<0){							
    t2w1r=t1+2.0;								/* if the neutron never touch the ellipse the time is set to be bigger than the time (t1) needed to pass the component */
    }else{
        zw1r=-pwr/2.0+sqrt((pwr*pwr/4.0)-qwr);					/* first solution for z (INNER wall)*/
        zw2r=-pwr/2.0-sqrt((pwr*pwr/4.0)-qwr);					/* second solution for z (INNER wall)*/
        t2w1r=(zw1r-z)/vz;							/* interaction time for first z value (INNER wall)*/
        t2w2r=(zw2r-z)/vz;							/* interactime time for second z value (INNER wall)*/
        if(t2w1r<1e-15)								/* solving the precision problem for the intersection times given by double variable type, to small times (<1e-15) gives scattering events */
        t2w1r=t1+2.0;								/* at the same postion again (time is set to zero). this results in a sign change in the velocity components, which results in a wall tunneling.*/
        if(t2w2r<1e-15)								/* see comments above*/
        t2w2r=t1+2.0;
        if(t2w2r<t2w1r)								/* choosing the smaller positive time solution (INNER wall)*/
        t2w1r=t2w2r;
        xintersecwr=m*(vz*t2w1r+z)+n;						/* crosscheck of the x-coordinate of the intersection point */
        if (xintersecwr>0){							/* for the right wall x-coordinate of the intersection point have to be negative */
        t2w1r=t1+2.0;}								/* if this is not the case the time is set to t1+2.0 (time point behind the component) */
        }
    pwrwt=2.0*(a2wrwt*m*n+b2wrwt*z0wr)/(a2wrwt*m*m+b2wrwt);			/* p parameter of quadratic equation for calulation the z component of the intersection point with respect to the neutron trajectory (OUTER wall)*/
    qwrwt=(a2wrwt*n*n+b2wrwt*z0wr*z0wr-a2wrwt*b2wrwt)/(a2wrwt*m*m+b2wrwt);	/* q parameter of quadratic equation for calulation the z component of the intersection point with respect to the neutron trajectory (OUTER wall)*/
    if ((pwrwt*pwrwt/4.0)-qwrwt<0){							
    t2w1rwt=t1+2.0;								/* if the neutron never touch the ellipse the time is set bigger than need to pass the component */
    }else{
        zw1rwt=-pwrwt/2.0+sqrt((pwrwt*pwrwt/4.0)-qwrwt);			/* first solution for z (OUTER wall) */
        zw2rwt=-pwrwt/2.0-sqrt((pwrwt*pwrwt/4.0)-qwrwt);			/* second solution for z (OUTER wall)*/
        t2w1rwt=(zw1rwt-z)/vz;							/* interaction time for first z value (OUTER wall)*/
        t2w2rwt=(zw2rwt-z)/vz;							/* interactime time for second z value (OUTER wall)*/
        if(t2w1rwt<1e-15)							/* solving the precision problem for the intersection times given by double variable type, to small times (<1e-15) gives scattering events */
        t2w1rwt=t1+2.0;								/* at the same postion again (time is set to zero). this results in a sign change in the velocity components, which results in a wall tunneling.*/
        if(t2w2rwt<1e-15)							/* see comments above*/
        t2w2rwt=t1+2.0;
        if(t2w2rwt<t2w1rwt)							/* choosing the smaller positive time solution (OUTER wall)*/
        t2w1rwt=t2w2rwt;
        xintersecwrwt=m*(vz*t2w1rwt+z)+n;					/* crosscheck of the x-coordinate of the intersection point */
        if (xintersecwrwt>0){							/* for the right wall x-coordinate of the intersection point have to be negative */
        t2w1rwt=t1+2.0;}							/* if this is not the case the time is set to t1+2.0 (time point behind the component) */
        }
    }

  if((loutwr!=0 && linwr==0)|| (loutwr==0 && linwr!=0))				/* for a parabolic focusing or defocusing right wall*/
  {										/* solving the elliptic equation in respect to the straight neutron trajectoty to get the interaction time*/
    m=vx/vz;									/* m parameter of the neutron trajectory*/
    n=-m*z+x;									/* n parameter of the neutron trajectory */
    pwr=(2.0*m*n*pawr+1.0)/(pawr*m*m);						/* p parameter of quadratic equation (INNER wall)*/
    qwr=n*n/(m*m)-pbwr/(pawr*m*m);						/* q parameter of quadratic equation (INNER wall)*/
    if(qwr>0 && qwr>(pwr*pwr/4)){						/* in the very special case of no intersection the quadratic equation has no solution (negative square root) the time is set to t1+2.0 */
    t2w1r=t1+2.0;
    }else{
    if(vx==0)									/* in the special case of vx = 0 is x a constant */
    {
      if(x<0){									/* only neutron with a negativ x-component can hit the RIGHT wall (INNER wall)*/
      t2w1r=(pbwr-pawr*x*x-z)/vz;
      }else{
      t2w1r=t1+2.0; 								/* the time solution for neutron with a positive x component is set to a time long behind the exit of the guide */
										/* (means will not  scatter with the right wall)*/
      }
    }else{									/* if vx is not zero and x is a real variable*/
      zw1r=-pwr/2.0+sqrt(pwr*pwr/4.0-qwr);					/* first z-solution for intersection (INNER wall)*/
      zw2r=-pwr/2.0-sqrt(pwr*pwr/4.0-qwr);					/* second z-solution for intersection (INNER wall)*/
      t2w1r=(zw1r-z)/vz;							/* first time solution (INNER wall)*/
      t2w2r=(zw2r-z)/vz;							/* second time solution (INNER wall)*/
      if(t2w1r<1e-15)								/* solving the precision problem for the intersection times given by double variable type, to small times (<1e-15) gives scattering events */
      t2w1r=t1+2.0;								/* at the same postion again (time is set to zero). this results in a sign change in the velocity components, which results in a wall tunneling.*/
      if(t2w2r<1e-15)								/* see comments above*/
      t2w2r=t1+2.0;
      if(t2w2r<t2w1r)								/* choosing the smaller positive time solution (INNER wall)*/	
      t2w1r=t2w2r;
    }
    xintersecwr=m*(vz*t2w1r+z)+n;						/* crosscheck of the x-coordinate of the intersection point */
    if (xintersecwr>0){								/* for the right wall the x-coordinate of the intersection point have to be negative */
    t2w1r=t1+2.0;}								/* if this is not the case the time is set to t1+2.0 (time point behind the component) */
    }
    pwrwt=(2.0*m*n*pawrwt+1.0)/(pawrwt*m*m);					/* p parameter of quadratic equation (OUTER wall)*/
    qwrwt=n*n/(m*m)-pbwrwt/(pawrwt*m*m);					/* q parameter of quadratic equation (OUTER wall)*/
    if(qwrwt>0 && qwrwt>(pwrwt*pwrwt/4)){					/* in the very special case of no intersection the quadratic equation has no solution (negative square root) and the time is set to t1+2.0 */
    t2w1rwt=t1+2.0;
    }else{
    if(vx==0)									/* in the special case of vx = 0 is x a constant */
    {
      if(x<0){
      t2w1rwt=(pbwrwt-pawrwt*x*x-z)/vz;						/* only neutron with a negativ x-component can hit the RIGHT wall (OUTER wall)*/
      }else{
      t2w1rwt=t1+2.0; 
      }
    }else{									/* if vx is not zero */
      zw1rwt=-pwrwt/2.0+sqrt(pwrwt*pwrwt/4.0-qwrwt);				/* first z-solution for intersection (OUTER wall)*/
      zw2rwt=-pwrwt/2.0-sqrt(pwrwt*pwrwt/4.0-qwrwt);				/* second z-solution for intersection (OUTER wall)*/
      t2w1rwt=(zw1rwt-z)/vz;							/* first time solution (OUTER wall)*/
      t2w2rwt=(zw2rwt-z)/vz;							/* second time solution (OUTER wall)*/
      if(t2w1rwt<1e-15)								/* solving the precision problem for the intersection times given by double variable type, to small times (<1e-15) gives scattering events */
      t2w1rwt=t1+2.0;								/* at the same postion again (time is set to zero). this results in a sign change in the velocity components, which results in a wall tunneling.*/
      if(t2w2rwt<1e-15)								/* see comments above*/
      t2w2rwt=t1+2.0;
      if(t2w2rwt<t2w1rwt)							/* choosing the smaller positive time solution (OUTER wall)*/
      t2w1rwt=t2w2rwt;
    }
    xintersecwrwt=m*(vz*t2w1rwt+z)+n;						/* crosscheck of the x-coordinate of the intersection point */
    if (xintersecwrwt>0){							/* for the right wall the x-coordinate of the intersection point have to be negative */
    t2w1rwt=t1+2.0;}								/* if this is not the case the time is set to t1+2.0 (time point behind the component) */
  }
  }

  if(loutwl==0 && linwl==0)							/* comments for the left wall are same like for the right wall*/
  {
  m=(w2l-w1l)/l;
  t2w1l=(m*z+(w1l)-x)/(vx-m*vz);
  t2w1lwt=(m*z+(w1lwt)-x)/(vx-m*vz);
  if(t2w1l<1e-15)
  t2w1l=t1+2.0;
  if(t2w1lwt<1e-15)
  t2w1lwt=t1+2.0;
  };

  if(loutwl!=0 && linwl!=0)
  { 
    m=vx/vz;
    n=-m*z+x;
    pwl=2.0*(a2wl*m*n+b2wl*z0wl)/(a2wl*m*m+b2wl);
    qwl=(a2wl*n*n+b2wl*z0wl*z0wl-a2wl*b2wl)/(a2wl*m*m+b2wl);
    if((pwl*pwl/4.0)-qwl<0){
    t2w1l=t1+2.0;
    }else{
        zw1l=-pwl/2.0+sqrt((pwl*pwl/4.0)-qwl);
        zw2l=-pwl/2.0-sqrt((pwl*pwl/4.0)-qwl);
        t2w1l=(zw1l-z)/vz;
        t2w2l=(zw2l-z)/vz;
        if(t2w1l<1e-15)
        t2w1l=t1+2.0;
        if(t2w2l<1e-15)
        t2w2l=t1+2.0;
        if(t2w2l<t2w1l)
        t2w1l=t2w2l;
        xintersecwl=m*(vz*t2w1l+z)+n;
        if (xintersecwl<0){
        t2w1l=t1+2.0;}
        }
    pwlwt=2.0*(a2wlwt*m*n+b2wlwt*z0wl)/(a2wlwt*m*m+b2wlwt);
    qwlwt=(a2wlwt*n*n+b2wlwt*z0wl*z0wl-a2wlwt*b2wlwt)/(a2wlwt*m*m+b2wlwt);
    if((pwlwt*pwlwt/4.0)-qwlwt<0){
    t2w1lwt=t1+2.0;
    }else{
        zw1lwt=-pwlwt/2.0+sqrt((pwlwt*pwlwt/4.0)-qwlwt);
        zw2lwt=-pwlwt/2.0-sqrt((pwlwt*pwlwt/4.0)-qwlwt);
        t2w1lwt=(zw1lwt-z)/vz;
        t2w2lwt=(zw2lwt-z)/vz;
        if(t2w1lwt<1e-15)
        t2w1lwt=t1+2.0;
        if(t2w2lwt<1e-15)
        t2w2lwt=t1+2.0;
        if(t2w2lwt<t2w1lwt)
        t2w1lwt=t2w2lwt;
        xintersecwlwt=m*(vz*t2w1lwt+z)+n;
        if (xintersecwlwt<0){
        t2w1lwt=t1+2.0;}
        }
  }

  if((loutwl!=0 && linwl==0) || (loutwl==0 && linwl!=0))
  {
    m=vx/vz;
    n=-m*z+x;
    pwl=(2.0*m*n*pawl+1.0)/(pawl*m*m);
    qwl=n*n/(m*m)-pbwl/(pawl*m*m);
    if(qwl>0 && qwl>(pwl*pwl/4)){
    t2w1l=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x>0){
      t2w1l=(pbwl-pawl*x*x-z)/vz;
      }else{
      t2w1l=t1+2.0;
      }
    }else{
      zw1l=-pwl/2.0+sqrt(pwl*pwl/4.0-qwl);
      zw2l=-pwl/2.0-sqrt(pwl*pwl/4.0-qwl);
      t2w1l=(zw1l-z)/vz;
      t2w2l=(zw2l-z)/vz;
      if(t2w1l<1e-15)
      t2w1l=t1+2.0;
      if(t2w2l<1e-15)
      t2w2l=t1+2.0;
      if(t2w2l<t2w1l)
      t2w1l=t2w2l;
    }
    }
    xintersecwl=m*(vz*t2w1l+z)+n;
    if (xintersecwl<0){
    t2w1l=t1+2.0;}
    pwlwt=(2.0*m*n*pawlwt+1.0)/(pawlwt*m*m);
    qwlwt=n*n/(m*m)-pbwlwt/(pawlwt*m*m);
    if(qwlwt>0 && qwlwt>(pwlwt*pwlwt/4)){
    t2w1lwt=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x>0){
      t2w1lwt=(pbwlwt-pawlwt*x*x-z)/vz;
      }else{
      t2w1lwt=t1+2.0;
      }
    }else{
      zw1lwt=-pwlwt/2.0+sqrt(pwlwt*pwlwt/4.0-qwlwt);
      zw2lwt=-pwlwt/2.0-sqrt(pwlwt*pwlwt/4.0-qwlwt);
      t2w1lwt=(zw1lwt-z)/vz;
      t2w2lwt=(zw2lwt-z)/vz;
      if(t2w1lwt<1e-15)
      t2w1lwt=t1+2.0;
      if(t2w2lwt<1e-15)
      t2w2lwt=t1+2.0;
      if(t2w2lwt<t2w1lwt)
      t2w1lwt=t2w2lwt;
    }
    xintersecwlwt=m*(vz*t2w1lwt+z)+n;
    if (xintersecwlwt<0){
    t2w1lwt=t1+2.0;}
  }
  }

  if(louthu==0 && linhu==0)							/* comments for the top wall are same like for the right wall (only the ralation between left and right become relation between up and down)*/
  {
  m=(h2u-h1u)/l;
  t2h1u=(m*z+(h1u)-y)/(vy-m*vz);
  t2h1uwt=(m*z+(h1uwt)-y)/(vy-m*vz);
  if(t2h1u<1e-15)
  t2h1u=t1+2.0;
  if(t2h1uwt<1e-15)
  t2h1uwt=t1+2.0;
  }


  if(louthu!=0 && linhu!=0)
  { 
    m=vy/vz;
    n=-m*z+y;
    phu=2.0*(a2hu*m*n+b2hu*z0hu)/(a2hu*m*m+b2hu);
    qhu=(a2hu*n*n+b2hu*z0hu*z0hu-a2hu*b2hu)/(a2hu*m*m+b2hu);
    if((phu*phu/4.0)-qhu<0){
    t2h1u=t1+2.0;
    }else{
        zh1u=-phu/2.0+sqrt((phu*phu/4.0)-qhu);
        zh2u=-phu/2.0-sqrt((phu*phu/4.0)-qhu);
        t2h1u=(zh1u-z)/vz;
        t2h2u=(zh2u-z)/vz;
        if(t2h1u<1e-15)
        t2h1u=t1+2.0;
        if(t2h2u<1e-15)
        t2h2u=t1+2.0;
        if(t2h2u<t2h1u)
        t2h1u=t2h2u;
        yintersechu=m*(vz*t2h1u+z)+n;
        if (yintersechu<0){
        t2h1u=t1+2.0;}
        }
    phuwt=2.0*(a2huwt*m*n+b2huwt*z0hu)/(a2huwt*m*m+b2huwt);
    qhuwt=(a2huwt*n*n+b2huwt*z0hu*z0hu-a2huwt*b2huwt)/(a2huwt*m*m+b2huwt);
    if((phuwt*phuwt/4.0)-qhuwt<0){
    t2h1uwt=t1+2.0;
    }else{
        zh1uwt=-phuwt/2.0+sqrt((phuwt*phuwt/4.0)-qhuwt);
        zh2uwt=-phuwt/2.0-sqrt((phuwt*phuwt/4.0)-qhuwt);
        t2h1uwt=(zh1uwt-z)/vz;
        t2h2uwt=(zh2uwt-z)/vz;
        if(t2h1uwt<1e-15)
        t2h1uwt=t1+2.0;
        if(t2h2uwt<1e-15)
        t2h2uwt=t1+2.0;
        if(t2h2uwt<t2h1uwt)
        t2h1uwt=t2h2uwt;
        yintersechuwt=m*(vz*t2h1uwt+z)+n;
        if (yintersechuwt<0){
        t2h1uwt=t1+2.0;}
        }
  }


  if((louthu!=0 && linhu==0)|| (louthu==0 && linhu!=0))
  {
    m=vy/vz;
    n=-m*z+y;
    phu=(2.0*m*n*pahu+1.0)/(pahu*m*m);	
    qhu=n*n/(m*m)-pbhu/(pahu*m*m);
    if(qhu>0 && qhu>(phu*phu/4)){
    t2h1u=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y>0){
      t2h1u=(pbhu-pahu*y*y-z)/vz;
      }else{
      t2h1u=t1+2.0;
      }
    }else{
      zh1u=-phu/2.0+sqrt(phu*phu/4.0-qhu);
      zh2u=-phu/2.0-sqrt(phu*phu/4.0-qhu);
      t2h1u=(zh1u-z)/vz;
      t2h2u=(zh2u-z)/vz;
      if(t2h1u<1e-15)
      t2h1u=t1+2.0;
      if(t2h2u<1e-15)
      t2h2u=t1+2.0;
      if(t2h2u<t2h1u)
      t2h1u=t2h2u;
    }
    yintersechu=m*(vz*t2h1u+z)+n;
    if (yintersechu<0){
    t2h1u=t1+2.0;}
  }
    phuwt=(2.0*m*n*pahuwt+1.0)/(pahuwt*m*m);						
    qhuwt=n*n/(m*m)-pbhuwt/(pahuwt*m*m);
    if(qhuwt>0 && qhuwt>(phuwt*phuwt/4)){
    t2h1uwt=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y>0){
      t2h1uwt=(pbhuwt-pahuwt*y*y-z)/vz;
      }else{
      t2h1uwt=t1+2.0;
      }
    }else{
      zh1uwt=-phuwt/2.0+sqrt(phuwt*phuwt/4.0-qhuwt);
      zh2uwt=-phuwt/2.0-sqrt(phuwt*phuwt/4.0-qhuwt);
      t2h1uwt=(zh1uwt-z)/vz;
      t2h2uwt=(zh2uwt-z)/vz;
      if(t2h1uwt<1e-15)
      t2h1uwt=t1+2.0;
      if(t2h2uwt<1e-15)
      t2h2uwt=t1+2.0;
      if(t2h2uwt<t2h1uwt)
      t2h1uwt=t2h2uwt;
    }
    yintersechuwt=m*(vz*t2h1uwt+z)+n;
    if (yintersechuwt<0){
    t2h1uwt=t1+2.0;}
  }
  }

  if(louthd==0 && linhd==0)							/* comments for the down wall are same like for the right wall (only the relation between left and right become relation between up and down)*/	
  {
  m=(-h2d+h1d)/l;
  t2h1d=(m*z+(-h1d)-y)/(vy-m*vz);
  t2h1dwt=(m*z+(-h1dwt)-y)/(vy-m*vz);
  if(t2h1d<1e-15)
  t2h1d=t1+2.0;
  if(t2h1dwt<1e-15)
  t2h1dwt=t1+2.0;
  }

  if(louthd!=0 && linhd!=0)
  { 
    m=vy/vz;
    n=-m*z+y;
    phd=2.0*(a2hd*m*n+b2hd*z0hd)/(a2hd*m*m+b2hd);
    qhd=(a2hd*n*n+b2hd*z0hd*z0hd-a2hd*b2hd)/(a2hd*m*m+b2hd);
    if((phd*phd/4.0)-qhd<0){
    t2h1d=t1+2.0;
    }else{
        zh1d=-phd/2.0+sqrt((phd*phd/4.0)-qhd);
        zh2d=-phd/2.0-sqrt((phd*phd/4.0)-qhd);
        t2h1d=(zh1d-z)/vz;
        t2h2d=(zh2d-z)/vz;
        if(t2h1d<1e-15)
        t2h1d=t1+2.0;
        if(t2h2d<1e-15)
        t2h2d=t1+2.0;
        if(t2h2d<t2h1d)
        t2h1d=t2h2d;
        yintersechd=m*(vz*t2h1d+z)+n;
        if (yintersechd>0){
        t2h1d=t1+2.0;}
        }
    phdwt=2.0*(a2hdwt*m*n+b2hdwt*z0hd)/(a2hdwt*m*m+b2hdwt);
    qhdwt=(a2hdwt*n*n+b2hdwt*z0hd*z0hd-a2hdwt*b2hdwt)/(a2hdwt*m*m+b2hdwt);
    if((phdwt*phdwt/4.0)-qhdwt<0){
    t2h1dwt=t1+2.0;
    }else{
        zh1dwt=-phdwt/2.0+sqrt((phdwt*phdwt/4.0)-qhdwt);
        zh2dwt=-phdwt/2.0-sqrt((phdwt*phdwt/4.0)-qhdwt);
        t2h1dwt=(zh1dwt-z)/vz;
        t2h2dwt=(zh2dwt-z)/vz;
        if(t2h1dwt<1e-15)
        t2h1dwt=t1+2.0;
        if(t2h2dwt<1e-15)
        t2h2dwt=t1+2.0;
        if(t2h2dwt<t2h1dwt)
        t2h1dwt=t2h2dwt;
        yintersechdwt=m*(vz*t2h1dwt+z)+n;
        if (yintersechdwt>0){
        t2h1dwt=t1+2.0;}
        }
  }

  if((louthd!=0 && linhd==0)|| (louthd==0 && linhd!=0))
  {
    m=vy/vz;
    n=-m*z+y;
    phd=(2.0*m*n*pahd+1.0)/(pahd*m*m);
    qhd=n*n/(m*m)-pbhd/(pahd*m*m);
    if(qhd>0 && qhd>(phd*phd/4)){
    t2h1d=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y<0){
      t2h1d=(pbhd-pahd*y*y-z)/vz;
      }else{
      t2h1d=t1+2.0;
      }
    }else{
      zh1d=-phd/2.0+sqrt(phd*phd/4.0-qhd);
      zh2d=-phd/2.0-sqrt(phd*phd/4.0-qhd);
      t2h1d=(zh1d-z)/vz;
      t2h2d=(zh2d-z)/vz;
      if(t2h1d<1e-15)
      t2h1d=t1+2.0;
      if(t2h2d<1e-15)
      t2h2d=t1+2.0;
      if(t2h2d<t2h1d)
      t2h1d=t2h2d;
    }
    yintersechd=m*(vz*t2h1d+z)+n;
    if (yintersechd>0){
    t2h1d=t1+2.0;}
  }
    phdwt=(2.0*m*n*pahdwt+1.0)/(pahdwt*m*m);
    qhdwt=n*n/(m*m)-pbhdwt/(pahdwt*m*m);
    if(qhdwt>0 && qhdwt>(phdwt*phdwt/4)){
    t2h1dwt=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y<0){
      t2h1dwt=(pbhdwt-pahdwt*y*y-z)/vz;
      }else{
      t2h1dwt=t1+2.0;
      }
    }else{
      zh1dwt=-phdwt/2.0+sqrt(phdwt*phdwt/4.0-qhdwt);
      zh2dwt=-phdwt/2.0-sqrt(phdwt*phdwt/4.0-qhdwt);
      t2h1dwt=(zh1dwt-z)/vz;
      t2h2dwt=(zh2dwt-z)/vz;
      if(t2h1dwt<1e-15)
      t2h1dwt=t1+2.0;
      if(t2h2dwt<1e-15)
      t2h2dwt=t1+2.0;
      if(t2h2dwt<t2h1dwt)
      t2h1dwt=t2h2dwt;
    }
    yintersechdwt=m*(vz*t2h1dwt+z)+n;
    if (yintersechdwt>0){
    t2h1dwt=t1+2.0;}
  }
  }



  if(loutwr1==0 && linwr1==0)
  {
  m=(-w2r1+w1r1)/l;
  t2w1r1=(m*z+(-w1r1)-x)/(vx-m*vz);
  t2w1rwt1=(m*z+(-w1rwt1)-x)/(vx-m*vz);
  if(t2w1r1<1e-15)
    t2w1r1=t1+2.0;
  if(t2w1rwt1<1e-15)
    t2w1rwt1=t1+2.0; 
  }


  if(loutwr1!=0 && linwr1!=0)
  { 
    m=vx/vz;
    n=-m*z+x;
    pwr1=2.0*(a2wr1*m*n+b2wr1*z0wr1)/(a2wr1*m*m+b2wr1);
    qwr1=(a2wr1*n*n+b2wr1*z0wr1*z0wr1-a2wr1*b2wr1)/(a2wr1*m*m+b2wr1);
    if ((pwr1*pwr1/4.0)-qwr1<0){
    t2w1r1=t1+2.0;
    }else{
        zw1r1=-pwr1/2.0+sqrt((pwr1*pwr1/4.0)-qwr1);
        zw2r1=-pwr1/2.0-sqrt((pwr1*pwr1/4.0)-qwr1);
        t2w1r1=(zw1r1-z)/vz;	
        t2w2r1=(zw2r1-z)/vz;
        if(t2w1r1<1e-15)
        t2w1r1=t1+2.0;
        if(t2w2r1<1e-15)
        t2w2r1=t1+2.0;
        if(t2w2r1<t2w1r1)
        t2w1r1=t2w2r1;
        xintersecwr1=m*(vz*t2w1r1+z)+n;	
        if (xintersecwr1>0){
        t2w1r1=t1+2.0;}	
        }
    pwrwt1=2.0*(a2wrwt1*m*n+b2wrwt1*z0wr1)/(a2wrwt1*m*m+b2wrwt1);
    qwrwt1=(a2wrwt1*n*n+b2wrwt1*z0wr1*z0wr1-a2wrwt1*b2wrwt1)/(a2wrwt1*m*m+b2wrwt1);
    if ((pwrwt1*pwrwt1/4.0)-qwrwt1<0){
    t2w1rwt1=t1+2.0;
    }else{
        zw1rwt1=-pwrwt1/2.0+sqrt((pwrwt1*pwrwt1/4.0)-qwrwt1);
        zw2rwt1=-pwrwt1/2.0-sqrt((pwrwt1*pwrwt1/4.0)-qwrwt1);
        t2w1rwt1=(zw1rwt1-z)/vz;
        t2w2rwt1=(zw2rwt1-z)/vz;
        if(t2w1rwt1<1e-15)
        t2w1rwt1=t1+2.0;
        if(t2w2rwt1<1e-15)
        t2w2rwt1=t1+2.0;
        if(t2w2rwt1<t2w1rwt1)
        t2w1rwt1=t2w2rwt1;
        xintersecwrwt1=m*(vz*t2w1rwt1+z)+n;
        if (xintersecwrwt1>0){
        t2w1rwt1=t1+2.0;}
        }
    }

  if((loutwr1!=0 && linwr1==0)|| (loutwr1==0 && linwr1!=0))
  {
    m=vx/vz;
    n=-m*z+x;
    pwr1=(2.0*m*n*pawr1+1.0)/(pawr1*m*m);
    qwr1=n*n/(m*m)-pbwr1/(pawr1*m*m);
    if(qwr1>0 && qwr1>(pwr1*pwr1/4)){
    t2w1r1=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x<0){
      t2w1r1=(pbwr1-pawr1*x*x-z)/vz;
      }else{
      t2w1r1=t1+2.0; 
      }
    }else{
      zw1r1=-pwr1/2.0+sqrt(pwr1*pwr1/4.0-qwr1);	
      zw2r1=-pwr1/2.0-sqrt(pwr1*pwr1/4.0-qwr1);	
      t2w1r1=(zw1r1-z)/vz;
      t2w2r1=(zw2r1-z)/vz;
      if(t2w1r1<1e-15)
      t2w1r1=t1+2.0;
      if(t2w2r1<1e-15)	
      t2w2r1=t1+2.0;
      if(t2w2r1<t2w1r1)
      t2w1r1=t2w2r1;
    }
    xintersecwr1=m*(vz*t2w1r1+z)+n;
    if (xintersecwr1>0){
    t2w1r1=t1+2.0;}
    }
    pwrwt1=(2.0*m*n*pawrwt1+1.0)/(pawrwt1*m*m);
    qwrwt1=n*n/(m*m)-pbwrwt1/(pawrwt1*m*m);
    if(qwrwt1>0 && qwrwt1>(pwrwt1*pwrwt1/4)){
    t2w1rwt1=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x<0){
      t2w1rwt1=(pbwrwt1-pawrwt1*x*x-z)/vz;
      }else{
      t2w1rwt1=t1+2.0; 
      }
    }else{						
      zw1rwt1=-pwrwt1/2.0+sqrt(pwrwt1*pwrwt1/4.0-qwrwt1);
      zw2rwt1=-pwrwt1/2.0-sqrt(pwrwt1*pwrwt1/4.0-qwrwt1);
      t2w1rwt1=(zw1rwt1-z)/vz;	
      t2w2rwt1=(zw2rwt1-z)/vz;	
      if(t2w1rwt1<1e-15)
      t2w1rwt1=t1+2.0;
      if(t2w2rwt1<1e-15)
      t2w2rwt1=t1+2.0;
      if(t2w2rwt1<t2w1rwt1)
      t2w1rwt1=t2w2rwt1;
    }
    xintersecwrwt1=m*(vz*t2w1rwt1+z)+n;	
    if (xintersecwrwt1>0){
    t2w1rwt1=t1+2.0;}
  }
  }

  if(loutwl1==0 && linwl1==0)
  {
  m=(w2l1-w1l1)/l;
  t2w1l1=(m*z+(w1l1)-x)/(vx-m*vz);
  t2w1lwt1=(m*z+(w1lwt1)-x)/(vx-m*vz);
  if(t2w1l1<1e-15)
  t2w1l1=t1+2.0;
  if(t2w1lwt1<1e-15)
  t2w1lwt1=t1+2.0;
  };

  if(loutwl1!=0 && linwl1!=0)
  { 
    m=vx/vz;
    n=-m*z+x;
    pwl1=2.0*(a2wl1*m*n+b2wl1*z0wl1)/(a2wl1*m*m+b2wl1);
    qwl1=(a2wl1*n*n+b2wl1*z0wl1*z0wl1-a2wl1*b2wl1)/(a2wl1*m*m+b2wl1);
    if((pwl1*pwl1/4.0)-qwl1<0){
    t2w1l1=t1+2.0;
    }else{
        zw1l1=-pwl1/2.0+sqrt((pwl1*pwl1/4.0)-qwl1);
        zw2l1=-pwl1/2.0-sqrt((pwl1*pwl1/4.0)-qwl1);
        t2w1l1=(zw1l1-z)/vz;
        t2w2l1=(zw2l1-z)/vz;
        if(t2w1l1<1e-15)
        t2w1l1=t1+2.0;
        if(t2w2l1<1e-15)
        t2w2l1=t1+2.0;
        if(t2w2l1<t2w1l1)
        t2w1l1=t2w2l1;
        xintersecwl1=m*(vz*t2w1l1+z)+n;
        if (xintersecwl1<0){
        t2w1l1=t1+2.0;}
        }
    pwlwt1=2.0*(a2wlwt1*m*n+b2wlwt1*z0wl1)/(a2wlwt1*m*m+b2wlwt1);
    qwlwt1=(a2wlwt1*n*n+b2wlwt1*z0wl1*z0wl1-a2wlwt1*b2wlwt1)/(a2wlwt1*m*m+b2wlwt1);
    if((pwlwt1*pwlwt1/4.0)-qwlwt1<0){
    t2w1lwt1=t1+2.0;
    }else{
        zw1lwt1=-pwlwt1/2.0+sqrt((pwlwt1*pwlwt1/4.0)-qwlwt1);
        zw2lwt1=-pwlwt1/2.0-sqrt((pwlwt1*pwlwt1/4.0)-qwlwt1);
        t2w1lwt1=(zw1lwt1-z)/vz;
        t2w2lwt1=(zw2lwt1-z)/vz;
        if(t2w1lwt1<1e-15)
        t2w1lwt1=t1+2.0;
        if(t2w2lwt1<1e-15)
        t2w2lwt1=t1+2.0;
        if(t2w2lwt1<t2w1lwt1)
        t2w1lwt1=t2w2lwt1;
        xintersecwlwt1=m*(vz*t2w1lwt1+z)+n;
        if (xintersecwlwt1<0){
        t2w1lwt1=t1+2.0;}
        }
  }

  if((loutwl1!=0 && linwl1==0) || (loutwl1==0 && linwl1!=0))
  {
    m=vx/vz;
    n=-m*z+x;
    pwl1=(2.0*m*n*pawl1+1.0)/(pawl1*m*m);
    qwl1=n*n/(m*m)-pbwl1/(pawl1*m*m);
    if(qwl1>0 && qwl1>(pwl1*pwl1/4)){
    t2w1l1=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x>0){
      t2w1l1=(pbwl1-pawl1*x*x-z)/vz;
      }else{
      t2w1l1=t1+2.0;
      }
    }else{
      zw1l1=-pwl1/2.0+sqrt(pwl1*pwl1/4.0-qwl1);
      zw2l1=-pwl1/2.0-sqrt(pwl1*pwl1/4.0-qwl1);
      t2w1l1=(zw1l1-z)/vz;
      t2w2l1=(zw2l1-z)/vz;
      if(t2w1l1<1e-15)
      t2w1l1=t1+2.0;
      if(t2w2l1<1e-15)
      t2w2l1=t1+2.0;
      if(t2w2l1<t2w1l1)
      t2w1l1=t2w2l1;
    }
    }
    xintersecwl1=m*(vz*t2w1l1+z)+n;
    if (xintersecwl1<0){
    t2w1l1=t1+2.0;}
    pwlwt1=(2.0*m*n*pawlwt1+1.0)/(pawlwt1*m*m);
    qwlwt1=n*n/(m*m)-pbwlwt1/(pawlwt1*m*m);
    if(qwlwt1>0 && qwlwt1>(pwlwt1*pwlwt1/4)){
    t2w1lwt1=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x>0){
      t2w1lwt1=(pbwlwt1-pawlwt1*x*x-z)/vz;
      }else{
      t2w1lwt1=t1+2.0;
      }
    }else{
      zw1lwt1=-pwlwt1/2.0+sqrt(pwlwt1*pwlwt1/4.0-qwlwt1);
      zw2lwt1=-pwlwt1/2.0-sqrt(pwlwt1*pwlwt1/4.0-qwlwt1);
      t2w1lwt1=(zw1lwt1-z)/vz;
      t2w2lwt1=(zw2lwt1-z)/vz;
      if(t2w1lwt1<1e-15)
      t2w1lwt1=t1+2.0;
      if(t2w2lwt1<1e-15)
      t2w2lwt1=t1+2.0;
      if(t2w2lwt1<t2w1lwt1)
      t2w1lwt1=t2w2lwt1;
    }
    xintersecwlwt1=m*(vz*t2w1lwt1+z)+n;
    if (xintersecwlwt1<0){
    t2w1lwt1=t1+2.0;}
  }
  }

  if(louthu1==0 && linhu1==0)
  {
  m=(h2u1-h1u1)/l;
  t2h1u1=(m*z+(h1u1)-y)/(vy-m*vz);
  t2h1uwt1=(m*z+(h1uwt1)-y)/(vy-m*vz);
  if(t2h1u1<1e-15)
  t2h1u1=t1+2.0;
  if(t2h1uwt1<1e-15)
  t2h1uwt1=t1+2.0;
  }


  if(louthu1!=0 && linhu1!=0)
  { 
    m=vy/vz;
    n=-m*z+y;
    phu1=2.0*(a2hu1*m*n+b2hu1*z0hu1)/(a2hu1*m*m+b2hu1);
    qhu1=(a2hu1*n*n+b2hu1*z0hu1*z0hu1-a2hu1*b2hu1)/(a2hu1*m*m+b2hu1);
    if((phu1*phu1/4.0)-qhu1<0){
    t2h1u1=t1+2.0;
    }else{
        zh1u1=-phu1/2.0+sqrt((phu1*phu1/4.0)-qhu1);
        zh2u1=-phu1/2.0-sqrt((phu1*phu1/4.0)-qhu1);
        t2h1u1=(zh1u1-z)/vz;
        t2h2u1=(zh2u1-z)/vz;
        if(t2h1u1<1e-15)
        t2h1u1=t1+2.0;
        if(t2h2u1<1e-15)
        t2h2u1=t1+2.0;
        if(t2h2u1<t2h1u1)
        t2h1u1=t2h2u1;
        yintersechu1=m*(vz*t2h1u1+z)+n;
        if (yintersechu1<0){
        t2h1u1=t1+2.0;}
        }
    phuwt1=2.0*(a2huwt1*m*n+b2huwt1*z0hu1)/(a2huwt1*m*m+b2huwt1);
    qhuwt1=(a2huwt1*n*n+b2huwt1*z0hu1*z0hu1-a2huwt1*b2huwt1)/(a2huwt1*m*m+b2huwt1);
    if((phuwt1*phuwt1/4.0)-qhuwt1<0){
    t2h1uwt1=t1+2.0;
    }else{
        zh1uwt1=-phuwt1/2.0+sqrt((phuwt1*phuwt1/4.0)-qhuwt1);
        zh2uwt1=-phuwt1/2.0-sqrt((phuwt1*phuwt1/4.0)-qhuwt1);
        t2h1uwt1=(zh1uwt1-z)/vz;
        t2h2uwt1=(zh2uwt1-z)/vz;
        if(t2h1uwt1<1e-15)
        t2h1uwt1=t1+2.0;
        if(t2h2uwt1<1e-15)
        t2h2uwt1=t1+2.0;
        if(t2h2uwt1<t2h1uwt1)
        t2h1uwt1=t2h2uwt1;
        yintersechuwt1=m*(vz*t2h1uwt1+z)+n;
        if (yintersechuwt1<0){
        t2h1uwt1=t1+2.0;}
        }
  }


  if((louthu1!=0 && linhu1==0)|| (louthu1==0 && linhu1!=0))
  {
    m=vy/vz;
    n=-m*z+y;
    phu1=(2.0*m*n*pahu1+1.0)/(pahu1*m*m);	
    qhu1=n*n/(m*m)-pbhu1/(pahu1*m*m);
    if(qhu1>0 && qhu1>(phu1*phu1/4)){
    t2h1u1=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y>0){
      t2h1u1=(pbhu1-pahu1*y*y-z)/vz;
      }else{
      t2h1u1=t1+2.0;
      }
    }else{
      zh1u1=-phu1/2.0+sqrt(phu1*phu1/4.0-qhu1);
      zh2u1=-phu1/2.0-sqrt(phu1*phu1/4.0-qhu1);
      t2h1u1=(zh1u1-z)/vz;
      t2h2u1=(zh2u1-z)/vz;
      if(t2h1u1<1e-15)
      t2h1u1=t1+2.0;
      if(t2h2u1<1e-15)
      t2h2u1=t1+2.0;
      if(t2h2u1<t2h1u1)
      t2h1u1=t2h2u1;
    }
    yintersechu1=m*(vz*t2h1u1+z)+n;
    if (yintersechu1<0){
    t2h1u1=t1+2.0;}
  }
    phuwt1=(2.0*m*n*pahuwt1+1.0)/(pahuwt1*m*m);						
    qhuwt1=n*n/(m*m)-pbhuwt1/(pahuwt1*m*m);
    if(qhuwt1>0 && qhuwt1>(phuwt1*phuwt1/4)){
    t2h1uwt1=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y>0){
      t2h1uwt1=(pbhuwt1-pahuwt1*y*y-z)/vz;
      }else{
      t2h1uwt1=t1+2.0;
      }
    }else{
      zh1uwt1=-phuwt1/2.0+sqrt(phuwt1*phuwt1/4.0-qhuwt1);
      zh2uwt1=-phuwt1/2.0-sqrt(phuwt1*phuwt1/4.0-qhuwt1);
      t2h1uwt1=(zh1uwt1-z)/vz;
      t2h2uwt1=(zh2uwt1-z)/vz;
      if(t2h1uwt1<1e-15)
      t2h1uwt1=t1+2.0;
      if(t2h2uwt1<1e-15)
      t2h2uwt1=t1+2.0;
      if(t2h2uwt1<t2h1uwt1)
      t2h1uwt1=t2h2uwt1;
    }
    yintersechuwt1=m*(vz*t2h1uwt1+z)+n;
    if (yintersechuwt1<0){
    t2h1uwt1=t1+2.0;}
  }
  }

  if(louthd1==0 && linhd1==0)
  {
  m=(-h2d1+h1d1)/l;
  t2h1d1=(m*z+(-h1d1)-y)/(vy-m*vz);
  t2h1dwt1=(m*z+(-h1dwt1)-y)/(vy-m*vz);
  if(t2h1d1<1e-15)
  t2h1d1=t1+2.0;
  if(t2h1dwt1<1e-15)
  t2h1dwt1=t1+2.0;
  }

  if(louthd1!=0 && linhd1!=0)
  { 
    m=vy/vz;
    n=-m*z+y;
    phd1=2.0*(a2hd1*m*n+b2hd1*z0hd1)/(a2hd1*m*m+b2hd1);
    qhd1=(a2hd1*n*n+b2hd1*z0hd1*z0hd1-a2hd1*b2hd1)/(a2hd1*m*m+b2hd1);
    if((phd1*phd1/4.0)-qhd1<0){
    t2h1d1=t1+2.0;
    }else{
        zh1d1=-phd1/2.0+sqrt((phd1*phd1/4.0)-qhd1);
        zh2d1=-phd1/2.0-sqrt((phd1*phd1/4.0)-qhd1);
        t2h1d1=(zh1d1-z)/vz;
        t2h2d1=(zh2d1-z)/vz;
        if(t2h1d1<1e-15)
        t2h1d1=t1+2.0;
        if(t2h2d1<1e-15)
        t2h2d1=t1+2.0;
        if(t2h2d1<t2h1d1)
        t2h1d1=t2h2d1;
        yintersechd1=m*(vz*t2h1d1+z)+n;
        if (yintersechd1>0){
        t2h1d1=t1+2.0;}
        }
    phdwt1=2.0*(a2hdwt1*m*n+b2hdwt1*z0hd1)/(a2hdwt1*m*m+b2hdwt1);
    qhdwt1=(a2hdwt1*n*n+b2hdwt1*z0hd1*z0hd1-a2hdwt1*b2hdwt1)/(a2hdwt1*m*m+b2hdwt1);
    if((phdwt1*phdwt1/4.0)-qhdwt1<0){
    t2h1dwt1=t1+2.0;
    }else{
        zh1dwt1=-phdwt1/2.0+sqrt((phdwt1*phdwt1/4.0)-qhdwt1);
        zh2dwt1=-phdwt1/2.0-sqrt((phdwt1*phdwt1/4.0)-qhdwt1);
        t2h1dwt1=(zh1dwt1-z)/vz;
        t2h2dwt1=(zh2dwt1-z)/vz;
        if(t2h1dwt1<1e-15)
        t2h1dwt1=t1+2.0;
        if(t2h2dwt1<1e-15)
        t2h2dwt1=t1+2.0;
        if(t2h2dwt1<t2h1dwt1)
        t2h1dwt1=t2h2dwt1;
        yintersechdwt1=m*(vz*t2h1dwt1+z)+n;
        if (yintersechdwt1>0){
        t2h1dwt1=t1+2.0;}
        }
  }

  if((louthd1!=0 && linhd1==0)|| (louthd1==0 && linhd1!=0))
  {
    m=vy/vz;
    n=-m*z+y;
    phd1=(2.0*m*n*pahd1+1.0)/(pahd1*m*m);
    qhd1=n*n/(m*m)-pbhd1/(pahd1*m*m);
    if(qhd1>0 && qhd1>(phd1*phd1/4)){
    t2h1d1=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y<0){
      t2h1d1=(pbhd1-pahd1*y*y-z)/vz;
      }else{
      t2h1d1=t1+2.0;
      }
    }else{
      zh1d1=-phd1/2.0+sqrt(phd1*phd1/4.0-qhd1);
      zh2d1=-phd1/2.0-sqrt(phd1*phd1/4.0-qhd1);
      t2h1d1=(zh1d1-z)/vz;
      t2h2d1=(zh2d1-z)/vz;
      if(t2h1d1<1e-15)
      t2h1d1=t1+2.0;
      if(t2h2d1<1e-15)
      t2h2d1=t1+2.0;
      if(t2h2d1<t2h1d1)
      t2h1d1=t2h2d1;
    }
    yintersechd1=m*(vz*t2h1d1+z)+n;
    if (yintersechd1>0){
    t2h1d1=t1+2.0;}
  }
    phdwt1=(2.0*m*n*pahdwt1+1.0)/(pahdwt1*m*m);
    qhdwt1=n*n/(m*m)-pbhdwt1/(pahdwt1*m*m);
    if(qhdwt1>0 && qhdwt1>(phdwt1*phdwt1/4)){
    t2h1dwt1=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y<0){
      t2h1dwt1=(pbhdwt1-pahdwt1*y*y-z)/vz;
      }else{
      t2h1dwt1=t1+2.0;
      }
    }else{
      zh1dwt1=-phdwt1/2.0+sqrt(phdwt1*phdwt1/4.0-qhdwt1);
      zh2dwt1=-phdwt1/2.0-sqrt(phdwt1*phdwt1/4.0-qhdwt1);
      t2h1dwt1=(zh1dwt1-z)/vz;
      t2h2dwt1=(zh2dwt1-z)/vz;
      if(t2h1dwt1<1e-15)
      t2h1dwt1=t1+2.0;
      if(t2h2dwt1<1e-15)
      t2h2dwt1=t1+2.0;
      if(t2h2dwt1<t2h1dwt1)
      t2h1dwt1=t2h2dwt1;
    }
    yintersechdwt1=m*(vz*t2h1dwt1+z)+n;
    if (yintersechdwt1>0){
    t2h1dwt1=t1+2.0;}
  }
  }


if(loutwr2==0 && linwr2==0)
  {
  m=(-w2r2+w1r2)/l;
  t2w1r2=(m*z+(-w1r2)-x)/(vx-m*vz);
  t2w1rwt2=(m*z+(-w1rwt2)-x)/(vx-m*vz);
  if(t2w1r2<1e-15)
    t2w1r2=t1+2.0;
  if(t2w1rwt2<1e-15)
    t2w1rwt2=t1+2.0; 
  }


  if(loutwr2!=0 && linwr2!=0)
  { 
    m=vx/vz;
    n=-m*z+x;
    pwr2=2.0*(a2wr2*m*n+b2wr2*z0wr2)/(a2wr2*m*m+b2wr2);
    qwr2=(a2wr2*n*n+b2wr2*z0wr2*z0wr2-a2wr2*b2wr2)/(a2wr2*m*m+b2wr2);
    if ((pwr2*pwr2/4.0)-qwr2<0){
    t2w1r2=t1+2.0;
    }else{
        zw1r2=-pwr2/2.0+sqrt((pwr2*pwr2/4.0)-qwr2);
        zw2r2=-pwr2/2.0-sqrt((pwr2*pwr2/4.0)-qwr2);
        t2w1r2=(zw1r2-z)/vz;
        t2w2r2=(zw2r2-z)/vz;
        if(t2w1r2<1e-15)
        t2w1r2=t1+2.0;
        if(t2w2r2<1e-15)
        t2w2r2=t1+2.0;
        if(t2w2r2<t2w1r2)
        t2w1r2=t2w2r2;
        xintersecwr2=m*(vz*t2w1r2+z)+n;
        if (xintersecwr2>0){
        t2w1r2=t1+2.0;}
        }
    pwrwt2=2.0*(a2wrwt2*m*n+b2wrwt2*z0wr2)/(a2wrwt2*m*m+b2wrwt2);
    qwrwt2=(a2wrwt2*n*n+b2wrwt2*z0wr2*z0wr2-a2wrwt2*b2wrwt2)/(a2wrwt2*m*m+b2wrwt2);
    if ((pwrwt2*pwrwt2/4.0)-qwrwt2<0){
    t2w1rwt2=t1+2.0;
    }else{
        zw1rwt2=-pwrwt2/2.0+sqrt((pwrwt2*pwrwt2/4.0)-qwrwt2);
        zw2rwt2=-pwrwt2/2.0-sqrt((pwrwt2*pwrwt2/4.0)-qwrwt2);
        t2w1rwt2=(zw1rwt2-z)/vz;
        t2w2rwt2=(zw2rwt2-z)/vz;
        if(t2w1rwt2<1e-15)
        t2w1rwt2=t1+2.0;
        if(t2w2rwt2<1e-15)
        t2w2rwt2=t1+2.0;
        if(t2w2rwt2<t2w1rwt2)
        t2w1rwt2=t2w2rwt2;
        xintersecwrwt2=m*(vz*t2w1rwt2+z)+n;
        if (xintersecwrwt2>0){
        t2w1rwt2=t1+2.0;}
        }
    }

  if((loutwr2!=0 && linwr2==0)|| (loutwr2==0 && linwr2!=0))
  {
    m=vx/vz;
    n=-m*z+x;
    pwr2=(2.0*m*n*pawr2+1.0)/(pawr2*m*m);
    qwr2=n*n/(m*m)-pbwr2/(pawr2*m*m);
    if(qwr2>0 && qwr2>(pwr2*pwr2/4)){
    t2w1r2=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x<0){
      t2w1r2=(pbwr2-pawr2*x*x-z)/vz;
      }else{
      t2w1r2=t1+2.0;
      }
    }else{
      zw1r2=-pwr2/2.0+sqrt(pwr2*pwr2/4.0-qwr2);
      zw2r2=-pwr2/2.0-sqrt(pwr2*pwr2/4.0-qwr2);
      t2w1r2=(zw1r2-z)/vz;
      t2w2r2=(zw2r2-z)/vz;
      if(t2w1r2<1e-15)
      t2w1r2=t1+2.0;
      if(t2w2r2<1e-15)
      t2w2r2=t1+2.0;
      if(t2w2r2<t2w1r2)
      t2w1r2=t2w2r2;
    }
    xintersecwr2=m*(vz*t2w1r2+z)+n;
    if (xintersecwr2>0){
    t2w1r2=t1+2.0;}
    }
    pwrwt2=(2.0*m*n*pawrwt2+1.0)/(pawrwt2*m*m);
    qwrwt2=n*n/(m*m)-pbwrwt2/(pawrwt2*m*m);
    if(qwrwt2>0 && qwrwt2>(pwrwt2*pwrwt2/4)){
    t2w1rwt2=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x<0){
      t2w1rwt2=(pbwrwt2-pawrwt2*x*x-z)/vz;
      }else{
      t2w1rwt2=t1+2.0; 
      }
    }else{
      zw1rwt2=-pwrwt2/2.0+sqrt(pwrwt2*pwrwt2/4.0-qwrwt2);
      zw2rwt2=-pwrwt2/2.0-sqrt(pwrwt2*pwrwt2/4.0-qwrwt2);
      t2w1rwt2=(zw1rwt2-z)/vz;
      t2w2rwt2=(zw2rwt2-z)/vz;
      if(t2w1rwt2<1e-15)
      t2w1rwt2=t1+2.0;	
      if(t2w2rwt2<1e-15)
      t2w2rwt2=t1+2.0;
      if(t2w2rwt2<t2w1rwt2)
      t2w1rwt2=t2w2rwt2;
    }
    xintersecwrwt2=m*(vz*t2w1rwt2+z)+n;	
    if (xintersecwrwt2>0){
    t2w1rwt2=t1+2.0;}
  }
  }

  if(loutwl2==0 && linwl2==0)
  {
  m=(w2l2-w1l2)/l;
  t2w1l2=(m*z+(w1l2)-x)/(vx-m*vz);
  t2w1lwt2=(m*z+(w1lwt2)-x)/(vx-m*vz);
  if(t2w1l2<1e-15)
  t2w1l2=t1+2.0;
  if(t2w1lwt2<1e-15)
  t2w1lwt2=t1+2.0;
  };

  if(loutwl2!=0 && linwl2!=0)
  { 
    m=vx/vz;
    n=-m*z+x;
    pwl2=2.0*(a2wl2*m*n+b2wl2*z0wl2)/(a2wl2*m*m+b2wl2);
    qwl2=(a2wl2*n*n+b2wl2*z0wl2*z0wl2-a2wl2*b2wl2)/(a2wl2*m*m+b2wl2);
    if((pwl2*pwl2/4.0)-qwl2<0){
    t2w1l2=t1+2.0;
    }else{
        zw1l2=-pwl2/2.0+sqrt((pwl2*pwl2/4.0)-qwl2);
        zw2l2=-pwl2/2.0-sqrt((pwl2*pwl2/4.0)-qwl2);
        t2w1l2=(zw1l2-z)/vz;
        t2w2l2=(zw2l2-z)/vz;
        if(t2w1l2<1e-15)
        t2w1l2=t1+2.0;
        if(t2w2l2<1e-15)
        t2w2l2=t1+2.0;
        if(t2w2l2<t2w1l2)
        t2w1l2=t2w2l2;
        xintersecwl2=m*(vz*t2w1l2+z)+n;
        if (xintersecwl2<0){
        t2w1l2=t1+2.0;}
        }
    pwlwt2=2.0*(a2wlwt2*m*n+b2wlwt2*z0wl2)/(a2wlwt2*m*m+b2wlwt2);
    qwlwt2=(a2wlwt2*n*n+b2wlwt2*z0wl2*z0wl2-a2wlwt2*b2wlwt2)/(a2wlwt2*m*m+b2wlwt2);
    if((pwlwt2*pwlwt2/4.0)-qwlwt2<0){
    t2w1lwt2=t1+2.0;
    }else{
        zw1lwt2=-pwlwt2/2.0+sqrt((pwlwt2*pwlwt2/4.0)-qwlwt2);
        zw2lwt2=-pwlwt2/2.0-sqrt((pwlwt2*pwlwt2/4.0)-qwlwt2);
        t2w1lwt2=(zw1lwt2-z)/vz;
        t2w2lwt2=(zw2lwt2-z)/vz;
        if(t2w1lwt2<1e-15)
        t2w1lwt2=t1+2.0;
        if(t2w2lwt2<1e-15)
        t2w2lwt2=t1+2.0;
        if(t2w2lwt2<t2w1lwt2)
        t2w1lwt2=t2w2lwt2;
        xintersecwlwt2=m*(vz*t2w1lwt2+z)+n;
        if (xintersecwlwt2<0){
        t2w1lwt2=t1+2.0;}
        }
  }

  if((loutwl2!=0 && linwl2==0) || (loutwl2==0 && linwl2!=0))
  {
    m=vx/vz;
    n=-m*z+x;
    pwl2=(2.0*m*n*pawl2+1.0)/(pawl2*m*m);
    qwl2=n*n/(m*m)-pbwl2/(pawl2*m*m);
    if(qwl2>0 && qwl2>(pwl2*pwl2/4)){
    t2w1l2=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x>0){
      t2w1l2=(pbwl2-pawl2*x*x-z)/vz;
      }else{
      t2w1l2=t1+2.0;
      }
    }else{
      zw1l2=-pwl2/2.0+sqrt(pwl2*pwl2/4.0-qwl2);
      zw2l2=-pwl2/2.0-sqrt(pwl2*pwl2/4.0-qwl2);
      t2w1l2=(zw1l2-z)/vz;
      t2w2l2=(zw2l2-z)/vz;
      if(t2w1l2<1e-15)
      t2w1l2=t1+2.0;
      if(t2w2l2<1e-15)
      t2w2l2=t1+2.0;
      if(t2w2l2<t2w1l2)
      t2w1l2=t2w2l2;
    }
    }
    xintersecwl2=m*(vz*t2w1l2+z)+n;
    if (xintersecwl2<0){
    t2w1l2=t1+2.0;}
    pwlwt2=(2.0*m*n*pawlwt2+1.0)/(pawlwt2*m*m);
    qwlwt2=n*n/(m*m)-pbwlwt2/(pawlwt2*m*m);
    if(qwlwt2>0 && qwlwt2>(pwlwt2*pwlwt2/4)){
    t2w1lwt2=t1+2.0;
    }else{
    if(vx==0)
    {
      if(x>0){
      t2w1lwt2=(pbwlwt2-pawlwt2*x*x-z)/vz;
      }else{
      t2w1lwt2=t1+2.0;
      }
    }else{
      zw1lwt2=-pwlwt2/2.0+sqrt(pwlwt2*pwlwt2/4.0-qwlwt2);
      zw2lwt2=-pwlwt2/2.0-sqrt(pwlwt2*pwlwt2/4.0-qwlwt2);
      t2w1lwt2=(zw1lwt2-z)/vz;
      t2w2lwt2=(zw2lwt2-z)/vz;
      if(t2w1lwt2<1e-15)
      t2w1lwt2=t1+2.0;
      if(t2w2lwt2<1e-15)
      t2w2lwt2=t1+2.0;
      if(t2w2lwt2<t2w1lwt2)
      t2w1lwt2=t2w2lwt2;
    }
    xintersecwlwt2=m*(vz*t2w1lwt2+z)+n;
    if (xintersecwlwt2<0){
    t2w1lwt2=t1+2.0;}
  }
  }

  if(louthu2==0 && linhu2==0)							/* comments for the top wall are same like for the right wall (only the ralation between left and right become relation between up and down)*/
  {
  m=(h2u2-h1u2)/l;
  t2h1u2=(m*z+(h1u2)-y)/(vy-m*vz);
  t2h1uwt2=(m*z+(h1uwt2)-y)/(vy-m*vz);
  if(t2h1u2<1e-15)
  t2h1u2=t1+2.0;
  if(t2h1uwt2<1e-15)
  t2h1uwt2=t1+2.0;
  }


  if(louthu2!=0 && linhu2!=0)
  { 
    m=vy/vz;
    n=-m*z+y;
    phu2=2.0*(a2hu2*m*n+b2hu2*z0hu2)/(a2hu2*m*m+b2hu2);
    qhu2=(a2hu2*n*n+b2hu2*z0hu2*z0hu2-a2hu2*b2hu2)/(a2hu2*m*m+b2hu2);
    if((phu2*phu2/4.0)-qhu2<0){
    t2h1u2=t1+2.0;
    }else{
        zh1u2=-phu2/2.0+sqrt((phu2*phu2/4.0)-qhu2);
        zh2u2=-phu2/2.0-sqrt((phu2*phu2/4.0)-qhu2);
        t2h1u2=(zh1u2-z)/vz;
        t2h2u2=(zh2u2-z)/vz;
        if(t2h1u2<1e-15)
        t2h1u2=t1+2.0;
        if(t2h2u2<1e-15)
        t2h2u2=t1+2.0;
        if(t2h2u2<t2h1u2)
        t2h1u2=t2h2u2;
        yintersechu2=m*(vz*t2h1u2+z)+n;
        if (yintersechu2<0){
        t2h1u2=t1+2.0;}
        }
    phuwt2=2.0*(a2huwt2*m*n+b2huwt2*z0hu2)/(a2huwt2*m*m+b2huwt2);
    qhuwt2=(a2huwt2*n*n+b2huwt2*z0hu2*z0hu2-a2huwt2*b2huwt2)/(a2huwt2*m*m+b2huwt2);
    if((phuwt2*phuwt2/4.0)-qhuwt2<0){
    t2h1uwt2=t1+2.0;
    }else{
        zh1uwt2=-phuwt2/2.0+sqrt((phuwt2*phuwt2/4.0)-qhuwt2);
        zh2uwt2=-phuwt2/2.0-sqrt((phuwt2*phuwt2/4.0)-qhuwt2);
        t2h1uwt2=(zh1uwt2-z)/vz;
        t2h2uwt2=(zh2uwt2-z)/vz;
        if(t2h1uwt2<1e-15)
        t2h1uwt2=t1+2.0;
        if(t2h2uwt2<1e-15)
        t2h2uwt2=t1+2.0;
        if(t2h2uwt2<t2h1uwt2)
        t2h1uwt2=t2h2uwt2;
        yintersechuwt2=m*(vz*t2h1uwt2+z)+n;
        if (yintersechuwt2<0){
        t2h1uwt2=t1+2.0;}
        }
  }


  if((louthu2!=0 && linhu2==0)|| (louthu2==0 && linhu2!=0))
  {
    m=vy/vz;
    n=-m*z+y;
    phu2=(2.0*m*n*pahu2+1.0)/(pahu2*m*m);	
    qhu2=n*n/(m*m)-pbhu2/(pahu2*m*m);
    if(qhu2>0 && qhu2>(phu2*phu2/4)){
    t2h1u2=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y>0){
      t2h1u2=(pbhu2-pahu2*y*y-z)/vz;
      }else{
      t2h1u2=t1+2.0;
      }
    }else{
      zh1u2=-phu2/2.0+sqrt(phu2*phu2/4.0-qhu2);
      zh2u2=-phu2/2.0-sqrt(phu2*phu2/4.0-qhu2);
      t2h1u2=(zh1u2-z)/vz;
      t2h2u2=(zh2u2-z)/vz;
      if(t2h1u2<1e-15)
      t2h1u2=t1+2.0;
      if(t2h2u2<1e-15)
      t2h2u2=t1+2.0;
      if(t2h2u2<t2h1u2)
      t2h1u2=t2h2u2;
    }
    yintersechu2=m*(vz*t2h1u2+z)+n;
    if (yintersechu2<0){
    t2h1u2=t1+2.0;}
  }
    phuwt2=(2.0*m*n*pahuwt2+1.0)/(pahuwt2*m*m);						
    qhuwt2=n*n/(m*m)-pbhuwt2/(pahuwt2*m*m);
    if(qhuwt2>0 && qhuwt2>(phuwt2*phuwt2/4)){
    t2h1uwt2=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y>0){
      t2h1uwt2=(pbhuwt2-pahuwt2*y*y-z)/vz;
      }else{
      t2h1uwt2=t1+2.0;
      }
    }else{
      zh1uwt2=-phuwt2/2.0+sqrt(phuwt2*phuwt2/4.0-qhuwt2);
      zh2uwt2=-phuwt2/2.0-sqrt(phuwt2*phuwt2/4.0-qhuwt2);
      t2h1uwt2=(zh1uwt2-z)/vz;
      t2h2uwt2=(zh2uwt2-z)/vz;
      if(t2h1uwt2<1e-15)
      t2h1uwt2=t1+2.0;
      if(t2h2uwt2<1e-15)
      t2h2uwt2=t1+2.0;
      if(t2h2uwt2<t2h1uwt2)
      t2h1uwt2=t2h2uwt2;
    }
    yintersechuwt2=m*(vz*t2h1uwt2+z)+n;
    if (yintersechuwt2<0){
    t2h1uwt2=t1+2.0;}
  }
  }

  if(louthd2==0 && linhd2==0)							/* comments for the down wall are same like for the right wall (only the relation between left and right become relation between up and down)*/	
  {
  m=(-h2d2+h1d2)/l;
  t2h1d2=(m*z+(-h1d2)-y)/(vy-m*vz);
  t2h1dwt2=(m*z+(-h1dwt2)-y)/(vy-m*vz);
  if(t2h1d2<1e-15)
  t2h1d2=t1+2.0;
  if(t2h1dwt2<1e-15)
  t2h1dwt2=t1+2.0;
  }

  if(louthd2!=0 && linhd2!=0)
  { 
    m=vy/vz;
    n=-m*z+y;
    phd2=2.0*(a2hd2*m*n+b2hd2*z0hd2)/(a2hd2*m*m+b2hd2);
    qhd2=(a2hd2*n*n+b2hd2*z0hd2*z0hd2-a2hd2*b2hd2)/(a2hd2*m*m+b2hd2);
    if((phd2*phd2/4.0)-qhd2<0){
    t2h1d2=t1+2.0;
    }else{
        zh1d2=-phd2/2.0+sqrt((phd2*phd2/4.0)-qhd2);
        zh2d2=-phd2/2.0-sqrt((phd2*phd2/4.0)-qhd2);
        t2h1d2=(zh1d2-z)/vz;
        t2h2d2=(zh2d2-z)/vz;
        if(t2h1d2<1e-15)
        t2h1d2=t1+2.0;
        if(t2h2d2<1e-15)
        t2h2d2=t1+2.0;
        if(t2h2d2<t2h1d2)
        t2h1d2=t2h2d2;
        yintersechd2=m*(vz*t2h1d2+z)+n;
        if (yintersechd2>0){
        t2h1d2=t1+2.0;}
        }
    phdwt2=2.0*(a2hdwt2*m*n+b2hdwt2*z0hd2)/(a2hdwt2*m*m+b2hdwt2);
    qhdwt2=(a2hdwt2*n*n+b2hdwt2*z0hd2*z0hd2-a2hdwt2*b2hdwt2)/(a2hdwt2*m*m+b2hdwt2);
    if((phdwt2*phdwt2/4.0)-qhdwt2<0){
    t2h1dwt2=t1+2.0;
    }else{
        zh1dwt2=-phdwt2/2.0+sqrt((phdwt2*phdwt2/4.0)-qhdwt2);
        zh2dwt2=-phdwt2/2.0-sqrt((phdwt2*phdwt2/4.0)-qhdwt2);
        t2h1dwt2=(zh1dwt2-z)/vz;
        t2h2dwt2=(zh2dwt2-z)/vz;
        if(t2h1dwt2<1e-15)
        t2h1dwt2=t1+2.0;
        if(t2h2dwt2<1e-15)
        t2h2dwt2=t1+2.0;
        if(t2h2dwt2<t2h1dwt2)
        t2h1dwt2=t2h2dwt2;
        yintersechdwt2=m*(vz*t2h1dwt2+z)+n;
        if (yintersechdwt2>0){
        t2h1dwt2=t1+2.0;}
        }
  }

  if((louthd2!=0 && linhd2==0)|| (louthd2==0 && linhd2!=0))
  {
    m=vy/vz;
    n=-m*z+y;
    phd2=(2.0*m*n*pahd2+1.0)/(pahd2*m*m);
    qhd2=n*n/(m*m)-pbhd2/(pahd2*m*m);
    if(qhd2>0 && qhd2>(phd2*phd2/4)){
    t2h1d2=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y<0){
      t2h1d2=(pbhd2-pahd2*y*y-z)/vz;
      }else{
      t2h1d2=t1+2.0;
      }
    }else{
      zh1d2=-phd2/2.0+sqrt(phd2*phd2/4.0-qhd2);
      zh2d2=-phd2/2.0-sqrt(phd2*phd2/4.0-qhd2);
      t2h1d2=(zh1d2-z)/vz;
      t2h2d2=(zh2d2-z)/vz;
      if(t2h1d2<1e-15)
      t2h1d2=t1+2.0;
      if(t2h2d2<1e-15)
      t2h2d2=t1+2.0;
      if(t2h2d2<t2h1d2)
      t2h1d2=t2h2d2;
    }
    yintersechd2=m*(vz*t2h1d2+z)+n;
    if (yintersechd2>0){
    t2h1d2=t1+2.0;}
  }
    phdwt2=(2.0*m*n*pahdwt2+1.0)/(pahdwt2*m*m);
    qhdwt2=n*n/(m*m)-pbhdwt2/(pahdwt2*m*m);
    if(qhdwt2>0 && qhdwt2>(phdwt2*phdwt2/4)){
    t2h1dwt2=t1+2.0;
    }else{
    if(vy==0)
    {
      if(y<0){
      t2h1dwt2=(pbhdwt2-pahdwt2*y*y-z)/vz;
      }else{
      t2h1dwt2=t1+2.0;
      }
    }else{
      zh1dwt2=-phdwt2/2.0+sqrt(phdwt2*phdwt2/4.0-qhdwt2);
      zh2dwt2=-phdwt2/2.0-sqrt(phdwt2*phdwt2/4.0-qhdwt2);
      t2h1dwt2=(zh1dwt2-z)/vz;
      t2h2dwt2=(zh2dwt2-z)/vz;
      if(t2h1dwt2<1e-15)
      t2h1dwt2=t1+2.0;
      if(t2h2dwt2<1e-15)
      t2h2dwt2=t1+2.0;
      if(t2h2dwt2<t2h1dwt2)
      t2h1dwt2=t2h2dwt2;
    }
    yintersechdwt2=m*(vz*t2h1dwt2+z)+n;
    if (yintersechdwt2>0){
    t2h1dwt2=t1+2.0;}
  }
  }

													/* TEST OF THE INNER INTERSECTION - TIMES */
													/* possible interactions outside the guide have to be eliminated*/

if(t2w1r<t1+2.0){											/* test of RIGHT INNER wall interaction time*/
if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1r+z)-h1d;								/* calculation of the lower y-limit given by a linear bottom wall and the interaction time*/
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1r+z))*(z0hd+(vz*t2w1r+z)))/a2hd);				/* calculation of the lower y-limit given by a elliptic bottom wall and the interaction time*/
      }else{
      ylimitd=-sqrt(((vz*t2w1r+z)-pbhd)/-pahd);							/* calculation of the lower y-limit given by a parabolic bottom wall and the interaction time*/
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1r+z)+h1u;								/* calculation of the upper y-limit given by a linear top wall and the interaction time*/
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1r+z))*(z0hu+(vz*t2w1r+z)))/a2hu);				/* calculation of the upper y-limit given by a elliptic top wall and the interaction time*/
     }else{
     ylimitu=sqrt(((vz*t2w1r+z)-pbhu)/-pahu);							/* calculation of the upper y-limit given by a parabolic top wall and the interaction time*/
    }
    }
  ytest=vy*t2w1r+y;											/* calculation of the y coordinate of the neutron at the interaction time */
  if (ytest<ylimitd || ytest>ylimitu){									/* if the neutron is below or above the outer bottom or top wall of the guide NO interaction is possible!*/
  t2w1r=t1+2.0;
  }
  }


if(t2w1l<t1+2.0){											/* test of LEFT INNER wall interaction time - analog to right wall*/
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1l+z)-h1d;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1l+z))*(z0hd+(vz*t2w1l+z)))/a2hd);
      }else{
      ylimitd=-sqrt(((vz*t2w1l+z)-pbhd)/-pahd);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1l+z)+h1u;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1l+z))*(z0hu+(vz*t2w1l+z)))/a2hu);
     }else{
     ylimitu=sqrt(((vz*t2w1l+z)-pbhu)/-pahu);
    }
    }
  ytest=vy*t2w1l+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1l=t1+2.0;
  }
  }

if(t2h1u<t1+2.0){											/* test of TOP INNER wall interaction time - analog to right wall*/
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1u+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1u+z))*(z0wr+(vz*t2h1u+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1u+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1u+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1u+z))*(z0wl+(vz*t2h1u+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1u+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1u+x;
  if (xtest<xlimitr || xtest>xlimitl){
  t2h1u=t1+2.0;
  }
  }


if(t2h1d<t1+2.0){											/* test of BOTTOM INNER wall interaction time - analog to right wall*/
if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1d+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1d+z))*(z0wr+(vz*t2h1d+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1d+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1d+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1d+z))*(z0wl+(vz*t2h1d+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1d+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1d+x;
  if (xtest<xlimitr || xtest>xlimitl)
  {
  t2h1d=t1+2.0;
  }
  }


													/* TEST OF THE OUTER INTERSECTION - TIMES */

if(t2w1rwt<t1+2.0){											/* test of RIGHT OUTER wall interaction time - analog inner wall*/
if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1rwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1rwt+z))*(z0hd+(vz*t2w1rwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1rwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1rwt+z))*(z0hu+(vz*t2w1rwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1rwt+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1rwt=t1+2.0;
  }
  }


if(t2w1lwt<t1+2.0){											/* test of LEFT OUTER wall interaction time - analog inner wall*/
if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1lwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1lwt+z))*(z0hd+(vz*t2w1lwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1lwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1lwt+z))*(z0hu+(vz*t2w1lwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1lwt+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1lwt=t1+2.0;
  }
  }

if(t2h1uwt<t1+2.0){											/* test of TOP OUTER wall interaction time - analog inner wall*/
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1uwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1uwt+z))*(z0wr+(vz*t2h1uwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1uwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1uwt+z))*(z0wl+(vz*t2h1uwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1uwt+x;
  if (xtest<xlimitr || xtest>xlimitl){
  t2h1uwt=t1+2.0;
  }
  }


if(t2h1dwt<t1+2.0){											/* test of BOTTOM OUTER wall interaction time - analog inner wall*/
if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1dwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1dwt+z))*(z0wr+(vz*t2h1dwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1dwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1dwt+z))*(z0wl+(vz*t2h1dwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1dwt+x;
  if (xtest<xlimitr || xtest>xlimitl)
  {
  t2h1dwt=t1+2.0;
  }
  }


								/*         INTERACTION OF FIRST SHELL                  */


									/* test INNER wall interaction time*/


if(t2w1r1<t1+2.0){
if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1r1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1r1+z))*(z0hd1+(vz*t2w1r1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1r1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1r1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1r1+z))*(z0hu1+(vz*t2w1r1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1r1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1r1+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1r1=t1+2.0;
  }
  }


if(t2w1l1<t1+2.0){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1l1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1l1+z))*(z0hd1+(vz*t2w1l1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1l1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1l1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1l1+z))*(z0hu1+(vz*t2w1l1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1l1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1l1+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1l1=t1+2.0;
  }
  }

if(t2h1u1<t1+2.0){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1u1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1u1+z))*(z0wr1+(vz*t2h1u1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1u1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1u1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1u1+z))*(z0wl1+(vz*t2h1u1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1u1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1u1+x;
  if (xtest<xlimitr || xtest>xlimitl){
  t2h1u1=t1+2.0;
  }
  }


if(t2h1d1<t1+2.0){
if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1d1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1d1+z))*(z0wr1+(vz*t2h1d1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1d1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1d1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1d1+z))*(z0wl1+(vz*t2h1d1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1d1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1d1+x;
  if (xtest<xlimitr || xtest>xlimitl)
  {
  t2h1d1=t1+2.0;
  }
  }


							/* TEST OF THE OUTER INTERSECTION - TIMES */



if(t2w1rwt1<t1+2.0){
if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1rwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1rwt1+z))*(z0hd1+(vz*t2w1rwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1rwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1rwt1+z))*(z0hu1+(vz*t2w1rwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1rwt1+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1rwt1=t1+2.0;
  }
  }


if(t2w1lwt1<t1+2.0){
if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1lwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1lwt1+z))*(z0hd1+(vz*t2w1lwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1lwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1lwt1+z))*(z0hu1+(vz*t2w1lwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1lwt1+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1lwt1=t1+2.0;
  }
  }

if(t2h1uwt1<t1+2.0){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1uwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1uwt1+z))*(z0wr1+(vz*t2h1uwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1uwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1uwt1+z))*(z0wl1+(vz*t2h1uwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1uwt1+x;
  if (xtest<xlimitr || xtest>xlimitl){
  t2h1uwt1=t1+2.0;
  }
  }


if(t2h1dwt1<t1+2.0){
if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1dwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1dwt1+z))*(z0wr1+(vz*t2h1dwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1dwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1dwt1+z))*(z0wl1+(vz*t2h1dwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1dwt1+x;
  if (xtest<xlimitr || xtest>xlimitl)
  {
  t2h1dwt1=t1+2.0;
  }
  }

								/* INTERACTION SECOND SHELL */

									/* test INNER wall interaction time*/


if(t2w1r2<t1+2.0){
if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1r2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1r2+z))*(z0hd2+(vz*t2w1r2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1r2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1r2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1r2+z))*(z0hu2+(vz*t2w1r2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1r2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1r2+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1r2=t1+2.0;
  }
  }


if(t2w1l2<t1+2.0){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1l2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1l2+z))*(z0hd2+(vz*t2w1l2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1l2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1l2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1l2+z))*(z0hu2+(vz*t2w1l2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1l2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1l2+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1l2=t1+2.0;
  }
  }

if(t2h1u2<t1+2.0){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1u2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1u2+z))*(z0wr2+(vz*t2h1u2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1u2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1u2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1u2+z))*(z0wl2+(vz*t2h1u2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1u2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1u2+x;
  if (xtest<xlimitr || xtest>xlimitl){
  t2h1u2=t1+2.0;
  }
  }


if(t2h1d2<t1+2.0){
if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1d2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1d2+z))*(z0wr2+(vz*t2h1d2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1d2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1d2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1d2+z))*(z0wl2+(vz*t2h1d2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1d2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1d2+x;
  if (xtest<xlimitr || xtest>xlimitl)
  {
  t2h1d2=t1+2.0;
  }
  }


							/* TEST OF THE OUTER INTERSECTION - TIMES */



if(t2w1rwt2<t1+2.0){
if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1rwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1rwt2+z))*(z0hd2+(vz*t2w1rwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1rwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1rwt2+z))*(z0hu2+(vz*t2w1rwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1rwt2+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1rwt2=t1+2.0;
  }
  }


if(t2w1lwt2<t1+2.0){
if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1lwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1lwt2+z))*(z0hd2+(vz*t2w1lwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1lwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1lwt2+z))*(z0hu2+(vz*t2w1lwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1lwt2+y;
  if (ytest<ylimitd || ytest>ylimitu){
  t2w1lwt2=t1+2.0;
  }
  }

if(t2h1uwt2<t1+2.0){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1uwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1uwt2+z))*(z0wr2+(vz*t2h1uwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1uwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1uwt2+z))*(z0wl2+(vz*t2h1uwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1uwt2+x;
  if (xtest<xlimitr || xtest>xlimitl){
  t2h1uwt2=t1+2.0;
  }
  }


if(t2h1dwt2<t1+2.0){
if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1dwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1dwt2+z))*(z0wr2+(vz*t2h1dwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1dwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1dwt2+z))*(z0wl2+(vz*t2h1dwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1dwt2+x;
  if (xtest<xlimitr || xtest>xlimitl)
  {
  t2h1dwt2=t1+2.0;
  }
  }




/* printf("t1 = %f \n",t1);
printf("t2w1r = %f \n",t2w1r);
printf("t2w1l = %f \n",t2w1l);
printf("t2h1u = %f \n",t2h1u);
printf("t2h1d = %f \n",t2h1d);
*/
/*
 printf("t1 = %f \n",t1);
printf("t2w1rwt = %f \n",t2w1rwt);
printf("t2w1lwt = %f \n",t2w1lwt);
printf("t2h1uwt = %f \n",t2h1uwt);
printf("t2h1dwt = %f \n",t2h1dwt);
*/

/*
printf("t2w1r1 = %f \n",t2w1r1);
printf("t2w1l1 = %f \n",t2w1l1);
printf("t2h1u1 = %f \n",t2h1u1);
printf("t2h1d1 = %f \n",t2h1d1);
*/

/*
printf("vx = %f \n",vx);
printf("x = %f \n",x); */

/*printf("mxr = %f \n", mxr);
printf("mxl = %f \n", mxl);
printf("myu = %f \n", myu);
printf("myd = %f \n", myd);*/

																				/* which wall is hit first? which geometry? */

  if (t1 < t2w1r && t1 < t2w1l && t1 < t2h1u && t1 < t2h1d && t1 < t2w1rwt && t1 < t2w1lwt && t1 < t2h1uwt && t1 < t2h1dwt && t1 < t2w1r1 && t1 < t2w1l1 && t1 < t2h1u1 && t1 < t2h1d1 && t1 < t2w1rwt1 && t1 < t2w1lwt1 && t1 < t2h1uwt1 && t1 < t2h1dwt1 && t1 < t2w1r2 && t1 < t2w1l2 && t1 < t2h1u2 && t1 < t2h1d2 && t1 < t2w1rwt2 && t1 < t2w1lwt2 && t1 < t2h1uwt2 && t1 < t2h1dwt2){					/* neutron pass the guide without interaction*/
  i=1;
  }

													/* neutron interacts with the INNER elliptic right wall and this wall is NOT transparent*/

  if (mxr!=-1 && t2w1r > 0 && t2w1r < t1 && t2w1r<t2w1l && t2w1r < t2h1u && t2w1r < t2h1d && t2w1r < t2w1rwt && t2w1r<t2w1lwt && t2w1r < t2h1uwt && t2w1r < t2h1dwt && t2w1r < t2w1r1 && t2w1r < t2w1l1 && t2w1r < t2h1u1 && t2w1r < t2h1d1 && t2w1r < t2w1rwt1 && t2w1r < t2w1lwt1 && t2w1r < t2h1uwt1 && t2w1r < t2h1dwt1 && t2w1r < t2w1r2 && t2w1r < t2w1l2 && t2w1r < t2h1u2 && t2w1r < t2h1d2 && t2w1r < t2w1rwt2 && t2w1r < t2w1lwt2 && t2w1r < t2h1uwt2 && t2w1r < t2h1dwt2 && ((linwr!=0) && (loutwr!=0) )) {	
    if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1r+z)-h1d;								/* calculation of the lower y-limit given by a linear INNER bottom wall and the interaction time*/
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1r+z))*(z0hd+(vz*t2w1r+z)))/a2hd);				/* calculation of the lower y-limit given by a elliptic INNER bottom wall and the interaction time*/
      }else{
      ylimitd=-sqrt(((vz*t2w1r+z)-pbhd)/-pahd);								/* calculation of the lower y-limit given by a parabolic INNER bottom wall and the interaction time*/
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1r+z)+h1u;								/* calculation of the upper y-limit given by a linear INNER top wall and the interaction time*/
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1r+z))*(z0hu+(vz*t2w1r+z)))/a2hu);				/* calculation of the upper y-limit given by a elliptic INNER top wall and the interaction time*/
     }else{
     ylimitu=sqrt(((vz*t2w1r+z)-pbhu)/-pahu);								/* calculation of the upper y-limit given by a parabolic INNER top wall and the interaction time*/
    }
    }
  ytest=vy*t2w1r+y;											/* calculation of y-coordinate of the neutron at the interaction time*/
  xlimitr=bwr*sqrt(1-((vz*t2w1r+z)+z0wr)*((vz*t2w1r+z)+z0wr)/a2wr);					/* calculation of right INNER limit given by a elliptic shape of the wall*/
  xtest=vx*t2w1r+x;											/* calculation of x-coordinate of the neutron at the interaction time*/
  if (ytest>=ylimitd && ytest<=ylimitu && x>=-xlimitr && mxr > 0){					/* only if the neutron is realy inside the guide (testet by the limits) and the wall is reflecting*/
  i=2;													/* the neutron will be reflected*/
  }else{
  i=18;													/* otherwise it will be absorbed*/
  }
  }

													/* neutron interacts with the parabolic right INNER wall - comments are analog to inner elliptic right wall */

  if (mxr!=-1 && t2w1r > 0 && t2w1r < t1 && t2w1r<t2w1l && t2w1r < t2h1u && t2w1r < t2h1d && t2w1r < t2w1rwt && t2w1r<t2w1lwt && t2w1r < t2h1uwt && t2w1r < t2h1dwt && t2w1r < t2w1r1 && t2w1r < t2w1l1 && t2w1r < t2h1u1 && t2w1r < t2h1d1 && t2w1r < t2w1rwt1 && t2w1r < t2w1lwt1 && t2w1r < t2h1uwt1 && t2w1r < t2h1dwt1 && t2w1r < t2w1r2 && t2w1r < t2w1l2 && t2w1r < t2h1u2 && t2w1r < t2h1d2 && t2w1r < t2w1rwt2 && t2w1r < t2w1lwt2 && t2w1r < t2h1uwt2 && t2w1r < t2h1dwt2 && ((loutwr!=0 && linwr==0) || (loutwr==0 && linwr!=0))){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1r+z)-h1d;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1r+z))*(z0hd+(vz*t2w1r+z)))/a2hd);
      }else{
      ylimitd=-sqrt(((vz*t2w1r+z)-pbhd)/-pahd);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1r+z)+h1u;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1r+z))*(z0hu+(vz*t2w1r+z)))/a2hu);
     }else{
     ylimitu=sqrt(((vz*t2w1r+z)-pbhu)/-pahu);
    }
    }
  ytest=vy*t2w1r+y;
  xtest=vx*t2w1r+x;
  xlimitr=-sqrt(pbwr-(vz*t2w1r+z)/pawr);
  if (ytest>ylimitd && ytest<ylimitu && x>=xlimitr && mxr > 0){
  i=3;
  }else{
  i=18;}
  }

													/* neutron interacts with the straight right INNER wall - comments are analog to inner elliptic right wall*/

  if (mxr!=-1 && t2w1r > 0 && t2w1r < t1 && t2w1r<t2w1l && t2w1r < t2h1u && t2w1r < t2h1d && t2w1r < t2w1rwt && t2w1r<t2w1lwt && t2w1r < t2h1uwt && t2w1r < t2h1dwt && t2w1r < t2w1r1 && t2w1r < t2w1l1 && t2w1r < t2h1u1 && t2w1r < t2h1d1 && t2w1r < t2w1rwt1 && t2w1r < t2w1lwt1 && t2w1r < t2h1uwt1 && t2w1r < t2h1dwt1 && t2w1r < t2w1r2 && t2w1r < t2w1l2 && t2w1r < t2h1u2 && t2w1r < t2h1d2 && t2w1r < t2w1rwt2 && t2w1r < t2w1lwt2 && t2w1r < t2h1uwt2 && t2w1r < t2h1dwt2 && (loutwr==0 && linwr==0)){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1r+z)-h1d;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1r+z))*(z0hd+(vz*t2w1r+z)))/a2hd);
      }else{
      ylimitd=-sqrt(((vz*t2w1r+z)-pbhd)/-pahd);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1r+z)+h1u;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1r+z))*(z0hu+(vz*t2w1r+z)))/a2hu);
     }else{
     ylimitu=sqrt(((vz*t2w1r+z)-pbhu)/-pahu);
    }
    }
  ytest=vy*t2w1r+y;
  xtest=vx*t2w1r+x;
  xlimitr=-(w2r+w1r)*(vz*t2w1r+z)/l-w1r;
  if (ytest>=ylimitd && ytest<=ylimitu && x>=xlimitr && mxr>0){
  i=4;
  }else{
  i=18;
  }
  }

													/* neutron interacts with the elliptic left INNER wall - comments are analog to inner elliptic right wall*/

  if (mxl!=-1 && t2w1l > 0 && t2w1l < t1 && t2w1l<t2w1r && t2w1l < t2h1u && t2w1l < t2h1d && t2w1l < t2w1lwt && t2w1l<t2w1rwt && t2w1l < t2h1uwt && t2w1l < t2h1dwt && t2w1l < t2w1r1 && t2w1l < t2w1l1 && t2w1l < t2h1u1 && t2w1l < t2h1d1 && t2w1l < t2w1rwt1 && t2w1l < t2w1lwt1 && t2w1l < t2h1uwt1 && t2w1l < t2h1dwt1 && t2w1l < t2w1r2 && t2w1l < t2w1l2 && t2w1l < t2h1u2 && t2w1l < t2h1d2 && t2w1l < t2w1rwt2 && t2w1l < t2w1lwt2 && t2w1l < t2h1uwt2 && t2w1l < t2h1dwt2 && ((linwl!=0) && (loutwl!=0) )){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1l+z)-h1d;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1l+z))*(z0hd+(vz*t2w1l+z)))/a2hd);
      }else{
      ylimitd=-sqrt(((vz*t2w1l+z)-pbhd)/-pahd);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1l+z)+h1u;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1l+z))*(z0hu+(vz*t2w1l+z)))/a2hu);
     }else{
     ylimitu=sqrt(((vz*t2w1l+z)-pbhu)/-pahu);
    }
    }
  ytest=vy*t2w1l+y;
  xlimitl=bwl*sqrt(1-((vz*t2w1l+z)+z0wl)*((vz*t2w1l+z)+z0wl)/a2wl);
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl>0){
  i=5;
  }else{
  i=19;
  }
  }

													/* neutron interacts with the parabolic left INNER wall - comments are analog to inner elliptic right wall*/

  if (mxl!=-1 && t2w1l > 0 && t2w1l < t1 && t2w1l<t2w1r && t2w1l < t2h1u && t2w1l < t2h1d && t2w1l < t2w1lwt && t2w1l<t2w1rwt && t2w1l < t2h1uwt && t2w1l < t2h1dwt && t2w1l < t2w1r1 && t2w1l < t2w1l1 && t2w1l < t2h1u1 && t2w1l < t2h1d1 && t2w1l < t2w1rwt1 && t2w1l < t2w1lwt1 && t2w1l < t2h1uwt1 && t2w1l < t2h1dwt1 && t2w1l < t2w1r2 && t2w1l < t2w1l2 && t2w1l < t2h1u2 && t2w1l < t2h1d2 && t2w1l < t2w1rwt2 && t2w1l < t2w1lwt2 && t2w1l < t2h1uwt2 && t2w1l < t2h1dwt2 && ((loutwl!=0 && linwl==0) || (loutwl==0 && linwl!=0))){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1l+z)-h1d;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1l+z))*(z0hd+(vz*t2w1l+z)))/a2hd);
      }else{
      ylimitd=-sqrt(((vz*t2w1l+z)-pbhd)/-pahd);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1l+z)+h1u;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1l+z))*(z0hu+(vz*t2w1l+z)))/a2hu);
     }else{
     ylimitu=sqrt(((vz*t2w1l+z)-pbhu)/-pahu);
    }
    }
  ytest=vy*t2w1l+y;
  xlimitl=sqrt(pbwl-(vz*t2w1l+z)/pawl);
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl>0){
  i=6;
  }else{
  i=19;
  }
  }

														/* neutron interacts with the straight left INNER wall - comments are analog to inner elliptic right wall*/

  if (mxl!=-1 && t2w1l > 0 && t2w1l < t1 && t2w1l<t2w1r && t2w1l < t2h1u && t2w1l < t2h1d && t2w1l < t2w1lwt && t2w1l<t2w1rwt && t2w1l < t2h1uwt && t2w1l < t2h1dwt && t2w1l < t2w1r1 && t2w1l < t2w1l1 && t2w1l < t2h1u1 && t2w1l < t2h1d1 && t2w1l < t2w1rwt1 && t2w1l < t2w1lwt1 && t2w1l < t2h1uwt1 && t2w1l < t2h1dwt1 && t2w1l < t2w1r2 && t2w1l < t2w1l2 && t2w1l < t2h1u2 && t2w1l < t2h1d2 && t2w1l < t2w1rwt2 && t2w1l < t2w1lwt2 && t2w1l < t2h1uwt2 && t2w1l < t2h1dwt2 && (loutwl==0 && linwl==0)){
 if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1l+z)-h1d;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhd*sqrt(1-((z0hd+(vz*t2w1l+z))*(z0hd+(vz*t2w1l+z)))/a2hd);
      }else{
      ylimitd=-sqrt(((vz*t2w1l+z)-pbhd)/-pahd);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1l+z)+h1u;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhu*sqrt(1-((z0hu+(vz*t2w1l+z))*(z0hu+(vz*t2w1l+z)))/a2hu);
     }else{
     ylimitu=sqrt(((vz*t2w1l+z)-pbhu)/-pahu);
    }
    }
  ytest=vy*t2w1l+y;
  xlimitl=(w2l-w1l)*(vz*t2w1l+z)/l+w1l;
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl>0){
  i=7;
  }else{
  i=19;
  }
  }

														/* neutron interacts with the elliptic top INNER wall - comments are analog to inner elliptic right wall*/

  if (myu!=-1 && t2h1u > 0 && t2h1u < t1 && t2h1u < t2w1r && t2h1u < t2w1l && t2h1u < t2h1d && t2h1u < t2h1uwt && t2h1u < t2w1rwt && t2h1u < t2w1lwt && t2h1u < t2h1dwt && t2h1u < t2w1r1 && t2h1u < t2w1l1 && t2h1u < t2h1u1 && t2h1u < t2h1d1 && t2h1u < t2w1rwt1 && t2h1u < t2w1lwt1 && t2h1u < t2h1uwt1 && t2h1u < t2h1dwt1 && t2h1u < t2w1r2 && t2h1u < t2w1l2 && t2h1u < t2h1u2 && t2h1u < t2h1d2 && t2h1u < t2w1rwt2 && t2h1u < t2w1lwt2 && t2h1u < t2h1uwt2 && t2h1u < t2h1dwt2 && (louthu !=0 && linhu!=0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1u+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1u+z))*(z0wr+(vz*t2h1u+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1u+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1u+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1u+z))*(z0wl+(vz*t2h1u+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1u+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1u+x;
  ylimitu=bhu*sqrt(1-((vz*t2h1u+z)+z0hu)*((vz*t2h1u+z)+z0hu)/a2hu);
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu>0 ){
  i=8;
  }else{
  i=20;
  }
  }
	
														/* neutron interacts with the parabolic top INNER wall - comments are analog to inner elliptic right wall*/

  if (myu!=-1 && t2h1u > 0 && t2h1u < t1 && t2h1u < t2w1r && t2h1u < t2w1l && t2h1u < t2h1d && t2h1u < t2h1uwt && t2h1u < t2w1rwt && t2h1u < t2w1lwt && t2h1u < t2h1dwt && t2h1u < t2w1r1 && t2h1u < t2w1l1 && t2h1u < t2h1u1 && t2h1u < t2h1d1 && t2h1u < t2w1rwt1 && t2h1u < t2w1lwt1 && t2h1u < t2h1uwt1 && t2h1u < t2h1dwt1 && t2h1u < t2w1r2 && t2h1u < t2w1l2 && t2h1u < t2h1u2 && t2h1u < t2h1d2 && t2h1u < t2w1rwt2 && t2h1u < t2w1lwt2 && t2h1u < t2h1uwt2 && t2h1u < t2h1dwt2 &&  ((louthu!=0 && linhu==0) || (louthu==0 && linhu!=0))){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1u+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1u+z))*(z0wr+(vz*t2h1u+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1u+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1u+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1u+z))*(z0wl+(vz*t2h1u+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1u+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1u+x;
  ylimitu=sqrt(pbhu-(vz*t2h1u+z)/pahu);
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu>0){
  i=9;
  }else{
  i=20;
  }
  }


															/* neutron interacts with the straight top INNER wall - comments are analog to inner elliptic right wall*/

  if (myu!=-1 && t2h1u > 0 && t2h1u < t1 && t2h1u < t2w1r && t2h1u < t2w1l && t2h1u < t2h1d && t2h1u < t2h1uwt && t2h1u < t2w1rwt && t2h1u < t2w1lwt && t2h1u < t2h1dwt && t2h1u < t2w1r1 && t2h1u < t2w1l1 && t2h1u < t2h1u1 && t2h1u < t2h1d1 && t2h1u < t2w1rwt1 && t2h1u < t2w1lwt1 && t2h1u < t2h1uwt1 && t2h1u < t2h1dwt1 &&  t2h1u < t2w1r2 && t2h1u < t2w1l2 && t2h1u < t2h1u2 && t2h1u < t2h1d2 && t2h1u < t2w1rwt2 && t2h1u < t2w1lwt2 && t2h1u < t2h1uwt2 && t2h1u < t2h1dwt2 &&  (louthu == 0 && linhu == 0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1u+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1u+z))*(z0wr+(vz*t2h1u+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1u+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1u+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1u+z))*(z0wl+(vz*t2h1u+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1u+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1u+x;
  ylimitu=(h2u-h1u)*(vz*t2h1u+z)/l+h1u;
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu>0 ){
  i=10;
  }else{
  i=20;
  }
  }

															/* neutron interacts with the elliptic down INNER wall - comments are analog to inner elliptic right wall*/

  if (myd!=-1 && t2h1d > 0 && t2h1d < t1 && t2h1d < t2w1r && t2h1d < t2w1l && t2h1d < t2h1u  && t2h1d < t2h1dwt && t2h1d < t2w1rwt && t2h1d < t2w1lwt && t2h1d < t2h1uwt && t2h1d < t2w1r1 && t2h1d < t2w1l1 && t2h1d < t2h1u1 && t2h1d < t2h1d1 && t2h1d < t2w1rwt1 && t2h1d < t2w1lwt1 && t2h1d < t2h1uwt1 && t2h1d < t2h1dwt1 && t2h1d < t2w1r2 && t2h1d < t2w1l2 && t2h1d < t2h1u2 && t2h1d < t2h1d2 && t2h1d < t2w1rwt2 && t2h1d < t2w1lwt2 && t2h1d < t2h1uwt2 && t2h1d < t2h1dwt2 && (louthd !=0 && linhd!=0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1d+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1d+z))*(z0wr+(vz*t2h1d+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1d+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1d+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1d+z))*(z0wl+(vz*t2h1d+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1d+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1d+x;
  ylimitd=-bhd*sqrt(1-((vz*t2h1d+z)+z0hd)*((vz*t2h1d+z)+z0hd)/a2hd);
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd>0){
  i=11;
  }else{
  i=21;
  }
  }

															/* neutron interacts with the parabolic down INNER wall - comments are analog to inner elliptic right wall*/

  if (myd!=-1 && t2h1d > 0 && t2h1d < t1 && t2h1d < t2w1r && t2h1d < t2w1l && t2h1d < t2h1u  && t2h1d < t2h1dwt && t2h1d < t2w1rwt && t2h1d < t2w1lwt && t2h1d < t2h1uwt && t2h1d < t2w1r1 && t2h1d < t2w1l1 && t2h1d < t2h1u1 && t2h1d < t2h1d1 && t2h1d < t2w1rwt1 && t2h1d < t2w1lwt1 && t2h1d < t2h1uwt1 && t2h1d < t2h1dwt1 && t2h1d < t2w1r2 && t2h1d < t2w1l2 && t2h1d < t2h1u2 && t2h1d < t2h1d2 && t2h1d < t2w1rwt2 && t2h1d < t2w1lwt2 && t2h1d < t2h1uwt2 && t2h1d < t2h1dwt2 && ((louthd !=0 && linhd==0) || (louthd ==0 && linhd!=0))){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1d+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1d+z))*(z0wr+(vz*t2h1d+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1d+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1d+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1d+z))*(z0wl+(vz*t2h1d+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1d+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1d+x;
  ylimitd=-sqrt(pbhd-(vz*t2h1d+z)/pahd);
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd>0 ){
  i=12;
  }else{
  i=21;
  }
  }

															/* neutron interacts with the straight down INNER wall - comments are analog to inner elliptic right wall*/

  if (myd!=-1 && t2h1d > 0 && t2h1d < t1 && t2h1d < t2w1r && t2h1d < t2w1l && t2h1d < t2h1u  && t2h1d < t2h1dwt && t2h1d < t2w1rwt && t2h1d < t2w1lwt && t2h1d < t2h1uwt && t2h1d < t2w1r1 && t2h1d < t2w1l1 && t2h1d < t2h1u1 && t2h1d < t2h1d1 && t2h1d < t2w1rwt1 && t2h1d < t2w1lwt1 && t2h1d < t2h1uwt1 && t2h1d < t2h1dwt1 && t2h1d < t2w1r2 && t2h1d < t2w1l2 && t2h1d < t2h1u2 && t2h1d < t2h1d2 && t2h1d < t2w1rwt2 && t2h1d < t2w1lwt2 && t2h1d < t2h1uwt2 && t2h1d < t2h1dwt2 && (louthd == 0 && linhd == 0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1d+z)-w1r;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwr*sqrt(1-((z0wr+(vz*t2h1d+z))*(z0wr+(vz*t2h1d+z)))/a2wr);
    }else{
    xlimitr=-sqrt(((vz*t2h1d+z)-pbwr)/-pawr);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1d+z)+w1l;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwl*sqrt(1-((z0wl+(vz*t2h1d+z))*(z0wl+(vz*t2h1d+z)))/a2wl);
      }else{
      xlimitl=sqrt(((vz*t2h1d+z)-pbwl)/-pawl);
      }
   }
  xtest=vx*t2h1d+x;
  ylimitd=(-h2d+h1d)*(vz*t2h1d+z)/l-h1d;
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd>0 ){
  i=13;
  }else{
  i=21;
  }
  }

   /* SAME INTERACTIONS BUT TRANSPERENT INNER WALLS - in these cases no limit check up is needed , because will neutrons will pass unchanged anyway*/

  if (mxr==-1 && t2w1r > 0 && t2w1r < t1 && t2w1r<t2w1l  && t2w1r < t2h1u && t2w1r < t2h1d && t2w1r < t2w1rwt && t2w1r<t2w1lwt  && t2w1r < t2h1uwt && t2w1r < t2h1dwt && t2w1r < t2w1r1 && t2w1r < t2w1l1 && t2w1r < t2h1u1 && t2w1r < t2h1d1 && t2w1r < t2w1rwt1 && t2w1r < t2w1lwt1 && t2w1r < t2h1uwt1 && t2w1r < t2h1dwt1 && t2w1r < t2w1r2 && t2w1r < t2w1l2 && t2w1r < t2h1u2 && t2w1r < t2h1d2 && t2w1r < t2w1rwt2 && t2w1r < t2w1lwt2 && t2w1r < t2h1uwt2 && t2w1r < t2h1dwt2 && ((linwr!=0) && (loutwr!=0) )) {
  i=14;
  }

  if (mxr==-1 && t2w1r > 0 && t2w1r < t1 && t2w1r<t2w1l  && t2w1r < t2h1u && t2w1r < t2h1d && t2w1r < t2w1rwt && t2w1r<t2w1lwt  && t2w1r < t2h1uwt && t2w1r < t2h1dwt && t2w1r < t2w1r1 && t2w1r < t2w1l1 && t2w1r < t2h1u1 && t2w1r < t2h1d1 && t2w1r < t2w1rwt1 && t2w1r < t2w1lwt1 && t2w1r < t2h1uwt1 && t2w1r < t2h1dwt1 && t2w1r < t2w1r2 && t2w1r < t2w1l2 && t2w1r < t2h1u2 && t2w1r < t2h1d2 && t2w1r < t2w1rwt2 && t2w1r < t2w1lwt2 && t2w1r < t2h1uwt2 && t2w1r < t2h1dwt2 && ((loutwr!=0 && linwr==0) || (loutwr==0 && linwr!=0))){
  i=14;
  }

  if (mxr==-1 && t2w1r > 0 && t2w1r < t1 && t2w1r<t2w1l  && t2w1r < t2h1u && t2w1r < t2h1d && t2w1r < t2w1rwt && t2w1r<t2w1lwt  && t2w1r < t2h1uwt && t2w1r < t2h1dwt && t2w1r < t2w1r1 && t2w1r < t2w1l1 && t2w1r < t2h1u1 && t2w1r < t2h1d1 && t2w1r < t2w1rwt1 && t2w1r < t2w1lwt1 && t2w1r < t2h1uwt1 && t2w1r < t2h1dwt1 && t2w1r < t2w1r2 && t2w1r < t2w1l2 && t2w1r < t2h1u2 && t2w1r < t2h1d2 && t2w1r < t2w1rwt2 && t2w1r < t2w1lwt2 && t2w1r < t2h1uwt2 && t2w1r < t2h1dwt2 && (loutwr==0 && linwr==0)){
  i=14;
  }

  if (mxl==-1 && t2w1l > 0 && t2w1l < t1 && ( t2w1l<t2w1r ) && t2w1l < t2h1u && t2w1l < t2h1d && t2w1l < t2w1lwt && t2w1l<t2w1rwt && t2w1l < t2h1uwt && t2w1l < t2h1dwt && t2w1l < t2w1r1 && t2w1l < t2w1l1 && t2w1l < t2h1u1 && t2w1l < t2h1d1 && t2w1l < t2w1rwt1 && t2w1l < t2w1lwt1 && t2w1l < t2h1uwt1 && t2w1l < t2h1dwt1 && t2w1l < t2w1r2 && t2w1l < t2w1l2 && t2w1l < t2h1u2 && t2w1l < t2h1d2 && t2w1l < t2w1rwt2 && t2w1l < t2w1lwt2 && t2w1l < t2h1uwt2 && t2w1l < t2h1dwt2 && ((linwl!=0) && (loutwl!=0) )){
  i=15;
  }

  if (mxl==-1 && t2w1l > 0 && t2w1l < t1 && ( t2w1l<t2w1r ) && t2w1l < t2h1u && t2w1l < t2h1d && t2w1l < t2w1lwt && t2w1l<t2w1rwt && t2w1l < t2h1uwt && t2w1l < t2h1dwt && t2w1l < t2w1r1 && t2w1l < t2w1l1 && t2w1l < t2h1u1 && t2w1l < t2h1d1 && t2w1l < t2w1rwt1 && t2w1l < t2w1lwt1 && t2w1l < t2h1uwt1 && t2w1l < t2h1dwt1 && t2w1l < t2w1r2 && t2w1l < t2w1l2 && t2w1l < t2h1u2 && t2w1l < t2h1d2 && t2w1l < t2w1rwt2 && t2w1l < t2w1lwt2 && t2w1l < t2h1uwt2 && t2w1l < t2h1dwt2 && ((loutwl!=0 && linwl==0) || (loutwl==0 && linwl!=0))){
  i=15;
  }

  if (mxl==-1 && t2w1l > 0 && t2w1l < t1 && ( t2w1l<t2w1r ) && t2w1l < t2h1u && t2w1l < t2h1d && t2w1l < t2w1lwt && t2w1l<t2w1rwt && t2w1l < t2h1uwt && t2w1l < t2h1dwt && t2w1l < t2w1r1 && t2w1l < t2w1l1 && t2w1l < t2h1u1 && t2w1l < t2h1d1 && t2w1l < t2w1rwt1 && t2w1l < t2w1lwt1 && t2w1l < t2h1uwt1 && t2w1l < t2h1dwt1 && t2w1l < t2w1r2 && t2w1l < t2w1l2 && t2w1l < t2h1u2 && t2w1l < t2h1d2 && t2w1l < t2w1rwt2 && t2w1l < t2w1lwt2 && t2w1l < t2h1uwt2 && t2w1l < t2h1dwt2 && (loutwl==0 && linwl==0)){
  i=15;
  }

  if (myu==-1 && t2h1u > 0 && t2h1u < t1 && t2h1u < t2w1r && t2h1u < t2w1l && t2h1u < t2h1d  && t2h1u < t2h1uwt && t2h1u < t2w1rwt && t2h1u < t2w1lwt && t2h1u < t2h1dwt  && t2h1u < t2w1r1 && t2h1u < t2w1l1 && t2h1u < t2h1u1 && t2h1u < t2h1d1 && t2h1u < t2w1rwt1 && t2h1u < t2w1lwt1 && t2h1u < t2h1uwt1 && t2h1u < t2h1dwt1 && t2h1u < t2w1r2 && t2h1u < t2w1l2 && t2h1u < t2h1u2 && t2h1u < t2h1d2 && t2h1u < t2w1rwt2 && t2h1u < t2w1lwt2 && t2h1u < t2h1uwt2 && t2h1u < t2h1dwt2 && (louthu !=0 && linhu!=0)){
  i=16;
  }

  if (myu==-1 && t2h1u > 0 && t2h1u < t1 && t2h1u < t2w1r && t2h1u < t2w1l && t2h1u < t2h1d  && t2h1u < t2h1uwt && t2h1u < t2w1rwt && t2h1u < t2w1lwt && t2h1u < t2h1dwt  && t2h1u < t2w1r1 && t2h1u < t2w1l1 && t2h1u < t2h1u1 && t2h1u < t2h1d1 && t2h1u < t2w1rwt1 && t2h1u < t2w1lwt1 && t2h1u < t2h1uwt1 && t2h1u < t2h1dwt1 && t2h1u < t2w1r2 && t2h1u < t2w1l2 && t2h1u < t2h1u2 && t2h1u < t2h1d2 && t2h1u < t2w1rwt2 && t2h1u < t2w1lwt2 && t2h1u < t2h1uwt2 && t2h1u < t2h1dwt2 && ((louthu!=0 && linhu==0) || (louthu==0 && linhu!=0))){
  i=16;
  }

  if (myu==-1 && t2h1u > 0 && t2h1u < t1 && t2h1u < t2w1r && t2h1u < t2w1l && t2h1u < t2h1d  && t2h1u < t2h1uwt && t2h1u < t2w1rwt && t2h1u < t2w1lwt && t2h1u < t2h1dwt  && t2h1u < t2w1r1 && t2h1u < t2w1l1 && t2h1u < t2h1u1 && t2h1u < t2h1d1 && t2h1u < t2w1rwt1 && t2h1u < t2w1lwt1 && t2h1u < t2h1uwt1 && t2h1u < t2h1dwt1 && t2h1u < t2w1r2 && t2h1u < t2w1l2 && t2h1u < t2h1u2 && t2h1u < t2h1d2 && t2h1u < t2w1rwt2 && t2h1u < t2w1lwt2 && t2h1u < t2h1uwt2 && t2h1u < t2h1dwt2 && (louthu == 0 && linhu == 0)){
  i=16;
  }

  if (myd==-1 && t2h1d > 0 && t2h1d < t1 && t2h1d < t2w1r && t2h1d < t2w1l && t2h1d < t2h1u  && t2h1d < t2h1dwt && t2h1d < t2w1rwt && t2h1d < t2w1lwt && t2h1d < t2h1uwt  && t2h1d < t2w1r1 && t2h1d < t2w1l1 && t2h1d < t2h1u1 && t2h1d < t2h1d1 && t2h1d < t2w1rwt1 && t2h1d < t2w1lwt1 && t2h1d < t2h1uwt1 && t2h1d < t2h1dwt1 && t2h1d < t2w1r2 && t2h1d < t2w1l2 && t2h1d < t2h1u2 && t2h1d < t2h1d2 && t2h1d < t2w1rwt2 && t2h1d < t2w1lwt2 && t2h1d < t2h1uwt2 && t2h1d < t2h1dwt2 && (louthd !=0 && linhd!=0)){
  i=17;
  }

  if (myd==-1 && t2h1d > 0 && t2h1d < t1 && t2h1d < t2w1r && t2h1d < t2w1l && t2h1d < t2h1u  && t2h1d < t2h1dwt && t2h1d < t2w1rwt && t2h1d < t2w1lwt && t2h1d < t2h1uwt  && t2h1d < t2w1r1 && t2h1d < t2w1l1 && t2h1d < t2h1u1 && t2h1d < t2h1d1 && t2h1d < t2w1rwt1 && t2h1d < t2w1lwt1 && t2h1d < t2h1uwt1 && t2h1d < t2h1dwt1 && t2h1d < t2w1r2 && t2h1d < t2w1l2 && t2h1d < t2h1u2 && t2h1d < t2h1d2 && t2h1d < t2w1rwt2 && t2h1d < t2w1lwt2 && t2h1d < t2h1uwt2 && t2h1d < t2h1dwt2 && ((louthd !=0 && linhd==0) || (louthd ==0 && linhd!=0))){
  i=17;
  }

  if (myd==-1 && t2h1d > 0 && t2h1d < t1 && t2h1d < t2w1r && t2h1d < t2w1l && t2h1d < t2h1u  && t2h1d < t2h1dwt && t2h1d < t2w1rwt && t2h1d < t2w1lwt && t2h1d < t2h1uwt  && t2h1d < t2w1r1 && t2h1d < t2w1l1 && t2h1d < t2h1u1 && t2h1d < t2h1d1 && t2h1d < t2w1rwt1 && t2h1d < t2w1lwt1 && t2h1d < t2h1uwt1 && t2h1d < t2h1dwt1 && t2h1d < t2w1r2 && t2h1d < t2w1l2 && t2h1d < t2h1u2 && t2h1d < t2h1d2 && t2h1d < t2w1rwt2 && t2h1d < t2w1lwt2 && t2h1d < t2h1uwt2 && t2h1d < t2h1dwt2 && (louthd == 0 && linhd == 0)){
  i=17;
  }

   
												/* EVERTHING AGAIN FOR THE OUTER WALLS */

												/* neutron interacts with the elliptic right OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxrOW!=-1 && t2w1rwt > 0 && t2w1rwt < t1 && t2w1rwt < t2w1r && t2w1rwt <t2w1l && t2w1rwt < t2h1u && t2w1rwt < t2h1d &&  t2w1rwt <t2w1lwt && t2w1rwt < t2h1uwt && t2w1rwt < t2h1dwt && t2w1rwt < t2w1r1 && t2w1rwt < t2w1l1 && t2w1rwt < t2h1u1 && t2w1rwt < t2h1d1 && t2w1rwt < t2w1rwt1 && t2w1rwt < t2w1lwt1 && t2w1rwt < t2h1uwt1 && t2w1rwt < t2h1dwt1 && t2w1rwt < t2w1r2 && t2w1rwt < t2w1l2 && t2w1rwt < t2h1u2 && t2w1rwt < t2h1d2 && t2w1rwt < t2w1rwt2 && t2w1rwt < t2w1lwt2 && t2w1rwt < t2h1uwt2 && t2w1rwt < t2h1dwt2 && ((linwr!=0) && (loutwr!=0) )){	
   if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1rwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1rwt+z))*(z0hd+(vz*t2w1rwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1rwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1rwt+z))*(z0hu+(vz*t2w1rwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1rwt+y;
  xtest=vx*t2w1rwt+x;
  xlimitrwt=-bwrwt*sqrt(1-((vz*t2w1rwt+z)+z0wr)*((vz*t2w1rwt+z)+z0wr)/a2wrwt);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest<=xlimitr && mxrOW > 0){
  i=22;
  }
  else{
  i=34;
  }
  }

													/* neutron interacts with the parabolic right OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxrOW!=-1 && t2w1rwt > 0 && t2w1rwt < t1 && t2w1rwt < t2w1r && t2w1rwt <t2w1l && t2w1rwt < t2h1u && t2w1rwt < t2h1d &&  t2w1rwt <t2w1lwt && t2w1rwt < t2h1uwt && t2w1rwt < t2h1dwt && t2w1rwt < t2w1r1 && t2w1rwt < t2w1l1 && t2w1rwt < t2h1u1 && t2w1rwt < t2h1d1 && t2w1rwt < t2w1rwt1 && t2w1rwt < t2w1lwt1 && t2w1rwt < t2h1uwt1 && t2w1rwt < t2h1dwt1 && t2w1rwt < t2w1r2 && t2w1rwt < t2w1l2 && t2w1rwt < t2h1u2 && t2w1rwt < t2h1d2 && t2w1rwt < t2w1rwt2 && t2w1rwt < t2w1lwt2 && t2w1rwt < t2h1uwt2 && t2w1rwt < t2h1dwt2 && ((loutwr!=0 && linwr==0) || (loutwr==0 && linwr!=0))){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1rwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1rwt+z))*(z0hd+(vz*t2w1rwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1rwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1rwt+z))*(z0hu+(vz*t2w1rwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1rwt+y;
  xtest=vx*t2w1rwt+x;
  xlimitr=-sqrt((pbwrwt-(vz*t2w1rwt+z))/pawrwt);
  if (ytest>ylimitd && ytest<ylimitu && xtest<=xlimitr && mxrOW > 0){
  i=23; 
  }else{
  i=34;}
  }

													/* neutron interacts with the straight right OUTER wall - comments are analog to inner elliptic right wall */

  if (mxrOW!=-1 && t2w1rwt > 0 && t2w1rwt < t1 && t2w1rwt < t2w1r && t2w1rwt <t2w1l && t2w1rwt < t2h1u && t2w1rwt < t2h1d &&  t2w1rwt <t2w1lwt && t2w1rwt < t2h1uwt && t2w1rwt < t2h1dwt && t2w1rwt < t2w1r1 && t2w1rwt < t2w1l1 && t2w1rwt < t2h1u1 && t2w1rwt < t2h1d1 && t2w1rwt < t2w1rwt1 && t2w1rwt < t2w1lwt1 && t2w1rwt < t2h1uwt1 && t2w1rwt < t2h1dwt1 && t2w1rwt < t2w1r2 && t2w1rwt < t2w1l2 && t2w1rwt < t2h1u2 && t2w1rwt < t2h1d2 && t2w1rwt < t2w1rwt2 && t2w1rwt < t2w1lwt2 && t2w1rwt < t2h1uwt2 && t2w1rwt < t2h1dwt2 && (loutwr==0 && linwr==0)){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1rwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1rwt+z))*(z0hd+(vz*t2w1rwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1rwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1rwt+z))*(z0hu+(vz*t2w1rwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1rwt+y; 
  xtest=vx*t2w1rwt+x;
  xlimitr=-(-w2r+w1r)*(vz*t2w1rwt+z)/l-w1rwt;
  if(ytest>=ylimitd && ytest<=ylimitu && xtest<=xlimitr && mxrOW>0){
  i=24;
  }else{
  i=34;
  }
  }

													/* neutron interacts with the elliptic left OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxlOW!=-1 && t2w1lwt > 0 && t2w1lwt < t1 && t2w1lwt < t2w1r && t2w1lwt <t2w1l && t2w1lwt < t2h1u && t2w1lwt < t2h1d &&  t2w1lwt <t2w1rwt && t2w1lwt < t2h1uwt && t2w1lwt < t2h1dwt && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1rwt1 && t2w1lwt < t2w1lwt1 && t2w1lwt < t2h1uwt1 && t2w1lwt < t2h1dwt1 && t2w1lwt < t2w1r2 && t2w1lwt < t2w1l2 && t2w1lwt < t2h1u2 && t2w1lwt < t2h1d2 && t2w1lwt < t2w1rwt2 && t2w1lwt < t2w1lwt2 && t2w1lwt < t2h1uwt2 && t2w1lwt < t2h1dwt2 && ((linwl!=0) && (loutwl!=0) )){
  if(linhd==0 && louthd==0)
   if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1lwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1lwt+z))*(z0hd+(vz*t2w1lwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1lwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1lwt+z))*(z0hu+(vz*t2w1lwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1lwt+y;
  xtest=vx*t2w1lwt+x;
  xlimitlwt=-bwlwt*sqrt(1-((vz*t2w1lwt+z)+z0wl)*((vz*t2w1lwt+z)+z0wl)/a2wlwt);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW>0){
  i=25;
  }else{
  i=35;
  }
  }

													/* neutron interacts with the parabolic left OUTER wall - comments are analog to inner elliptic right wall */

  if (mxlOW!=-1 && t2w1lwt > 0 && t2w1lwt < t1 && t2w1lwt < t2w1r && t2w1lwt <t2w1l && t2w1lwt < t2h1u && t2w1lwt < t2h1d &&  t2w1lwt <t2w1rwt && t2w1lwt < t2h1uwt && t2w1lwt < t2h1dwt && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1rwt1 && t2w1lwt < t2w1lwt1 && t2w1lwt < t2h1uwt1 && t2w1lwt < t2h1dwt1 && t2w1lwt < t2w1r2 && t2w1lwt < t2w1l2 && t2w1lwt < t2h1u2 && t2w1lwt < t2h1d2 && t2w1lwt < t2w1rwt2 && t2w1lwt < t2w1lwt2 && t2w1lwt < t2h1uwt2 && t2w1lwt < t2h1dwt2 && ((loutwl!=0 && linwl==0) || (loutwl==0 && linwl!=0))){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1lwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1lwt+z))*(z0hd+(vz*t2w1lwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1lwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1lwt+z))*(z0hu+(vz*t2w1lwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1lwt+y;
  xtest=vx*t2w1lwt+x;
  xlimitl=-sqrt((pbwlwt-(vz*t2w1lwt+z))/pawlwt);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW>0){
  i=26;
  }else{
  i=35;
  }
  }

														/* neutron interacts with the straight left OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxlOW!=-1 && t2w1lwt > 0 && t2w1lwt < t1 && t2w1lwt < t2w1r && t2w1lwt <t2w1l && t2w1lwt < t2h1u && t2w1lwt < t2h1d &&  t2w1lwt <t2w1rwt && t2w1lwt < t2h1uwt && t2w1lwt < t2h1dwt && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1rwt1 && t2w1lwt < t2w1lwt1 && t2w1lwt < t2h1uwt1 && t2w1lwt < t2h1dwt1 && t2w1lwt < t2w1r2 && t2w1lwt < t2w1l2 && t2w1lwt < t2h1u2 && t2w1lwt < t2h1d2 && t2w1lwt < t2w1rwt2 && t2w1lwt < t2w1lwt2 && t2w1lwt < t2h1uwt2 && t2w1lwt < t2h1dwt2 && (loutwl==0 && linwl==0)){
  if(linhd==0 && louthd==0)
   {
      ylimitd=(-h2d+h1d)/l*(vz*t2w1lwt+z)-h1dwt;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ylimitd=-bhdwt*sqrt(1-((z0hd+(vz*t2w1lwt+z))*(z0hd+(vz*t2w1lwt+z)))/a2hdwt);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt+z)-pbhdwt)/-pahdwt);
      }
   }
   if(linhu==0 && louthu==0)
    {
     ylimitu=(h2u-h1u)/l*(vz*t2w1lwt+z)+h1uwt;
    }else{
     if(linhu!=0 && louthu!=0)
     {
     ylimitu=bhuwt*sqrt(1-((z0hu+(vz*t2w1lwt+z))*(z0hu+(vz*t2w1lwt+z)))/a2huwt);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt+z)-pbhuwt)/-pahuwt);
    }
    }
  ytest=vy*t2w1lwt+y; 
  xtest=vx*t2w1lwt+x;
  xlimitl=(w2l-w1l)*(vz*t2w1lwt+z)/l+w1lwt;
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW>0){
  i=27;
  }else{
  i=35;
  }
  }

															/* neutron interacts with the elliptic top OUTER wall - comments are analog to inner elliptic right wall*/

  if (myuOW!=-1 && t2h1uwt > 0 && t2h1uwt < t1 && t2h1uwt < t2w1r && t2h1uwt < t2w1l && t2h1uwt < t2h1d && t2h1uwt < t2h1u && t2h1uwt < t2w1rwt && t2h1uwt < t2w1lwt && t2h1uwt < t2h1dwt && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1rwt1 && t2h1uwt < t2w1lwt1 && t2h1uwt < t2h1uwt1 && t2h1uwt < t2h1dwt1 && t2h1uwt < t2w1r2 && t2h1uwt < t2w1l2 && t2h1uwt < t2h1u2 && t2h1uwt < t2h1d2 && t2h1uwt < t2w1rwt2 && t2h1uwt < t2w1lwt2 && t2h1uwt < t2h1uwt2 && t2h1uwt < t2h1dwt2 && (louthu !=0 && linhu!=0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1uwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1uwt+z))*(z0wr+(vz*t2h1uwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1uwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1uwt+z))*(z0wl+(vz*t2h1uwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1uwt+x;
  ytest=vy*t2w1lwt+y;
  ylimitu=bhuwt*sqrt(1-((vz*t2h1uwt+z)+z0hu)*((vz*t2h1uwt+z)+z0hu)/a2huwt);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW>0 ){
  i=28;
  }else{
  i=36;
  }
  }
	
															/* neutron interacts with the parabolic top OUTER wall - comments are analog to inner elliptic right wall */

  if (myuOW!=-1 && t2h1uwt > 0 && t2h1uwt < t1 && t2h1uwt < t2w1r && t2h1uwt < t2w1l && t2h1uwt < t2h1d && t2h1uwt < t2h1u && t2h1uwt < t2w1rwt && t2h1uwt < t2w1lwt && t2h1uwt < t2h1dwt && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1rwt1 && t2h1uwt < t2w1lwt1 && t2h1uwt < t2h1uwt1 && t2h1uwt < t2h1dwt1 && t2h1uwt < t2w1r2 && t2h1uwt < t2w1l2 && t2h1uwt < t2h1u2 && t2h1uwt < t2h1d2 && t2h1uwt < t2w1rwt2 && t2h1uwt < t2w1lwt2 && t2h1uwt < t2h1uwt2 && t2h1uwt < t2h1dwt2 && ((louthu!=0 && linhu==0) || (louthu==0 && linhu!=0))){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1uwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1uwt+z))*(z0wr+(vz*t2h1uwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1uwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1uwt+z))*(z0wl+(vz*t2h1uwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1uwt+x;
  ytest=vy*t2w1lwt+y;
  ylimitu=sqrt((pbhuwt-(vz*t2h1uwt+z))/pahuwt);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW>0){
  i=29;
  }else{
  i=36;
  }
  }


															/* neutron interacts with the straight top OUTER wall - comments are analog to inner elliptic right wall*/

  if (myuOW!=-1 && t2h1uwt > 0 && t2h1uwt < t1 && t2h1uwt < t2w1r && t2h1uwt < t2w1l && t2h1uwt < t2h1d && t2h1uwt < t2h1u && t2h1uwt < t2w1rwt && t2h1uwt < t2w1lwt && t2h1uwt < t2h1dwt && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1rwt1 && t2h1uwt < t2w1lwt1 && t2h1uwt < t2h1uwt1 && t2h1uwt < t2h1dwt1 && t2h1uwt < t2w1r2 && t2h1uwt < t2w1l2 && t2h1uwt < t2h1u2 && t2h1uwt < t2h1d2 && t2h1uwt < t2w1rwt2 && t2h1uwt < t2w1lwt2 && t2h1uwt < t2h1uwt2 && t2h1uwt < t2h1dwt2 && (louthu == 0 && linhu == 0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1uwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1uwt+z))*(z0wr+(vz*t2h1uwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1uwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1uwt+z))*(z0wl+(vz*t2h1uwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1uwt+x;
  ytest=vy*t2w1lwt+y;
  ylimitu=(h2u-h1u)*(vz*t2h1uwt+z)/l+h1uwt;
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW>0 ){
  i=30;
  }else{
  i=36;
  }
  }

															/* neutron interacts with the elliptic down OUTER wall - comments are analog to inner elliptic right wall*/

  if (mydOW!=-1 && t2h1dwt > 0 && t2h1dwt < t1 && t2h1dwt < t2w1r && t2h1dwt < t2w1l && t2h1dwt < t2h1u  && t2h1dwt < t2h1d && t2h1dwt < t2w1rwt && t2h1dwt < t2w1lwt && t2h1dwt < t2h1uwt  && t2h1dwt < t2w1r1 && t2h1dwt < t2w1l1 && t2h1dwt < t2h1u1 && t2h1dwt < t2h1d1 && t2h1dwt < t2w1rwt1 && t2h1dwt < t2w1lwt1 && t2h1dwt < t2h1uwt1 && t2h1dwt < t2h1dwt1 && t2h1dwt < t2w1r2 && t2h1dwt < t2w1l2 && t2h1dwt < t2h1u2 && t2h1dwt < t2h1d2 && t2h1dwt < t2w1rwt2 && t2h1dwt < t2w1lwt2 && t2h1dwt < t2h1uwt2 && t2h1dwt < t2h1dwt2 && (louthd !=0 && linhd!=0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1dwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1dwt+z))*(z0wr+(vz*t2h1dwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1dwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1dwt+z))*(z0wl+(vz*t2h1dwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1dwt+x;
  ytest=vy*t2w1lwt+y;
  ylimitd=-bhdwt*sqrt(1-((vz*t2h1dwt+z)+z0hd)*((vz*t2h1dwt+z)+z0hd)/a2hdwt);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW>0){
  i=31;
  }else{
  i=37;
  }
  }

															/* neutron interacts with the parabolic down OUTER wall - comments are analog to inner elliptic right wall */

  if (mydOW!=-1 && t2h1dwt > 0 && t2h1dwt < t1 && t2h1dwt < t2w1r && t2h1dwt < t2w1l && t2h1dwt < t2h1u  && t2h1dwt < t2h1d && t2h1dwt < t2w1rwt && t2h1dwt < t2w1lwt && t2h1dwt < t2h1uwt  && t2h1dwt < t2w1r1 && t2h1dwt < t2w1l1 && t2h1dwt < t2h1u1 && t2h1dwt < t2h1d1 && t2h1dwt < t2w1rwt1 && t2h1dwt < t2w1lwt1 && t2h1dwt < t2h1uwt1 && t2h1dwt < t2h1dwt1 && t2h1dwt < t2w1r2 && t2h1dwt < t2w1l2 && t2h1dwt < t2h1u2 && t2h1dwt < t2h1d2 && t2h1dwt < t2w1rwt2 && t2h1dwt < t2w1lwt2 && t2h1dwt < t2h1uwt2 && t2h1dwt < t2h1dwt2 && ((louthd !=0 && linhd==0) || (louthd ==0 && linhd!=0))){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1dwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1dwt+z))*(z0wr+(vz*t2h1dwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
     xlimitl=(w2l-w1l)/l*(vz*t2h1dwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1dwt+z))*(z0wl+(vz*t2h1dwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1dwt+x;
  ytest=vy*t2w1lwt+y;
  ylimitd=-sqrt((pbhdwt-(vz*t2h1dwt+z))/pahdwt);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW>0 ){
  i=32;
  }else{
  i=37;
  }
  }

															/* neutron interacts with the straight down OUTER wall - comments are analog to inner elliptic right wall*/

  if (mydOW!=-1 && t2h1dwt > 0 && t2h1dwt < t1 && t2h1dwt < t2w1r && t2h1dwt < t2w1l && t2h1dwt < t2h1u  && t2h1dwt < t2h1d && t2h1dwt < t2w1rwt && t2h1dwt < t2w1lwt && t2h1dwt < t2h1uwt  && t2h1dwt < t2w1r1 && t2h1dwt < t2w1l1 && t2h1dwt < t2h1u1 && t2h1dwt < t2h1d1 && t2h1dwt < t2w1rwt1 && t2h1dwt < t2w1lwt1 && t2h1dwt < t2h1uwt1 && t2h1dwt < t2h1dwt1 && t2h1dwt < t2w1r2 && t2h1dwt < t2w1l2 && t2h1dwt < t2h1u2 && t2h1dwt < t2h1d2 && t2h1dwt < t2w1rwt2 && t2h1dwt < t2w1lwt2 && t2h1dwt < t2h1uwt2 && t2h1dwt < t2h1dwt2 && (louthd == 0 && linhd == 0)){
  if(linwr==0 && loutwr==0)
  {
    xlimitr=(-w2r+w1r)/l*(vz*t2h1dwt+z)-w1rwt;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xlimitr=-bwrwt*sqrt(1-((z0wr+(vz*t2h1dwt+z))*(z0wr+(vz*t2h1dwt+z)))/a2wrwt);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt+z)-pbwrwt)/-pawrwt);
    }
  }
  if(linwl==0 && loutwl == 0)
   {
      xlimitl=(w2l-w1l)/l*(vz*t2h1dwt+z)+w1lwt;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xlimitl=bwlwt*sqrt(1-((z0wl+(vz*t2h1dwt+z))*(z0wl+(vz*t2h1dwt+z)))/a2wlwt);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt+z)-pbwlwt)/-pawlwt);
      }
   }
  xtest=vx*t2h1dwt+x;
  ytest=vy*t2w1lwt+y;
  ylimitd=(-h2d+h1d)*(vz*t2h1dwt+z)/l-h1dwt;
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW>0 ){
  i=33;
  }else{
  i=37;
  }
  }

   /* SAME INTERACTIONS BUT TRANSPERENT OUTER WALLS */

  if (mxrOW==-1 && t2w1rwt > 0 && t2w1rwt < t1 && t2w1rwt < t2w1r && t2w1rwt <t2w1l && t2w1rwt < t2h1u && t2w1rwt < t2h1d &&  t2w1rwt <t2w1lwt && t2w1rwt < t2h1uwt && t2w1rwt < t2h1dwt && t2w1rwt < t2w1r1 && t2w1rwt < t2w1l1 && t2w1rwt < t2h1u1 && t2w1rwt < t2h1d1 && t2w1rwt < t2w1rwt1 && t2w1rwt < t2w1lwt1 && t2w1rwt < t2h1uwt1 && t2w1rwt < t2h1dwt1 &&t2w1rwt < t2w1r2 && t2w1rwt < t2w1l2 && t2w1rwt < t2h1u2 && t2w1rwt < t2h1d2 && t2w1rwt < t2w1rwt2 && t2w1rwt < t2w1lwt2 && t2w1rwt < t2h1uwt2 && t2w1rwt < t2h1dwt2 && ((linwr!=0) && (loutwr!=0) )) {
  i=38;
  }

  if (mxrOW==-1 && t2w1rwt > 0 && t2w1rwt < t1 && t2w1rwt < t2w1r && t2w1rwt <t2w1l && t2w1rwt < t2h1u && t2w1rwt < t2h1d &&  t2w1rwt <t2w1lwt && t2w1rwt < t2h1uwt && t2w1rwt < t2h1dwt && t2w1rwt < t2w1r1 && t2w1rwt < t2w1l1 && t2w1rwt < t2h1u1 && t2w1rwt < t2h1d1 && t2w1rwt < t2w1rwt1 && t2w1rwt < t2w1lwt1 && t2w1rwt < t2h1uwt1 && t2w1rwt < t2h1dwt1 && t2w1rwt < t2w1r2 && t2w1rwt < t2w1l2 && t2w1rwt < t2h1u2 && t2w1rwt < t2h1d2 && t2w1rwt < t2w1rwt2 && t2w1rwt < t2w1lwt2 && t2w1rwt < t2h1uwt2 && t2w1rwt < t2h1dwt2 && ((loutwr!=0 && linwr==0) || (loutwr==0 && linwr!=0))){
  i=38;
  }

  if (mxrOW==-1 && t2w1rwt > 0 && t2w1rwt < t1 && t2w1rwt < t2w1r && t2w1rwt <t2w1l && t2w1rwt < t2h1u && t2w1rwt < t2h1d &&  t2w1rwt <t2w1lwt && t2w1rwt < t2h1uwt && t2w1rwt < t2h1dwt && t2w1rwt < t2w1r1 && t2w1rwt < t2w1l1 && t2w1rwt < t2h1u1 && t2w1rwt < t2h1d1 && t2w1rwt < t2w1rwt1 && t2w1rwt < t2w1lwt1 && t2w1rwt < t2h1uwt1 && t2w1rwt < t2h1dwt1 && t2w1rwt < t2w1r2 && t2w1rwt < t2w1l2 && t2w1rwt < t2h1u2 && t2w1rwt < t2h1d2 && t2w1rwt < t2w1rwt2 && t2w1rwt < t2w1lwt2 && t2w1rwt < t2h1uwt2 && t2w1rwt < t2h1dwt2 && (loutwr==0 && linwr==0)){
  i=38;
  }

  if (mxlOW==-1 && t2w1lwt > 0 && t2w1lwt < t1 && t2w1lwt <t2w1r && t2w1lwt < t2w1l && t2w1lwt < t2h1u && t2w1lwt < t2h1d &&  t2w1lwt < t2w1rwt && t2w1lwt < t2h1uwt && t2w1lwt < t2h1dwt && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1rwt1 && t2w1lwt < t2w1lwt1 && t2w1lwt < t2h1uwt1 && t2w1lwt < t2h1dwt1 && t2w1lwt < t2w1r2 && t2w1lwt < t2w1l2 && t2w1lwt < t2h1u2 && t2w1lwt < t2h1d2 && t2w1lwt < t2w1rwt2 && t2w1lwt < t2w1lwt2 && t2w1lwt < t2h1uwt2 && t2w1lwt < t2h1dwt2 && ((linwl!=0) && (loutwl!=0) )){
  i=39;
  }

  if (mxlOW==-1 && t2w1lwt > 0 && t2w1lwt < t1 && t2w1lwt <t2w1r && t2w1lwt < t2w1l && t2w1lwt < t2h1u && t2w1lwt < t2h1d &&  t2w1lwt < t2w1rwt && t2w1lwt < t2h1uwt && t2w1lwt < t2h1dwt && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1rwt1 && t2w1lwt < t2w1lwt1 && t2w1lwt < t2h1uwt1 && t2w1lwt < t2h1dwt1 && t2w1lwt < t2w1r2 && t2w1lwt < t2w1l2 && t2w1lwt < t2h1u2 && t2w1lwt < t2h1d2 && t2w1lwt < t2w1rwt2 && t2w1lwt < t2w1lwt2 && t2w1lwt < t2h1uwt2 && t2w1lwt < t2h1dwt2 && ((loutwl!=0 && linwl==0) || (loutwl==0 && linwl!=0))){
  i=39;
  }

  if (mxlOW==-1 && t2w1lwt > 0 && t2w1lwt < t1 && t2w1lwt <t2w1r && t2w1lwt < t2w1l && t2w1lwt < t2h1u && t2w1lwt < t2h1d &&  t2w1lwt < t2w1rwt && t2w1lwt < t2h1uwt && t2w1lwt < t2h1dwt && t2w1lwt < t2w1r1 && t2w1lwt < t2w1l1 && t2w1lwt < t2h1u1 && t2w1lwt < t2h1d1 && t2w1lwt < t2w1rwt1 && t2w1lwt < t2w1lwt1 && t2w1lwt < t2h1uwt1 && t2w1lwt < t2h1dwt1 && t2w1lwt < t2w1r2 && t2w1lwt < t2w1l2 && t2w1lwt < t2h1u2 && t2w1lwt < t2h1d2 && t2w1lwt < t2w1rwt2 && t2w1lwt < t2w1lwt2 && t2w1lwt < t2h1uwt2 && t2w1lwt < t2h1dwt2 && (loutwl==0 && linwl==0)){
  i=39;
  }

  if (myuOW==-1 && t2h1uwt > 0 && t2h1uwt < t1 && t2h1uwt < t2w1r && t2h1uwt < t2w1l && t2h1uwt < t2h1d && t2h1uwt < t2h1u && t2h1uwt < t2w1rwt && t2h1uwt < t2w1lwt && t2h1uwt < t2h1dwt && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1rwt1 && t2h1uwt < t2w1lwt1 && t2h1uwt < t2h1uwt1 && t2h1uwt < t2h1dwt1 && t2h1uwt < t2w1r2 && t2h1uwt < t2w1l2 && t2h1uwt < t2h1u2 && t2h1uwt < t2h1d2 && t2h1uwt < t2w1rwt2 && t2h1uwt < t2w1lwt2 && t2h1uwt < t2h1uwt2 && t2h1uwt < t2h1dwt2 && (louthu !=0 && linhu!=0)){
  i=40;
  }

  if (myuOW==-1 && t2h1uwt > 0 && t2h1uwt < t1 && t2h1uwt < t2w1r && t2h1uwt < t2w1l && t2h1uwt < t2h1d && t2h1uwt < t2h1u && t2h1uwt < t2w1rwt && t2h1uwt < t2w1lwt && t2h1uwt < t2h1dwt && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1rwt1 && t2h1uwt < t2w1lwt1 && t2h1uwt < t2h1uwt1 && t2h1uwt < t2h1dwt1 && t2h1uwt < t2w1r2 && t2h1uwt < t2w1l2 && t2h1uwt < t2h1u2 && t2h1uwt < t2h1d2 && t2h1uwt < t2w1rwt2 && t2h1uwt < t2w1lwt2 && t2h1uwt < t2h1uwt2 && t2h1uwt < t2h1dwt2 && ((louthu!=0 && linhu==0) || (louthu==0 && linhu!=0))){
  i=40;
  }

  if (myuOW==-1 && t2h1uwt > 0 && t2h1uwt < t1 && t2h1uwt < t2w1r && t2h1uwt < t2w1l && t2h1uwt < t2h1d && t2h1uwt < t2h1u && t2h1uwt < t2w1rwt && t2h1uwt < t2w1lwt && t2h1uwt < t2h1dwt && t2h1uwt < t2w1r1 && t2h1uwt < t2w1l1 && t2h1uwt < t2h1u1 && t2h1uwt < t2h1d1 && t2h1uwt < t2w1rwt1 && t2h1uwt < t2w1lwt1 && t2h1uwt < t2h1uwt1 && t2h1uwt < t2h1dwt1 && t2h1uwt < t2w1r2 && t2h1uwt < t2w1l2 && t2h1uwt < t2h1u2 && t2h1uwt < t2h1d2 && t2h1uwt < t2w1rwt2 && t2h1uwt < t2w1lwt2 && t2h1uwt < t2h1uwt2 && t2h1uwt < t2h1dwt2 && (louthu == 0 && linhu == 0)){
  i=40;
  }

  if (mydOW==-1 && t2h1dwt > 0 && t2h1dwt < t1 && t2h1dwt < t2w1r && t2h1dwt < t2w1l && t2h1dwt < t2h1u  && t2h1dwt < t2h1d && t2h1dwt < t2w1rwt && t2h1dwt < t2w1lwt && t2h1dwt < t2h1uwt  && t2h1dwt < t2w1r1 && t2h1dwt < t2w1l1 && t2h1dwt < t2h1u1 && t2h1dwt < t2h1d1 && t2h1dwt < t2w1rwt1 && t2h1dwt < t2w1lwt1 && t2h1dwt < t2h1uwt1 && t2h1dwt < t2h1dwt1 && t2h1dwt < t2w1r2 && t2h1dwt < t2w1l2 && t2h1dwt < t2h1u2 && t2h1dwt < t2h1d2 && t2h1dwt < t2w1rwt2 && t2h1dwt < t2w1lwt2 && t2h1dwt < t2h1uwt2 && t2h1dwt < t2h1dwt2 && (louthd !=0 && linhd!=0)){
  i=41;
  }

  if (mydOW==-1 && t2h1dwt > 0 && t2h1dwt < t1 && t2h1dwt < t2w1r && t2h1dwt < t2w1l && t2h1dwt < t2h1u  && t2h1dwt < t2h1d && t2h1dwt < t2w1rwt && t2h1dwt < t2w1lwt && t2h1dwt < t2h1uwt  && t2h1dwt < t2w1r1 && t2h1dwt < t2w1l1 && t2h1dwt < t2h1u1 && t2h1dwt < t2h1d1 && t2h1dwt < t2w1rwt1 && t2h1dwt < t2w1lwt1 && t2h1dwt < t2h1uwt1 && t2h1dwt < t2h1dwt1 && t2h1dwt < t2w1r2 && t2h1dwt < t2w1l2 && t2h1dwt < t2h1u2 && t2h1dwt < t2h1d2 && t2h1dwt < t2w1rwt2 && t2h1dwt < t2w1lwt2 && t2h1dwt < t2h1uwt2 && t2h1dwt < t2h1dwt2 &&  ((louthd !=0 && linhd==0) || (louthd ==0 && linhd!=0))){
  i=41;
  }

  if (mydOW==-1 && t2h1dwt > 0 && t2h1dwt < t1 && t2h1dwt < t2w1r && t2h1dwt < t2w1l && t2h1dwt < t2h1u  && t2h1dwt < t2h1d && t2h1dwt < t2w1rwt && t2h1dwt < t2w1lwt && t2h1dwt < t2h1uwt  && t2h1dwt < t2w1r1 && t2h1dwt < t2w1l1 && t2h1dwt < t2h1u1 && t2h1dwt < t2h1d1 && t2h1dwt < t2w1rwt1 && t2h1dwt < t2w1lwt1 && t2h1dwt < t2h1uwt1 && t2h1dwt < t2h1dwt1 && t2h1dwt < t2w1r2 && t2h1dwt < t2w1l2 && t2h1dwt < t2h1u2 && t2h1dwt < t2h1d2 && t2h1dwt < t2w1rwt2 && t2h1dwt < t2w1lwt2 && t2h1dwt < t2h1uwt2 && t2h1dwt < t2h1dwt2 &&  (louthd == 0 && linhd == 0)){
  i=41;
  }


													/* FIRST SHELL */



if (mxr1!=-1 && t2w1r1 > 0 && t2w1r1 < t1 && t2w1r1 < t2w1r && t2w1r1<t2w1l && t2w1r1 < t2h1u && t2w1r1 < t2h1d && t2w1r1 < t2w1rwt && t2w1r1 < t2w1lwt && t2w1r1 < t2h1uwt && t2w1r1 < t2h1dwt && t2w1r1 < t2w1l1 && t2w1r1 < t2h1u1 && t2w1r1 < t2h1d1 && t2w1r1 < t2w1rwt1 && t2w1r1 < t2w1lwt1 && t2w1r1 < t2h1uwt1 && t2w1r1 < t2h1dwt1 && t2w1r1 < t2w1r2 && t2w1r1<t2w1l2 && t2w1r1 < t2h1u2 && t2w1r1 < t2h1d2 && t2w1r1 < t2w1rwt2 && t2w1r1 < t2w1lwt2 && t2w1r1 < t2h1uwt2 && t2w1r1 < t2h1dwt2 && ((linwr1!=0) && (loutwr1!=0) )) {
   if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1r1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1r1+z))*(z0hd1+(vz*t2w1r1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1r1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1r1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1r1+z))*(z0hu1+(vz*t2w1r1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1r1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1r1+y;
  xlimitr=bwr1*sqrt(1-((vz*t2w1r1+z)+z0wr1)*((vz*t2w1r1+z)+z0wr1)/a2wr1);
  xtest=vx*t2w1r1+x;
  if (ytest>=ylimitd && ytest<=ylimitu && x>=-xlimitr && mxr1 > 0){
  i=42;
  }else{
  i=54;
  }
  }

  if (mxr1!=-1 && t2w1r1 > 0 && t2w1r1 < t1 && t2w1r1 < t2w1r && t2w1r1<t2w1l && t2w1r1 < t2h1u && t2w1r1 < t2h1d && t2w1r1 < t2w1rwt && t2w1r1 < t2w1lwt && t2w1r1 < t2h1uwt && t2w1r1 < t2h1dwt && t2w1r1 < t2w1l1 && t2w1r1 < t2h1u1 && t2w1r1 < t2h1d1 && t2w1r1 < t2w1rwt1 && t2w1r1 < t2w1lwt1 && t2w1r1 < t2h1uwt1 && t2w1r1 < t2h1dwt1 && t2w1r1 < t2w1r2 && t2w1r1<t2w1l2 && t2w1r1 < t2h1u2 && t2w1r1 < t2h1d2 && t2w1r1 < t2w1rwt2 && t2w1r1 < t2w1lwt2 && t2w1r1 < t2h1uwt2 && t2w1r1 < t2h1dwt2 && ((loutwr1!=0 && linwr1==0) || (loutwr1==0 && linwr1!=0))){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1r1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1r1+z))*(z0hd1+(vz*t2w1r1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1r1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1r1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1r1+z))*(z0hu1+(vz*t2w1r1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1r1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1r1+y;
  xtest=vx*t2w1r1+x;
  xlimitr=-sqrt(pbwr1-(vz*t2w1r1+z)/pawr1);
  if (ytest>ylimitd && ytest<ylimitu && x>=xlimitr && mxr1 > 0){
  i=43;
  }else{
  i=54;}
  }

  if (mxr1!=-1 && t2w1r1 > 0 && t2w1r1 < t1 && t2w1r1 < t2w1r && t2w1r1<t2w1l && t2w1r1 < t2h1u && t2w1r1 < t2h1d && t2w1r1 < t2w1rwt && t2w1r1 < t2w1lwt && t2w1r1 < t2h1uwt && t2w1r1 < t2h1dwt && t2w1r1 < t2w1l1 && t2w1r1 < t2h1u1 && t2w1r1 < t2h1d1 && t2w1r1 < t2w1rwt1 && t2w1r1 < t2w1lwt1 && t2w1r1 < t2h1uwt1 && t2w1r1 < t2h1dwt1 && t2w1r1 < t2w1r2 && t2w1r1<t2w1l2 && t2w1r1 < t2h1u2 && t2w1r1 < t2h1d2 && t2w1r1 < t2w1rwt2 && t2w1r1 < t2w1lwt2 && t2w1r1 < t2h1uwt2 && t2w1r1 < t2h1dwt2 && (loutwr1==0 && linwr1==0)){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1r1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1r1+z))*(z0hd1+(vz*t2w1r1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1r1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1r1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1r1+z))*(z0hu1+(vz*t2w1r1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1r1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1r1+y;
  xtest=vx*t2w1r1+x;
  xlimitr=-(w2r1+w1r1)*(vz*t2w1r1+z)/l-w1r1;
  if (ytest>=ylimitd && ytest<=ylimitu && x>=xlimitr && mxr1>0){
  i=44;
  }else{
  i=54;
  }
  }

  if (mxl1!=-1 && t2w1l1 > 0 && t2w1l1 < t1 && t2w1l1 < t2w1r && t2w1l1 < t2w1l && t2w1l1 < t2h1u && t2w1l1 < t2h1d && t2w1l1 < t2w1lwt && t2w1l1<t2w1rwt && t2w1l1 < t2h1uwt && t2w1l1 < t2h1dwt && t2w1l1 < t2w1r1 && t2w1l1 < t2h1u1 && t2w1l1 < t2h1d1 && t2w1l1 < t2w1rwt1 && t2w1l1<t2w1lwt1 && t2w1l1 < t2h1uwt1 && t2w1l1 < t2h1dwt1 && t2w1l1 < t2w1r2 && t2w1l1 < t2w1l2 && t2w1l1 < t2h1u2 && t2w1l1 < t2h1d2 && t2w1l1 < t2w1lwt2 && t2w1l1<t2w1rwt2 && t2w1l1 < t2h1uwt2 && t2w1l1 < t2h1dwt2 && ((linwl1!=0) && (loutwl1!=0) )){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1l1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1l1+z))*(z0hd1+(vz*t2w1l1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1l1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1l1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1l1+z))*(z0hu1+(vz*t2w1l1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1l1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1l1+y;
  xlimitl=bwl1*sqrt(1-((vz*t2w1l1+z)+z0wl1)*((vz*t2w1l1+z)+z0wl1)/a2wl1);
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl1>0){
  i=45;
  }else{
  i=55;
  }
  }

  if (mxl1!=-1 && t2w1l1 > 0 && t2w1l1 < t1 && t2w1l1 < t2w1r && t2w1l1 < t2w1l && t2w1l1 < t2h1u && t2w1l1 < t2h1d && t2w1l1 < t2w1lwt && t2w1l1<t2w1rwt && t2w1l1 < t2h1uwt && t2w1l1 < t2h1dwt && t2w1l1 < t2w1r1 && t2w1l1 < t2h1u1 && t2w1l1 < t2h1d1 && t2w1l1 < t2w1rwt1 && t2w1l1<t2w1lwt1 && t2w1l1 < t2h1uwt1 && t2w1l1 < t2h1dwt1 && t2w1l1 < t2w1r2 && t2w1l1 < t2w1l2 && t2w1l1 < t2h1u2 && t2w1l1 < t2h1d2 && t2w1l1 < t2w1lwt2 && t2w1l1<t2w1rwt2 && t2w1l1 < t2h1uwt2 && t2w1l1 < t2h1dwt2 && ((loutwl1!=0 && linwl1==0) || (loutwl1==0 && linwl1!=0))){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1l1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1l1+z))*(z0hd1+(vz*t2w1l1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1l1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1l1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1l1+z))*(z0hu1+(vz*t2w1l1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1l1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1l1+y;
  xlimitl=sqrt(pbwl1-(vz*t2w1l1+z)/pawl1);
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl1>0){
  i=46;
  }else{
  i=55;
  }
  }

  if (mxl1!=-1 && t2w1l1 > 0 && t2w1l1 < t1 && t2w1l1 < t2w1r && t2w1l1 < t2w1l && t2w1l1 < t2h1u && t2w1l1 < t2h1d && t2w1l1 < t2w1lwt && t2w1l1<t2w1rwt && t2w1l1 < t2h1uwt && t2w1l1 < t2h1dwt && t2w1l1 < t2w1r1 && t2w1l1 < t2h1u1 && t2w1l1 < t2h1d1 && t2w1l1 < t2w1rwt1 && t2w1l1<t2w1lwt1 && t2w1l1 < t2h1uwt1 && t2w1l1 < t2h1dwt1 && t2w1l1 < t2w1r2 && t2w1l1 < t2w1l2 && t2w1l1 < t2h1u2 && t2w1l1 < t2h1d2 && t2w1l1 < t2w1lwt2 && t2w1l1<t2w1rwt2 && t2w1l1 < t2h1uwt2 && t2w1l1 < t2h1dwt2 && (loutwl1==0 && linwl1==0)){
   if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1l1+z)-h1d1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhd1*sqrt(1-((z0hd1+(vz*t2w1l1+z))*(z0hd1+(vz*t2w1l1+z)))/a2hd1);
      }else{
      ylimitd=-sqrt(((vz*t2w1l1+z)-pbhd1)/-pahd1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1l1+z)+h1u1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhu1*sqrt(1-((z0hu1+(vz*t2w1l1+z))*(z0hu1+(vz*t2w1l1+z)))/a2hu1);
     }else{
     ylimitu=sqrt(((vz*t2w1l1+z)-pbhu1)/-pahu1);
    }
    }
  ytest=vy*t2w1l1+y;
  xlimitl=(w2l1-w1l1)*(vz*t2w1l1+z)/l+w1l1;
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl1>0){
  i=47;
  }else{
  i=55;
  }
  }

  if (myu1!=-1 && t2h1u1 > 0 && t2h1u1 < t1 && t2h1u1 < t2w1r && t2h1u1 < t2w1l && t2h1u1 < t2h1u && t2h1u1 < t2h1d && t2h1u1 < t2h1uwt && t2h1u1 < t2w1rwt && t2h1u1 < t2w1lwt && t2h1u1 < t2h1dwt && t2h1u1 < t2w1r1 && t2h1u1 < t2w1l1  && t2h1u1 < t2h1d1 && t2h1u1 < t2h1uwt1 && t2h1u1 < t2w1rwt1 && t2h1u1 < t2w1lwt1 && t2h1u1 < t2h1dwt1 && t2h1u1 < t2w1r2 && t2h1u1 < t2w1l2 && t2h1u1 < t2h1u2 && t2h1u1 < t2h1d2 && t2h1u1 < t2h1uwt2 && t2h1u1 < t2w1rwt2 && t2h1u1 < t2w1lwt2 && t2h1u1 < t2h1dwt2 && (louthu1 !=0 && linhu1!=0)){
 if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1u1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1u1+z))*(z0wr1+(vz*t2h1u1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1u1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1u1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1u1+z))*(z0wl1+(vz*t2h1u1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1u1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1u1+x;
  ylimitu=bhu1*sqrt(1-((vz*t2h1u1+z)+z0hu1)*((vz*t2h1u1+z)+z0hu1)/a2hu1);
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu1>0 ){
  i=48;
  }else{
  i=56;
  }
  }


  if (myu1!=-1 && t2h1u1 > 0 && t2h1u1 < t1 && t2h1u1 < t2w1r && t2h1u1 < t2w1l && t2h1u1 < t2h1u && t2h1u1 < t2h1d && t2h1u1 < t2h1uwt && t2h1u1 < t2w1rwt && t2h1u1 < t2w1lwt && t2h1u1 < t2h1dwt && t2h1u1 < t2w1r1 && t2h1u1 < t2w1l1  && t2h1u1 < t2h1d1 && t2h1u1 < t2h1uwt1 && t2h1u1 < t2w1rwt1 && t2h1u1 < t2w1lwt1 && t2h1u1 < t2h1dwt1 && t2h1u1 < t2w1r2 && t2h1u1 < t2w1l2 && t2h1u1 < t2h1u2 && t2h1u1 < t2h1d2 && t2h1u1 < t2h1uwt2 && t2h1u1 < t2w1rwt2 && t2h1u1 < t2w1lwt2 && t2h1u1 < t2h1dwt2 && ((louthu1!=0 && linhu1==0) || (louthu1==0 && linhu1!=0))){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1u1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1u1+z))*(z0wr1+(vz*t2h1u1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1u1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1u1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1u1+z))*(z0wl1+(vz*t2h1u1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1u1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1u1+x;
  ylimitu=sqrt(pbhu1-(vz*t2h1u1+z)/pahu1);
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu1>0){
  i=49;
  }else{
  i=56;
  }
  }

  if (myu1!=-1 && t2h1u1 > 0 && t2h1u1 < t1 && t2h1u1 < t2w1r && t2h1u1 < t2w1l && t2h1u1 < t2h1u && t2h1u1 < t2h1d && t2h1u1 < t2h1uwt && t2h1u1 < t2w1rwt && t2h1u1 < t2w1lwt && t2h1u1 < t2h1dwt && t2h1u1 < t2w1r1 && t2h1u1 < t2w1l1  && t2h1u1 < t2h1d1 && t2h1u1 < t2h1uwt1 && t2h1u1 < t2w1rwt1 && t2h1u1 < t2w1lwt1 && t2h1u1 < t2h1dwt1 && t2h1u1 < t2w1r2 && t2h1u1 < t2w1l2 && t2h1u1 < t2h1u2 && t2h1u1 < t2h1d2 && t2h1u1 < t2h1uwt2 && t2h1u1 < t2w1rwt2 && t2h1u1 < t2w1lwt2 && t2h1u1 < t2h1dwt2 && (louthu1 == 0 && linhu1 == 0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1u1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1u1+z))*(z0wr1+(vz*t2h1u1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1u1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1u1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1u1+z))*(z0wl1+(vz*t2h1u1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1u1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1u1+x;
  ylimitu=(h2u1-h1u1)*(vz*t2h1u1+z)/l+h1u1;
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu1>0 ){
  i=50;
  }else{
  i=56;
  }
  }

  if (myd1!=-1 && t2h1d1 > 0 && t2h1d1 < t1 && t2h1d1 < t2w1r && t2h1d1 < t2w1l && t2h1d1 < t2h1u && t2h1d1 < t2h1d && t2h1d1 < t2h1dwt && t2h1d1 < t2w1rwt && t2h1d1 < t2w1lwt && t2h1d1 < t2h1uwt && t2h1d1 < t2w1r1 && t2h1d1 < t2w1l1 && t2h1d1 < t2h1u1 && t2h1d1 < t2h1dwt1 && t2h1d1 < t2w1rwt1 && t2h1d1 < t2w1lwt1 && t2h1d1 < t2h1uwt1 && t2h1d1 < t2w1r2 && t2h1d1 < t2w1l2 && t2h1d1 < t2h1u2 && t2h1d1 < t2h1d2 && t2h1d1 < t2h1dwt2 && t2h1d1 < t2w1rwt2 && t2h1d1 < t2w1lwt2 && t2h1d1 < t2h1uwt2 && (louthd1 !=0 && linhd1!=0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1d1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1d1+z))*(z0wr1+(vz*t2h1d1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1d1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1d1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1d1+z))*(z0wl1+(vz*t2h1d1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1d1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1d1+x;
  ylimitd=-bhd1*sqrt(1-((vz*t2h1d1+z)+z0hd1)*((vz*t2h1d1+z)+z0hd1)/a2hd1);
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd1>0){
  i=51;
  }else{
  i=57;
  }
  }

  if (myd1!=-1 && t2h1d1 > 0 && t2h1d1 < t1 && t2h1d1 < t2w1r && t2h1d1 < t2w1l && t2h1d1 < t2h1u && t2h1d1 < t2h1d && t2h1d1 < t2h1dwt && t2h1d1 < t2w1rwt && t2h1d1 < t2w1lwt && t2h1d1 < t2h1uwt && t2h1d1 < t2w1r1 && t2h1d1 < t2w1l1 && t2h1d1 < t2h1u1 && t2h1d1 < t2h1dwt1 && t2h1d1 < t2w1rwt1 && t2h1d1 < t2w1lwt1 && t2h1d1 < t2h1uwt1 && t2h1d1 < t2w1r2 && t2h1d1 < t2w1l2 && t2h1d1 < t2h1u2 && t2h1d1 < t2h1d2 && t2h1d1 < t2h1dwt2 && t2h1d1 < t2w1rwt2 && t2h1d1 < t2w1lwt2 && t2h1d1 < t2h1uwt2 && ((louthd1 !=0 && linhd1==0) || (louthd1 ==0 && linhd1!=0))){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1d1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1d1+z))*(z0wr1+(vz*t2h1d1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1d1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1d1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1d1+z))*(z0wl1+(vz*t2h1d1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1d1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1d1+x;
  ylimitd=-sqrt(pbhd1-(vz*t2h1d1+z)/pahd1);
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd1>0 ){
  i=52;
  }else{
  i=57;
  }
  }

  if (myd1!=-1 && t2h1d1 > 0 && t2h1d1 < t1 && t2h1d1 < t2w1r && t2h1d1 < t2w1l && t2h1d1 < t2h1u && t2h1d1 < t2h1d && t2h1d1 < t2h1dwt && t2h1d1 < t2w1rwt && t2h1d1 < t2w1lwt && t2h1d1 < t2h1uwt && t2h1d1 < t2w1r1 && t2h1d1 < t2w1l1 && t2h1d1 < t2h1u1 && t2h1d1 < t2h1dwt1 && t2h1d1 < t2w1rwt1 && t2h1d1 < t2w1lwt1 && t2h1d1 < t2h1uwt1 && t2h1d1 < t2w1r2 && t2h1d1 < t2w1l2 && t2h1d1 < t2h1u2 && t2h1d1 < t2h1d2 && t2h1d1 < t2h1dwt2 && t2h1d1 < t2w1rwt2 && t2h1d1 < t2w1lwt2 && t2h1d1 < t2h1uwt2 && (louthd1 == 0 && linhd1 == 0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1d1+z)-w1r1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwr1*sqrt(1-((z0wr1+(vz*t2h1d1+z))*(z0wr1+(vz*t2h1d1+z)))/a2wr1);
    }else{
    xlimitr=-sqrt(((vz*t2h1d1+z)-pbwr1)/-pawr1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1d1+z)+w1l1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwl1*sqrt(1-((z0wl1+(vz*t2h1d1+z))*(z0wl1+(vz*t2h1d1+z)))/a2wl1);
      }else{
      xlimitl=sqrt(((vz*t2h1d1+z)-pbwl1)/-pawl1);
      }
   }
  xtest=vx*t2h1d1+x;
  ylimitd=(-h2d1+h1d1)*(vz*t2h1d1+z)/l-h1d1;
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd1>0 ){
  i=53;
  }else{
  i=57;
  }
  }

if (mxr1==-1 && t2w1r1 > 0 && t2w1r1 < t1 && t2w1r1 < t2w1r && t2w1r1<t2w1l && t2w1r1 < t2h1u && t2w1r1 < t2h1d && t2w1r1 < t2w1rwt && t2w1r1 < t2w1lwt && t2w1r1 < t2h1uwt && t2w1r1 < t2h1dwt && t2w1r1 < t2w1l1 && t2w1r1 < t2h1u1 && t2w1r1 < t2h1d1 && t2w1r1 < t2w1rwt1 && t2w1r1 < t2w1lwt1 && t2w1r1 < t2h1uwt1 && t2w1r1 < t2h1dwt1 && t2w1r1 < t2w1r2 && t2w1r1<t2w1l2 && t2w1r1 < t2h1u2 && t2w1r1 < t2h1d2 && t2w1r1 < t2w1rwt2 && t2w1r1 < t2w1lwt2 && t2w1r1 < t2h1uwt2 && t2w1r1 < t2h1dwt2 && ((linwr1!=0) && (loutwr1!=0) )) {
  i=58;
  }

  if (mxr1==-1 && t2w1r1 > 0 && t2w1r1 < t1 && t2w1r1 < t2w1r && t2w1r1<t2w1l && t2w1r1 < t2h1u && t2w1r1 < t2h1d && t2w1r1 < t2w1rwt && t2w1r1 < t2w1lwt && t2w1r1 < t2h1uwt && t2w1r1 < t2h1dwt && t2w1r1 < t2w1l1 && t2w1r1 < t2h1u1 && t2w1r1 < t2h1d1 && t2w1r1 < t2w1rwt1 && t2w1r1 < t2w1lwt1 && t2w1r1 < t2h1uwt1 && t2w1r1 < t2h1dwt1 && t2w1r1 < t2w1r2 && t2w1r1<t2w1l2 && t2w1r1 < t2h1u2 && t2w1r1 < t2h1d2 && t2w1r1 < t2w1rwt2 && t2w1r1 < t2w1lwt2 && t2w1r1 < t2h1uwt2 && t2w1r1 < t2h1dwt2 && ((loutwr1!=0 && linwr1==0) || (loutwr1==0 && linwr1!=0))){
  i=58;
  }

  if (mxr1==-1 && t2w1r1 > 0 && t2w1r1 < t1 && t2w1r1 < t2w1r && t2w1r1<t2w1l && t2w1r1 < t2h1u && t2w1r1 < t2h1d && t2w1r1 < t2w1rwt && t2w1r1 < t2w1lwt && t2w1r1 < t2h1uwt && t2w1r1 < t2h1dwt && t2w1r1 < t2w1l1 && t2w1r1 < t2h1u1 && t2w1r1 < t2h1d1 && t2w1r1 < t2w1rwt1 && t2w1r1 < t2w1lwt1 && t2w1r1 < t2h1uwt1 && t2w1r1 < t2h1dwt1 && t2w1r1 < t2w1r2 && t2w1r1<t2w1l2 && t2w1r1 < t2h1u2 && t2w1r1 < t2h1d2 && t2w1r1 < t2w1rwt2 && t2w1r1 < t2w1lwt2 && t2w1r1 < t2h1uwt2 && t2w1r1 < t2h1dwt2 && (loutwr1==0 && linwr1==0)){
  i=58;
  }

  if (mxl1==-1 && t2w1l1 > 0 && t2w1l1 < t1 && t2w1l1 < t2w1r && t2w1l1 < t2w1l && t2w1l1 < t2h1u && t2w1l1 < t2h1d && t2w1l1 < t2w1lwt && t2w1l1<t2w1rwt && t2w1l1 < t2h1uwt && t2w1l1 < t2h1dwt && t2w1l1 < t2w1r1 && t2w1l1 < t2h1u1 && t2w1l1 < t2h1d1 && t2w1l1 < t2w1rwt1 && t2w1l1<t2w1lwt1 && t2w1l1 < t2h1uwt1 && t2w1l1 < t2h1dwt1 &&  t2w1l1 < t2w1r2 && t2w1l1 < t2w1l2 && t2w1l1 < t2h1u2 && t2w1l1 < t2h1d2 && t2w1l1 < t2w1lwt2 && t2w1l1<t2w1rwt2 && t2w1l1 < t2h1uwt2 && t2w1l1 < t2h1dwt2 && ((linwl1!=0) && (loutwl1!=0) )){
  i=59;
  }

  if (mxl1==-1 && t2w1l1 > 0 && t2w1l1 < t1 && t2w1l1 < t2w1r && t2w1l1 < t2w1l && t2w1l1 < t2h1u && t2w1l1 < t2h1d && t2w1l1 < t2w1lwt && t2w1l1<t2w1rwt && t2w1l1 < t2h1uwt && t2w1l1 < t2h1dwt && t2w1l1 < t2w1r1 && t2w1l1 < t2h1u1 && t2w1l1 < t2h1d1 && t2w1l1 < t2w1rwt1 && t2w1l1<t2w1lwt1 && t2w1l1 < t2h1uwt1 && t2w1l1 < t2h1dwt1 &&  t2w1l1 < t2w1r2 && t2w1l1 < t2w1l2 && t2w1l1 < t2h1u2 && t2w1l1 < t2h1d2 && t2w1l1 < t2w1lwt2 && t2w1l1<t2w1rwt2 && t2w1l1 < t2h1uwt2 && t2w1l1 < t2h1dwt2 && ((loutwl1!=0 && linwl1==0) || (loutwl1==0 && linwl1!=0))){
  i=59;
  }

  if (mxl1==-1 && t2w1l1 > 0 && t2w1l1 < t1 && t2w1l1 < t2w1r && t2w1l1 < t2w1l && t2w1l1 < t2h1u && t2w1l1 < t2h1d && t2w1l1 < t2w1lwt && t2w1l1<t2w1rwt && t2w1l1 < t2h1uwt && t2w1l1 < t2h1dwt && t2w1l1 < t2w1r1 && t2w1l1 < t2h1u1 && t2w1l1 < t2h1d1 && t2w1l1 < t2w1rwt1 && t2w1l1<t2w1lwt1 && t2w1l1 < t2h1uwt1 && t2w1l1 < t2h1dwt1 && t2w1l1 < t2w1r2 && t2w1l1 < t2w1l2 && t2w1l1 < t2h1u2 && t2w1l1 < t2h1d2 && t2w1l1 < t2w1lwt2 && t2w1l1<t2w1rwt2 && t2w1l1 < t2h1uwt2 && t2w1l1 < t2h1dwt2 && (loutwl1==0 && linwl1==0)){
  i=59;
  }

  if (myu1==-1 && t2h1u1 > 0 && t2h1u1 < t1 && t2h1u1 < t2w1r && t2h1u1 < t2w1l && t2h1u1 < t2h1u && t2h1u1 < t2h1d && t2h1u1 < t2h1uwt && t2h1u1 < t2w1rwt && t2h1u1 < t2w1lwt && t2h1u1 < t2h1dwt && t2h1u1 < t2w1r1 && t2h1u1 < t2w1l1  && t2h1u1 < t2h1d1 && t2h1u1 < t2h1uwt1 && t2h1u1 < t2w1rwt1 && t2h1u1 < t2w1lwt1 && t2h1u1 < t2h1dwt1 && t2h1u1 < t2w1r2 && t2h1u1 < t2w1l2 && t2h1u1 < t2h1u2 && t2h1u1 < t2h1d2 && t2h1u1 < t2h1uwt2 && t2h1u1 < t2w1rwt2 && t2h1u1 < t2w1lwt2 && t2h1u1 < t2h1dwt2 && (louthu1 !=0 && linhu1!=0)){
  i=60;
  }

  if (myu1==-1 && t2h1u1 > 0 && t2h1u1 < t1 && t2h1u1 < t2w1r && t2h1u1 < t2w1l && t2h1u1 < t2h1u && t2h1u1 < t2h1d && t2h1u1 < t2h1uwt && t2h1u1 < t2w1rwt && t2h1u1 < t2w1lwt && t2h1u1 < t2h1dwt && t2h1u1 < t2w1r1 && t2h1u1 < t2w1l1  && t2h1u1 < t2h1d1 && t2h1u1 < t2h1uwt1 && t2h1u1 < t2w1rwt1 && t2h1u1 < t2w1lwt1 && t2h1u1 < t2h1dwt1 && t2h1u1 < t2w1r2 && t2h1u1 < t2w1l2 && t2h1u1 < t2h1u2 && t2h1u1 < t2h1d2 && t2h1u1 < t2h1uwt2 && t2h1u1 < t2w1rwt2 && t2h1u1 < t2w1lwt2 && t2h1u1 < t2h1dwt2 && ((louthu1!=0 && linhu1==0) || (louthu1==0 && linhu1!=0))){
  i=60;
  }

  if (myu1==-1 && t2h1u1 > 0 && t2h1u1 < t1 && t2h1u1 < t2w1r && t2h1u1 < t2w1l && t2h1u1 < t2h1u && t2h1u1 < t2h1d && t2h1u1 < t2h1uwt && t2h1u1 < t2w1rwt && t2h1u1 < t2w1lwt && t2h1u1 < t2h1dwt && t2h1u1 < t2w1r1 && t2h1u1 < t2w1l1  && t2h1u1 < t2h1d1 && t2h1u1 < t2h1uwt1 && t2h1u1 < t2w1rwt1 && t2h1u1 < t2w1lwt1 && t2h1u1 < t2h1dwt1 && t2h1u1 < t2w1r2 && t2h1u1 < t2w1l2 && t2h1u1 < t2h1u2 && t2h1u1 < t2h1d2 && t2h1u1 < t2h1uwt2 && t2h1u1 < t2w1rwt2 && t2h1u1 < t2w1lwt2 && t2h1u1 < t2h1dwt2 && (louthu1 == 0 && linhu1 == 0)){
  i=60;
  }

  if (myd1==-1 && t2h1d1 > 0 && t2h1d1 < t1 && t2h1d1 < t2w1r && t2h1d1 < t2w1l && t2h1d1 < t2h1u && t2h1d1 < t2h1d && t2h1d1 < t2h1dwt && t2h1d1 < t2w1rwt && t2h1d1 < t2w1lwt && t2h1d1 < t2h1uwt && t2h1d1 < t2w1r1 && t2h1d1 < t2w1l1 && t2h1d1 < t2h1u1 && t2h1d1 < t2h1dwt1 && t2h1d1 < t2w1rwt1 && t2h1d1 < t2w1lwt1 && t2h1d1 < t2h1uwt1 && t2h1d1 < t2w1r2 && t2h1d1 < t2w1l2 && t2h1d1 < t2h1u2 && t2h1d1 < t2h1d2 && t2h1d1 < t2h1dwt2 && t2h1d1 < t2w1rwt2 && t2h1d1 < t2w1lwt2 && t2h1d1 < t2h1uwt2 && (louthd1 !=0 && linhd1!=0)){
  i=61;
  }

  if (myd1==-1 && t2h1d1 > 0 && t2h1d1 < t1 && t2h1d1 < t2w1r && t2h1d1 < t2w1l && t2h1d1 < t2h1u && t2h1d1 < t2h1d && t2h1d1 < t2h1dwt && t2h1d1 < t2w1rwt && t2h1d1 < t2w1lwt && t2h1d1 < t2h1uwt && t2h1d1 < t2w1r1 && t2h1d1 < t2w1l1 && t2h1d1 < t2h1u1 && t2h1d1 < t2h1dwt1 && t2h1d1 < t2w1rwt1 && t2h1d1 < t2w1lwt1 && t2h1d1 < t2h1uwt1 && t2h1d1 < t2w1r2 && t2h1d1 < t2w1l2 && t2h1d1 < t2h1u2 && t2h1d1 < t2h1d2 && t2h1d1 < t2h1dwt2 && t2h1d1 < t2w1rwt2 && t2h1d1 < t2w1lwt2 && t2h1d1 < t2h1uwt2 && ((louthd1 !=0 && linhd1==0) || (louthd1 ==0 && linhd1!=0))){
  i=61;
  }

  if (myd1==-1 && t2h1d1 > 0 && t2h1d1 < t1 && t2h1d1 < t2w1r && t2h1d1 < t2w1l && t2h1d1 < t2h1u && t2h1d1 < t2h1d && t2h1d1 < t2h1dwt && t2h1d1 < t2w1rwt && t2h1d1 < t2w1lwt && t2h1d1 < t2h1uwt && t2h1d1 < t2w1r1 && t2h1d1 < t2w1l1 && t2h1d1 < t2h1u1 && t2h1d1 < t2h1dwt1 && t2h1d1 < t2w1rwt1 && t2h1d1 < t2w1lwt1 && t2h1d1 < t2h1uwt1 && t2h1d1 < t2w1r2 && t2h1d1 < t2w1l2 && t2h1d1 < t2h1u2 && t2h1d1 < t2h1d2 && t2h1d1 < t2h1dwt2 && t2h1d1 < t2w1rwt2 && t2h1d1 < t2w1lwt2 && t2h1d1 < t2h1uwt2 && (louthd1 == 0 && linhd1 == 0)){
  i=61;
  }




  if (mxrOW1!=-1 && t2w1rwt1 > 0 && t2w1rwt1 < t1 && t2w1rwt1 < t2w1r && t2w1rwt1 <t2w1l && t2w1rwt1 < t2h1u && t2w1rwt1 < t2h1d && t2w1rwt1 <t2w1rwt && t2w1rwt1 <t2w1lwt && t2w1rwt1 < t2h1uwt && t2w1rwt1 < t2h1dwt && t2w1rwt1 < t2w1r1 && t2w1rwt1 < t2w1l1 && t2w1rwt1 < t2h1u1 && t2w1rwt1 < t2h1d1 && t2w1rwt1 <t2w1lwt1 && t2w1rwt1 < t2h1uwt1 && t2w1rwt1 < t2h1dwt1 && t2w1rwt1 < t2w1r2 && t2w1rwt1 <t2w1l2 && t2w1rwt1 < t2h1u2 && t2w1rwt1 < t2h1d2 && t2w1rwt1 <t2w1rwt2 && t2w1rwt1 <t2w1lwt2 && t2w1rwt1 < t2h1uwt2 && t2w1rwt1 < t2h1dwt2 && ((linwr1!=0) && (loutwr1!=0) )){	
   if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1rwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1rwt1+z))*(z0hd1+(vz*t2w1rwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1rwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1rwt1+z))*(z0hu1+(vz*t2w1rwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1rwt1+y;
  xtest=vx*t2w1rwt1+x;
  xlimitrwt=-bwrwt1*sqrt(1-((vz*t2w1rwt1+z)+z0wr1)*((vz*t2w1rwt1+z)+z0wr1)/a2wrwt1);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest<=xlimitr && mxrOW1 > 0){
  i=62;
  }
  else{
  i=74;
  }
  }


  if (mxrOW1!=-1 && t2w1rwt1 > 0 && t2w1rwt1 < t1 && t2w1rwt1 < t2w1r && t2w1rwt1 <t2w1l && t2w1rwt1 < t2h1u && t2w1rwt1 < t2h1d && t2w1rwt1 <t2w1rwt && t2w1rwt1 <t2w1lwt && t2w1rwt1 < t2h1uwt && t2w1rwt1 < t2h1dwt && t2w1rwt1 < t2w1r1 && t2w1rwt1 < t2w1l1 && t2w1rwt1 < t2h1u1 && t2w1rwt1 < t2h1d1 && t2w1rwt1 <t2w1lwt1 && t2w1rwt1 < t2h1uwt1 && t2w1rwt1 < t2h1dwt1 && t2w1rwt1 < t2w1r2 && t2w1rwt1 <t2w1l2 && t2w1rwt1 < t2h1u2 && t2w1rwt1 < t2h1d2 && t2w1rwt1 <t2w1rwt2 && t2w1rwt1 <t2w1lwt2 && t2w1rwt1 < t2h1uwt2 && t2w1rwt1 < t2h1dwt2 && ((loutwr1!=0 && linwr1==0) || (loutwr1==0 && linwr1!=0))){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1rwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1rwt1+z))*(z0hd1+(vz*t2w1rwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1rwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1rwt1+z))*(z0hu1+(vz*t2w1rwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1rwt1+y;
  xtest=vx*t2w1rwt1+x;
  xlimitr=-sqrt((pbwrwt1-(vz*t2w1rwt1+z))/pawrwt1);
  if (ytest>ylimitd && ytest<ylimitu && xtest<=xlimitr && mxrOW1 > 0){
  i=63; 
  }else{
  i=74;
  }
  }


  if (mxrOW1!=-1 && t2w1rwt1 > 0 && t2w1rwt1 < t1 && t2w1rwt1 < t2w1r && t2w1rwt1 <t2w1l && t2w1rwt1 < t2h1u && t2w1rwt1 < t2h1d && t2w1rwt1 <t2w1rwt && t2w1rwt1 <t2w1lwt && t2w1rwt1 < t2h1uwt && t2w1rwt1 < t2h1dwt && t2w1rwt1 < t2w1r1 && t2w1rwt1 < t2w1l1 && t2w1rwt1 < t2h1u1 && t2w1rwt1 < t2h1d1 && t2w1rwt1 <t2w1lwt1 && t2w1rwt1 < t2h1uwt1 && t2w1rwt1 < t2h1dwt1 && t2w1rwt1 < t2w1r2 && t2w1rwt1 <t2w1l2 && t2w1rwt1 < t2h1u2 && t2w1rwt1 < t2h1d2 && t2w1rwt1 <t2w1rwt2 && t2w1rwt1 <t2w1lwt2 && t2w1rwt1 < t2h1uwt2 && t2w1rwt1 < t2h1dwt2 && (loutwr1==0 && linwr1==0) ){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1rwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1rwt1+z))*(z0hd1+(vz*t2w1rwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1rwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1rwt1+z))*(z0hu1+(vz*t2w1rwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1rwt1+y; 
  xtest=vx*t2w1rwt1+x;
  xlimitr=-(-w2r1+w1r1)*(vz*t2w1rwt1+z)/l-w1rwt1;
  if(ytest>=ylimitd && ytest<=ylimitu && xtest<=xlimitr && mxrOW1>0){
  i=64;
  }else{
  i=74;
  }
  }


 if (mxlOW1!=-1 && t2w1lwt1 > 0 && t2w1lwt1 < t1 && t2w1lwt1 < t2w1r && t2w1lwt1 <t2w1l && t2w1lwt1 < t2h1u && t2w1lwt1 < t2h1d &&  t2w1lwt1 <t2w1rwt && t2w1lwt1 < t2w1lwt && t2w1lwt1 < t2h1uwt && t2w1lwt1 < t2h1dwt && t2w1lwt1 < t2w1r1 && t2w1lwt1 < t2w1l1 && t2w1lwt1 < t2h1u1 && t2w1lwt1 < t2h1d1 && t2w1lwt1 <t2w1rwt1 && t2w1lwt1 < t2h1uwt1 && t2w1lwt1 < t2h1dwt1 && t2w1lwt1 < t2w1r2 && t2w1lwt1 <t2w1l2 && t2w1lwt1 < t2h1u2 && t2w1lwt1 < t2h1d2 &&  t2w1lwt1 <t2w1rwt2 && t2w1lwt1 < t2w1lwt2 && t2w1lwt1 < t2h1uwt2 && t2w1lwt1 < t2h1dwt2 && ((linwl1!=0) && (loutwl1!=0) )){
   if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1lwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1lwt1+z))*(z0hd1+(vz*t2w1lwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1lwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1lwt1+z))*(z0hu1+(vz*t2w1lwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1lwt1+y;
  xtest=vx*t2w1lwt1+x;
  xlimitlwt=-bwlwt1*sqrt(1-((vz*t2w1lwt1+z)+z0wl1)*((vz*t2w1lwt1+z)+z0wl1)/a2wlwt1);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW1>0){
  i=65;
  }else{
  i=75;
  }
  }


  if (mxlOW1!=-1 && t2w1lwt1 > 0 && t2w1lwt1 < t1 && t2w1lwt1 < t2w1r && t2w1lwt1 <t2w1l && t2w1lwt1 < t2h1u && t2w1lwt1 < t2h1d &&  t2w1lwt1 <t2w1rwt && t2w1lwt1 < t2w1lwt && t2w1lwt1 < t2h1uwt && t2w1lwt1 < t2h1dwt && t2w1lwt1 < t2w1r1 && t2w1lwt1 < t2w1l1 && t2w1lwt1 < t2h1u1 && t2w1lwt1 < t2h1d1 && t2w1lwt1 <t2w1rwt1 && t2w1lwt1 < t2h1uwt1 && t2w1lwt1 < t2h1dwt1 && t2w1lwt1 < t2w1r2 && t2w1lwt1 <t2w1l2 && t2w1lwt1 < t2h1u2 && t2w1lwt1 < t2h1d2 &&  t2w1lwt1 <t2w1rwt2 && t2w1lwt1 < t2w1lwt2 && t2w1lwt1 < t2h1uwt2 && t2w1lwt1 < t2h1dwt2 && ((loutwl1!=0 && linwl1==0) || (loutwl1==0 && linwl1!=0))){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1lwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1lwt1+z))*(z0hd1+(vz*t2w1lwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1lwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1lwt1+z))*(z0hu1+(vz*t2w1lwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1lwt1+y;
  xtest=vx*t2w1lwt1+x;
  xlimitl=-sqrt((pbwlwt1-(vz*t2w1lwt1+z))/pawlwt1);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW1>0){
  i=66;
  }else{
  i=75;
  }
  }


  if (mxlOW1!=-1 && t2w1lwt1 > 0 && t2w1lwt1 < t1 && t2w1lwt1 < t2w1r && t2w1lwt1 <t2w1l && t2w1lwt1 < t2h1u && t2w1lwt1 < t2h1d &&  t2w1lwt1 <t2w1rwt && t2w1lwt1 < t2w1lwt && t2w1lwt1 < t2h1uwt && t2w1lwt1 < t2h1dwt && t2w1lwt1 < t2w1r1 && t2w1lwt1 < t2w1l1 && t2w1lwt1 < t2h1u1 && t2w1lwt1 < t2h1d1 && t2w1lwt1 <t2w1rwt1 && t2w1lwt1 < t2h1uwt1 && t2w1lwt1 < t2h1dwt1 && t2w1lwt1 < t2w1r2 && t2w1lwt1 <t2w1l2 && t2w1lwt1 < t2h1u2 && t2w1lwt1 < t2h1d2 &&  t2w1lwt1 <t2w1rwt2 && t2w1lwt1 < t2w1lwt2 && t2w1lwt1 < t2h1uwt2 && t2w1lwt1 < t2h1dwt2 &&  (loutwl1==0 && linwl1==0)){
  if(linhd1==0 && louthd1==0)
   {
      ylimitd=(-h2d1+h1d1)/l*(vz*t2w1lwt1+z)-h1dwt1;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ylimitd=-bhdwt1*sqrt(1-((z0hd1+(vz*t2w1lwt1+z))*(z0hd1+(vz*t2w1lwt1+z)))/a2hdwt1);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt1+z)-pbhdwt1)/-pahdwt1);
      }
   }
   if(linhu1==0 && louthu1==0)
    {
     ylimitu=(h2u1-h1u1)/l*(vz*t2w1lwt1+z)+h1uwt1;
    }else{
     if(linhu1!=0 && louthu1!=0)
     {
     ylimitu=bhuwt1*sqrt(1-((z0hu1+(vz*t2w1lwt1+z))*(z0hu1+(vz*t2w1lwt1+z)))/a2huwt1);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt1+z)-pbhuwt1)/-pahuwt1);
    }
    }
  ytest=vy*t2w1lwt1+y; 
  xtest=vx*t2w1lwt1+x;
  xlimitl=(w2l1-w1l1)*(vz*t2w1lwt1+z)/l+w1lwt1;
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW1>0){
  i=67;
  }else{
  i=75;
  }
  }


  if (myuOW1!=-1 && t2h1uwt1 > 0 && t2h1uwt1 < t1 && t2h1uwt1 < t2w1r && t2h1uwt1 < t2w1l && t2h1uwt1 < t2h1d && t2h1uwt1 < t2h1u && t2h1uwt1 < t2w1rwt && t2h1uwt1 < t2w1lwt && t2h1uwt1 < t2h1uwt && t2h1uwt1 < t2h1dwt && t2h1uwt1 < t2w1r1 && t2h1uwt1 < t2w1l1 && t2h1uwt1 < t2h1u1 && t2h1uwt1 < t2h1d1  && t2h1uwt1 < t2w1rwt1 && t2h1uwt1 < t2w1lwt1 && t2h1uwt1 < t2h1dwt1 && t2h1uwt1 < t2w1r2 && t2h1uwt1 < t2w1l2 && t2h1uwt1 < t2h1d2 && t2h1uwt1 < t2h1u2 && t2h1uwt1 < t2w1rwt2 && t2h1uwt1 < t2w1lwt2 && t2h1uwt1 < t2h1uwt2 && t2h1uwt1 < t2h1dwt2 && (louthu1 !=0 && linhu1!=0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1uwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1uwt1+z))*(z0wr1+(vz*t2h1uwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1uwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1uwt1+z))*(z0wl1+(vz*t2h1uwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1uwt1+x;
  ytest=vy*t2w1lwt1+y;
  ylimitu=bhuwt1*sqrt(1-((vz*t2h1uwt1+z)+z0hu1)*((vz*t2h1uwt1+z)+z0hu1)/a2huwt1);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW1>0 ){
  i=68;
  }else{
  i=76;
  }
  }


  if (myuOW1!=-1 && t2h1uwt1 > 0 && t2h1uwt1 < t1 && t2h1uwt1 < t2w1r && t2h1uwt1 < t2w1l && t2h1uwt1 < t2h1d && t2h1uwt1 < t2h1u && t2h1uwt1 < t2w1rwt && t2h1uwt1 < t2w1lwt && t2h1uwt1 < t2h1uwt && t2h1uwt1 < t2h1dwt && t2h1uwt1 < t2w1r1 && t2h1uwt1 < t2w1l1 && t2h1uwt1 < t2h1u1 && t2h1uwt1 < t2h1d1  && t2h1uwt1 < t2w1rwt1 && t2h1uwt1 < t2w1lwt1 && t2h1uwt1 < t2h1dwt1 && t2h1uwt1 < t2w1r2 && t2h1uwt1 < t2w1l2 && t2h1uwt1 < t2h1d2 && t2h1uwt1 < t2h1u2 && t2h1uwt1 < t2w1rwt2 && t2h1uwt1 < t2w1lwt2 && t2h1uwt1 < t2h1uwt2 && t2h1uwt1 < t2h1dwt2 &&((louthu1!=0 && linhu1==0) || (louthu1==0 && linhu1!=0))){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1uwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1uwt1+z))*(z0wr1+(vz*t2h1uwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1uwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1uwt1+z))*(z0wl1+(vz*t2h1uwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1uwt1+x;
  ytest=vy*t2w1lwt1+y;
  ylimitu=sqrt((pbhuwt1-(vz*t2h1uwt1+z))/pahuwt1);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW1>0){
  i=69;
  }else{
  i=76;
  }
  }


  if (myuOW1!=-1 && t2h1uwt1 > 0 && t2h1uwt1 < t1 && t2h1uwt1 < t2w1r && t2h1uwt1 < t2w1l && t2h1uwt1 < t2h1d && t2h1uwt1 < t2h1u && t2h1uwt1 < t2w1rwt && t2h1uwt1 < t2w1lwt && t2h1uwt1 < t2h1uwt && t2h1uwt1 < t2h1dwt && t2h1uwt1 < t2w1r1 && t2h1uwt1 < t2w1l1 && t2h1uwt1 < t2h1u1 && t2h1uwt1 < t2h1d1  && t2h1uwt1 < t2w1rwt1 && t2h1uwt1 < t2w1lwt1 && t2h1uwt1 < t2h1dwt1 && t2h1uwt1 < t2w1r2 && t2h1uwt1 < t2w1l2 && t2h1uwt1 < t2h1d2 && t2h1uwt1 < t2h1u2 && t2h1uwt1 < t2w1rwt2 && t2h1uwt1 < t2w1lwt2 && t2h1uwt1 < t2h1uwt2 && t2h1uwt1 < t2h1dwt2 &&(louthu1 == 0 && linhu1 == 0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1uwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1uwt1+z))*(z0wr1+(vz*t2h1uwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1uwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1uwt1+z))*(z0wl1+(vz*t2h1uwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1uwt1+x;
  ytest=vy*t2w1lwt1+y;
  ylimitu=(h2u1-h1u1)*(vz*t2h1uwt1+z)/l+h1uwt1;
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW1>0 ){
  i=70;
  }else{
  i=76;
  }
  }


  if (mydOW1!=-1 && t2h1dwt1 > 0 && t2h1dwt1 < t1 && t2h1dwt1 < t2w1r && t2h1dwt1 < t2w1l && t2h1dwt1 < t2h1u  && t2h1dwt1 < t2h1d && t2h1dwt1 < t2w1rwt && t2h1dwt1 < t2w1lwt && t2h1dwt1 < t2h1uwt  && t2h1dwt1 <t2h1dwt && t2h1dwt1 < t2w1r1 && t2h1dwt1 < t2w1l1 && t2h1dwt1 < t2h1u1 && t2h1dwt1 < t2h1d1 && t2h1dwt1 < t2w1rwt1 && t2h1dwt1 < t2w1lwt1 && t2h1dwt1 < t2h1uwt1  && t2h1dwt1 < t2w1r2 && t2h1dwt1 < t2w1l2 && t2h1dwt1 < t2h1u2  && t2h1dwt1 < t2h1d2 && t2h1dwt1 < t2w1rwt2 && t2h1dwt1 < t2w1lwt2 && t2h1dwt1 < t2h1uwt2  && t2h1dwt1 <t2h1dwt2 && (louthd1 !=0 && linhd1!=0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1dwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1dwt1+z))*(z0wr1+(vz*t2h1dwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1dwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1dwt1+z))*(z0wl1+(vz*t2h1dwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1dwt1+x;
  ytest=vy*t2w1lwt1+y;
  ylimitd=-bhdwt1*sqrt(1-((vz*t2h1dwt1+z)+z0hd1)*((vz*t2h1dwt1+z)+z0hd1)/a2hdwt1);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW1>0){
  i=71;
  }else{
  i=77;
  }
  }


  if (mydOW1!=-1 && t2h1dwt1 > 0 && t2h1dwt1 < t1 && t2h1dwt1 < t2w1r && t2h1dwt1 < t2w1l && t2h1dwt1 < t2h1u  && t2h1dwt1 < t2h1d && t2h1dwt1 < t2w1rwt && t2h1dwt1 < t2w1lwt && t2h1dwt1 < t2h1uwt  && t2h1dwt1 <t2h1dwt && t2h1dwt1 < t2w1r1 && t2h1dwt1 < t2w1l1 && t2h1dwt1 < t2h1u1 && t2h1dwt1 < t2h1d1 && t2h1dwt1 < t2w1rwt1 && t2h1dwt1 < t2w1lwt1 && t2h1dwt1 < t2h1uwt1  && t2h1dwt1 < t2w1r2 && t2h1dwt1 < t2w1l2 && t2h1dwt1 < t2h1u2  && t2h1dwt1 < t2h1d2 && t2h1dwt1 < t2w1rwt2 && t2h1dwt1 < t2w1lwt2 && t2h1dwt1 < t2h1uwt2  && t2h1dwt1 <t2h1dwt2 && ((louthd1 !=0 && linhd1==0) || (louthd1 ==0 && linhd1!=0))){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1dwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1dwt1+z))*(z0wr1+(vz*t2h1dwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
     xlimitl=(w2l1-w1l1)/l*(vz*t2h1dwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1dwt1+z))*(z0wl1+(vz*t2h1dwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1dwt1+x;
  ytest=vy*t2w1lwt1+y;
  ylimitd=-sqrt((pbhdwt1-(vz*t2h1dwt1+z))/pahdwt1);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW1>0 ){
  i=72;
  }else{
  i=77;
  }
  }


  if (mydOW1!=-1 && t2h1dwt1 > 0 && t2h1dwt1 < t1 && t2h1dwt1 < t2w1r && t2h1dwt1 < t2w1l && t2h1dwt1 < t2h1u  && t2h1dwt1 < t2h1d && t2h1dwt1 < t2w1rwt && t2h1dwt1 < t2w1lwt && t2h1dwt1 < t2h1uwt  && t2h1dwt1 <t2h1dwt && t2h1dwt1 < t2w1r1 && t2h1dwt1 < t2w1l1 && t2h1dwt1 < t2h1u1 && t2h1dwt1 < t2h1d1 && t2h1dwt1 < t2w1rwt1 && t2h1dwt1 < t2w1lwt1 && t2h1dwt1 < t2h1uwt1  && t2h1dwt1 < t2w1r2 && t2h1dwt1 < t2w1l2 && t2h1dwt1 < t2h1u2  && t2h1dwt1 < t2h1d2 && t2h1dwt1 < t2w1rwt2 && t2h1dwt1 < t2w1lwt2 && t2h1dwt1 < t2h1uwt2  && t2h1dwt1 <t2h1dwt2 && (louthd1 == 0 && linhd1 == 0)){
  if(linwr1==0 && loutwr1==0)
  {
    xlimitr=(-w2r1+w1r1)/l*(vz*t2h1dwt1+z)-w1rwt1;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xlimitr=-bwrwt1*sqrt(1-((z0wr1+(vz*t2h1dwt1+z))*(z0wr1+(vz*t2h1dwt1+z)))/a2wrwt1);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt1+z)-pbwrwt1)/-pawrwt1);
    }
  }
  if(linwl1==0 && loutwl1 == 0)
   {
      xlimitl=(w2l1-w1l1)/l*(vz*t2h1dwt1+z)+w1lwt1;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xlimitl=bwlwt1*sqrt(1-((z0wl1+(vz*t2h1dwt1+z))*(z0wl1+(vz*t2h1dwt1+z)))/a2wlwt1);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt1+z)-pbwlwt1)/-pawlwt1);
      }
   }
  xtest=vx*t2h1dwt1+x;
  ytest=vy*t2w1lwt1+y;
  ylimitd=(-h2d1+h1d1)*(vz*t2h1dwt1+z)/l-h1dwt1;
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW1>0 ){
  i=73;
  }else{
  i=77;
  }
  }

if (mxrOW1==-1 && t2w1rwt1 > 0 && t2w1rwt1 < t1 && t2w1rwt1 < t2w1r && t2w1rwt1 <t2w1l && t2w1rwt1 < t2h1u && t2w1rwt1 < t2h1d && t2w1rwt1 <t2w1rwt && t2w1rwt1 <t2w1lwt && t2w1rwt1 < t2h1uwt && t2w1rwt1 < t2h1dwt && t2w1rwt1 < t2w1r1 && t2w1rwt1 < t2w1l1 && t2w1rwt1 < t2h1u1 && t2w1rwt1 < t2h1d1 && t2w1rwt1 <t2w1lwt1 && t2w1rwt1 < t2h1uwt1 && t2w1rwt1 < t2h1dwt1 && t2w1rwt1 < t2w1r2 && t2w1rwt1 <t2w1l2 && t2w1rwt1 < t2h1u2 && t2w1rwt1 < t2h1d2 && t2w1rwt1 <t2w1rwt2 && t2w1rwt1 <t2w1lwt2 && t2w1rwt1 < t2h1uwt2 && t2w1rwt1 < t2h1dwt2 && ((linwr1!=0) && (loutwr1!=0) )) {
  i=78;
  }

  if (mxrOW1==-1 && t2w1rwt1 > 0 && t2w1rwt1 < t1 && t2w1rwt1 < t2w1r && t2w1rwt1 <t2w1l && t2w1rwt1 < t2h1u && t2w1rwt1 < t2h1d && t2w1rwt1 <t2w1rwt && t2w1rwt1 <t2w1lwt && t2w1rwt1 < t2h1uwt && t2w1rwt1 < t2h1dwt && t2w1rwt1 < t2w1r1 && t2w1rwt1 < t2w1l1 && t2w1rwt1 < t2h1u1 && t2w1rwt1 < t2h1d1 && t2w1rwt1 <t2w1lwt1 && t2w1rwt1 < t2h1uwt1 && t2w1rwt1 < t2h1dwt1 && t2w1rwt1 < t2w1r2 && t2w1rwt1 <t2w1l2 && t2w1rwt1 < t2h1u2 && t2w1rwt1 < t2h1d2 && t2w1rwt1 <t2w1rwt2 && t2w1rwt1 <t2w1lwt2 && t2w1rwt1 < t2h1uwt2 && t2w1rwt1 < t2h1dwt2 && ((loutwr1!=0 && linwr1==0) || (loutwr1==0 && linwr1!=0))){
  i=78;
  }

  if (mxrOW1==-1 && t2w1rwt1 > 0 && t2w1rwt1 < t1 && t2w1rwt1 < t2w1r && t2w1rwt1 <t2w1l && t2w1rwt1 < t2h1u && t2w1rwt1 < t2h1d && t2w1rwt1 <t2w1rwt && t2w1rwt1 <t2w1lwt && t2w1rwt1 < t2h1uwt && t2w1rwt1 < t2h1dwt && t2w1rwt1 < t2w1r1 && t2w1rwt1 < t2w1l1 && t2w1rwt1 < t2h1u1 && t2w1rwt1 < t2h1d1 && t2w1rwt1 <t2w1lwt1 && t2w1rwt1 < t2h1uwt1 && t2w1rwt1 < t2h1dwt1 && t2w1rwt1 < t2w1r2 && t2w1rwt1 <t2w1l2 && t2w1rwt1 < t2h1u2 && t2w1rwt1 < t2h1d2 && t2w1rwt1 <t2w1rwt2 && t2w1rwt1 <t2w1lwt2 && t2w1rwt1 < t2h1uwt2 && t2w1rwt1 < t2h1dwt2 &&  (loutwr1==0 && linwr1==0)){
  i=78;
  }

  if (mxlOW1==-1 && t2w1lwt1 > 0 && t2w1lwt1 < t1 && t2w1lwt1 < t2w1r && t2w1lwt1 <t2w1l && t2w1lwt1 < t2h1u && t2w1lwt1 < t2h1d &&  t2w1lwt1 <t2w1rwt && t2w1lwt1 < t2w1lwt && t2w1lwt1 < t2h1uwt && t2w1lwt1 < t2h1dwt && t2w1lwt1 < t2w1r1 && t2w1lwt1 < t2w1l1 && t2w1lwt1 < t2h1u1 && t2w1lwt1 < t2h1d1 && t2w1lwt1 <t2w1rwt1 && t2w1lwt1 < t2h1uwt1 && t2w1lwt1 < t2h1dwt1 && t2w1lwt1 < t2w1r2 && t2w1lwt1 <t2w1l2 && t2w1lwt1 < t2h1u2 && t2w1lwt1 < t2h1d2 &&  t2w1lwt1 <t2w1rwt2 && t2w1lwt1 < t2w1lwt2 && t2w1lwt1 < t2h1uwt2 && t2w1lwt1 < t2h1dwt2 &&  ((linwl1!=0) && (loutwl1!=0) )){
  i=79;
  }

  if (mxlOW1==-1 && t2w1lwt1 > 0 && t2w1lwt1 < t1 && t2w1lwt1 < t2w1r && t2w1lwt1 <t2w1l && t2w1lwt1 < t2h1u && t2w1lwt1 < t2h1d &&  t2w1lwt1 <t2w1rwt && t2w1lwt1 < t2w1lwt && t2w1lwt1 < t2h1uwt && t2w1lwt1 < t2h1dwt && t2w1lwt1 < t2w1r1 && t2w1lwt1 < t2w1l1 && t2w1lwt1 < t2h1u1 && t2w1lwt1 < t2h1d1 && t2w1lwt1 <t2w1rwt1 && t2w1lwt1 < t2h1uwt1 && t2w1lwt1 < t2h1dwt1 && t2w1lwt1 < t2w1r2 && t2w1lwt1 <t2w1l2 && t2w1lwt1 < t2h1u2 && t2w1lwt1 < t2h1d2 &&  t2w1lwt1 <t2w1rwt2 && t2w1lwt1 < t2w1lwt2 && t2w1lwt1 < t2h1uwt2 && t2w1lwt1 < t2h1dwt2 && ((loutwl1!=0 && linwl1==0) || (loutwl1==0 && linwl1!=0))){
  i=79;
  }

  if (mxlOW1==-1 && t2w1lwt1 > 0 && t2w1lwt1 < t1 && t2w1lwt1 < t2w1r && t2w1lwt1 <t2w1l && t2w1lwt1 < t2h1u && t2w1lwt1 < t2h1d &&  t2w1lwt1 <t2w1rwt && t2w1lwt1 < t2w1lwt && t2w1lwt1 < t2h1uwt && t2w1lwt1 < t2h1dwt && t2w1lwt1 < t2w1r1 && t2w1lwt1 < t2w1l1 && t2w1lwt1 < t2h1u1 && t2w1lwt1 < t2h1d1 && t2w1lwt1 <t2w1rwt1 && t2w1lwt1 < t2h1uwt1 && t2w1lwt1 < t2h1dwt1 && t2w1lwt1 < t2w1r2 && t2w1lwt1 <t2w1l2 && t2w1lwt1 < t2h1u2 && t2w1lwt1 < t2h1d2 &&  t2w1lwt1 <t2w1rwt2 && t2w1lwt1 < t2w1lwt2 && t2w1lwt1 < t2h1uwt2 && t2w1lwt1 < t2h1dwt2 && (loutwl1==0 && linwl1==0)){
  i=79;
  }

  if (myuOW1==-1 && t2h1uwt1 > 0 && t2h1uwt1 < t1 && t2h1uwt1 < t2w1r && t2h1uwt1 < t2w1l && t2h1uwt1 < t2h1d && t2h1uwt1 < t2h1u && t2h1uwt1 < t2w1rwt && t2h1uwt1 < t2w1lwt && t2h1uwt1 < t2h1uwt && t2h1uwt1 < t2h1dwt && t2h1uwt1 < t2w1r1 && t2h1uwt1 < t2w1l1 && t2h1uwt1 < t2h1u1 && t2h1uwt1 < t2h1d1  && t2h1uwt1 < t2w1rwt1 && t2h1uwt1 < t2w1lwt1 && t2h1uwt1 < t2h1dwt1 && t2h1uwt1 < t2w1r2 && t2h1uwt1 < t2w1l2 && t2h1uwt1 < t2h1d2 && t2h1uwt1 < t2h1u2 && t2h1uwt1 < t2w1rwt2 && t2h1uwt1 < t2w1lwt2 && t2h1uwt1 < t2h1uwt2 && t2h1uwt1 < t2h1dwt2 && (louthu1 !=0 && linhu1!=0)){
  i=80;
  }

  if (myuOW1==-1 && t2h1uwt1 > 0 && t2h1uwt1 < t1 && t2h1uwt1 < t2w1r && t2h1uwt1 < t2w1l && t2h1uwt1 < t2h1d && t2h1uwt1 < t2h1u && t2h1uwt1 < t2w1rwt && t2h1uwt1 < t2w1lwt && t2h1uwt1 < t2h1uwt && t2h1uwt1 < t2h1dwt && t2h1uwt1 < t2w1r1 && t2h1uwt1 < t2w1l1 && t2h1uwt1 < t2h1u1 && t2h1uwt1 < t2h1d1  && t2h1uwt1 < t2w1rwt1 && t2h1uwt1 < t2w1lwt1 && t2h1uwt1 < t2h1dwt1 && t2h1uwt1 < t2w1r2 && t2h1uwt1 < t2w1l2 && t2h1uwt1 < t2h1d2 && t2h1uwt1 < t2h1u2 && t2h1uwt1 < t2w1rwt2 && t2h1uwt1 < t2w1lwt2 && t2h1uwt1 < t2h1uwt2 && t2h1uwt1 < t2h1dwt2 && ((louthu1!=0 && linhu1==0) || (louthu1==0 && linhu1!=0))){
  i=80;
  }

  if (myuOW1==-1 && t2h1uwt1 > 0 && t2h1uwt1 < t1 && t2h1uwt1 < t2w1r && t2h1uwt1 < t2w1l && t2h1uwt1 < t2h1d && t2h1uwt1 < t2h1u && t2h1uwt1 < t2w1rwt && t2h1uwt1 < t2w1lwt && t2h1uwt1 < t2h1uwt && t2h1uwt1 < t2h1dwt && t2h1uwt1 < t2w1r1 && t2h1uwt1 < t2w1l1 && t2h1uwt1 < t2h1u1 && t2h1uwt1 < t2h1d1  && t2h1uwt1 < t2w1rwt1 && t2h1uwt1 < t2w1lwt1 && t2h1uwt1 < t2h1dwt1 && t2h1uwt1 < t2w1r2 && t2h1uwt1 < t2w1l2 && t2h1uwt1 < t2h1d2 && t2h1uwt1 < t2h1u2 && t2h1uwt1 < t2w1rwt2 && t2h1uwt1 < t2w1lwt2 && t2h1uwt1 < t2h1uwt2 && t2h1uwt1 < t2h1dwt2 && (louthu1 == 0 && linhu1 == 0)){
  i=80;
  }

  if (mydOW1==-1 && t2h1dwt1 > 0 && t2h1dwt1 < t1 && t2h1dwt1 < t2w1r && t2h1dwt1 < t2w1l && t2h1dwt1 < t2h1u  && t2h1dwt1 < t2h1d && t2h1dwt1 < t2w1rwt && t2h1dwt1 < t2w1lwt && t2h1dwt1 < t2h1uwt  && t2h1dwt1 <t2h1dwt && t2h1dwt1 < t2w1r1 && t2h1dwt1 < t2w1l1 && t2h1dwt1 < t2h1u1 && t2h1dwt1 < t2h1d1 && t2h1dwt1 < t2w1rwt1 && t2h1dwt1 < t2w1lwt1 && t2h1dwt1 < t2h1uwt1  && t2h1dwt1 < t2w1r2 && t2h1dwt1 < t2w1l2 && t2h1dwt1 < t2h1u2  && t2h1dwt1 < t2h1d2 && t2h1dwt1 < t2w1rwt2 && t2h1dwt1 < t2w1lwt2 && t2h1dwt1 < t2h1uwt2  && t2h1dwt1 <t2h1dwt2 && (louthd1 !=0 && linhd1!=0)){
  i=81;
  }

  if (mydOW1==-1 && t2h1dwt1 > 0 && t2h1dwt1 < t1 && t2h1dwt1 < t2w1r && t2h1dwt1 < t2w1l && t2h1dwt1 < t2h1u  && t2h1dwt1 < t2h1d && t2h1dwt1 < t2w1rwt && t2h1dwt1 < t2w1lwt && t2h1dwt1 < t2h1uwt  && t2h1dwt1 <t2h1dwt && t2h1dwt1 < t2w1r1 && t2h1dwt1 < t2w1l1 && t2h1dwt1 < t2h1u1 && t2h1dwt1 < t2h1d1 && t2h1dwt1 < t2w1rwt1 && t2h1dwt1 < t2w1lwt1 && t2h1dwt1 < t2h1uwt1  && t2h1dwt1 < t2w1r2 && t2h1dwt1 < t2w1l2 && t2h1dwt1 < t2h1u2  && t2h1dwt1 < t2h1d2 && t2h1dwt1 < t2w1rwt2 && t2h1dwt1 < t2w1lwt2 && t2h1dwt1 < t2h1uwt2  && t2h1dwt1 <t2h1dwt2 &&  ((louthd1 !=0 && linhd1==0) || (louthd1 ==0 && linhd1!=0))){
  i=81;
  }

  if (mydOW1==-1 && t2h1dwt1 > 0 && t2h1dwt1 < t1 && t2h1dwt1 < t2w1r && t2h1dwt1 < t2w1l && t2h1dwt1 < t2h1u  && t2h1dwt1 < t2h1d && t2h1dwt1 < t2w1rwt && t2h1dwt1 < t2w1lwt && t2h1dwt1 < t2h1uwt  && t2h1dwt1 <t2h1dwt && t2h1dwt1 < t2w1r1 && t2h1dwt1 < t2w1l1 && t2h1dwt1 < t2h1u1 && t2h1dwt1 < t2h1d1 && t2h1dwt1 < t2w1rwt1 && t2h1dwt1 < t2w1lwt1 && t2h1dwt1 < t2h1uwt1  && t2h1dwt1 < t2w1r2 && t2h1dwt1 < t2w1l2 && t2h1dwt1 < t2h1u2  && t2h1dwt1 < t2h1d2 && t2h1dwt1 < t2w1rwt2 && t2h1dwt1 < t2w1lwt2 && t2h1dwt1 < t2h1uwt2  && t2h1dwt1 <t2h1dwt2 && (louthd1 == 0 && linhd1 == 0)){
  i=81;
  }

												/* SECOND SHELL */

if (mxr2!=-1 && t2w1r2 > 0 && t2w1r2 < t1 && t2w1r2 < t2w1r && t2w1r2 <t2w1l && t2w1r2 < t2h1u && t2w1r2 < t2h1d && t2w1r2 <t2w1rwt && t2w1r2 <t2w1lwt && t2w1r2 < t2h1uwt && t2w1r2 < t2h1dwt && t2w1r2 < t2w1r1 && t2w1r2 < t2w1l1 && t2w1r2 < t2h1u1 && t2w1r2 < t2h1d1 && t2w1r2 <t2w1rwt1 && t2w1r2 <t2w1lwt1 && t2w1r2 < t2h1uwt1 && t2w1r2 < t2h1dwt1 && t2w1r2 <t2w1l2 && t2w1r2 < t2h1u2 && t2w1r2 < t2h1d2 && t2w1r2 <t2w1rwt2 && t2w1r2 <t2w1lwt2 && t2w1r2 < t2h1uwt2 && t2w1r2 < t2h1dwt2 && ((linwr2!=0) && (loutwr2!=0) )) {	
    if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1r2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1r2+z))*(z0hd2+(vz*t2w1r2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1r2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1r2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1r2+z))*(z0hu2+(vz*t2w1r2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1r2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1r2+y;
  xlimitr=bwr2*sqrt(1-((vz*t2w1r2+z)+z0wr2)*((vz*t2w1r2+z)+z0wr2)/a2wr2);
  xtest=vx*t2w1r2+x;
  if (ytest>=ylimitd && ytest<=ylimitu && x>=-xlimitr && mxr2 > 0){
  i=82;
  }else{
  i=98;
  }
  }

													/* neutron interacts with the parabolic right INNER wall - comments are analog to inner elliptic right wall */

  if (mxr2!=-1 && t2w1r2 > 0 && t2w1r2 < t1 && t2w1r2 < t2w1r && t2w1r2 <t2w1l && t2w1r2 < t2h1u && t2w1r2 < t2h1d && t2w1r2 <t2w1rwt && t2w1r2 <t2w1lwt && t2w1r2 < t2h1uwt && t2w1r2 < t2h1dwt && t2w1r2 < t2w1r1 && t2w1r2 < t2w1l1 && t2w1r2 < t2h1u1 && t2w1r2 < t2h1d1 && t2w1r2 <t2w1rwt1 && t2w1r2 <t2w1lwt1 && t2w1r2 < t2h1uwt1 && t2w1r2 < t2h1dwt1 && t2w1r2 <t2w1l2 && t2w1r2 < t2h1u2 && t2w1r2 < t2h1d2 && t2w1r2 <t2w1rwt2 && t2w1r2 <t2w1lwt2 && t2w1r2 < t2h1uwt2 && t2w1r2 < t2h1dwt2 && ((loutwr2!=0 && linwr2==0) || (loutwr2==0 && linwr2!=0))){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1r2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1r2+z))*(z0hd2+(vz*t2w1r2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1r2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1r2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1r2+z))*(z0hu2+(vz*t2w1r2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1r2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1r2+y;
  xtest=vx*t2w1r2+x;
  xlimitr=-sqrt(pbwr2-(vz*t2w1r2+z)/pawr2);
  if (ytest>ylimitd && ytest<ylimitu && x>=xlimitr && mxr2 > 0){
  i=83;
  }else{
  i=98;}
  }

													/* neutron interacts with the straight right INNER wall - comments are analog to inner elliptic right wall*/

  if (mxr2!=-1 && t2w1r2 > 0 && t2w1r2 < t1 && t2w1r2 < t2w1r && t2w1r2 <t2w1l && t2w1r2 < t2h1u && t2w1r2 < t2h1d && t2w1r2 <t2w1rwt && t2w1r2 <t2w1lwt && t2w1r2 < t2h1uwt && t2w1r2 < t2h1dwt && t2w1r2 < t2w1r1 && t2w1r2 < t2w1l1 && t2w1r2 < t2h1u1 && t2w1r2 < t2h1d1 && t2w1r2 <t2w1rwt1 && t2w1r2 <t2w1lwt1 && t2w1r2 < t2h1uwt1 && t2w1r2 < t2h1dwt1 && t2w1r2 <t2w1l2 && t2w1r2 < t2h1u2 && t2w1r2 < t2h1d2 && t2w1r2 <t2w1rwt2 && t2w1r2 <t2w1lwt2 && t2w1r2 < t2h1uwt2 && t2w1r2 < t2h1dwt2 && (loutwr2==0 && linwr2==0)){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1r2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1r2+z))*(z0hd2+(vz*t2w1r2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1r2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1r2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1r2+z))*(z0hu2+(vz*t2w1r2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1r2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1r2+y;
  xtest=vx*t2w1r2+x;
  xlimitr=-(w2r2+w1r2)*(vz*t2w1r2+z)/l-w1r2;
  if (ytest>=ylimitd && ytest<=ylimitu && x>=xlimitr && mxr2>0){
  i=84;
  }else{
  i=98;
  }
  }

													/* neutron interacts with the elliptic left INNER wall - comments are analog to inner elliptic right wall*/

  if (mxl2!=-1 && t2w1l2 > 0 && t2w1l2 < t1 && t2w1l2 < t2w1r && t2w1l2 <t2w1l && t2w1l2 < t2h1u && t2w1l2 < t2h1d && t2w1l2 <t2w1rwt && t2w1l2 <t2w1lwt && t2w1l2 < t2h1uwt && t2w1l2 < t2h1dwt && t2w1l2 < t2w1r1 && t2w1l2 < t2w1l1 && t2w1l2 < t2h1u1 && t2w1l2 < t2h1d1 && t2w1l2 <t2w1rwt1 && t2w1l2 <t2w1lwt1 && t2w1l2 < t2h1uwt1 && t2w1l2 < t2h1dwt1 && t2w1l2 <t2w1r2 && t2w1l2 < t2h1u2 && t2w1l2 < t2h1d2 && t2w1l2 <t2w1rwt2 && t2w1l2 <t2w1lwt2 && t2w1l2 < t2h1uwt2 && t2w1l2 < t2h1dwt2 && ((linwl2!=0) && (loutwl2!=0) )){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1l2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1l2+z))*(z0hd2+(vz*t2w1l2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1l2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1l2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1l2+z))*(z0hu2+(vz*t2w1l2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1l2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1l2+y;
  xlimitl=bwl2*sqrt(1-((vz*t2w1l2+z)+z0wl2)*((vz*t2w1l2+z)+z0wl2)/a2wl2);
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl2>0){
  i=85;
  }else{
  i=99;
  }
  }

													/* neutron interacts with the parabolic left INNER wall - comments are analog to inner elliptic right wall*/

  if (mxl2!=-1 && t2w1l2 > 0 && t2w1l2 < t1 && t2w1l2 < t2w1r && t2w1l2 <t2w1l && t2w1l2 < t2h1u && t2w1l2 < t2h1d && t2w1l2 <t2w1rwt && t2w1l2 <t2w1lwt && t2w1l2 < t2h1uwt && t2w1l2 < t2h1dwt && t2w1l2 < t2w1r1 && t2w1l2 < t2w1l1 && t2w1l2 < t2h1u1 && t2w1l2 < t2h1d1 && t2w1l2 <t2w1rwt1 && t2w1l2 <t2w1lwt1 && t2w1l2 < t2h1uwt1 && t2w1l2 < t2h1dwt1 && t2w1l2 <t2w1r2 && t2w1l2 < t2h1u2 && t2w1l2 < t2h1d2 && t2w1l2 <t2w1rwt2 && t2w1l2 <t2w1lwt2 && t2w1l2 < t2h1uwt2 && t2w1l2 < t2h1dwt2 && ((loutwl2!=0 && linwl2==0) || (loutwl2==0 && linwl2!=0))){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1l2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1l2+z))*(z0hd2+(vz*t2w1l2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1l2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1l2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1l2+z))*(z0hu2+(vz*t2w1l2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1l2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1l2+y;
  xlimitl=sqrt(pbwl2-(vz*t2w1l2+z)/pawl2);
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl2>0){
  i=86;
  }else{
  i=99;
  }
  }

														/* neutron interacts with the straight left INNER wall - comments are analog to inner elliptic right wall*/

  if (mxl2!=-1 && t2w1l2 > 0 && t2w1l2 < t1 && t2w1l2 < t2w1r && t2w1l2 <t2w1l && t2w1l2 < t2h1u && t2w1l2 < t2h1d && t2w1l2 <t2w1rwt && t2w1l2 <t2w1lwt && t2w1l2 < t2h1uwt && t2w1l2 < t2h1dwt && t2w1l2 < t2w1r1 && t2w1l2 < t2w1l1 && t2w1l2 < t2h1u1 && t2w1l2 < t2h1d1 && t2w1l2 <t2w1rwt1 && t2w1l2 <t2w1lwt1 && t2w1l2 < t2h1uwt1 && t2w1l2 < t2h1dwt1 && t2w1l2 <t2w1r2 && t2w1l2 < t2h1u2 && t2w1l2 < t2h1d2 && t2w1l2 <t2w1rwt2 && t2w1l2 <t2w1lwt2 && t2w1l2 < t2h1uwt2 && t2w1l2 < t2h1dwt2 && (loutwl2==0 && linwl2==0)){
 if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1l2+z)-h1d2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhd2*sqrt(1-((z0hd2+(vz*t2w1l2+z))*(z0hd2+(vz*t2w1l2+z)))/a2hd2);
      }else{
      ylimitd=-sqrt(((vz*t2w1l2+z)-pbhd2)/-pahd2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1l2+z)+h1u2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhu2*sqrt(1-((z0hu2+(vz*t2w1l2+z))*(z0hu2+(vz*t2w1l2+z)))/a2hu2);
     }else{
     ylimitu=sqrt(((vz*t2w1l2+z)-pbhu2)/-pahu2);
    }
    }
  ytest=vy*t2w1l2+y;
  xlimitl=(w2l2-w1l2)*(vz*t2w1l2+z)/l+w1l2;
  if (ytest>=ylimitd && ytest<=ylimitu && x<=xlimitl && mxl2>0){
  i=87;
  }else{
  i=99;
  }
  }

														/* neutron interacts with the elliptic top INNER wall - comments are analog to inner elliptic right wall*/

  if (myu2!=-1 && t2h1u2 > 0 && t2h1u2 < t1 && t2h1u2 < t2w1r && t2h1u2 <t2w1l && t2h1u2 < t2h1u && t2h1u2 < t2h1d && t2h1u2 <t2w1rwt && t2h1u2 <t2w1lwt && t2h1u2 < t2h1uwt && t2h1u2 < t2h1dwt && t2h1u2 < t2w1r1 && t2h1u2 < t2w1l1 && t2h1u2 < t2h1u1 && t2h1u2 < t2h1d1 && t2h1u2 <t2w1rwt1 && t2h1u2 <t2w1lwt1 && t2h1u2 < t2h1uwt1 && t2h1u2 < t2h1dwt1 && t2h1u2 <t2w1r2 && t2h1u2 < t2w1l2 && t2h1u2 < t2h1d2 && t2h1u2 <t2w1rwt2 && t2h1u2 <t2w1lwt2 && t2h1u2 < t2h1uwt2 && t2h1u2 < t2h1dwt2 && (louthu2 !=0 && linhu2!=0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1u2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1u2+z))*(z0wr2+(vz*t2h1u2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1u2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1u2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1u2+z))*(z0wl2+(vz*t2h1u2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1u2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1u2+x;
  ylimitu=bhu2*sqrt(1-((vz*t2h1u2+z)+z0hu2)*((vz*t2h1u2+z)+z0hu2)/a2hu2);
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu2>0 ){
  i=88;
  }else{
  i=100;
  }
  }
	
														/* neutron interacts with the parabolic top INNER wall - comments are analog to inner elliptic right wall*/

  if (myu2!=-1 && t2h1u2 > 0 && t2h1u2 < t1 && t2h1u2 < t2w1r && t2h1u2 <t2w1l && t2h1u2 < t2h1u && t2h1u2 < t2h1d && t2h1u2 <t2w1rwt && t2h1u2 <t2w1lwt && t2h1u2 < t2h1uwt && t2h1u2 < t2h1dwt && t2h1u2 < t2w1r1 && t2h1u2 < t2w1l1 && t2h1u2 < t2h1u1 && t2h1u2 < t2h1d1 && t2h1u2 <t2w1rwt1 && t2h1u2 <t2w1lwt1 && t2h1u2 < t2h1uwt1 && t2h1u2 < t2h1dwt1 && t2h1u2 <t2w1r2 && t2h1u2 < t2w1l2 && t2h1u2 < t2h1d2 && t2h1u2 <t2w1rwt2 && t2h1u2 <t2w1lwt2 && t2h1u2 < t2h1uwt2 && t2h1u2 < t2h1dwt2 && ((louthu2!=0 && linhu2==0) || (louthu2==0 && linhu2!=0))){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1u2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1u2+z))*(z0wr2+(vz*t2h1u2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1u2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1u2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1u2+z))*(z0wl2+(vz*t2h1u2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1u2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1u2+x;
  ylimitu=sqrt(pbhu2-(vz*t2h1u2+z)/pahu2);
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu2>0){
  i=89;
  }else{
  i=100;
  }
  }


															/* neutron interacts with the straight top INNER wall - comments are analog to inner elliptic right wall*/

  if (myu2!=-1 && t2h1u2 > 0 && t2h1u2 < t1 && t2h1u2 < t2w1r && t2h1u2 <t2w1l && t2h1u2 < t2h1u && t2h1u2 < t2h1d && t2h1u2 <t2w1rwt && t2h1u2 <t2w1lwt && t2h1u2 < t2h1uwt && t2h1u2 < t2h1dwt && t2h1u2 < t2w1r1 && t2h1u2 < t2w1l1 && t2h1u2 < t2h1u1 && t2h1u2 < t2h1d1 && t2h1u2 <t2w1rwt1 && t2h1u2 <t2w1lwt1 && t2h1u2 < t2h1uwt1 && t2h1u2 < t2h1dwt1 && t2h1u2 <t2w1r2 && t2h1u2 < t2w1l2 && t2h1u2 < t2h1d2 && t2h1u2 <t2w1rwt2 && t2h1u2 <t2w1lwt2 && t2h1u2 < t2h1uwt2 && t2h1u2 < t2h1dwt2 && (louthu2 == 0 && linhu2 == 0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1u2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1u2+z))*(z0wr2+(vz*t2h1u2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1u2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1u2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1u2+z))*(z0wl2+(vz*t2h1u2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1u2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1u2+x;
  ylimitu=(h2u2-h1u2)*(vz*t2h1u2+z)/l+h1u2;
  if (xtest>=xlimitr && xtest<=xlimitl && y<=ylimitu && myu2>0 ){
  i=90;
  }else{
  i=100;
  }
  }

															/* neutron interacts with the elliptic down INNER wall - comments are analog to inner elliptic right wall*/

  if (myd2!=-1 && t2h1d2 > 0 && t2h1d2 < t1 && t2h1d2 < t2w1r && t2h1d2 <t2w1l && t2h1d2 < t2h1u && t2h1d2 < t2h1d && t2h1d2 <t2w1rwt && t2h1d2 <t2w1lwt && t2h1d2 < t2h1uwt && t2h1d2 < t2h1dwt && t2h1d2 < t2w1r1 && t2h1d2 < t2w1l1 && t2h1d2 < t2h1u1 && t2h1d2 < t2h1d1 && t2h1d2 <t2w1rwt1 && t2h1d2 <t2w1lwt1 && t2h1d2 < t2h1uwt1 && t2h1d2 < t2h1dwt1 && t2h1d2 <t2w1r2 && t2h1d2 < t2w1l2 && t2h1d2 < t2h1u2 && t2h1d2 <t2w1rwt2 && t2h1d2 <t2w1lwt2 && t2h1d2 < t2h1uwt2 && t2h1d2 < t2h1dwt2 && (louthd2 !=0 && linhd2!=0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1d2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1d2+z))*(z0wr2+(vz*t2h1d2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1d2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1d2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1d2+z))*(z0wl2+(vz*t2h1d2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1d2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1d2+x;
  ylimitd=-bhd2*sqrt(1-((vz*t2h1d2+z)+z0hd2)*((vz*t2h1d2+z)+z0hd2)/a2hd2);
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd2>0){
  i=91;
  }else{
  i=101;
  }
  }

															/* neutron interacts with the parabolic down INNER wall - comments are analog to inner elliptic right wall*/

  if (myd2!=-1 && t2h1d2 > 0 && t2h1d2 < t1 && t2h1d2 < t2w1r && t2h1d2 <t2w1l && t2h1d2 < t2h1u && t2h1d2 < t2h1d && t2h1d2 <t2w1rwt && t2h1d2 <t2w1lwt && t2h1d2 < t2h1uwt && t2h1d2 < t2h1dwt && t2h1d2 < t2w1r1 && t2h1d2 < t2w1l1 && t2h1d2 < t2h1u1 && t2h1d2 < t2h1d1 && t2h1d2 <t2w1rwt1 && t2h1d2 <t2w1lwt1 && t2h1d2 < t2h1uwt1 && t2h1d2 < t2h1dwt1 && t2h1d2 <t2w1r2 && t2h1d2 < t2w1l2 && t2h1d2 < t2h1u2 && t2h1d2 <t2w1rwt2 && t2h1d2 <t2w1lwt2 && t2h1d2 < t2h1uwt2 && t2h1d2 < t2h1dwt2 && ((louthd2 !=0 && linhd2==0) || (louthd2 ==0 && linhd2!=0))){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1d2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1d2+z))*(z0wr2+(vz*t2h1d2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1d2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1d2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1d2+z))*(z0wl2+(vz*t2h1d2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1d2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1d2+x;
  ylimitd=-sqrt(pbhd2-(vz*t2h1d2+z)/pahd2);
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd2>0 ){
  i=92;
  }else{
  i=101;
  }
  }

															/* neutron interacts with the straight down INNER wall - comments are analog to inner elliptic right wall*/

  if (myd2!=-1 && t2h1d2 > 0 && t2h1d2 < t1 && t2h1d2 < t2w1r && t2h1d2 <t2w1l && t2h1d2 < t2h1u && t2h1d2 < t2h1d && t2h1d2 <t2w1rwt && t2h1d2 <t2w1lwt && t2h1d2 < t2h1uwt && t2h1d2 < t2h1dwt && t2h1d2 < t2w1r1 && t2h1d2 < t2w1l1 && t2h1d2 < t2h1u1 && t2h1d2 < t2h1d1 && t2h1d2 <t2w1rwt1 && t2h1d2 <t2w1lwt1 && t2h1d2 < t2h1uwt1 && t2h1d2 < t2h1dwt1 && t2h1d2 <t2w1r2 && t2h1d2 < t2w1l2 && t2h1d2 < t2h1u2 && t2h1d2 <t2w1rwt2 && t2h1d2 <t2w1lwt2 && t2h1d2 < t2h1uwt2 && t2h1d2 < t2h1dwt2 && (louthd2 == 0 && linhd2 == 0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1d2+z)-w1r2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwr2*sqrt(1-((z0wr2+(vz*t2h1d2+z))*(z0wr2+(vz*t2h1d2+z)))/a2wr2);
    }else{
    xlimitr=-sqrt(((vz*t2h1d2+z)-pbwr2)/-pawr2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1d2+z)+w1l2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwl2*sqrt(1-((z0wl2+(vz*t2h1d2+z))*(z0wl2+(vz*t2h1d2+z)))/a2wl2);
      }else{
      xlimitl=sqrt(((vz*t2h1d2+z)-pbwl2)/-pawl2);
      }
   }
  xtest=vx*t2h1d2+x;
  ylimitd=(-h2d2+h1d2)*(vz*t2h1d2+z)/l-h1d2;
  if (xtest>=xlimitr && xtest<=xlimitl && y>=ylimitd && myd2>0 ){
  i=93;
  }else{
  i=101;
  }
  }

   /* SAME INTERACTIONS BUT TRANSPERENT INNER WALLS - in these cases no limit check up is needed , because will neutrons will pass unchanged anyway*/

  if (mxr2==-1 && t2w1r2 > 0 && t2w1r2 < t1 && t2w1r2 < t2w1r && t2w1r2 <t2w1l && t2w1r2 < t2h1u && t2w1r2 < t2h1d && t2w1r2 <t2w1rwt && t2w1r2 <t2w1lwt && t2w1r2 < t2h1uwt && t2w1r2 < t2h1dwt && t2w1r2 < t2w1r1 && t2w1r2 < t2w1l1 && t2w1r2 < t2h1u1 && t2w1r2 < t2h1d1 && t2w1r2 <t2w1rwt1 && t2w1r2 <t2w1lwt1 && t2w1r2 < t2h1uwt1 && t2w1r2 < t2h1dwt1 && t2w1r2 <t2w1l2 && t2w1r2 < t2h1u2 && t2w1r2 < t2h1d2 && t2w1r2 <t2w1rwt2 && t2w1r2 <t2w1lwt2 && t2w1r2 < t2h1uwt2 && t2w1r2 < t2h1dwt2 && ((linwr2!=0) && (loutwr2!=0) )) {
  i=94;
  }

  if (mxr2==-1 && t2w1r2 > 0 && t2w1r2 < t1 && t2w1r2 < t2w1r && t2w1r2 <t2w1l && t2w1r2 < t2h1u && t2w1r2 < t2h1d && t2w1r2 <t2w1rwt && t2w1r2 <t2w1lwt && t2w1r2 < t2h1uwt && t2w1r2 < t2h1dwt && t2w1r2 < t2w1r1 && t2w1r2 < t2w1l1 && t2w1r2 < t2h1u1 && t2w1r2 < t2h1d1 && t2w1r2 <t2w1rwt1 && t2w1r2 <t2w1lwt1 && t2w1r2 < t2h1uwt1 && t2w1r2 < t2h1dwt1 && t2w1r2 <t2w1l2 && t2w1r2 < t2h1u2 && t2w1r2 < t2h1d2 && t2w1r2 <t2w1rwt2 && t2w1r2 <t2w1lwt2 && t2w1r2 < t2h1uwt2 && t2w1r2 < t2h1dwt2 && ((loutwr2!=0 && linwr2==0) || (loutwr2==0 && linwr2!=0))){
  i=94;
  }

  if (mxr2==-1 && t2w1r2 > 0 && t2w1r2 < t1 && t2w1r2 < t2w1r && t2w1r2 <t2w1l && t2w1r2 < t2h1u && t2w1r2 < t2h1d && t2w1r2 <t2w1rwt && t2w1r2 <t2w1lwt && t2w1r2 < t2h1uwt && t2w1r2 < t2h1dwt && t2w1r2 < t2w1r1 && t2w1r2 < t2w1l1 && t2w1r2 < t2h1u1 && t2w1r2 < t2h1d1 && t2w1r2 <t2w1rwt1 && t2w1r2 <t2w1lwt1 && t2w1r2 < t2h1uwt1 && t2w1r2 < t2h1dwt1 && t2w1r2 <t2w1l2 && t2w1r2 < t2h1u2 && t2w1r2 < t2h1d2 && t2w1r2 <t2w1rwt2 && t2w1r2 <t2w1lwt2 && t2w1r2 < t2h1uwt2 && t2w1r2 < t2h1dwt2 && (loutwr2==0 && linwr2==0)){
  i=94;
  }

  if (mxl2==-1 && t2w1l2 > 0 && t2w1l2 < t1 && t2w1l2 < t2w1r && t2w1l2 <t2w1l && t2w1l2 < t2h1u && t2w1l2 < t2h1d && t2w1l2 <t2w1rwt && t2w1l2 <t2w1lwt && t2w1l2 < t2h1uwt && t2w1l2 < t2h1dwt && t2w1l2 < t2w1r1 && t2w1l2 < t2w1l1 && t2w1l2 < t2h1u1 && t2w1l2 < t2h1d1 && t2w1l2 <t2w1rwt1 && t2w1l2 <t2w1lwt1 && t2w1l2 < t2h1uwt1 && t2w1l2 < t2h1dwt1 && t2w1l2 <t2w1r2 && t2w1l2 < t2h1u2 && t2w1l2 < t2h1d2 && t2w1l2 <t2w1rwt2 && t2w1l2 <t2w1lwt2 && t2w1l2 < t2h1uwt2 && t2w1l2 < t2h1dwt2 && ((linwl2!=0) && (loutwl2!=0) )){
  i=95;
  }

  if (mxl2==-1 && t2w1l2 > 0 && t2w1l2 < t1 && t2w1l2 < t2w1r && t2w1l2 <t2w1l && t2w1l2 < t2h1u && t2w1l2 < t2h1d && t2w1l2 <t2w1rwt && t2w1l2 <t2w1lwt && t2w1l2 < t2h1uwt && t2w1l2 < t2h1dwt && t2w1l2 < t2w1r1 && t2w1l2 < t2w1l1 && t2w1l2 < t2h1u1 && t2w1l2 < t2h1d1 && t2w1l2 <t2w1rwt1 && t2w1l2 <t2w1lwt1 && t2w1l2 < t2h1uwt1 && t2w1l2 < t2h1dwt1 && t2w1l2 <t2w1r2 && t2w1l2 < t2h1u2 && t2w1l2 < t2h1d2 && t2w1l2 <t2w1rwt2 && t2w1l2 <t2w1lwt2 && t2w1l2 < t2h1uwt2 && t2w1l2 < t2h1dwt2 &&  ((loutwl2!=0 && linwl2==0) || (loutwl2==0 && linwl2!=0))){
  i=95;
  }

  if (mxl2==-1 && t2w1l2 > 0 && t2w1l2 < t1 && t2w1l2 < t2w1r && t2w1l2 <t2w1l && t2w1l2 < t2h1u && t2w1l2 < t2h1d && t2w1l2 <t2w1rwt && t2w1l2 <t2w1lwt && t2w1l2 < t2h1uwt && t2w1l2 < t2h1dwt && t2w1l2 < t2w1r1 && t2w1l2 < t2w1l1 && t2w1l2 < t2h1u1 && t2w1l2 < t2h1d1 && t2w1l2 <t2w1rwt1 && t2w1l2 <t2w1lwt1 && t2w1l2 < t2h1uwt1 && t2w1l2 < t2h1dwt1 && t2w1l2 <t2w1r2 && t2w1l2 < t2h1u2 && t2w1l2 < t2h1d2 && t2w1l2 <t2w1rwt2 && t2w1l2 <t2w1lwt2 && t2w1l2 < t2h1uwt2 && t2w1l2 < t2h1dwt2 && (loutwl2==0 && linwl2==0)){
  i=95;
  }

  if (myu2==-1 && t2h1u2 > 0 && t2h1u2 < t1 && t2h1u2 < t2w1r && t2h1u2 <t2w1l && t2h1u2 < t2h1u && t2h1u2 < t2h1d && t2h1u2 <t2w1rwt && t2h1u2 <t2w1lwt && t2h1u2 < t2h1uwt && t2h1u2 < t2h1dwt && t2h1u2 < t2w1r1 && t2h1u2 < t2w1l1 && t2h1u2 < t2h1u1 && t2h1u2 < t2h1d1 && t2h1u2 <t2w1rwt1 && t2h1u2 <t2w1lwt1 && t2h1u2 < t2h1uwt1 && t2h1u2 < t2h1dwt1 && t2h1u2 <t2w1r2 && t2h1u2 < t2w1l2 && t2h1u2 < t2h1d2 && t2h1u2 <t2w1rwt2 && t2h1u2 <t2w1lwt2 && t2h1u2 < t2h1uwt2 && t2h1u2 < t2h1dwt2 && (louthu2 !=0 && linhu2!=0)){
  i=96;
  }

  if (myu2==-1 && t2h1u2 > 0 && t2h1u2 < t1 && t2h1u2 < t2w1r && t2h1u2 <t2w1l && t2h1u2 < t2h1u && t2h1u2 < t2h1d && t2h1u2 <t2w1rwt && t2h1u2 <t2w1lwt && t2h1u2 < t2h1uwt && t2h1u2 < t2h1dwt && t2h1u2 < t2w1r1 && t2h1u2 < t2w1l1 && t2h1u2 < t2h1u1 && t2h1u2 < t2h1d1 && t2h1u2 <t2w1rwt1 && t2h1u2 <t2w1lwt1 && t2h1u2 < t2h1uwt1 && t2h1u2 < t2h1dwt1 && t2h1u2 <t2w1r2 && t2h1u2 < t2w1l2 && t2h1u2 < t2h1d2 && t2h1u2 <t2w1rwt2 && t2h1u2 <t2w1lwt2 && t2h1u2 < t2h1uwt2 && t2h1u2 < t2h1dwt2 && ((louthu2!=0 && linhu2==0) || (louthu2==0 && linhu2!=0))){
  i=96;
  }

  if (myu2==-1 && t2h1u2 > 0 && t2h1u2 < t1 && t2h1u2 < t2w1r && t2h1u2 <t2w1l && t2h1u2 < t2h1u && t2h1u2 < t2h1d && t2h1u2 <t2w1rwt && t2h1u2 <t2w1lwt && t2h1u2 < t2h1uwt && t2h1u2 < t2h1dwt && t2h1u2 < t2w1r1 && t2h1u2 < t2w1l1 && t2h1u2 < t2h1u1 && t2h1u2 < t2h1d1 && t2h1u2 <t2w1rwt1 && t2h1u2 <t2w1lwt1 && t2h1u2 < t2h1uwt1 && t2h1u2 < t2h1dwt1 && t2h1u2 <t2w1r2 && t2h1u2 < t2w1l2 && t2h1u2 < t2h1d2 && t2h1u2 <t2w1rwt2 && t2h1u2 <t2w1lwt2 && t2h1u2 < t2h1uwt2 && t2h1u2 < t2h1dwt2 && (louthu2 == 0 && linhu2 == 0)){
  i=96;
  }

  if (myd2==-1 && t2h1d2 > 0 && t2h1d2 < t1 && t2h1d2 < t2w1r && t2h1d2 <t2w1l && t2h1d2 < t2h1u && t2h1d2 < t2h1d && t2h1d2 <t2w1rwt && t2h1d2 <t2w1lwt && t2h1d2 < t2h1uwt && t2h1d2 < t2h1dwt && t2h1d2 < t2w1r1 && t2h1d2 < t2w1l1 && t2h1d2 < t2h1u1 && t2h1d2 < t2h1d1 && t2h1d2 <t2w1rwt1 && t2h1d2 <t2w1lwt1 && t2h1d2 < t2h1uwt1 && t2h1d2 < t2h1dwt1 && t2h1d2 <t2w1r2 && t2h1d2 < t2w1l2 && t2h1d2 < t2h1u2 && t2h1d2 <t2w1rwt2 && t2h1d2 <t2w1lwt2 && t2h1d2 < t2h1uwt2 && t2h1d2 < t2h1dwt2 && (louthd2 !=0 && linhd2!=0)){
  i=97;
  }

  if (myd2==-1 && t2h1d2 > 0 && t2h1d2 < t1 && t2h1d2 < t2w1r && t2h1d2 <t2w1l && t2h1d2 < t2h1u && t2h1d2 < t2h1d && t2h1d2 <t2w1rwt && t2h1d2 <t2w1lwt && t2h1d2 < t2h1uwt && t2h1d2 < t2h1dwt && t2h1d2 < t2w1r1 && t2h1d2 < t2w1l1 && t2h1d2 < t2h1u1 && t2h1d2 < t2h1d1 && t2h1d2 <t2w1rwt1 && t2h1d2 <t2w1lwt1 && t2h1d2 < t2h1uwt1 && t2h1d2 < t2h1dwt1 && t2h1d2 <t2w1r2 && t2h1d2 < t2w1l2 && t2h1d2 < t2h1u2 && t2h1d2 <t2w1rwt2 && t2h1d2 <t2w1lwt2 && t2h1d2 < t2h1uwt2 && t2h1d2 < t2h1dwt2 && ((louthd2 !=0 && linhd2==0) || (louthd2 ==0 && linhd2!=0))){
  i=97;
  }

  if (myd2==-1 && t2h1d2 > 0 && t2h1d2 < t1 && t2h1d2 < t2w1r && t2h1d2 <t2w1l && t2h1d2 < t2h1u && t2h1d2 < t2h1d && t2h1d2 <t2w1rwt && t2h1d2 <t2w1lwt && t2h1d2 < t2h1uwt && t2h1d2 < t2h1dwt && t2h1d2 < t2w1r1 && t2h1d2 < t2w1l1 && t2h1d2 < t2h1u1 && t2h1d2 < t2h1d1 && t2h1d2 <t2w1rwt1 && t2h1d2 <t2w1lwt1 && t2h1d2 < t2h1uwt1 && t2h1d2 < t2h1dwt1 && t2h1d2 <t2w1r2 && t2h1d2 < t2w1l2 && t2h1d2 < t2h1u2 && t2h1d2 <t2w1rwt2 && t2h1d2 <t2w1lwt2 && t2h1d2 < t2h1uwt2 && t2h1d2 < t2h1dwt2 && (louthd2 == 0 && linhd2 == 0)){
  i=97;
  }

   
												/* EVERTHING AGAIN FOR THE OUTER WALLS */

												/* neutron interacts with the elliptic right OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxrOW2!=-1 && t2w1rwt2 > 0 && t2w1rwt2 < t1 && t2w1rwt2 < t2w1r && t2w1rwt2 <t2w1l && t2w1rwt2 < t2h1u && t2w1rwt2 < t2h1d && t2w1rwt2 <t2w1rwt && t2w1rwt2 <t2w1lwt && t2w1rwt2 < t2h1uwt && t2w1rwt2 < t2h1dwt && t2w1rwt2 < t2w1r1 && t2w1rwt2 < t2w1l1 && t2w1rwt2 < t2h1u1 && t2w1rwt2 < t2h1d1 && t2w1rwt2 <t2w1rwt1 && t2w1rwt2 <t2w1lwt1 && t2w1rwt2 < t2h1uwt1 && t2w1rwt2 < t2h1dwt1 && t2w1rwt2 <t2w1r2 && t2w1rwt2 <t2w1l2 && t2w1rwt2 < t2h1u2 && t2w1rwt2 < t2h1d2 && t2w1rwt2 <t2w1lwt2 && t2w1rwt2 < t2h1uwt2 && t2w1rwt2 < t2h1dwt2 && ((linwr2!=0) && (loutwr2!=0) )){	
   if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1rwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1rwt2+z))*(z0hd2+(vz*t2w1rwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1rwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1rwt2+z))*(z0hu2+(vz*t2w1rwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1rwt2+y;
  xtest=vx*t2w1rwt2+x;
  xlimitrwt=-bwrwt2*sqrt(1-((vz*t2w1rwt2+z)+z0wr2)*((vz*t2w1rwt2+z)+z0wr2)/a2wrwt2);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest<=xlimitr && mxrOW2 > 0){
  i=102;
  }
  else{
  i=114;
  }
  }

													/* neutron interacts with the parabolic right OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxrOW2!=-1 && t2w1rwt2 > 0 && t2w1rwt2 < t1 && t2w1rwt2 < t2w1r && t2w1rwt2 <t2w1l && t2w1rwt2 < t2h1u && t2w1rwt2 < t2h1d && t2w1rwt2 <t2w1rwt && t2w1rwt2 <t2w1lwt && t2w1rwt2 < t2h1uwt && t2w1rwt2 < t2h1dwt && t2w1rwt2 < t2w1r1 && t2w1rwt2 < t2w1l1 && t2w1rwt2 < t2h1u1 && t2w1rwt2 < t2h1d1 && t2w1rwt2 <t2w1rwt1 && t2w1rwt2 <t2w1lwt1 && t2w1rwt2 < t2h1uwt1 && t2w1rwt2 < t2h1dwt1 && t2w1rwt2 <t2w1r2 && t2w1rwt2 <t2w1l2 && t2w1rwt2 < t2h1u2 && t2w1rwt2 < t2h1d2 && t2w1rwt2 <t2w1lwt2 && t2w1rwt2 < t2h1uwt2 && t2w1rwt2 < t2h1dwt2 && ((loutwr2!=0 && linwr2==0) || (loutwr2==0 && linwr2!=0))){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1rwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1rwt2+z))*(z0hd2+(vz*t2w1rwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1rwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1rwt2+z))*(z0hu2+(vz*t2w1rwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1rwt2+y;
  xtest=vx*t2w1rwt2+x;
  xlimitr=-sqrt((pbwrwt2-(vz*t2w1rwt2+z))/pawrwt2);
  if (ytest>ylimitd && ytest<ylimitu && xtest<=xlimitr && mxrOW2 > 0){
  i=103; 
  }else{
  i=114;}
  }

													/* neutron interacts with the straight right OUTER wall - comments are analog to inner elliptic right wall */

  if (mxrOW2!=-1 && t2w1rwt2 > 0 && t2w1rwt2 < t1 && t2w1rwt2 < t2w1r && t2w1rwt2 <t2w1l && t2w1rwt2 < t2h1u && t2w1rwt2 < t2h1d && t2w1rwt2 <t2w1rwt && t2w1rwt2 <t2w1lwt && t2w1rwt2 < t2h1uwt && t2w1rwt2 < t2h1dwt && t2w1rwt2 < t2w1r1 && t2w1rwt2 < t2w1l1 && t2w1rwt2 < t2h1u1 && t2w1rwt2 < t2h1d1 && t2w1rwt2 <t2w1rwt1 && t2w1rwt2 <t2w1lwt1 && t2w1rwt2 < t2h1uwt1 && t2w1rwt2 < t2h1dwt1 && t2w1rwt2 <t2w1r2 && t2w1rwt2 <t2w1l2 && t2w1rwt2 < t2h1u2 && t2w1rwt2 < t2h1d2 && t2w1rwt2 <t2w1lwt2 && t2w1rwt2 < t2h1uwt2 && t2w1rwt2 < t2h1dwt2 &&  (loutwr2==0 && linwr2==0)){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1rwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1rwt2+z))*(z0hd2+(vz*t2w1rwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1rwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1rwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1rwt2+z))*(z0hu2+(vz*t2w1rwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1rwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1rwt2+y; 
  xtest=vx*t2w1rwt2+x;
  xlimitr=-(-w2r2+w1r2)*(vz*t2w1rwt2+z)/l-w1rwt2;
  if(ytest>=ylimitd && ytest<=ylimitu && xtest<=xlimitr && mxrOW2>0){
  i=104;
  }else{
  i=114;
  }
  }

													/* neutron interacts with the elliptic left OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxlOW2!=-1 && t2w1lwt2 > 0 && t2w1lwt2 < t1 && t2w1lwt2 < t2w1r && t2w1lwt2 <t2w1l && t2w1lwt2 < t2h1u && t2w1lwt2 < t2h1d && t2w1lwt2 <t2w1rwt && t2w1lwt2 <t2w1lwt && t2w1lwt2 < t2h1uwt && t2w1lwt2 < t2h1dwt && t2w1lwt2 < t2w1r1 && t2w1lwt2 < t2w1l1 && t2w1lwt2 < t2h1u1 && t2w1lwt2 < t2h1d1 && t2w1lwt2 <t2w1rwt1 && t2w1lwt2 <t2w1lwt1 && t2w1lwt2 < t2h1uwt1 && t2w1lwt2 < t2h1dwt1 && t2w1lwt2 <t2w1r2 && t2w1lwt2 <t2w1l2 && t2w1lwt2 < t2h1u2 && t2w1lwt2 < t2h1d2 && t2w1lwt2 <t2w1rwt2 && t2w1lwt2 < t2h1uwt2 && t2w1lwt2 < t2h1dwt2 &&  ((linwl2!=0) && (loutwl2!=0) )){
  if(linhd2==0 && louthd2==0)
   if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1lwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1lwt2+z))*(z0hd2+(vz*t2w1lwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1lwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1lwt2+z))*(z0hu2+(vz*t2w1lwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1lwt2+y;
  xtest=vx*t2w1lwt2+x;
  xlimitlwt=-bwlwt2*sqrt(1-((vz*t2w1lwt2+z)+z0wl2)*((vz*t2w1lwt2+z)+z0wl2)/a2wlwt2);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW2>0){
  i=105;
  }else{
  i=115;
  }
  }

													/* neutron interacts with the parabolic left OUTER wall - comments are analog to inner elliptic right wall */

  if (mxlOW2!=-1 &&& t2w1lwt2 > 0 && t2w1lwt2 < t1 && t2w1lwt2 < t2w1r && t2w1lwt2 <t2w1l && t2w1lwt2 < t2h1u && t2w1lwt2 < t2h1d && t2w1lwt2 <t2w1rwt && t2w1lwt2 <t2w1lwt && t2w1lwt2 < t2h1uwt && t2w1lwt2 < t2h1dwt && t2w1lwt2 < t2w1r1 && t2w1lwt2 < t2w1l1 && t2w1lwt2 < t2h1u1 && t2w1lwt2 < t2h1d1 && t2w1lwt2 <t2w1rwt1 && t2w1lwt2 <t2w1lwt1 && t2w1lwt2 < t2h1uwt1 && t2w1lwt2 < t2h1dwt1 && t2w1lwt2 <t2w1r2 && t2w1lwt2 <t2w1l2 && t2w1lwt2 < t2h1u2 && t2w1lwt2 < t2h1d2 && t2w1lwt2 <t2w1rwt2 && t2w1lwt2 < t2h1uwt2 && t2w1lwt2 < t2h1dwt2 && ((loutwl2!=0 && linwl2==0) || (loutwl2==0 && linwl2!=0))){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1lwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1lwt2+z))*(z0hd2+(vz*t2w1lwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1lwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1lwt2+z))*(z0hu2+(vz*t2w1lwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1lwt2+y;
  xtest=vx*t2w1lwt2+x;
  xlimitl=-sqrt((pbwlwt2-(vz*t2w1lwt2+z))/pawlwt2);
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW2>0){
  i=106;
  }else{
  i=115;
  }
  }

														/* neutron interacts with the straight left OUTER wall - comments are analog to inner elliptic right wall*/

  if (mxlOW2!=-1 && t2w1lwt2 > 0 && t2w1lwt2 < t1 && t2w1lwt2 < t2w1r && t2w1lwt2 <t2w1l && t2w1lwt2 < t2h1u && t2w1lwt2 < t2h1d && t2w1lwt2 <t2w1rwt && t2w1lwt2 <t2w1lwt && t2w1lwt2 < t2h1uwt && t2w1lwt2 < t2h1dwt && t2w1lwt2 < t2w1r1 && t2w1lwt2 < t2w1l1 && t2w1lwt2 < t2h1u1 && t2w1lwt2 < t2h1d1 && t2w1lwt2 <t2w1rwt1 && t2w1lwt2 <t2w1lwt1 && t2w1lwt2 < t2h1uwt1 && t2w1lwt2 < t2h1dwt1 && t2w1lwt2 <t2w1r2 && t2w1lwt2 <t2w1l2 && t2w1lwt2 < t2h1u2 && t2w1lwt2 < t2h1d2 && t2w1lwt2 <t2w1rwt2 && t2w1lwt2 < t2h1uwt2 && t2w1lwt2 < t2h1dwt2 && (loutwl2==0 && linwl2==0)){
  if(linhd2==0 && louthd2==0)
   {
      ylimitd=(-h2d2+h1d2)/l*(vz*t2w1lwt2+z)-h1dwt2;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ylimitd=-bhdwt2*sqrt(1-((z0hd2+(vz*t2w1lwt2+z))*(z0hd2+(vz*t2w1lwt2+z)))/a2hdwt2);
      }else{
      ylimitd=-sqrt(((vz*t2w1lwt2+z)-pbhdwt2)/-pahdwt2);
      }
   }
   if(linhu2==0 && louthu2==0)
    {
     ylimitu=(h2u2-h1u2)/l*(vz*t2w1lwt2+z)+h1uwt2;
    }else{
     if(linhu2!=0 && louthu2!=0)
     {
     ylimitu=bhuwt2*sqrt(1-((z0hu2+(vz*t2w1lwt2+z))*(z0hu2+(vz*t2w1lwt2+z)))/a2huwt2);
     }else{
     ylimitu=sqrt(((vz*t2w1lwt2+z)-pbhuwt2)/-pahuwt2);
    }
    }
  ytest=vy*t2w1lwt2+y; 
  xtest=vx*t2w1lwt2+x;
  xlimitl=(w2l2-w1l2)*(vz*t2w1lwt2+z)/l+w1lwt2;
  if (ytest>=ylimitd && ytest<=ylimitu && xtest>=xlimitl && mxlOW2>0){
  i=107;
  }else{
  i=115;
  }
  }

															/* neutron interacts with the elliptic top OUTER wall - comments are analog to inner elliptic right wall*/

  if (myuOW2!=-1 && t2h1uwt2 > 0 && t2h1uwt2 < t1 && t2h1uwt2 < t2w1r && t2h1uwt2 <t2w1l && t2h1uwt2 < t2h1u && t2h1uwt2 < t2h1d && t2h1uwt2 <t2w1rwt && t2h1uwt2 <t2w1lwt && t2h1uwt2 < t2h1uwt && t2h1uwt2 < t2h1dwt && t2h1uwt2 < t2w1r1 && t2h1uwt2 < t2w1l1 && t2h1uwt2 < t2h1u1 && t2h1uwt2 < t2h1d1 && t2h1uwt2 <t2w1rwt1 && t2h1uwt2 <t2w1lwt1 && t2h1uwt2 < t2h1uwt1 && t2h1uwt2 < t2h1dwt1 && t2h1uwt2 <t2w1r2 && t2h1uwt2 <t2w1l2 && t2h1uwt2 < t2h1u2 && t2h1uwt2 < t2h1d2 && t2h1uwt2 <t2w1rwt2 && t2h1uwt2 < t2w1lwt2 && t2h1uwt2 < t2h1dwt2 && (louthu2 !=0 && linhu2!=0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1uwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1uwt2+z))*(z0wr2+(vz*t2h1uwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1uwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1uwt2+z))*(z0wl2+(vz*t2h1uwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1uwt2+x;
  ytest=vy*t2w1lwt2+y;
  ylimitu=bhuwt2*sqrt(1-((vz*t2h1uwt2+z)+z0hu2)*((vz*t2h1uwt2+z)+z0hu2)/a2huwt2);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW2>0 ){
  i=108;
  }else{
  i=116;
  }
  }
	
															/* neutron interacts with the parabolic top OUTER wall - comments are analog to inner elliptic right wall */

  if (myuOW2!=-1 && t2h1uwt2 > 0 && t2h1uwt2 < t1 && t2h1uwt2 < t2w1r && t2h1uwt2 <t2w1l && t2h1uwt2 < t2h1u && t2h1uwt2 < t2h1d && t2h1uwt2 <t2w1rwt && t2h1uwt2 <t2w1lwt && t2h1uwt2 < t2h1uwt && t2h1uwt2 < t2h1dwt && t2h1uwt2 < t2w1r1 && t2h1uwt2 < t2w1l1 && t2h1uwt2 < t2h1u1 && t2h1uwt2 < t2h1d1 && t2h1uwt2 <t2w1rwt1 && t2h1uwt2 <t2w1lwt1 && t2h1uwt2 < t2h1uwt1 && t2h1uwt2 < t2h1dwt1 && t2h1uwt2 <t2w1r2 && t2h1uwt2 <t2w1l2 && t2h1uwt2 < t2h1u2 && t2h1uwt2 < t2h1d2 && t2h1uwt2 <t2w1rwt2 && t2h1uwt2 < t2w1lwt2 && t2h1uwt2 < t2h1dwt2 && ((louthu2!=0 && linhu2==0) || (louthu2==0 && linhu2!=0))){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1uwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1uwt2+z))*(z0wr2+(vz*t2h1uwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1uwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1uwt2+z))*(z0wl2+(vz*t2h1uwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1uwt2+x;
  ytest=vy*t2w1lwt2+y;
  ylimitu=sqrt((pbhuwt2-(vz*t2h1uwt2+z))/pahuwt2);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW2>0){
  i=109;
  }else{
  i=116;
  }
  }


															/* neutron interacts with the straight top OUTER wall - comments are analog to inner elliptic right wall*/

  if (myuOW2!=-1 && t2h1uwt2 > 0 && t2h1uwt2 < t1 && t2h1uwt2 < t2w1r && t2h1uwt2 <t2w1l && t2h1uwt2 < t2h1u && t2h1uwt2 < t2h1d && t2h1uwt2 <t2w1rwt && t2h1uwt2 <t2w1lwt && t2h1uwt2 < t2h1uwt && t2h1uwt2 < t2h1dwt && t2h1uwt2 < t2w1r1 && t2h1uwt2 < t2w1l1 && t2h1uwt2 < t2h1u1 && t2h1uwt2 < t2h1d1 && t2h1uwt2 <t2w1rwt1 && t2h1uwt2 <t2w1lwt1 && t2h1uwt2 < t2h1uwt1 && t2h1uwt2 < t2h1dwt1 && t2h1uwt2 <t2w1r2 && t2h1uwt2 <t2w1l2 && t2h1uwt2 < t2h1u2 && t2h1uwt2 < t2h1d2 && t2h1uwt2 <t2w1rwt2 && t2h1uwt2 < t2w1lwt2 && t2h1uwt2 < t2h1dwt2 && (louthu2 == 0 && linhu2 == 0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1uwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1uwt2+z))*(z0wr2+(vz*t2h1uwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1uwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1uwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1uwt2+z))*(z0wl2+(vz*t2h1uwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1uwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1uwt2+x;
  ytest=vy*t2w1lwt2+y;
  ylimitu=(h2u2-h1u2)*(vz*t2h1uwt2+z)/l+h1uwt2;
  if (xtest>=xlimitr && xtest<=xlimitl && ytest>=ylimitu && myuOW2>0 ){
  i=110;
  }else{
  i=116;
  }
  }

															/* neutron interacts with the elliptic down OUTER wall - comments are analog to inner elliptic right wall*/

  if (mydOW2!=-1 && t2h1dwt2 > 0 && t2h1dwt2 < t1 && t2h1dwt2 < t2w1r && t2h1dwt2 <t2w1l && t2h1dwt2 < t2h1u && t2h1dwt2 < t2h1d && t2h1dwt2 <t2w1rwt && t2h1dwt2 <t2w1lwt && t2h1dwt2 < t2h1uwt && t2h1dwt2 < t2h1dwt && t2h1dwt2 < t2w1r1 && t2h1dwt2 < t2w1l1 && t2h1dwt2 < t2h1u1 && t2h1dwt2 < t2h1d1 && t2h1dwt2 <t2w1rwt1 && t2h1dwt2 <t2w1lwt1 && t2h1dwt2 < t2h1uwt1 && t2h1dwt2 < t2h1dwt1 && t2h1dwt2 <t2w1r2 && t2h1dwt2 <t2w1l2 && t2h1dwt2 < t2h1u2 && t2h1dwt2 < t2h1d2 && t2h1dwt2 <t2w1rwt2 && t2h1dwt2 < t2w1lwt2 && t2h1dwt2 < t2h1uwt2 && (louthd2 !=0 && linhd2!=0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1dwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1dwt2+z))*(z0wr2+(vz*t2h1dwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1dwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1dwt2+z))*(z0wl2+(vz*t2h1dwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1dwt2+x;
  ytest=vy*t2w1lwt2+y;
  ylimitd=-bhdwt2*sqrt(1-((vz*t2h1dwt2+z)+z0hd2)*((vz*t2h1dwt2+z)+z0hd2)/a2hdwt2);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW2>0){
  i=111;
  }else{
  i=117;
  }
  }

															/* neutron interacts with the parabolic down OUTER wall - comments are analog to inner elliptic right wall */

  if (mydOW2!=-1 && t2h1dwt2 > 0 && t2h1dwt2 < t1 && t2h1dwt2 < t2w1r && t2h1dwt2 <t2w1l && t2h1dwt2 < t2h1u && t2h1dwt2 < t2h1d && t2h1dwt2 <t2w1rwt && t2h1dwt2 <t2w1lwt && t2h1dwt2 < t2h1uwt && t2h1dwt2 < t2h1dwt && t2h1dwt2 < t2w1r1 && t2h1dwt2 < t2w1l1 && t2h1dwt2 < t2h1u1 && t2h1dwt2 < t2h1d1 && t2h1dwt2 <t2w1rwt1 && t2h1dwt2 <t2w1lwt1 && t2h1dwt2 < t2h1uwt1 && t2h1dwt2 < t2h1dwt1 && t2h1dwt2 <t2w1r2 && t2h1dwt2 <t2w1l2 && t2h1dwt2 < t2h1u2 && t2h1dwt2 < t2h1d2 && t2h1dwt2 <t2w1rwt2 && t2h1dwt2 < t2w1lwt2 && t2h1dwt2 < t2h1uwt2 && ((louthd2 !=0 && linhd2==0) || (louthd2 ==0 && linhd2!=0))){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1dwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1dwt2+z))*(z0wr2+(vz*t2h1dwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
     xlimitl=(w2l2-w1l2)/l*(vz*t2h1dwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1dwt2+z))*(z0wl2+(vz*t2h1dwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1dwt2+x;
  ytest=vy*t2w1lwt2+y;
  ylimitd=-sqrt((pbhdwt2-(vz*t2h1dwt2+z))/pahdwt2);
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW2>0 ){
  i=112;
  }else{
  i=117;
  }
  }

															/* neutron interacts with the straight down OUTER wall - comments are analog to inner elliptic right wall*/

  if (mydOW2!=-1 && t2h1dwt2 > 0 && t2h1dwt2 < t1 && t2h1dwt2 < t2w1r && t2h1dwt2 <t2w1l && t2h1dwt2 < t2h1u && t2h1dwt2 < t2h1d && t2h1dwt2 <t2w1rwt && t2h1dwt2 <t2w1lwt && t2h1dwt2 < t2h1uwt && t2h1dwt2 < t2h1dwt && t2h1dwt2 < t2w1r1 && t2h1dwt2 < t2w1l1 && t2h1dwt2 < t2h1u1 && t2h1dwt2 < t2h1d1 && t2h1dwt2 <t2w1rwt1 && t2h1dwt2 <t2w1lwt1 && t2h1dwt2 < t2h1uwt1 && t2h1dwt2 < t2h1dwt1 && t2h1dwt2 <t2w1r2 && t2h1dwt2 <t2w1l2 && t2h1dwt2 < t2h1u2 && t2h1dwt2 < t2h1d2 && t2h1dwt2 <t2w1rwt2 && t2h1dwt2 < t2w1lwt2 && t2h1dwt2 < t2h1uwt2 && (louthd2 == 0 && linhd2 == 0)){
  if(linwr2==0 && loutwr2==0)
  {
    xlimitr=(-w2r2+w1r2)/l*(vz*t2h1dwt2+z)-w1rwt2;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xlimitr=-bwrwt2*sqrt(1-((z0wr2+(vz*t2h1dwt2+z))*(z0wr2+(vz*t2h1dwt2+z)))/a2wrwt2);
    }else{
    xlimitr=-sqrt(((vz*t2h1dwt2+z)-pbwrwt2)/-pawrwt2);
    }
  }
  if(linwl2==0 && loutwl2 == 0)
   {
      xlimitl=(w2l2-w1l2)/l*(vz*t2h1dwt2+z)+w1lwt2;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xlimitl=bwlwt2*sqrt(1-((z0wl2+(vz*t2h1dwt2+z))*(z0wl2+(vz*t2h1dwt2+z)))/a2wlwt2);
      }else{
      xlimitl=sqrt(((vz*t2h1dwt2+z)-pbwlwt2)/-pawlwt2);
      }
   }
  xtest=vx*t2h1dwt2+x;
  ytest=vy*t2w1lwt2+y;
  ylimitd=(-h2d2+h1d2)*(vz*t2h1dwt2+z)/l-h1dwt2;
  if (xtest>=xlimitr && xtest<=xlimitl && ytest<=ylimitd && mydOW2>0 ){
  i=113;
  }else{
  i=117;
  }
  }


  if (mxrOW2==-1 && t2w1rwt2 > 0 && t2w1rwt2 < t1 && t2w1rwt2 < t2w1r && t2w1rwt2 <t2w1l && t2w1rwt2 < t2h1u && t2w1rwt2 < t2h1d && t2w1rwt2 <t2w1rwt && t2w1rwt2 <t2w1lwt && t2w1rwt2 < t2h1uwt && t2w1rwt2 < t2h1dwt && t2w1rwt2 < t2w1r1 && t2w1rwt2 < t2w1l1 && t2w1rwt2 < t2h1u1 && t2w1rwt2 < t2h1d1 && t2w1rwt2 <t2w1rwt1 && t2w1rwt2 <t2w1lwt1 && t2w1rwt2 < t2h1uwt1 && t2w1rwt2 < t2h1dwt1 && t2w1rwt2 <t2w1r2 && t2w1rwt2 <t2w1l2 && t2w1rwt2 < t2h1u2 && t2w1rwt2 < t2h1d2 && t2w1rwt2 <t2w1lwt2 && t2w1rwt2 < t2h1uwt2 && t2w1rwt2 < t2h1dwt2 &&  ((linwr2!=0) && (loutwr2!=0) )) {
  i=118;
  }

  if (mxrOW2==-1 && t2w1rwt2 > 0 && t2w1rwt2 < t1 && t2w1rwt2 < t2w1r && t2w1rwt2 <t2w1l && t2w1rwt2 < t2h1u && t2w1rwt2 < t2h1d && t2w1rwt2 <t2w1rwt && t2w1rwt2 <t2w1lwt && t2w1rwt2 < t2h1uwt && t2w1rwt2 < t2h1dwt && t2w1rwt2 < t2w1r1 && t2w1rwt2 < t2w1l1 && t2w1rwt2 < t2h1u1 && t2w1rwt2 < t2h1d1 && t2w1rwt2 <t2w1rwt1 && t2w1rwt2 <t2w1lwt1 && t2w1rwt2 < t2h1uwt1 && t2w1rwt2 < t2h1dwt1 && t2w1rwt2 <t2w1r2 && t2w1rwt2 <t2w1l2 && t2w1rwt2 < t2h1u2 && t2w1rwt2 < t2h1d2 && t2w1rwt2 <t2w1lwt2 && t2w1rwt2 < t2h1uwt2 && t2w1rwt2 < t2h1dwt2 &&  ((loutwr2!=0 && linwr2==0) || (loutwr2==0 && linwr2!=0))){
  i=118;
  }

  if (mxrOW2==-1 && t2w1rwt2 > 0 && t2w1rwt2 < t1 && t2w1rwt2 < t2w1r && t2w1rwt2 <t2w1l && t2w1rwt2 < t2h1u && t2w1rwt2 < t2h1d && t2w1rwt2 <t2w1rwt && t2w1rwt2 <t2w1lwt && t2w1rwt2 < t2h1uwt && t2w1rwt2 < t2h1dwt && t2w1rwt2 < t2w1r1 && t2w1rwt2 < t2w1l1 && t2w1rwt2 < t2h1u1 && t2w1rwt2 < t2h1d1 && t2w1rwt2 <t2w1rwt1 && t2w1rwt2 <t2w1lwt1 && t2w1rwt2 < t2h1uwt1 && t2w1rwt2 < t2h1dwt1 && t2w1rwt2 <t2w1r2 && t2w1rwt2 <t2w1l2 && t2w1rwt2 < t2h1u2 && t2w1rwt2 < t2h1d2 && t2w1rwt2 <t2w1lwt2 && t2w1rwt2 < t2h1uwt2 && t2w1rwt2 < t2h1dwt2 && (loutwr2==0 && linwr2==0)){
  i=118;
  }

  if (mxlOW2==-1 && t2w1lwt2 > 0 && t2w1lwt2 < t1 && t2w1lwt2 < t2w1r && t2w1lwt2 <t2w1l && t2w1lwt2 < t2h1u && t2w1lwt2 < t2h1d && t2w1lwt2 <t2w1rwt && t2w1lwt2 <t2w1lwt && t2w1lwt2 < t2h1uwt && t2w1lwt2 < t2h1dwt && t2w1lwt2 < t2w1r1 && t2w1lwt2 < t2w1l1 && t2w1lwt2 < t2h1u1 && t2w1lwt2 < t2h1d1 && t2w1lwt2 <t2w1rwt1 && t2w1lwt2 <t2w1lwt1 && t2w1lwt2 < t2h1uwt1 && t2w1lwt2 < t2h1dwt1 && t2w1lwt2 <t2w1r2 && t2w1lwt2 <t2w1l2 && t2w1lwt2 < t2h1u2 && t2w1lwt2 < t2h1d2 && t2w1lwt2 <t2w1rwt2 && t2w1lwt2 < t2h1uwt2 && t2w1lwt2 < t2h1dwt2 && ((linwl2!=0) && (loutwl2!=0) )){
  i=119;
  }

  if (mxlOW2==-1 && t2w1lwt2 > 0 && t2w1lwt2 < t1 && t2w1lwt2 < t2w1r && t2w1lwt2 <t2w1l && t2w1lwt2 < t2h1u && t2w1lwt2 < t2h1d && t2w1lwt2 <t2w1rwt && t2w1lwt2 <t2w1lwt && t2w1lwt2 < t2h1uwt && t2w1lwt2 < t2h1dwt && t2w1lwt2 < t2w1r1 && t2w1lwt2 < t2w1l1 && t2w1lwt2 < t2h1u1 && t2w1lwt2 < t2h1d1 && t2w1lwt2 <t2w1rwt1 && t2w1lwt2 <t2w1lwt1 && t2w1lwt2 < t2h1uwt1 && t2w1lwt2 < t2h1dwt1 && t2w1lwt2 <t2w1r2 && t2w1lwt2 <t2w1l2 && t2w1lwt2 < t2h1u2 && t2w1lwt2 < t2h1d2 && t2w1lwt2 <t2w1rwt2 && t2w1lwt2 < t2h1uwt2 && t2w1lwt2 < t2h1dwt2 &&  ((loutwl2!=0 && linwl2==0) || (loutwl2==0 && linwl2!=0))){
  i=119;
  }

  if (mxlOW2==-1 && t2w1lwt2 > 0 && t2w1lwt2 < t1 && t2w1lwt2 < t2w1r && t2w1lwt2 <t2w1l && t2w1lwt2 < t2h1u && t2w1lwt2 < t2h1d && t2w1lwt2 <t2w1rwt && t2w1lwt2 <t2w1lwt && t2w1lwt2 < t2h1uwt && t2w1lwt2 < t2h1dwt && t2w1lwt2 < t2w1r1 && t2w1lwt2 < t2w1l1 && t2w1lwt2 < t2h1u1 && t2w1lwt2 < t2h1d1 && t2w1lwt2 <t2w1rwt1 && t2w1lwt2 <t2w1lwt1 && t2w1lwt2 < t2h1uwt1 && t2w1lwt2 < t2h1dwt1 && t2w1lwt2 <t2w1r2 && t2w1lwt2 <t2w1l2 && t2w1lwt2 < t2h1u2 && t2w1lwt2 < t2h1d2 && t2w1lwt2 <t2w1rwt2 && t2w1lwt2 < t2h1uwt2 && t2w1lwt2 < t2h1dwt2 && (loutwl2==0 && linwl2==0)){
  i=119;
  }

  if (myuOW2==-1 && t2h1uwt2 > 0 && t2h1uwt2 < t1 && t2h1uwt2 < t2w1r && t2h1uwt2 <t2w1l && t2h1uwt2 < t2h1u && t2h1uwt2 < t2h1d && t2h1uwt2 <t2w1rwt && t2h1uwt2 <t2w1lwt && t2h1uwt2 < t2h1uwt && t2h1uwt2 < t2h1dwt && t2h1uwt2 < t2w1r1 && t2h1uwt2 < t2w1l1 && t2h1uwt2 < t2h1u1 && t2h1uwt2 < t2h1d1 && t2h1uwt2 <t2w1rwt1 && t2h1uwt2 <t2w1lwt1 && t2h1uwt2 < t2h1uwt1 && t2h1uwt2 < t2h1dwt1 && t2h1uwt2 <t2w1r2 && t2h1uwt2 <t2w1l2 && t2h1uwt2 < t2h1u2 && t2h1uwt2 < t2h1d2 && t2h1uwt2 <t2w1rwt2 && t2h1uwt2 < t2w1lwt2 && t2h1uwt2 < t2h1dwt2 && (louthu2 !=0 && linhu2!=0)){
  i=120;
  }

  if (myuOW2==-1 && t2h1uwt2 > 0 && t2h1uwt2 < t1 && t2h1uwt2 < t2w1r && t2h1uwt2 <t2w1l && t2h1uwt2 < t2h1u && t2h1uwt2 < t2h1d && t2h1uwt2 <t2w1rwt && t2h1uwt2 <t2w1lwt && t2h1uwt2 < t2h1uwt && t2h1uwt2 < t2h1dwt && t2h1uwt2 < t2w1r1 && t2h1uwt2 < t2w1l1 && t2h1uwt2 < t2h1u1 && t2h1uwt2 < t2h1d1 && t2h1uwt2 <t2w1rwt1 && t2h1uwt2 <t2w1lwt1 && t2h1uwt2 < t2h1uwt1 && t2h1uwt2 < t2h1dwt1 && t2h1uwt2 <t2w1r2 && t2h1uwt2 <t2w1l2 && t2h1uwt2 < t2h1u2 && t2h1uwt2 < t2h1d2 && t2h1uwt2 <t2w1rwt2 && t2h1uwt2 < t2w1lwt2 && t2h1uwt2 < t2h1dwt2 && ((louthu2 !=0 && linhu2==0) || (louthu2 ==0 && linhu2!=0))) {
  i=120;
  }

  if (myuOW2==-1 && t2h1uwt2 > 0 && t2h1uwt2 < t1 && t2h1uwt2 < t2w1r && t2h1uwt2 <t2w1l && t2h1uwt2 < t2h1u && t2h1uwt2 < t2h1d && t2h1uwt2 <t2w1rwt && t2h1uwt2 <t2w1lwt && t2h1uwt2 < t2h1uwt && t2h1uwt2 < t2h1dwt && t2h1uwt2 < t2w1r1 && t2h1uwt2 < t2w1l1 && t2h1uwt2 < t2h1u1 && t2h1uwt2 < t2h1d1 && t2h1uwt2 <t2w1rwt1 && t2h1uwt2 <t2w1lwt1 && t2h1uwt2 < t2h1uwt1 && t2h1uwt2 < t2h1dwt1 && t2h1uwt2 <t2w1r2 && t2h1uwt2 <t2w1l2 && t2h1uwt2 < t2h1u2 && t2h1uwt2 < t2h1d2 && t2h1uwt2 <t2w1rwt2 && t2h1uwt2 < t2w1lwt2 && t2h1uwt2 < t2h1dwt2 && (louthu2 == 0 && linhu2 == 0)){
  i=120;
  }

  if (mydOW2==-1 && t2h1dwt2 > 0 && t2h1dwt2 < t1 && t2h1dwt2 < t2w1r && t2h1dwt2 <t2w1l && t2h1dwt2 < t2h1u && t2h1dwt2 < t2h1d && t2h1dwt2 <t2w1rwt && t2h1dwt2 <t2w1lwt && t2h1dwt2 < t2h1uwt && t2h1dwt2 < t2h1dwt && t2h1dwt2 < t2w1r1 && t2h1dwt2 < t2w1l1 && t2h1dwt2 < t2h1u1 && t2h1dwt2 < t2h1d1 && t2h1dwt2 <t2w1rwt1 && t2h1dwt2 <t2w1lwt1 && t2h1dwt2 < t2h1uwt1 && t2h1dwt2 < t2h1dwt1 && t2h1dwt2 <t2w1r2 && t2h1dwt2 <t2w1l2 && t2h1dwt2 < t2h1u2 && t2h1dwt2 < t2h1d2 && t2h1dwt2 <t2w1rwt2 && t2h1dwt2 < t2w1lwt2 && t2h1dwt2 < t2h1uwt2 && (louthd2 !=0 && linhd2!=0)){
  i=120;
  }

  if (mydOW2==-1 && t2h1dwt2 > 0 && t2h1dwt2 < t1 && t2h1dwt2 < t2w1r && t2h1dwt2 <t2w1l && t2h1dwt2 < t2h1u && t2h1dwt2 < t2h1d && t2h1dwt2 <t2w1rwt && t2h1dwt2 <t2w1lwt && t2h1dwt2 < t2h1uwt && t2h1dwt2 < t2h1dwt && t2h1dwt2 < t2w1r1 && t2h1dwt2 < t2w1l1 && t2h1dwt2 < t2h1u1 && t2h1dwt2 < t2h1d1 && t2h1dwt2 <t2w1rwt1 && t2h1dwt2 <t2w1lwt1 && t2h1dwt2 < t2h1uwt1 && t2h1dwt2 < t2h1dwt1 && t2h1dwt2 <t2w1r2 && t2h1dwt2 <t2w1l2 && t2h1dwt2 < t2h1u2 && t2h1dwt2 < t2h1d2 && t2h1dwt2 <t2w1rwt2 && t2h1dwt2 < t2w1lwt2 && t2h1dwt2 < t2h1uwt2 && ((louthd2 !=0 && linhd2==0) || (louthd2 ==0 && linhd2!=0))){
  i=120;
  }

  if (mydOW2==-1 && t2h1dwt2 > 0 && t2h1dwt2 < t1 && t2h1dwt2 < t2w1r && t2h1dwt2 <t2w1l && t2h1dwt2 < t2h1u && t2h1dwt2 < t2h1d && t2h1dwt2 <t2w1rwt && t2h1dwt2 <t2w1lwt && t2h1dwt2 < t2h1uwt && t2h1dwt2 < t2h1dwt && t2h1dwt2 < t2w1r1 && t2h1dwt2 < t2w1l1 && t2h1dwt2 < t2h1u1 && t2h1dwt2 < t2h1d1 && t2h1dwt2 <t2w1rwt1 && t2h1dwt2 <t2w1lwt1 && t2h1dwt2 < t2h1uwt1 && t2h1dwt2 < t2h1dwt1 && t2h1dwt2 <t2w1r2 && t2h1dwt2 <t2w1l2 && t2h1dwt2 < t2h1u2 && t2h1dwt2 < t2h1d2 && t2h1dwt2 <t2w1rwt2 && t2h1dwt2 < t2w1lwt2 && t2h1dwt2 < t2h1uwt2 && (louthd2 == 0 && linhd2 == 0)){
  i=120;
  }



switch(i){ /* the principal for the calculation is in every case the same: 1.) one needs the surface normal vector at the intersection point. 2.) calculation of the velocity vector after the interaction by  */
           /* vector subrtation (the basic idea and explanations can be found in the 'Mcstas component manual' in the section 'straight guide') */

  case 1: 										/* no interaction, propagation to the end of the guide */
        PROP_DT(t1);
        break;

  case 2: 
        PROP_DT(t2w1r);									/* propagation to interaction point */
        vxin=vx;									/* saving the velocity vector before the interaction*/
        vyin=vy;
        vzin=vz;
        nx=-x;										/* surface normal vector components at the intersection point */
        nz=-x*x/((a2wr/(z+z0wr))-(z0wr+z));
        n2=sqrt(nx*nx+nz*nz);								/* lenght of the surface normal */
        pf=2.0*(vx*nx+vz*nz)/n2;							/* prefactor for the calculation of the velocity vector after the interaction */
        vx-=pf*nx/n2;									/* velocity vector after the interaction*/
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));	/* calculation the q-vector to calculated the reflectivity*/
        break;

 case 3: 
        PROP_DT(t2w1r);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-0.5/pawr;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 4: 
        PROP_DT(t2w1r);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=l;
        nz=w2r-w1r;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 5: 
        PROP_DT(t2w1l);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-x*x/((a2wl/(z+z0wl))-(z0wl+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        SCATTER;
        break;

 case 6: 
        PROP_DT(t2w1l);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-0.5/pawl;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 7: 
        PROP_DT(t2w1l);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-l;
        nz=w2l-w1l;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 8: 
        PROP_DT(t2h1u);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-y*y/((a2hu/(z+z0hu))-(z0hu+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 9: 
        PROP_DT(t2h1u);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-0.5/pahu;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 10: 
        PROP_DT(t2h1u);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-l;
        nz=h2u-h1u;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 11: 
        PROP_DT(t2h1d);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-y*y/((a2hd/(z+z0hd))-(z0hd+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 12: 
        PROP_DT(t2h1d);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-0.5/pahd;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 13: 
        PROP_DT(t2h1d);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=l;
        nz=h2d-h1d;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 14:										/* transperent walls - no interaction */
	 PROP_DT(t2w1r);
         break;

  case 15:
	 PROP_DT(t2w1l);
         break;

  case 16:
	 PROP_DT(t2h1u);
         break;

  case 17:
	 PROP_DT(t2h1d);
         break;
  
   case 18:										/* absorbing walls - neutrons are absorbed at interaction point*/
	 PROP_DT(t2w1r);
         ABSORB;
         break;

  case 19:
	 PROP_DT(t2w1l);
         ABSORB;
         break;

  case 20:
	 PROP_DT(t2h1u);
         ABSORB;
         break;

  case 21:
	 PROP_DT(t2h1d);
         ABSORB;
         break;

											/* OUTER WALLS - analog to inner walls, but sign of surface normal vector is changed */

  case 22: 
        PROP_DT(t2w1rwt);								/* propagation to interaction point */
        vxin=vx;									/* saving the velocity vector before the interaction*/
        vyin=vy;
        vzin=vz;
        nx=x;										/* surface normal vector components at the intersection point */
        nz=x*x/((a2wrwt/(z+z0wr))-(z0wr+z));
        n2=sqrt(nx*nx+nz*nz);								/* lenght of the surface normal */
        pf=2.0*(vx*nx+vz*nz)/n2;							/* prefactor for the calculation of the velocity vector after the interaction */
        vx-=pf*nx/n2;									/* velocity vector after the interaction*/
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));	/* calculation the q-vector to calculated the reflectivity*/
        break;

 case 23: 
        PROP_DT(t2w1rwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=0.5/pawrwt;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 24: 
        PROP_DT(t2w1rwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-l;
        nz=-(w2r-w1r);
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 25: 
        PROP_DT(t2w1lwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=x*x/((a2wlwt/(z+z0wl))-(z0wl+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 26: 
        PROP_DT(t2w1lwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=0.5/pawlwt;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 27: 
        PROP_DT(t2w1lwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=l;
        nz=-(w2l-w1l);
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 28: 
        PROP_DT(t2h1uwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=y*y/((a2huwt/(z+z0hu))-(z0hu+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 29: 
        PROP_DT(t2h1uwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=0.5/pahuwt;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 30: 
        PROP_DT(t2h1uwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=l;
        nz=-(h2u-h1u);
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 31: 
        PROP_DT(t2h1dwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=y*y/((a2hdwt/(z+z0hd))-(z0hd+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 32: 
        PROP_DT(t2h1dwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=0.5/pahdwt;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 33: 
        PROP_DT(t2h1dwt);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-l;
        nz=-(h2d-h1d);
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 34:
	 PROP_DT(t2w1rwt);
         ABSORB;
         break;

  case 35:
	 PROP_DT(t2w1lwt);
         ABSORB;
         break;

  case 36:
	 PROP_DT(t2h1uwt);
         ABSORB;
         break;

  case 37:
	 PROP_DT(t2h1dwt);
         ABSORB;
         break;

  case 38:
	 PROP_DT(t2w1rwt);
         break;

  case 39:
	 PROP_DT(t2w1lwt);
         break;

  case 40:
	 PROP_DT(t2h1uwt);
         break;

  case 41:
	 PROP_DT(t2h1dwt);
         break;

  case 42: 
        PROP_DT(t2w1r1);									/* propagation to interaction point */
        vxin=vx;									/* saving the velocity vector before the interaction*/
        vyin=vy;
        vzin=vz;
        nx=-x;										/* surface normal vector components at the intersection point */
        nz=-x*x/((a2wr1/(z+z0wr1))-(z0wr1+z));
        n2=sqrt(nx*nx+nz*nz);								/* lenght of the surface normal */
        pf=2.0*(vx*nx+vz*nz)/n2;							/* prefactor for the calculation of the velocity vector after the interaction */
        vx-=pf*nx/n2;									/* velocity vector after the interaction*/
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));	/* calculation the q-vector to calculated the reflectivity*/
        break;

 case 43: 
        PROP_DT(t2w1r1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-0.5/pawr1;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 44: 
        PROP_DT(t2w1r1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=l;
        nz=w2r1-w1r1;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 45: 
        PROP_DT(t2w1l1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-x*x/((a2wl1/(z+z0wl1))-(z0wl1+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 46: 
        PROP_DT(t2w1l1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-0.5/pawl1;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 47: 
        PROP_DT(t2w1l1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-l;
        nz=w2l1-w1l1;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 48: 
        PROP_DT(t2h1u1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-y*y/((a2hu1/(z+z0hu1))-(z0hu1+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 49: 
        PROP_DT(t2h1u1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-0.5/pahu1;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 50: 
        PROP_DT(t2h1u1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-l;
        nz=h2u1-h1u1;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 51: 
        PROP_DT(t2h1d1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-y*y/((a2hd1/(z+z0hd1))-(z0hd1+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 52: 
        PROP_DT(t2h1d1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-0.5/pahd1;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 53: 
        PROP_DT(t2h1d1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=l;
        nz=h2d1-h1d1;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 54:	
	 PROP_DT(t2w1r1);
         ABSORB;
         break;

  case 55:
	 PROP_DT(t2w1l1);
         ABSORB;
         break;

  case 56:
	 PROP_DT(t2h1u1);
         ABSORB;
         break;

  case 57:
	 PROP_DT(t2h1d1);
         ABSORB;
         break;

  case 58:
         PROP_DT(t2w1r1);
         break;

  case 59:
         PROP_DT(t2w1l1);
         break;

  case 60:
         PROP_DT(t2h1u1);
         break;

  case 61:
	 PROP_DT(t2h1d1);
         break;


  case 62: 
        PROP_DT(t2w1rwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=x*x/((a2wrwt1/(z+z0wr1))-(z0wr1+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 63: 
        PROP_DT(t2w1rwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=0.5/pawrwt1;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 64: 
        PROP_DT(t2w1rwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-l;
        nz=-(w2r1-w1r1);
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 65: 
        PROP_DT(t2w1lwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=x*x/((a2wlwt1/(z+z0wl1))-(z0wl1+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 66: 
        PROP_DT(t2w1lwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=0.5/pawlwt1;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 67: 
        PROP_DT(t2w1lwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=l;
        nz=-(w2l1-w1l1);
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 68: 
        PROP_DT(t2h1uwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=y*y/((a2huwt1/(z+z0hu1))-(z0hu1+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 69: 
        PROP_DT(t2h1uwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=0.5/pahuwt1;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 70: 
        PROP_DT(t2h1uwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=l;
        nz=-(h2u1-h1u1);
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 71: 
        PROP_DT(t2h1dwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=y*y/((a2hdwt1/(z+z0hd1))-(z0hd1+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 72: 
        PROP_DT(t2h1dwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=0.5/pahdwt1;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 73: 
        PROP_DT(t2h1dwt1);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-l;
        nz=-(h2d1-h1d1);
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 74:
	 PROP_DT(t2w1rwt1);
         ABSORB;
         break;

  case 75:
	 PROP_DT(t2w1lwt1);
         ABSORB;
         break;

  case 76:
	 PROP_DT(t2h1uwt1);
         ABSORB;
         break;

  case 77:
	 PROP_DT(t2h1dwt1);
         ABSORB;
         break;

  case 78:
	 PROP_DT(t2w1rwt1);
         break;

  case 79:
	 PROP_DT(t2w1lwt1);
         break;

  case 80:
	 PROP_DT(t2h1uwt1);
         break;

  case 81:
	 PROP_DT(t2h1dwt1);
         break;

 case 82: 
        PROP_DT(t2w1r2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-x*x/((a2wr2/(z+z0wr2))-(z0wr2+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 83: 
        PROP_DT(t2w1r2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-0.5/pawr2;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 84: 
        PROP_DT(t2w1r2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=l;
        nz=w2r2-w1r2;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 85: 
        PROP_DT(t2w1l2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-x*x/((a2wl2/(z+z0wl2))-(z0wl2+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        SCATTER;
        break;

 case 86: 
        PROP_DT(t2w1l2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-x;
        nz=-0.5/pawl2;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 87: 
        PROP_DT(t2w1l2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-l;
        nz=w2l2-w1l2;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 88: 
        PROP_DT(t2h1u2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-y*y/((a2hu2/(z+z0hu2))-(z0hu2+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 89: 
        PROP_DT(t2h1u2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-0.5/pahu2;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 90: 
        PROP_DT(t2h1u2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-l;
        nz=h2u2-h1u2;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 91: 
        PROP_DT(t2h1d2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-y*y/((a2hd2/(z+z0hd2))-(z0hd2+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 92: 
        PROP_DT(t2h1d2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-y;
        nz=-0.5/pahd2;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 93: 
        PROP_DT(t2h1d2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=l;
        nz=h2d2-h1d2;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 94:										/* transperent walls - no interaction */
	 PROP_DT(t2w1r2);
         break;

  case 95:
	 PROP_DT(t2w1l2);
         break;

  case 96:
	 PROP_DT(t2h1u2);
         break;

  case 97:
	 PROP_DT(t2h1d2);
         break;
  
   case 98:										/* absorbing walls - neutrons are absorbed at interaction point*/
	 PROP_DT(t2w1r2);
         ABSORB;
         break;

  case 99:
	 PROP_DT(t2w1l2);
         ABSORB;
         break;

  case 100:
	 PROP_DT(t2h1u2);
         ABSORB;
         break;

  case 101:
	 PROP_DT(t2h1d2);
         ABSORB;
         break;

											/* OUTER WALLS - analog to inner walls, but sign of surface normal vector is changed */

  case 102: 
        PROP_DT(t2w1rwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=x*x/((a2wrwt2/(z+z0wr2))-(z0wr2+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 103: 
        PROP_DT(t2w1rwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=0.5/pawrwt2;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 104: 
        PROP_DT(t2w1rwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=-l;
        nz=-(w2r2-w1r2);
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 105: 
        PROP_DT(t2w1lwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=x*x/((a2wlwt2/(z+z0wl2))-(z0wl2+z));
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 106: 
        PROP_DT(t2w1lwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=x;
        nz=0.5/pawlwt2;
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 107: 
        PROP_DT(t2w1lwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        nx=l;
        nz=-(w2l2-w1l2);
        n2=sqrt(nx*nx+nz*nz);
        pf=2.0*(vx*nx+vz*nz)/n2;
        vx-=pf*nx/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 108: 
        PROP_DT(t2h1uwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=y*y/((a2huwt2/(z+z0hu2))-(z0hu2+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 109: 
        PROP_DT(t2h1uwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=0.5/pahuwt2;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 110: 
        PROP_DT(t2h1uwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=l;
        nz=-(h2u2-h1u2);
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 111: 
        PROP_DT(t2h1dwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=y*y/((a2hdwt2/(z+z0hd2))-(z0hd2+z));
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

 case 112: 
        PROP_DT(t2h1dwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=y;
        nz=0.5/pahdwt2;
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 113: 
        PROP_DT(t2h1dwt2);
        vxin=vx;
        vyin=vy;
        vzin=vz;
        ny=-l;
        nz=-(h2d2-h1d2);
        n2=sqrt(ny*ny+nz*nz);
        pf=2.0*(vy*ny+vz*nz)/n2;
        vy-=pf*ny/n2;
        vz-=pf*nz/n2;
        q=V2Q*sqrt((vxin-vx)*(vxin-vx)+(vyin-vy)*(vyin-vy)+(vzin-vz)*(vzin-vz));
        break;

  case 114:
	 PROP_DT(t2w1rwt2);
         ABSORB;
         break;

  case 115:
	 PROP_DT(t2w1lwt2);
         ABSORB;
         break;

  case 116:
	 PROP_DT(t2h1uwt2);
         ABSORB;
         break;

  case 117:
	 PROP_DT(t2h1dwt2);
         ABSORB;
         break;

  case 118:
	 PROP_DT(t2w1rwt2);
         break;

  case 119:
	 PROP_DT(t2w1lwt2);
         break;

  case 120:
	 PROP_DT(t2h1uwt2);
         break;

  case 121:
	 PROP_DT(t2h1dwt2);
         break;


 }




 if (((i==2) ||(i==3) || (i == 4 ))){								/* calculating the the probability that the neutron is reflected at the RIGHT INNER wall*/
          if (RIreflect && strlen(RIreflect))
              {
               p=Table_Value(riTable, q, 1);
              }else{
                 if(mxr > 0 && q > Qcxr){
                 double arg = (q - mxr*Qcxr)/Wxr;
                 if(arg<10){
                   p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxr*(q-Qcxr));
                 }else
                 ABSORB;
                }
              }
           }

  if (((i==22) ||(i==23) || (i==24 ))){								/* calculating the the probability that the neutron is reflected at the RIGHT OUTER wall*/
          if (ROreflect && strlen(ROreflect))
              {
               p=Table_Value(roTable, q, 1);
              }else{
                 if(mxrOW > 0 && q > QcxrOW){
                   double arg = (q - mxrOW*QcxrOW)/WxrOW;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxrOW*(q-QcxrOW));
                   }
                   else
                   ABSORB;
                  }
               }
             }

  if (((i==5) ||(i==6) || (i == 7 ) ) ){							/* calculating the the probability that the neutron is reflected at the LEFT INNER wall*/
          if (LIreflect && strlen(LIreflect))
              {
               p=Table_Value(liTable, q, 1);
              }else{
                 if(mxl > 0 && q > Qcxl){
                   double arg = (q - mxl*Qcxl)/Wxl;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxl*(q-Qcxl));
                   }else
                   ABSORB;
                }
               }
          }

  if (((i==25) || (i==26) || (i==27 )) && mxlOW >0 && q > QcxlOW ){				/* calculating the the probability that the neutron is reflected at the LEFT OUTER wall*/
         if (LOreflect && strlen(LOreflect))
              {
               p=Table_Value(loTable, q, 1);
              }else{
                 if(mxlOW > 0 && q > QcxlOW){
                   double arg = (q - mxlOW*QcxlOW)/WxlOW;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxlOW*(q-QcxlOW));
                   }
                   else
                   ABSORB;
                 }
               }
          }

  if (((i==8) ||(i==9) || (i == 10 ))){								/* calculating the the probability that the neutron is reflected at the TOP INNER wall*/
	  if (UIreflect && strlen(UIreflect))
              {
               p=Table_Value(uiTable, q, 1);
              }else{
                 if(myu > 0 && q > Qcyu){
                 double arg = (q - myu*Qcyu)/Wyu;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphayu*(q-Qcyu));
                   }else
                   ABSORB;
                 }
              }
            }

  if (((i==28) || (i==29) || (i==30 )) ){							/* calculating the the probability that the neutron is reflected at the TOP OUTER wall*/
	  if (UOreflect && strlen(UOreflect))
              {
               p=Table_Value(uoTable, q, 1);
              }else{
                 if(myuOW > 0 && q > QcyuOW){
                   double arg = (q - myuOW*QcyuOW)/WyuOW;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphayuOW*(q-QcyuOW));
                   }else
                   ABSORB;
                   }
               }
           }

  if (((i==11) ||(i==12) || (i == 13 ))){							/* calculating the the probability that the neutron is reflected at the BOTTOM INNER wall*/
          if (DIreflect && strlen(DIreflect))
              {
               p=Table_Value(diTable, q, 1);
              }else{
                 if(myd > 0 && q > Qcyd){
                   double arg = (q - myd*Qcyd)/Wyd;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphayd*(q-Qcyd));
                   }else
                   ABSORB;
                   }
               }
            }

   if (((i==31) || (i==32) || (i==33 )) ){							/* calculating the the probability that the neutron is reflected at the BOTTOM OUTER wall*/
          if (DOreflect && strlen(DOreflect))
              {
               p=Table_Value(doTable, q, 1);
              }else{
                 if(mydOW > 0 && q > QcydOW){
                   double arg = (q - mydOW*QcydOW)/WydOW;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaydOW*(q-QcydOW));
                   }else
                   ABSORB;
                   }
                 }
           }


  if (((i==42) ||(i==43) || (i == 44 )) ){					/* calculating the the probability that the neutron is reflected at the RIGHT INNER wall*/
          if (RIreflect1 && strlen(RIreflect1))
              {
               p=Table_Value(riTable1, q, 1);
              }else{
                 if(mxr1 > 0 && q > Qcxr1){
                   double arg = (q - mxr1*Qcxr1)/Wxr1;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxr1*(q-Qcxr1));
                   }else
                   ABSORB;
                   }
               }
          }

  if (((i==45) ||(i==46) || (i == 47 ) )){					/* calculating the the probability that the neutron is reflected at the LEFT INNER wall*/
          if (LIreflect1 && strlen(LIreflect1))
              {
               p=Table_Value(liTable1, q, 1);
              }else{
                 if(mxl1 > 0 && q > Qcxl1){
                   double arg = (q - mxl1*Qcxl1)/Wxl1;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxl1*(q-Qcxl1));
                   }else
                   ABSORB;
                  }
              }
           }

  if (((i==48) ||(i==49) || (i == 50 )) ){					/* calculating the the probability that the neutron is reflected at the TOP INNER wall*/
	  if (UIreflect1 && strlen(UIreflect1))
              {
               p=Table_Value(uiTable1, q, 1);
              }else{
                 if(myu1 > 0 && q > Qcyu1){
                   double arg = (q - myu1*Qcyu1)/Wyu1;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphayu1*(q-Qcyu1));
                   }else
                   ABSORB;
                   }
               }
            }

  if (((i==51) ||(i==52) || (i == 53 )) ){					/* calculating the the probability that the neutron is reflected at the BOTTOM INNER wall*/
          if (DIreflect1 && strlen(DIreflect1))
              {
               p=Table_Value(diTable1, q, 1);
              }else{
                 if(myd1 > 0 && q > Qcyd1){
                   double arg = (q - myd1*Qcyd1)/Wyd1;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphayd1*(q-Qcyd1));
                   }else
                   ABSORB;
                   }
               }
           }

   if (((i==62) ||(i==63) || (i==64 ))){	
          if (ROreflect1 && strlen(ROreflect1))
              {
               p=Table_Value(roTable1, q, 1);
              }else{
                 if(mxrOW1 > 0 && q > QcxrOW1){
                   double arg = (q - mxrOW1*QcxrOW1)/WxrOW1;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxrOW1*(q-QcxrOW1));
                   }
                   else
                   ABSORB;
                  }
               }
             }

   if (((i==65) || (i==66) || (i==67 )) && mxlOW1 >0 && q > QcxlOW1 ){
         if (LOreflect1 && strlen(LOreflect1))
              {
               p=Table_Value(loTable1, q, 1);
              }else{
                 if(mxlOW1 > 0 && q > QcxlOW1){
                   double arg = (q - mxlOW1*QcxlOW1)/WxlOW1;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxlOW1*(q-QcxlOW1));
                   }
                   else
                   ABSORB;
                 }
               }
          }

   if (((i==68) || (i==69) || (i==70 )) ){
	  if (UOreflect1 && strlen(UOreflect1))
              {
               p=Table_Value(uoTable1, q, 1);
              }else{
                 if(myuOW1 > 0 && q > QcyuOW1){
                   double arg = (q - myuOW1*QcyuOW1)/WyuOW1;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphayuOW1*(q-QcyuOW1));
                   }else
                   ABSORB;
                   }
               }
           }

    if (((i==71) || (i==72) || (i==73 )) ){
          if (DOreflect1 && strlen(DOreflect1))
              {
               p=Table_Value(doTable1, q, 1);
              }else{
                 if(mydOW1 > 0 && q > QcydOW1){
                   double arg = (q - mydOW1*QcydOW1)/WydOW1;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaydOW1*(q-QcydOW1));
                   }else
                   ABSORB;
                   }
                 }
           }


    if (((i==82) ||(i==83) || (i == 84 ))){
          if (RIreflect2 && strlen(RIreflect2))
              {
               p=Table_Value(riTable2, q, 1);
              }else{
                 if(mxr2 > 0 && q > Qcxr2){
                 double arg = (q - mxr2*Qcxr2)/Wxr2;
                 if(arg<10){
                   p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxr2*(q-Qcxr2));
                 }else
                 ABSORB;
                }
              }
           }

  if (((i==102) ||(i==103) || (i==104 ))){	
          if (ROreflect2 && strlen(ROreflect2))
              {
               p=Table_Value(roTable2, q, 1);
              }else{
                 if(mxrOW2 > 0 && q > QcxrOW2){
                   double arg = (q - mxrOW2*QcxrOW2)/WxrOW2;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxrOW2*(q-QcxrOW2));
                   }
                   else
                   ABSORB;
                  }
               }
             }

  if (((i==85) ||(i==86) || (i == 87 ) ) ){
          if (LIreflect2 && strlen(LIreflect2))
              {
               p=Table_Value(liTable2, q, 1);
              }else{
                 if(mxl2 > 0 && q > Qcxl2){
                   double arg = (q - mxl2*Qcxl2)/Wxl2;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxl2*(q-Qcxl2));
                   }else
                   ABSORB;
                }
               }
          }

  if (((i==105) || (i==106) || (i==107 )) && mxlOW2 >0 && q > QcxlOW2 ){
         if (LOreflect2 && strlen(LOreflect2))
              {
               p=Table_Value(loTable2, q, 1);
              }else{
                 if(mxlOW2 > 0 && q > QcxlOW2){
                   double arg = (q - mxlOW2*QcxlOW2)/WxlOW2;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaxlOW2*(q-QcxlOW2));
                   }
                   else
                   ABSORB;
                 }
               }
          }

  if (((i==88) ||(i==89) || (i == 90 ))){
	  if (UIreflect2 && strlen(UIreflect2))
              {
               p=Table_Value(uiTable2, q, 1);
              }else{
                 if(myu2 > 0 && q > Qcyu2){
                 double arg = (q - myu2*Qcyu2)/Wyu2;
                   if(arg<10){
                     p *= 0.5*(1.0-tanh(arg))*(1.0-alphayu2*(q-Qcyu2));
                   }else
                   ABSORB;
                 }
              }
            }

  if (((i==108) || (i==109) || (i==110 )) ){
	  if (UOreflect2 && strlen(UOreflect2))
              {
               p=Table_Value(uoTable2, q, 1);
              }else{
                 if(myuOW2 > 0 && q > QcyuOW2){
                   double arg = (q - myuOW2*QcyuOW2)/WyuOW2;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphayuOW2*(q-QcyuOW2));
                   }else
                   ABSORB;
                   }
               }
           }

  if (((i==91) ||(i==92) || (i == 93 ))){
          if (DIreflect2 && strlen(DIreflect2))
              {
               p=Table_Value(diTable2, q, 1);
              }else{
                 if(myd2 > 0 && q > Qcyd2){
                   double arg = (q - myd2*Qcyd2)/Wyd2;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphayd2*(q-Qcyd2));
                   }else
                   ABSORB;
                   }
               }
            }

   if (((i==111) || (i==112) || (i==113 )) ){
          if (DOreflect2 && strlen(DOreflect2))
              {
               p=Table_Value(doTable2, q, 1);
              }else{
                 if(mydOW2 > 0 && q > QcydOW2){
                   double arg = (q - mydOW2*QcydOW2)/WydOW2;
                   if(arg<10){
                      p *= 0.5*(1.0-tanh(arg))*(1.0-alphaydOW2*(q-QcydOW2));
                   }else
                   ABSORB;
                   }
                 }
           }


  p *= R0;
  SCATTER;

} while (z<l);												/* repeat the interaction loop untill the neutron pass the end of guide */


  if(x <= -w2r && x >= -w2rwt && y <= mru2*x+nru2 && y >= mrd2*x+nrd2 && mxr!=-1 && mxrOW!=-1)		/* absorbing the neutron if it hit the RIGHT exit wall and the wall is not transparent*/
      ABSORB;
  if(x >=  w2l && x <=  w2lwt && y <= mlu2*x+nlu2 && y >= mld2*x+nld2 && mxl!=-1 && mxlOW!=-1) 		/* absorbing the neutron if it hit the LEFT exit wall and the wall is not transparent*/
      ABSORB;
  if(y <= -h2d && y >= -h2dwt && x <= (y-nld2)/mld2 && x>= (y-nrd2)/mrd2 && myd!=-1 && mydOW!=-1) 	/* absorbing the neutron if it hit the BOTTOM exit wall and the wall is not transparent*/
      ABSORB; 
  if(y >=  h2u && y <=  h2uwt && x <= (y-nlu2)/mlu2 && x>= (y-nru2)/mru2 && myu!=-1 && myuOW!=-1)	/* absorbing the neutron if it hit the TOP exit wall and the wall is not transparent*/
      ABSORB;

  if(x <= -w2r1 && x >= -w2rwt1 && y <= mru21*x+nru21 && y >= mrd21*x+nrd21 && mxr1!=-1 && mxrOW1!=-1)
      ABSORB;
  if(x >=  w2l1 && x <=  w2lwt1 && y <= mlu21*x+nlu21 && y >= mld21*x+nld21 && mxl1!=-1 && mxlOW1!=-1) 
      ABSORB;
  if(y <= -h2d1 && y >= -h2dwt1 && x <= (y-nld21)/mld21 && x>= (y-nrd21)/mrd21 && myd1!=-1 && mydOW1!=-1) 
      ABSORB; 
  if(y >=  h2u1 && y <=  h2uwt1 && x <= (y-nlu21)/mlu21 && x>= (y-nru21)/mru21 && myu1!=-1 && myuOW1!=-1)
      ABSORB;

   if(x <= -w2r2 && x >= -w2rwt2 && y <= mru22*x+nru22 && y >= mrd22*x+nrd22 && mxr2!=-1 && mxrOW2!=-1)
      ABSORB;
  if(x >=  w2l2 && x <=  w2lwt2 && y <= mlu21*x+nlu22 && y >= mld22*x+nld22 && mxl2!=-1 && mxlOW2!=-1) 
      ABSORB;
  if(y <= -h2d2 && y >= -h2dwt2 && x <= (y-nld22)/mld22 && x>= (y-nrd22)/mrd22 && myd2!=-1 && mydOW2!=-1) 
      ABSORB; 
  if(y >=  h2u2 && y <=  h2uwt2 && x <= (y-nlu22)/mlu22 && x>= (y-nru22)/mru22 && myu2!=-1 && myuOW2!=-1)
      ABSORB;
%}



FINALLY
%{

%}

MCDISPLAY
%{
  int i,imax;
  double x1,y1,z,x2,y2,z1,z0wr,z0wl,z0hu,z0hd,xwt,ywt,x1wt,y1wt;
  double mr,ml,mu,md,nr1,nl1,nu1,nd1,nr2,nl2,nu2,nd2;
  double lbwl,lbwr,lbhu,lbhd;								/* length between focal points , needed for elliptic case */

  double x11,y11,x21,y21,z11,z0wr1,z0wl1,z0hu1,z0hd1,xwt1,ywt1,x1wt1,y1wt1;
  double mr1,ml1,mu1,md1,nr11,nl11,nu11,nd11,nr21,nl21,nu21,nd21;
  double lbwl1,lbwr1,lbhu1,lbhd1;

  double x12,y12,x22,y22,z12,z0wr2,z0wl2,z0hu2,z0hd2,xwt2,ywt2,x1wt2,y1wt2;
  double mr2,ml2,mu2,md2,nr12,nl12,nu12,nd12,nr22,nl22,nu22,nd22;
  double lbwl2,lbwr2,lbhu2,lbhd2;

  magnify("xy");


  imax=100;										/* maximum points for every line in z direction*/

  lbwr=linwr+l+loutwr;
  lbwl=linwl+l+loutwl;
  lbhu=linhu+l+louthu;
  lbhd=linhd+l+louthd;

  lbwr1=linwr1+l+loutwr1;
  lbwl1=linwl1+l+loutwl1;
  lbhu1=linhu1+l+louthu1;
  lbhd1=linhd1+l+louthd1;

  lbwr2=linwr2+l+loutwr2;
  lbwl2=linwl2+l+loutwl2;
  lbhu2=linhu2+l+louthu2;
  lbhd2=linhd2+l+louthd2;

  if (linwr==0 && loutwr==0){
   mr=(-w2r+w1r)/l;
   nr1=-w1r;
   nr2=-(w1rwt);
   }


if (linwl==0 && loutwl==0){
   ml=(w2l-w1l)/l;
   nl1=w1l;
   nl2=(w1lwt);
   }


if (linhu == 0 && louthu==0) 
  {
   mu=(h2u-h1u)/l;
   nu1=h1u;
   nu2=(h1uwt);
  }


if (linhd == 0 && louthd==0) 
  {
   md=(-h2d+h1d)/l;
   nd1=-h1d;
   nd2=-(h1dwt);
  }

  z0wr=(linwr-l-loutwr)/2.0;
  z0wl=(linwl-l-loutwl)/2.0;
  z0hu=lbhu/2.0-l-louthu;
  z0hd=lbhd/2.0-l-louthd;

  z0wr1=(linwr1-l-loutwr1)/2.0;
  z0wl1=(linwl1-l-loutwl1)/2.0;
  z0hu1=lbhu1/2.0-l-louthu1;
  z0hd1=lbhd1/2.0-l-louthd1;

  if(myd!=-1) line(w1l, -h1d, 0.0, -w1r, -h1d, 0.0);							/* entrance window given by the INNER walls*/
  if(myu!=-1)line(w1l, h1u, 0.0, -w1r, h1u, 0.0);
  if(mxl!=-1)line(w1l, -h1d, 0.0, w1l, h1u, 0.0);
  if(mxr!=-1)line( -w1r, h1u, 0.0, -w1r, -h1d, 0.0);

  if(myd!=-1)line(w2l, -h2d, l, -w2r, -h2d, l);								/* exit window given by the INNER walls*/
  if(myu!=-1)line(w2l, h2u,  l, -w2r, h2u, l);
  if(mxl!=-1)line(w2l, -h2d, l, w2l, h2u, l);
  if(mxr!=-1)line( -w2r, -h2d,  l, -w2r, h2u, l);

  if(mydOW!=-1) line((w1lwt), -(h1dwt), 0.0, -(w1rwt), -(h1dwt), 0.0);					/* entrance window given by the OUTER walls */
  if(myuOW!=-1)line((w1lwt), (h1uwt), 0.0, -(w1rwt), (h1uwt), 0.0);
  if(mxlOW!=-1)line((w1lwt), -(h1dwt), 0.0, (w1lwt), (h1uwt), 0.0);
  if(mxrOW!=-1)line( -(w1rwt), (h1uwt), 0.0, -(w1rwt), -(h1dwt), 0.0);

  if(mydOW!=-1)line((w2lwt), -(h2dwt), l, -(w2rwt), -(h2dwt), l);					/* exit windows given by the OUTER walls*/
  if(myuOW!=-1)line((w2lwt), (h2uwt),  l, -(w2rwt), (h2uwt), l);
  if(mxlOW!=-1)line((w2lwt), -(h2dwt), l, (w2lwt), (h2uwt), l);
  if(mxrOW!=-1)line( -(w2rwt), -(h2dwt),  l, -(w2rwt), (h2uwt), l);

  if((myd!=-1 && mydOW!=-1) || (mxl!=-1 && mxlOW!=-1)) line(w1l, -h1d, 0.0, (w1lwt), -(h1dwt), 0.0);	/* corner connection lines for the entrance windows*/	
  if((myu!=-1 && myuOW!=-1) || (mxl!=-1 && mxlOW!=-1)) line(w1l, h1u, 0.0, (w1lwt), (h1uwt), 0.0);
  if((myd!=-1 && mydOW!=-1) || (mxr!=-1 && mxrOW!=-1)) line(-w1r, -h1d, 0.0,-(w1rwt),  -(h1dwt), 0.0);
  if((myu!=-1 && myuOW!=-1) || (mxr!=-1 && mxrOW!=-1)) line( -w1r, h1u, 0.0, -(w1rwt), (h1uwt), 0.0);

  if((myd!=-1 && mydOW!=-1) || (mxl!=-1 && mxlOW!=-1)) line(w2l, -h2d, l, (w2lwt), -(h2dwt), l);	/* corner connection lines for the exit windows*/
  if((myu!=-1 && myuOW!=-1) || (mxl!=-1 && mxlOW!=-1)) line(w2l, h2u, l, (w2lwt), (h2uwt), l);
  if((myd!=-1 && mydOW!=-1) || (mxr!=-1 && mxrOW!=-1)) line(-w2r, -h2d, l,-(w2rwt),  -(h2dwt), l);
  if((myu!=-1 && myuOW!=-1) || (mxr!=-1 && mxrOW!=-1)) line( -w2r, h2u, l, -(w2rwt), (h2uwt), l);

for(i=0;i<imax;i++){											/* calculation of the points for the INNER LEFT BOTTOM line */
   z=i*l/imax;
   z1=(i+1)*l/imax;
  if(linwl==0 && loutwl == 0)
   {
     x1=ml*z+nl1;
     x2=ml*z1+nl1;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      x1=bwl*sqrt(1-((z0wl+z)*(z0wl+z))/(awl*awl));
      x2=bwl*sqrt(1-((z0wl+z1)*(z0wl+z1))/(awl*awl));
      }else{
      x1=sqrt((z-pbwl)/-pawl);
      x2=sqrt((z1-pbwl)/-pawl);
      }
   }
  if(linhd==0 && louthd==0)
   {
     y1=md*z+nd1;
     y2=md*z1+nd1;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      y1=-bhd*sqrt(1-((z0hd+z)*(z0hd+z))/(ahd*ahd));
      y2=-bhd*sqrt(1-((z0hd+z1)*(z0hd+z1))/(ahd*ahd));
      }else{
      y1=-sqrt((z-pbhd)/-pahd);
      y2=-sqrt((z1-pbhd)/-pahd);
      }
   }
  if(mxl!=-1 || myd!=-1)line((double)x1, (double)y1, (double)z, (double)x2, (double)y2, (double)z1); 
 }

for(i=0;i<imax;i++){											/* calculation of the points for the INNER RIGHT BOTTOM line */
  z=i*l/imax;
  z1=(i+1)*l/imax;
  if(linwr==0 && loutwr==0)
  {
    x1=mr*z+nr1;
    x2=mr*z1+nr1;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    x1=-bwr*sqrt(1-((z0wr+z)*(z0wr+z))/(awr*awr));
    x2=-bwr*sqrt(1-((z0wr+z1)*(z0wr+z1))/(awr*awr));
    }else{
    x1=-sqrt((z-pbwr)/-pawr);
    x2=-sqrt((z1-pbwr)/-pawr);
    }
  }
  if(linhd==0 && louthd==0)
  {
    y1=md*z+nd1;
    y2=md*z1+nd1;
  }else{
    if(linhd!=0 && louthd!=0)
    {
    y1=-bhd*sqrt(1-((z0hd+z)*(z0hd+z))/(ahd*ahd));
    y2=-bhd*sqrt(1-((z0hd+z1)*(z0hd+z1))/(ahd*ahd));
    }else{
    y1=-sqrt((z-pbhd)/-pahd);
    y2=-sqrt((z1-pbhd)/-pahd);
    }
  }
  if(mxr!=-1 || myd!=-1) line((double)x1, (double)y1, (double)z, (double)x2, (double)y2, (double)z1); 
}


for(i=0;i<imax;i++){											/* calculation of the points for the INNER RIGHT TOP line */
  z=i*l/imax;
  z1=(i+1)*l/imax;
  if(linwr==0 && loutwr==0)
  {
    x1=mr*z+nr1;
    x2=mr*z1+nr1;
   }else{
     if(linwr!=0 && loutwr!=0){
     x1=-bwr*sqrt(1-((z0wr+z)*(z0wr+z))/(awr*awr));
     x2=-bwr*sqrt(1-((z0wr+z1)*(z0wr+z1))/(awr*awr));
     }else{
     x1=-sqrt((z-pbwr)/-pawr);
     x2=-sqrt((z1-pbwr)/-pawr);
     }
   }
   if(linhu==0 && louthu==0)
  {
    y1=mu*z+nu1;
    y2=mu*z1+nu1;
  }else{
    if(linhu!=0 && louthu!=0)
    {
    y1=bhu*sqrt(1-((z0hu+z)*(z0hu+z))/(ahu*ahu));
    y2=bhu*sqrt(1-((z0hu+z1)*(z0hu+z1))/(ahu*ahu));
    }else{
    y1=sqrt((z-pbhu)/-pahu);
    y2=sqrt((z1-pbhu)/-pahu);
    }
  }
  if(mxr!=-1 || myu!=-1)line((double)x1, (double)y1, (double)z, (double)x2, (double)y2, (double)z1); 
}

for(i=0;i<imax;i++){											/* calculation of the points for the INNER LEFT TOP line */
  z=i*l/imax;
  z1=(i+1)*l/imax;
  if(linwl==0 && loutwl==0)
  {
    x1=ml*z+nl1;
    x2=ml*z1+nl1;
   }else{
     if(linwl!=0 && loutwl!=0)
     {
     x1=bwl*sqrt(1-((z0wl+z)*(z0wl+z))/(awl*awl));
     x2=bwl*sqrt(1-((z0wl+z1)*(z0wl+z1))/(awl*awl));
     }else{
     x1=sqrt((z-pbwl)/-pawl);
     x2=sqrt((z1-pbwl)/-pawl);
     }
   }
   if(linhu==0 && louthu==0)
  {
    y1=mu*z+nu1;
    y2=mu*z1+nu1;
  }else{
    if(linhu!=0 && louthu!=0)
    {
    y1=bhu*sqrt(1-((z0hu+z)*(z0hu+z))/(ahu*ahu));
    y2=bhu*sqrt(1-((z0hu+z1)*(z0hu+z1))/(ahu*ahu));
    }else{
    y1=sqrt((z-pbhu)/-pahu);
    y2=sqrt((z1-pbhu)/-pahu);
    }
  }
  if(mxl!=-1 || myu!=-1)line((double)x1, (double)y1, (double)z, (double)x2, (double)y2, (double)z1); 
}																	/* END INNER LINES*/


for(i=0;i<imax;i++){											/* calculation of the points for the OUTER LEFT BOTTOM line */
   z=i*l/imax;
   z1=(i+1)*l/imax;
  if(linwl==0 && loutwl == 0)
   {
     xwt=ml*z+nl2;
     x1wt=ml*z1+nl2;
   }else{
      if(linwl!=0 && loutwl != 0)
      {
      xwt=bwlwt*sqrt(1-((z0wl+z)*(z0wl+z))/(awlwt*awlwt));
      x1wt=bwlwt*sqrt(1-((z0wl+z1)*(z0wl+z1))/(awlwt*awlwt));
      }else{
      xwt=sqrt((z-pbwlwt)/-pawlwt);
      x1wt=sqrt((z1-pbwlwt)/-pawlwt);
      }
   }
  if(linhd==0 && louthd==0)
   {
     ywt=md*z+nd2;
     y1wt=md*z1+nd2;
    }else{
      if(linhd!=0 && louthd!=0)
      {
      ywt=-bhdwt*sqrt(1-((z0hd+z)*(z0hd+z))/(ahdwt*ahdwt));
      y1wt=-bhdwt*sqrt(1-((z0hd+z1)*(z0hd+z1))/(ahdwt*ahdwt));
      }else{
      ywt=-sqrt((z-pbhdwt)/-pahdwt);
      y1wt=-sqrt((z1-pbhdwt)/-pahdwt);
      }
   }
  if(mxlOW!=-1 || mydOW!=-1)line((double)xwt, (double)ywt, (double)z, (double)x1wt, (double)y1wt, (double)z1); 
 }

for(i=0;i<imax;i++){											/* calculation of the points for the OUTER RIGHT BOTTOM line */
  z=i*l/imax;
  z1=(i+1)*l/imax;
  if(linwr==0 && loutwr==0)
  {
    xwt=mr*z+nr2;
    x1wt=mr*z1+nr2;
  }else{
    if(linwr!=0 && loutwr!=0)
    {
    xwt=-bwrwt*sqrt(1-((z0wr+z)*(z0wr+z))/(awrwt*awrwt));
    x1wt=-bwrwt*sqrt(1-((z0wr+z1)*(z0wr+z1))/(awrwt*awrwt));
    }else{
    xwt=-sqrt((z-pbwrwt)/-pawrwt);
    x1wt=-sqrt((z1-pbwrwt)/-pawrwt);
    }
  }
  if(linhd==0 && louthd==0)
  {
    ywt=md*z+nd2;
    y1wt=md*z1+nd2;
  }else{
    if(linhd!=0 && louthd!=0)
    {
    ywt=-bhdwt*sqrt(1-((z0hd+z)*(z0hd+z))/(ahdwt*ahdwt));
    y1wt=-bhdwt*sqrt(1-((z0hd+z1)*(z0hd+z1))/(ahdwt*ahdwt));
    }else{
    ywt=-sqrt((z-pbhdwt)/-pahdwt);
    y1wt=-sqrt((z1-pbhdwt)/-pahdwt);
    }
  }
  if(mxrOW!=-1 || mydOW!=-1) line((double)xwt, (double)ywt, (double)z, (double)x1wt, (double)y1wt, (double)z1); 
}


for(i=0;i<imax;i++){											/* calculation of the points for the OUTER RIGHT TOP line */
  z=i*l/imax;
  z1=(i+1)*l/imax;
  if(linwr==0 && loutwr==0)
  {
    xwt=mr*z+nr2;
    x1wt=mr*z1+nr2;
   }else{
     if(linwr!=0 && loutwr!=0){
     xwt=-bwrwt*sqrt(1-((z0wr+z)*(z0wr+z))/(awrwt*awrwt));
     x1wt=-bwrwt*sqrt(1-((z0wr+z1)*(z0wr+z1))/(awrwt*awrwt));
     }else{
     xwt=-sqrt((z-pbwrwt)/-pawrwt);
     x1wt=-sqrt((z1-pbwrwt)/-pawrwt);
     }
   }
   if(linhu==0 && louthu==0)
  {
    ywt=mu*z+nu2;
    y1wt=mu*z1+nu2;
  }else{
    if(linhu!=0 && louthu!=0)
    {
    ywt=bhuwt*sqrt(1-((z0hu+z)*(z0hu+z))/(ahuwt*ahuwt));
    y1wt=bhuwt*sqrt(1-((z0hu+z1)*(z0hu+z1))/(ahuwt*ahuwt));
    }else{
    ywt=sqrt((z-pbhuwt)/-pahuwt);
    y1wt=sqrt((z1-pbhuwt)/-pahuwt);
    }
  }
   if(mxrOW!=-1 || myuOW!=-1)line((double)xwt, (double)ywt, (double)z, (double)x1wt, (double)y1wt, (double)z1); 
}

for(i=0;i<imax;i++){											/* calculation of the points for the OUTER LEFT TOP line */
  z=i*l/imax;
  z1=(i+1)*l/imax;
  if(linwl==0 && loutwl==0)
  {
    xwt=ml*z+nl2;
    x1wt=ml*z1+nl2;
   }else{
     if(linwl!=0 && loutwl!=0)
     {
     xwt=bwlwt*sqrt(1-((z0wl+z)*(z0wl+z))/(awlwt*awlwt));
     x1wt=bwlwt*sqrt(1-((z0wl+z1)*(z0wl+z1))/(awlwt*awlwt));
     }else{
     xwt=sqrt((z-pbwlwt)/-pawlwt);
     x1wt=sqrt((z1-pbwlwt)/-pawlwt);
     }
   }
   if(linhu==0 && louthu==0)
  {
    ywt=mu*z+nu2;
    y1wt=mu*z1+nu2;
  }else{
    if(linhu!=0 && louthu!=0)
    {
    ywt=bhuwt*sqrt(1-((z0hu+z)*(z0hu+z))/(ahuwt*ahuwt));
    y1wt=bhuwt*sqrt(1-((z0hu+z1)*(z0hu+z1))/(ahuwt*ahuwt));
    }else{
    ywt=sqrt((z-pbhuwt)/-pahuwt);
    y1wt=sqrt((z1-pbhuwt)/-pahuwt);
    }
  }
  if(mxlOW!=-1 || myuOW!=-1)line((double)xwt, (double)ywt, (double)z, (double)x1wt, (double)y1wt, (double)z1); 
}



  if (linwr1==0 && loutwr1==0){
   mr1=(-w2r1+w1r1)/l;
   nr11=-w1r1;
   nr21=-(w1rwt1);
   }


if (linwl1==0 && loutwl1==0){
   ml1=(w2l1-w1l1)/l;
   nl11=w1l1;
   nl21=(w1lwt1);
   }


if (linhu1 == 0 && louthu1==0) 
  {
   mu1=(h2u1-h1u1)/l;
   nu11=h1u1;
   nu21=(h1uwt1);
  }


if (linhd1 == 0 && louthd1==0) 
  {
   md1=(-h2d1+h1d1)/l;
   nd11=-h1d1;
   nd21=-(h1dwt1);
  }

  z0wr1=(linwr1-l-loutwr1)/2.0;
  z0wl1=(linwl1-l-loutwl1)/2.0;
  z0hu1=lbhu1/2.0-l-louthu1;
  z0hd1=lbhd1/2.0-l-louthd1;

  z0wr1=(linwr1-l-loutwr1)/2.0;
  z0wl1=(linwl1-l-loutwl1)/2.0;
  z0hu1=lbhu1/2.0-l-louthu1;
  z0hd1=lbhd1/2.0-l-louthd1;

  if(myd1!=-1) line(w1l1, -h1d1, 0.0, -w1r1, -h1d1, 0.0);							/* entrance window given by the INNER walls*/
  if(myu1!=-1)line(w1l1, h1u1, 0.0, -w1r1, h1u1, 0.0);
  if(mxl1!=-1)line(w1l1, -h1d1, 0.0, w1l1, h1u1, 0.0);
  if(mxr1!=-1)line( -w1r1, h1u1, 0.0, -w1r1, -h1d1, 0.0);

  if(myd1!=-1)line(w2l1, -h2d1, l, -w2r1, -h2d1, l);								/* exit window given by the INNER walls*/
  if(myu1!=-1)line(w2l1, h2u1,  l, -w2r1, h2u1, l);
  if(mxl1!=-1)line(w2l1, -h2d1, l, w2l1, h2u1, l);
  if(mxr1!=-1)line( -w2r1, -h2d1,  l, -w2r1, h2u1, l);

  if(mydOW1!=-1) line((w1lwt1), -(h1dwt1), 0.0, -(w1rwt1), -(h1dwt1), 0.0);					/* entrance window given by the OUTER walls */
  if(myuOW1!=-1)line((w1lwt1), (h1uwt1), 0.0, -(w1rwt1), (h1uwt1), 0.0);
  if(mxlOW1!=-1)line((w1lwt1), -(h1dwt1), 0.0, (w1lwt1), (h1uwt1), 0.0);
  if(mxrOW1!=-1)line( -(w1rwt1), (h1uwt1), 0.0, -(w1rwt1), -(h1dwt1), 0.0);

  if(mydOW1!=-1)line((w2lwt1), -(h2dwt1), l, -(w2rwt1), -(h2dwt1), l);					/* exit windows given by the OUTER walls*/
  if(myuOW1!=-1)line((w2lwt1), (h2uwt1),  l, -(w2rwt1), (h2uwt1), l);
  if(mxlOW1!=-1)line((w2lwt1), -(h2dwt1), l, (w2lwt1), (h2uwt1), l);
  if(mxrOW1!=-1)line( -(w2rwt1), -(h2dwt1),  l, -(w2rwt1), (h2uwt1), l);

  if((myd1!=-1 && mydOW1!=-1) || (mxl1!=-1 && mxlOW1!=-1)) line(w1l1, -h1d1, 0.0, (w1lwt1), -(h1dwt1), 0.0);	/* corner connection lines for the entrance windows*/	
  if((myu1!=-1 && myuOW1!=-1) || (mxl1!=-1 && mxlOW1!=-1)) line(w1l1, h1u1, 0.0, (w1lwt1), (h1uwt1), 0.0);
  if((myd1!=-1 && mydOW1!=-1) || (mxr1!=-1 && mxrOW1!=-1)) line(-w1r1, -h1d1, 0.0,-(w1rwt1),  -(h1dwt1), 0.0);
  if((myu1!=-1 && myuOW1!=-1) || (mxr1!=-1 && mxrOW1!=-1)) line( -w1r1, h1u1, 0.0, -(w1rwt1), (h1uwt1), 0.0);

  if((myd1!=-1 && mydOW1!=-1) || (mxl1!=-1 && mxlOW1!=-1)) line(w2l1, -h2d1, l, (w2lwt1), -(h2dwt1), l);	/* corner connection lines for the exit windows*/
  if((myu1!=-1 && myuOW1!=-1) || (mxl1!=-1 && mxlOW1!=-1)) line(w2l1, h2u1, l, (w2lwt1), (h2uwt1), l);
  if((myd1!=-1 && mydOW1!=-1) || (mxr1!=-1 && mxrOW1!=-1)) line(-w2r1, -h2d1, l,-(w2rwt1),  -(h2dwt1), l);
  if((myu1!=-1 && myuOW1!=-1) || (mxr1!=-1 && mxrOW1!=-1)) line( -w2r1, h2u1, l, -(w2rwt1), (h2uwt1), l);

for(i=0;i<imax;i++){											/* calculation of the points for the INNER LEFT BOTTOM line */
   z=i*l/imax;
   z11=(i+1)*l/imax;
  if(linwl1==0 && loutwl1 == 0)
   {
     x11=ml1*z+nl11;
     x21=ml1*z11+nl11;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      x11=bwl1*sqrt(1-((z0wl1+z)*(z0wl1+z))/(awl1*awl1));
      x21=bwl1*sqrt(1-((z0wl1+z11)*(z0wl1+z11))/(awl1*awl1));
      }else{
      x11=sqrt((z-pbwl1)/-pawl1);
      x21=sqrt((z11-pbwl1)/-pawl1);
      }
   }
  if(linhd1==0 && louthd1==0)
   {
     y11=md1*z+nd11;
     y21=md1*z11+nd11;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      y11=-bhd1*sqrt(1-((z0hd1+z)*(z0hd1+z))/(ahd1*ahd1));
      y21=-bhd1*sqrt(1-((z0hd1+z11)*(z0hd1+z11))/(ahd1*ahd1));
      }else{
      y11=-sqrt((z-pbhd1)/-pahd1);
      y21=-sqrt((z11-pbhd1)/-pahd1);
      }
   }
  if(mxl1!=-1 || myd1!=-1)line((double)x11, (double)y11, (double)z, (double)x21, (double)y21, (double)z11); 
 }

for(i=0;i<imax;i++){											/* calculation of the points for the INNER RIGHT BOTTOM line */
  z=i*l/imax;
  z11=(i+1)*l/imax;
  if(linwr1==0 && loutwr1==0)
  {
    x11=mr1*z+nr11;
    x21=mr1*z11+nr11;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    x11=-bwr1*sqrt(1-((z0wr1+z)*(z0wr1+z))/(awr1*awr1));
    x21=-bwr1*sqrt(1-((z0wr1+z11)*(z0wr1+z11))/(awr1*awr1));
    }else{
    x11=-sqrt((z-pbwr1)/-pawr1);
    x21=-sqrt((z11-pbwr1)/-pawr1);
    }
  }
  if(linhd1==0 && louthd1==0)
  {
    y11=md1*z+nd11;
    y21=md1*z11+nd11;
  }else{
    if(linhd1!=0 && louthd1!=0)
    {
    y11=-bhd1*sqrt(1-((z0hd1+z)*(z0hd1+z))/(ahd1*ahd1));
    y21=-bhd1*sqrt(1-((z0hd1+z11)*(z0hd1+z11))/(ahd1*ahd1));
    }else{
    y11=-sqrt((z-pbhd1)/-pahd1);
    y21=-sqrt((z11-pbhd1)/-pahd1);
    }
  }
  if(mxr1!=-1 || myd1!=-1) line((double)x11, (double)y11, (double)z, (double)x21, (double)y21, (double)z11); 
}


for(i=0;i<imax;i++){											/* calculation of the points for the INNER RIGHT TOP line */
  z=i*l/imax;
  z11=(i+1)*l/imax;
  if(linwr1==0 && loutwr1==0)
  {
    x11=mr1*z+nr11;
    x21=mr1*z11+nr11;
   }else{
     if(linwr1!=0 && loutwr1!=0){
     x11=-bwr1*sqrt(1-((z0wr1+z)*(z0wr1+z))/(awr1*awr1));
     x21=-bwr1*sqrt(1-((z0wr1+z11)*(z0wr1+z11))/(awr1*awr1));
     }else{
     x11=-sqrt((z-pbwr1)/-pawr1);
     x21=-sqrt((z11-pbwr1)/-pawr1);
     }
   }
   if(linhu1==0 && louthu1==0)
  {
    y11=mu1*z+nu11;
    y21=mu1*z11+nu11;
  }else{
    if(linhu1!=0 && louthu1!=0)
    {
    y11=bhu1*sqrt(1-((z0hu1+z)*(z0hu1+z))/(ahu1*ahu1));
    y21=bhu1*sqrt(1-((z0hu1+z11)*(z0hu1+z11))/(ahu1*ahu1));
    }else{
    y11=sqrt((z-pbhu1)/-pahu1);
    y21=sqrt((z11-pbhu1)/-pahu1);
    }
  }
  if(mxr1!=-1 || myu1!=-1)line((double)x11, (double)y11, (double)z, (double)x21, (double)y21, (double)z11); 
}

for(i=0;i<imax;i++){											/* calculation of the points for the INNER LEFT TOP line */
  z=i*l/imax;
  z11=(i+1)*l/imax;
  if(linwl1==0 && loutwl1==0)
  {
    x11=ml1*z+nl11;
    x21=ml1*z11+nl11;
   }else{
     if(linwl1!=0 && loutwl1!=0)
     {
     x11=bwl1*sqrt(1-((z0wl1+z)*(z0wl1+z))/(awl1*awl1));
     x21=bwl1*sqrt(1-((z0wl1+z11)*(z0wl1+z11))/(awl1*awl1));
     }else{
     x11=sqrt((z-pbwl1)/-pawl1);
     x21=sqrt((z11-pbwl1)/-pawl1);
     }
   }
   if(linhu1==0 && louthu1==0)
  {
    y11=mu1*z+nu11;
    y21=mu1*z11+nu11;
  }else{
    if(linhu1!=0 && louthu1!=0)
    {
    y11=bhu1*sqrt(1-((z0hu1+z)*(z0hu1+z))/(ahu1*ahu1));
    y21=bhu1*sqrt(1-((z0hu1+z11)*(z0hu1+z11))/(ahu1*ahu1));
    }else{
    y11=sqrt((z-pbhu1)/-pahu1);
    y21=sqrt((z11-pbhu1)/-pahu1);
    }
  }
  if(mxl1!=-1 || myu1!=-1)line((double)x11, (double)y11, (double)z, (double)x21, (double)y21, (double)z11); 
}																	/* END INNER LINES*/


for(i=0;i<imax;i++){											/* calculation of the points for the OUTER LEFT BOTTOM line */
   z=i*l/imax;
   z11=(i+1)*l/imax;
  if(linwl1==0 && loutwl1 == 0)
   {
     xwt1=ml1*z+nl21;
     x1wt1=ml1*z11+nl21;
   }else{
      if(linwl1!=0 && loutwl1 != 0)
      {
      xwt1=bwlwt1*sqrt(1-((z0wl1+z)*(z0wl1+z))/(awlwt1*awlwt1));
      x1wt1=bwlwt1*sqrt(1-((z0wl1+z11)*(z0wl1+z11))/(awlwt1*awlwt1));
      }else{
      xwt1=sqrt((z-pbwlwt1)/-pawlwt1);
      x1wt1=sqrt((z11-pbwlwt1)/-pawlwt1);
      }
   }
  if(linhd1==0 && louthd1==0)
   {
     ywt1=md1*z+nd21;
     y1wt1=md1*z11+nd21;
    }else{
      if(linhd1!=0 && louthd1!=0)
      {
      ywt1=-bhdwt1*sqrt(1-((z0hd1+z)*(z0hd1+z))/(ahdwt1*ahdwt1));
      y1wt1=-bhdwt1*sqrt(1-((z0hd1+z11)*(z0hd1+z11))/(ahdwt1*ahdwt1));
      }else{
      ywt1=-sqrt((z-pbhdwt1)/-pahdwt1);
      y1wt1=-sqrt((z11-pbhdwt1)/-pahdwt1);
      }
   }
  if(mxlOW1!=-1 || mydOW1!=-1)line((double)xwt1, (double)ywt1, (double)z, (double)x1wt1, (double)y1wt1, (double)z11); 
 }

for(i=0;i<imax;i++){											/* calculation of the points for the OUTER RIGHT BOTTOM line */
  z=i*l/imax;
  z11=(i+1)*l/imax;
  if(linwr1==0 && loutwr1==0)
  {
    xwt1=mr1*z+nr21;
    x1wt1=mr1*z11+nr21;
  }else{
    if(linwr1!=0 && loutwr1!=0)
    {
    xwt1=-bwrwt1*sqrt(1-((z0wr1+z)*(z0wr1+z))/(awrwt1*awrwt1));
    x1wt1=-bwrwt1*sqrt(1-((z0wr1+z11)*(z0wr1+z11))/(awrwt1*awrwt1));
    }else{
    xwt1=-sqrt((z-pbwrwt1)/-pawrwt1);
    x1wt1=-sqrt((z11-pbwrwt1)/-pawrwt1);
    }
  }
  if(linhd1==0 && louthd1==0)
  {
    ywt1=md1*z+nd21;
    y1wt1=md1*z11+nd21;
  }else{
    if(linhd1!=0 && louthd1!=0)
    {
    ywt1=-bhdwt1*sqrt(1-((z0hd1+z)*(z0hd1+z))/(ahdwt1*ahdwt1));
    y1wt1=-bhdwt1*sqrt(1-((z0hd1+z11)*(z0hd1+z11))/(ahdwt1*ahdwt1));
    }else{
    ywt1=-sqrt((z-pbhdwt1)/-pahdwt1);
    y1wt1=-sqrt((z11-pbhdwt1)/-pahdwt1);
    }
  }
  if(mxrOW1!=-1 || mydOW1!=-1) line((double)xwt1, (double)ywt1, (double)z, (double)x1wt1, (double)y1wt1, (double)z11); 
}


for(i=0;i<imax;i++){											/* calculation of the points for the OUTER RIGHT TOP line */
  z=i*l/imax;
  z11=(i+1)*l/imax;
  if(linwr1==0 && loutwr1==0)
  {
    xwt1=mr1*z+nr21;
    x1wt1=mr1*z11+nr21;
   }else{
     if(linwr1!=0 && loutwr1!=0){
     xwt1=-bwrwt1*sqrt(1-((z0wr1+z)*(z0wr1+z))/(awrwt1*awrwt1));
     x1wt1=-bwrwt1*sqrt(1-((z0wr1+z11)*(z0wr1+z11))/(awrwt1*awrwt1));
     }else{
     xwt1=-sqrt((z-pbwrwt1)/-pawrwt1);
     x1wt1=-sqrt((z11-pbwrwt1)/-pawrwt1);
     }
   }
   if(linhu1==0 && louthu1==0)
  {
    ywt1=mu1*z+nu21;
    y1wt1=mu1*z11+nu21;
  }else{
    if(linhu1!=0 && louthu1!=0)
    {
    ywt1=bhuwt1*sqrt(1-((z0hu1+z)*(z0hu1+z))/(ahuwt1*ahuwt1));
    y1wt1=bhuwt1*sqrt(1-((z0hu1+z11)*(z0hu1+z11))/(ahuwt1*ahuwt1));
    }else{
    ywt1=sqrt((z-pbhuwt1)/-pahuwt1);
    y1wt1=sqrt((z11-pbhuwt1)/-pahuwt1);
    }
  }
   if(mxrOW1!=-1 || myuOW1!=-1)line((double)xwt1, (double)ywt1, (double)z, (double)x1wt1, (double)y1wt1, (double)z11); 
}

for(i=0;i<imax;i++){											/* calculation of the points for the OUTER LEFT TOP line */
  z=i*l/imax;
  z11=(i+1)*l/imax;
  if(linwl1==0 && loutwl1==0)
  {
    xwt1=ml1*z+nl21;
    x1wt1=ml1*z11+nl21;
   }else{
     if(linwl1!=0 && loutwl1!=0)
     {
     xwt1=bwlwt1*sqrt(1-((z0wl1+z)*(z0wl1+z))/(awlwt1*awlwt1));
     x1wt1=bwlwt1*sqrt(1-((z0wl1+z11)*(z0wl1+z11))/(awlwt1*awlwt1));
     }else{
     xwt1=sqrt((z-pbwlwt1)/-pawlwt1);
     x1wt1=sqrt((z11-pbwlwt1)/-pawlwt1);
     }
   }
   if(linhu1==0 && louthu1==0)
  {
    ywt1=mu1*z+nu21;
    y1wt1=mu1*z11+nu21;
  }else{
    if(linhu1!=0 && louthu1!=0)
    {
    ywt1=bhuwt1*sqrt(1-((z0hu1+z)*(z0hu1+z))/(ahuwt1*ahuwt1));
    y1wt1=bhuwt1*sqrt(1-((z0hu1+z11)*(z0hu1+z11))/(ahuwt1*ahuwt1));
    }else{
    ywt1=sqrt((z-pbhuwt1)/-pahuwt1);
    y1wt1=sqrt((z11-pbhuwt1)/-pahuwt1);
    }
  }
  if(mxlOW1!=-1 || myuOW1!=-1)line((double)xwt1, (double)ywt1, (double)z, (double)x1wt1, (double)y1wt1, (double)z11); 
}

 if (linwr2==0 && loutwr2==0){
   mr2=(-w2r2+w1r2)/l;
   nr12=-w1r2;
   nr22=-(w1rwt2);
   }


if (linwl2==0 && loutwl2==0){
   ml2=(w2l2-w1l2)/l;
   nl12=w1l2;
   nl22=(w1lwt2);
   }


if (linhu2 == 0 && louthu2==0) 
  {
   mu2=(h2u2-h1u2)/l;
   nu12=h1u2;
   nu22=(h1uwt2);
  }


if (linhd2 == 0 && louthd2==0) 
  {
   md2=(-h2d2+h1d2)/l;
   nd12=-h1d2;
   nd22=-(h1dwt2);
  }

  z0wr2=(linwr2-l-loutwr2)/2.0;
  z0wl2=(linwl2-l-loutwl2)/2.0;
  z0hu2=lbhu2/2.0-l-louthu2;
  z0hd2=lbhd2/2.0-l-louthd2;

  z0wr1=(linwr1-l-loutwr1)/2.0;
  z0wl1=(linwl1-l-loutwl1)/2.0;
  z0hu1=lbhu1/2.0-l-louthu1;
  z0hd1=lbhd1/2.0-l-louthd1;

  if(myd2!=-1) line(w1l2, -h1d2, 0.0, -w1r2, -h1d2, 0.0);							/* entrance window given by the INNER walls*/
  if(myu2!=-1)line(w1l2, h1u2, 0.0, -w1r2, h1u2, 0.0);
  if(mxl2!=-1)line(w1l2, -h1d2, 0.0, w1l2, h1u2, 0.0);
  if(mxr2!=-1)line( -w1r2, h1u2, 0.0, -w1r2, -h1d2, 0.0);

  if(myd2!=-1)line(w2l2, -h2d2, l, -w2r2, -h2d2, l);								/* exit window given by the INNER walls*/
  if(myu2!=-1)line(w2l2, h2u2,  l, -w2r2, h2u2, l);
  if(mxl2!=-1)line(w2l2, -h2d2, l, w2l2, h2u2, l);
  if(mxr2!=-1)line( -w2r2, -h2d2,  l, -w2r2, h2u2, l);

  if(mydOW2!=-1) line((w1lwt2), -(h1dwt2), 0.0, -(w1rwt2), -(h1dwt2), 0.0);					/* entrance window given by the OUTER walls */
  if(myuOW2!=-1)line((w1lwt2), (h1uwt2), 0.0, -(w1rwt2), (h1uwt2), 0.0);
  if(mxlOW2!=-1)line((w1lwt2), -(h1dwt2), 0.0, (w1lwt2), (h1uwt2), 0.0);
  if(mxrOW2!=-1)line( -(w1rwt2), (h1uwt2), 0.0, -(w1rwt2), -(h1dwt2), 0.0);

  if(mydOW2!=-1)line((w2lwt2), -(h2dwt2), l, -(w2rwt2), -(h2dwt2), l);					/* exit windows given by the OUTER walls*/
  if(myuOW2!=-1)line((w2lwt2), (h2uwt2),  l, -(w2rwt2), (h2uwt2), l);
  if(mxlOW2!=-1)line((w2lwt2), -(h2dwt2), l, (w2lwt2), (h2uwt2), l);
  if(mxrOW2!=-1)line( -(w2rwt2), -(h2dwt2),  l, -(w2rwt2), (h2uwt2), l);

  if((myd2!=-1 && mydOW2!=-1) || (mxl2!=-1 && mxlOW2!=-1)) line(w1l2, -h1d2, 0.0, (w1lwt2), -(h1dwt2), 0.0);	/* corner connection lines for the entrance windows*/	
  if((myu2!=-1 && myuOW2!=-1) || (mxl2!=-1 && mxlOW2!=-1)) line(w1l2, h1u2, 0.0, (w1lwt2), (h1uwt2), 0.0);
  if((myd2!=-1 && mydOW2!=-1) || (mxr2!=-1 && mxrOW2!=-1)) line(-w1r2, -h1d2, 0.0,-(w1rwt2),  -(h1dwt2), 0.0);
  if((myu2!=-1 && myuOW2!=-1) || (mxr2!=-1 && mxrOW2!=-1)) line( -w1r2, h1u2, 0.0, -(w1rwt2), (h1uwt2), 0.0);

  if((myd2!=-1 && mydOW2!=-1) || (mxl2!=-1 && mxlOW2!=-1)) line(w2l2, -h2d2, l, (w2lwt2), -(h2dwt2), l);	/* corner connection lines for the exit windows*/
  if((myu2!=-1 && myuOW2!=-1) || (mxl2!=-1 && mxlOW2!=-1)) line(w2l2, h2u2, l, (w2lwt2), (h2uwt2), l);
  if((myd2!=-1 && mydOW2!=-1) || (mxr2!=-1 && mxrOW2!=-1)) line(-w2r2, -h2d2, l,-(w2rwt2),  -(h2dwt2), l);
  if((myu2!=-1 && myuOW2!=-1) || (mxr2!=-1 && mxrOW2!=-1)) line( -w2r2, h2u2, l, -(w2rwt2), (h2uwt2), l);

for(i=0;i<imax;i++){											/* calculation of the points for the INNER LEFT BOTTOM line */
   z=i*l/imax;
   z12=(i+1)*l/imax;
  if(linwl2==0 && loutwl2 == 0)
   {
     x12=ml2*z+nl12;
     x22=ml2*z12+nl12;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      x12=bwl2*sqrt(1-((z0wl2+z)*(z0wl2+z))/(awl2*awl2));
      x22=bwl2*sqrt(1-((z0wl2+z12)*(z0wl2+z12))/(awl2*awl2));
      }else{
      x12=sqrt((z-pbwl2)/-pawl2);
      x22=sqrt((z12-pbwl2)/-pawl2);
      }
   }
  if(linhd2==0 && louthd2==0)
   {
     y12=md2*z+nd12;
     y22=md2*z12+nd12;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      y12=-bhd2*sqrt(1-((z0hd2+z)*(z0hd2+z))/(ahd2*ahd2));
      y22=-bhd2*sqrt(1-((z0hd2+z12)*(z0hd2+z12))/(ahd2*ahd2));
      }else{
      y12=-sqrt((z-pbhd2)/-pahd2);
      y22=-sqrt((z12-pbhd2)/-pahd2);
      }
   }
  if(mxl2!=-1 || myd2!=-1)line((double)x12, (double)y12, (double)z, (double)x22, (double)y22, (double)z12); 
 }

for(i=0;i<imax;i++){											/* calculation of the points for the INNER RIGHT BOTTOM line */
  z=i*l/imax;
  z12=(i+1)*l/imax;
  if(linwr2==0 && loutwr2==0)
  {
    x12=mr2*z+nr12;
    x22=mr2*z12+nr12;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    x12=-bwr2*sqrt(1-((z0wr2+z)*(z0wr2+z))/(awr2*awr2));
    x22=-bwr2*sqrt(1-((z0wr2+z12)*(z0wr2+z12))/(awr2*awr2));
    }else{
    x12=-sqrt((z-pbwr2)/-pawr2);
    x22=-sqrt((z12-pbwr2)/-pawr2);
    }
  }
  if(linhd2==0 && louthd2==0)
  {
    y12=md2*z+nd12;
    y22=md2*z12+nd12;
  }else{
    if(linhd2!=0 && louthd2!=0)
    {
    y12=-bhd2*sqrt(1-((z0hd2+z)*(z0hd2+z))/(ahd2*ahd2));
    y22=-bhd2*sqrt(1-((z0hd2+z12)*(z0hd2+z12))/(ahd2*ahd2));
    }else{
    y12=-sqrt((z-pbhd2)/-pahd2);
    y22=-sqrt((z12-pbhd2)/-pahd2);
    }
  }
  if(mxr2!=-1 || myd2!=-1) line((double)x12, (double)y12, (double)z, (double)x22, (double)y22, (double)z12); 
}


for(i=0;i<imax;i++){											/* calculation of the points for the INNER RIGHT TOP line */
  z=i*l/imax;
  z12=(i+1)*l/imax;
  if(linwr2==0 && loutwr2==0)
  {
    x12=mr2*z+nr12;
    x22=mr2*z12+nr12;
   }else{
     if(linwr2!=0 && loutwr2!=0){
     x12=-bwr2*sqrt(1-((z0wr2+z)*(z0wr2+z))/(awr2*awr2));
     x22=-bwr2*sqrt(1-((z0wr2+z12)*(z0wr2+z12))/(awr2*awr2));
     }else{
     x12=-sqrt((z-pbwr2)/-pawr2);
     x22=-sqrt((z12-pbwr2)/-pawr2);
     }
   }
   if(linhu2==0 && louthu2==0)
  {
    y12=mu2*z+nu12;
    y22=mu2*z12+nu12;
  }else{
    if(linhu2!=0 && louthu2!=0)
    {
    y12=bhu2*sqrt(1-((z0hu2+z)*(z0hu2+z))/(ahu2*ahu2));
    y22=bhu2*sqrt(1-((z0hu2+z12)*(z0hu2+z12))/(ahu2*ahu2));
    }else{
    y12=sqrt((z-pbhu2)/-pahu2);
    y22=sqrt((z12-pbhu2)/-pahu2);
    }
  }
  if(mxr2!=-1 || myu2!=-1)line((double)x12, (double)y12, (double)z, (double)x22, (double)y22, (double)z12); 
}

for(i=0;i<imax;i++){											/* calculation of the points for the INNER LEFT TOP line */
  z=i*l/imax;
  z12=(i+1)*l/imax;
  if(linwl2==0 && loutwl2==0)
  {
    x12=ml2*z+nl12;
    x22=ml2*z12+nl12;
   }else{
     if(linwl2!=0 && loutwl2!=0)
     {
     x12=bwl2*sqrt(1-((z0wl2+z)*(z0wl2+z))/(awl2*awl2));
     x22=bwl2*sqrt(1-((z0wl2+z12)*(z0wl2+z12))/(awl2*awl2));
     }else{
     x12=sqrt((z-pbwl2)/-pawl2);
     x22=sqrt((z12-pbwl2)/-pawl2);
     }
   }
   if(linhu2==0 && louthu2==0)
  {
    y12=mu2*z+nu12;
    y22=mu2*z12+nu12;
  }else{
    if(linhu2!=0 && louthu2!=0)
    {
    y12=bhu2*sqrt(1-((z0hu2+z)*(z0hu2+z))/(ahu2*ahu2));
    y22=bhu2*sqrt(1-((z0hu2+z12)*(z0hu2+z12))/(ahu2*ahu2));
    }else{
    y12=sqrt((z-pbhu2)/-pahu2);
    y22=sqrt((z12-pbhu2)/-pahu2);
    }
  }
  if(mxl2!=-1 || myu2!=-1)line((double)x12, (double)y12, (double)z, (double)x22, (double)y22, (double)z12); 
}																	/* END INNER LINES*/


for(i=0;i<imax;i++){											/* calculation of the points for the OUTER LEFT BOTTOM line */
   z=i*l/imax;
   z12=(i+1)*l/imax;
  if(linwl2==0 && loutwl2 == 0)
   {
     xwt2=ml2*z+nl22;
     x1wt2=ml2*z12+nl22;
   }else{
      if(linwl2!=0 && loutwl2 != 0)
      {
      xwt2=bwlwt2*sqrt(1-((z0wl2+z)*(z0wl2+z))/(awlwt2*awlwt2));
      x1wt2=bwlwt2*sqrt(1-((z0wl2+z12)*(z0wl2+z12))/(awlwt2*awlwt2));
      }else{
      xwt2=sqrt((z-pbwlwt2)/-pawlwt2);
      x1wt2=sqrt((z12-pbwlwt2)/-pawlwt2);
      }
   }
  if(linhd2==0 && louthd2==0)
   {
     ywt2=md2*z+nd22;
     y1wt2=md2*z12+nd22;
    }else{
      if(linhd2!=0 && louthd2!=0)
      {
      ywt2=-bhdwt2*sqrt(1-((z0hd2+z)*(z0hd2+z))/(ahdwt2*ahdwt2));
      y1wt2=-bhdwt2*sqrt(1-((z0hd2+z12)*(z0hd2+z12))/(ahdwt2*ahdwt2));
      }else{
      ywt2=-sqrt((z-pbhdwt2)/-pahdwt2);
      y1wt2=-sqrt((z12-pbhdwt2)/-pahdwt2);
      }
   }
  if(mxlOW2!=-1 || mydOW2!=-1)line((double)xwt2, (double)ywt2, (double)z, (double)x1wt2, (double)y1wt2, (double)z12); 
 }

for(i=0;i<imax;i++){											/* calculation of the points for the OUTER RIGHT BOTTOM line */
  z=i*l/imax;
  z12=(i+1)*l/imax;
  if(linwr2==0 && loutwr2==0)
  {
    xwt2=mr2*z+nr22;
    x1wt2=mr2*z12+nr22;
  }else{
    if(linwr2!=0 && loutwr2!=0)
    {
    xwt2=-bwrwt2*sqrt(1-((z0wr2+z)*(z0wr2+z))/(awrwt2*awrwt2));
    x1wt2=-bwrwt2*sqrt(1-((z0wr2+z12)*(z0wr2+z12))/(awrwt2*awrwt2));
    }else{
    xwt2=-sqrt((z-pbwrwt2)/-pawrwt2);
    x1wt2=-sqrt((z12-pbwrwt2)/-pawrwt2);
    }
  }
  if(linhd2==0 && louthd2==0)
  {
    ywt2=md2*z+nd22;
    y1wt2=md2*z12+nd22;
  }else{
    if(linhd2!=0 && louthd2!=0)
    {
    ywt2=-bhdwt2*sqrt(1-((z0hd2+z)*(z0hd2+z))/(ahdwt2*ahdwt2));
    y1wt2=-bhdwt2*sqrt(1-((z0hd2+z12)*(z0hd2+z12))/(ahdwt2*ahdwt2));
    }else{
    ywt2=-sqrt((z-pbhdwt2)/-pahdwt2);
    y1wt2=-sqrt((z12-pbhdwt2)/-pahdwt2);
    }
  }
  if(mxrOW2!=-1 || mydOW2!=-1) line((double)xwt2, (double)ywt2, (double)z, (double)x1wt2, (double)y1wt2, (double)z12); 
}


for(i=0;i<imax;i++){											/* calculation of the points for the OUTER RIGHT TOP line */
  z=i*l/imax;
  z12=(i+1)*l/imax;
  if(linwr2==0 && loutwr2==0)
  {
    xwt2=mr2*z+nr22;
    x1wt2=mr2*z12+nr22;
   }else{
     if(linwr2!=0 && loutwr2!=0){
     xwt2=-bwrwt2*sqrt(1-((z0wr2+z)*(z0wr2+z))/(awrwt2*awrwt2));
     x1wt2=-bwrwt2*sqrt(1-((z0wr2+z12)*(z0wr2+z12))/(awrwt2*awrwt2));
     }else{
     xwt2=-sqrt((z-pbwrwt2)/-pawrwt2);
     x1wt2=-sqrt((z12-pbwrwt2)/-pawrwt2);
     }
   }
   if(linhu2==0 && louthu2==0)
  {
    ywt2=mu2*z+nu22;
    y1wt2=mu2*z12+nu22;
  }else{
    if(linhu2!=0 && louthu2!=0)
    {
    ywt2=bhuwt2*sqrt(1-((z0hu2+z)*(z0hu2+z))/(ahuwt2*ahuwt2));
    y1wt2=bhuwt2*sqrt(1-((z0hu2+z12)*(z0hu2+z12))/(ahuwt2*ahuwt2));
    }else{
    ywt2=sqrt((z-pbhuwt2)/-pahuwt2);
    y1wt2=sqrt((z12-pbhuwt2)/-pahuwt2);
    }
  }
   if(mxrOW2!=-1 || myuOW2!=-1)line((double)xwt2, (double)ywt2, (double)z, (double)x1wt2, (double)y1wt2, (double)z12); 
}

for(i=0;i<imax;i++){											/* calculation of the points for the OUTER LEFT TOP line */
  z=i*l/imax;
  z12=(i+1)*l/imax;
  if(linwl2==0 && loutwl2==0)
  {
    xwt2=ml2*z+nl22;
    x1wt2=ml2*z12+nl22;
   }else{
     if(linwl2!=0 && loutwl2!=0)
     {
     xwt2=bwlwt2*sqrt(1-((z0wl2+z)*(z0wl2+z))/(awlwt2*awlwt2));
     x1wt2=bwlwt2*sqrt(1-((z0wl2+z12)*(z0wl2+z12))/(awlwt2*awlwt2));
     }else{
     xwt2=sqrt((z-pbwlwt2)/-pawlwt2);
     x1wt2=sqrt((z12-pbwlwt2)/-pawlwt2);
     }
   }
   if(linhu2==0 && louthu2==0)
  {
    ywt2=mu2*z+nu22;
    y1wt2=mu2*z12+nu22;
  }else{
    if(linhu2!=0 && louthu2!=0)
    {
    ywt2=bhuwt2*sqrt(1-((z0hu2+z)*(z0hu2+z))/(ahuwt2*ahuwt2));
    y1wt2=bhuwt2*sqrt(1-((z0hu2+z12)*(z0hu2+z12))/(ahuwt2*ahuwt2));
    }else{
    ywt2=sqrt((z-pbhuwt2)/-pahuwt2);
    y1wt2=sqrt((z12-pbhuwt2)/-pahuwt2);
    }
  }
  if(mxlOW2!=-1 || myuOW2!=-1)line((double)xwt2, (double)ywt2, (double)z, (double)x1wt2, (double)y1wt2, (double)z12); 
}



%}

END


