# Re: [fluka-discuss]: Writting SOURCE user routine generating from file with mixture of particles?

From: Mina Nozar <nozarm_at_triumf.ca>
Date: Thu, 14 Nov 2013 12:59:42 -0800

Hello Vahan,

Question 2:

* 100 FORMAT(I2,1X,3(E10.4,1X),3(E23.16,1X),2(E10.4,1X))*
2) what does mean this: *3(E10.4,1X)... 3-in front of parentheses?*

the format statement above means:

I2: 2 spaces for an integer
1X: 1 blank space - for particle id
3(E10.4,1X): (4 sig figures, 10 figures total, followed by 1 blank
space) repeated three times - so for three numbers in scientific
notation - for particle position (X,Y,Z)
3(E23.16,1X): (16 sig figures, 23 spaces total, followed by 1 blank
space) repeated three times - for particle direction cosines (cosX,
cosY, cosZ)
2(E10.4,1X): for particle energy and weight.

3(E23.16,1X) is a short hand for E23.16,1X, E23.16,1X, E23.16,1X and
you can use the latter if you prefer.

I would imagine depending on your project, you might want higher sig.
figs for particle position, energy, and weight as well. I'll leave this
for others to comment.

Question 3:
3) what does mean *ETRACK-AM(JTRACK)? because in help docs. **ETRACK was
mentioned as energy. so what is a* .... *-AM(JTRACK) part?*

ETRACK = total energy of the particle (rest + kinetic)
AM = rest mass of particle
ETRACK - AM = Kinetic energy of particle.

Best wishes,
Mina

On 13-11-14 12:09 PM, Vahan Petrosyan wrote:
> Many Thanks all of you for this great discussion! It helped me very much.
> I also get data as Mina does but when I copy them to MS. Excel all
> columns are pasted in one cell instead to separate columns.
>
> 1) I want to ask how can I output data of mgdraw in columns using
> fortran77 ie. tabs.? (what do I write instead of 1X?)
> * 100 FORMAT(I2,1X,3(E10.4,1X),3(E23.16,1X),2(E10.4,1X))*
> 2) what does mean this: *3(E10.4,1X)... 3-in front of parentheses?*
> 3) what does mean *ETRACK-AM(JTRACK)? because in help docs. **ETRACK
> was mentioned as energy. so what is a* .... *-AM(JTRACK) part?*
>
> Thank You!
>
> On 11/14/2013 11:18 PM, Mina Nozar wrote:
>> Dear Alberto,
>>
>> No problem and thank you very much for the fix. I tried:
>>
>> *...**
>> ** WRITE(IODRAW,100) JTRACK,XSCO,YSCO,ZSCO,CXTRCK,CYTRCK,CZTRCK,**
>> ** & ETRACK-AM(JTRACK),WTRACK**
>> ** END IF**
>> **....*
>>
>> * 100 FORMAT(I2,1X,3(E10.4,1X),3(E23.16,1X),2(E10.4,1X))*
>>
>> and now get:
>>
>> * 8 -.2635E+03 0.6864E+02 0.2944E+04 -0.6332783577022189E+00
>> -0.3722034999484587E+00 -0.6785448226109299E+00 0.6606E-06 0.6400E-05**
>> ** 7 -.2635E+03 0.6589E+02 0.2946E+04 -0.4822515648543289E+00
>> -0.8047950128287192E+00 0.3460323908560768E+00 0.8389E-03 0.2133E-06**
>> ** 7 -.2635E+03 0.7252E+02 0.2941E+04 -0.7274812055368878E+00
>> 0.1436728665088557E+00 -0.6709166885834075E+00 0.1702E-03 0.2133E-06**
>> ** 8 -.2635E+03 0.7615E+02 0.2963E+04 -0.6197521724979730E+00
>> 0.3405052282917437E+00 0.7070809247816193E+00 0.4350E-04 0.6400E-05**
>> ** 8 -.2635E+03 0.8386E+02 0.2965E+04 -0.9697606488622998E+00
>> -0.2337286859370908E+00 0.7025087393258518E-01 0.7173E-04 0.6400E-05*
>>
>>
>> so it looks good. And within 16 sig. figs. the magnitude of dir.
>> cosines is normalized to 1. If I read these number in, then
>>
>> *TXFLK(NPFLKA) = CosX(line)**
>> **TYFLK(NPFLKA) = CosY(line)*
>> *TZFLK(NPFLKA) = SQRT ( ONEONE - TXFLK(NPFLKA)**2
>> & - TYFLK(NPFLKA)**2 )*
>>
>> is not needed and
>>
>> *TZFLK(NPFLKA) = CosZ(line)*
>>
>> should work fine.
>>
>>
>> Please bear with me as I ask this question. I am trying to
>> understand what the ramifications of using unnormalized dir. cosines
>> would be (i.e. if I didn't write and read in the full 16 sig. fig.
>> numbers).
>>
>> The reason behind the two step (for the project I am working on) is
>> to test out different shielding configurations for the upstream
>> section (in the backward direction around the beamline). And because
>> there will be few iterations as the beamline components and positions
>> get finalized. It takes much less time to do the iterations. Once I
>> am happy with the final setup, I would run a long statistics single step.
>>
>> Thank you and best wishes,
>> Mina
>>
>>
>>
>> On 13-11-13 10:35 PM, Fasso, Alberto wrote:
>>> Sorry Mina,
>>> I wrote in a hurry, and I miscalculated the total number figures needed. Instead of E20.16, write E23.16 (16, plus one for the sign, one for the decimal point, 3 for the exponent, and a couple for some separation blanks). About the latter, add some spaces also between the other numbers.
>>>
>>> Apologies
>>>
>>> Alberto
>>> ________________________________________
>>> From: Mina Nozar [nozarm_at_triumf.ca]
>>> Sent: Wednesday, November 13, 2013 5:34 PM
>>> To: Fasso, Alberto;fluka-discuss_at_fluka.org
>>> Cc:Andrea.Mairani_at_mi.infn.it; Vahan Petrosyan
>>> Subject: Re: [fluka-discuss]: Writting SOURCE user routine generating from file with mixture of particles?
>>>
>>> Hi Alberto,
>>>
>>> Do you know why the output from mgdraw looks like this now?
>>>
>>> 8
>>> -.2635E+030.6864E+020.2944E+04************************************************************0.6606E-060.6400E-05
>>> 7
>>> -.2635E+030.6589E+020.2946E+04************************************************************0.8389E-030.2133E-06
>>> 7
>>> -.2635E+030.7252E+020.2941E+04************************************************************0.1702E-030.2133E-06
>>> 8
>>> -.2635E+030.7615E+020.2963E+04************************************************************0.4350E-040.6400E-05
>>>
>>> The format statement I have is:
>>> 100 FORMAT(I2,1X,3(E10.4),3(E20.16),2(E10.4),1X)
>>>
>>> Do I need to force a new line after so many characters?
>>>
>>> Thank you,
>>> Mina
>>>
>>> On 13-11-13 02:09 AM, Alberto Fasso' wrote:
>>>> Dear Mina,
>>>>
>>>> those lines you report are not written "by FLUKA"! (ENTRY BXDRAW in the
>>>> mgdraw.f routine does not produce any output by default). They are
>>>> written by you, probably using a WRITE(...,*) statement. While the
>>>> values of the variables
>>>> have in the code 16 significant figures, what they have in that output is
>>>> only 4 figures: the sum of the squares of the cosines, which is
>>>> exactly = 1.0
>>>> (within 16 significant figures!) in the code, is now 1.0 within only 4
>>>> figures,
>>>> as you can see from your test.
>>>>
>>>> There are two ways you can fix this problem.
>>>> 1) write the cosines with 16 significant figures, using
>>>> FORMAT(...,E20.16,...)
>>>> 2) read COSX, COSY and COSZ, calculate COSNEW as
>>>> SQRT(ONEONE - COSX**2 - COSY**2), give it the sign of COSZ
>>>> using the Fortran function SIGN(COSNEW,COSZ), and set COSZ = COSNEW
>>>>
>>>> Alberto
>>>>
>>>> On Tue, 12 Nov 2013, Mina Nozar wrote:
>>>>
>>>>> Here is the first few lines from the data file written out by FLUKA,
>>>>> containg x,y,z, cosx,cosy,cosz, E, weight of neutrons and photons.
>>>>>
>>>>>
>>>>> 8 -.2635E+03 0.6864E+02 0.2944E+04 -.6333E+00 -.3722E+00 -.6785E+00
>>>>> 0.6606E-06 0.6400E-05
>>>>> 7 -.2635E+03 0.6589E+02 0.2946E+04 -.4823E+00 -.8048E+00 0.3460E+00
>>>>> 0.8389E-03 0.2133E-06
>>>>> 7 -.2635E+03 0.7252E+02 0.2941E+04 -.7275E+00 0.1437E+00 -.6709E+00
>>>>> 0.1702E-03 0.2133E-06
>>>>> 8 -.2635E+03 0.7615E+02 0.2963E+04 -.6198E+00 0.3405E+00 0.7071E+00
>>>>> 0.4350E-04 0.6400E-05
>>>>> 8 -.2635E+03 0.8386E+02 0.2965E+04 -.9698E+00 -.2337E+00 0.7025E-01
>>>>> 0.7173E-04 0.6400E-05
>>>>> 7 -.2635E+03 0.7403E+02 0.2909E+04 -.9050E+00 0.4251E+00 0.1854E-01
>>>>> 0.2451E-02 0.1030E-07
>>>>> 7 -.2635E+03 0.6947E+02 0.2910E+04 -.6588E+00 0.4806E+00 0.5788E+00
>>>>> 0.8012E-03 0.1031E-07
>>>>> 7 -.2635E+03 0.7410E+02 0.2914E+04 -.8432E+00 -.2508E+00 0.4755E+00
>>>>> 0.5228E-03 0.1840E-07
>>>>> ...
>>>>> ...
>>>>> ...
>>>>>
>>>>> and sqrt(cosx^2 + cosy^2 + cosz^2):
>>>>>
>>>>> sqrt(.6333E+00^2 + .3722E+00^2 + .6785E+00^2) = 0.99998198...
>>>>> sqrt(.4823E+00^2 + .8048E+00^2 + .3460E+00^2) = 1.00000161648...
>>>>> sqrt(.7275E+00^2 + .1437E+00^2 + .6709E+00^2) = 1.00000637497...
>>>>> sqrt(.6198E+00^2 + .3405E+00^2 + .7071E+00^2) = 1.000041349...
>>>>> sqrt(.9698E+00^2 + .2337E+00^2 + .7025E-01^2) = 1.0000313957...
>>>>> sqrt(.9050E+00^2 + .4251E+00^2 + .1854E-01^2) = 1.000003937...
>>>>> sqrt(.6588E+00^2 + .4806E+00^2 + .5788E+00^2) = 1.000001619...
>>>>> sqrt(.8432E+00^2 + .2508E+00^2 + .4755E+00^2) = 0.99999356...
>>>>>
>>>>>
>>>>> Mina
>>>>>
>>>>> On 13-11-12 04:57 PM, Mina Nozar wrote:
>>>>>> Hello Andrea,
>>>>>>
>>>>>> But I get the same problem with an output file writtin by FLUKA
>>>>>> (through usrdump and mgdraw.f). What is the solution then?
>>>>>>
>>>>>> thanks,
>>>>>> Mina
>>>>>>
>>>>>>
>>>>>> On 13-11-12 12:41 PM,Andrea.Mairani_at_mi.infn.it wrote:
>>>>>>> Dear Vahan,
>>>>>>> What are the columns #5,6 and 7?
>>>>>>> As Mina wrote,
>>>>>>>> The problem seems to be in the following line:
>>>>>>>>
>>>>>>>> * TZFLK (NPFLKA) = SQRT ( ONEONE - TXFLK (NPFLKA)**2
>>>>>>>> * & - TYFLK (NPFLKA)**2 )
>>>>>>> but you should NOT change it, the problem is that TXFLK (NPFLKA)**2 +
>>>>>>> TYFLK (NPFLKA)**2 is greater than 1 (!) in your case and you have the
>>>>>>> floating exception....
>>>>>>> Cheers,
>>>>>>> Andrea
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> I commented it out and added:
>>>>>>>>
>>>>>>>> TZFLK (NPFLKA) = COSZ(I)
>>>>>>>>
>>>>>>>>
>>>>>>>> The above fix gets rid of the core dump but again, I don't know
>>>>>>>> why the
>>>>>>>> original line causes a core dump. I have run into this problem
>>>>>>>> before.
>>>>>>>> I am sending this response to the list. Maybe someone has an
>>>>>>>> explanation (I am neither a FLUKA nor a FORTRAN expert).
>>>>>>>>
>>>>>>>>
>>>>>>>> I ran your project with the 'test.dat' file and produced output files
>>>>>>>> (please check the numbers, I didn't look at the source file in
>>>>>>>> detail).
>>>>>>>> 3 0.2 0.3 -0.9 -0.2 -0.4 -0.9 0.003
>>>>>>>> 1 0.3 -0.3 -0.6 0.5 0.5 -0.3 0.007
>>>>>>>> 3 -0.3 -0.3 -0.5 -0.5 -0.9 0.8 0.006
>>>>>>>>
>>>>>>>>
>>>>>>>> I don't think you need the data file to be in the D+/-xx format (from
>>>>>>>> your 'test-correct.dat' file). FLUKA itself doesn't write output
>>>>>>>> from
>>>>>>>> the first step (scoring particles crossing a boundary (boundaries) in
>>>>>>>> this format.
>>>>>>>> 1 20D-01 1D-02 -1D+00 -1D-01 1D-01 1D-01 1D-04
>>>>>>>> 3 10.2D-01 1.3D-02 -14D+00 -8D-01 1.2D-01 1D-01 1D-03
>>>>>>>> 8 20D-01 1D-02 -1D+00 -1.1D-01 1D-01 1D-01 200D-04
>>>>>>>> 3 19D-01 10D-02 -18D+00 -1D-01 -1D-01 -1D-01 1D-04
>>>>>>>>
>>>>>>>> Again, I am not an expert, so I'll leave it to the experts to
>>>>>>>> comment.
>>>>>>>>
>>>>>>>> Best wishes,
>>>>>>>> Mina
>>>>>>>>
>>>>>>>>
>>>>>>>> On 13-11-09 06:36 AM, Vahan Petrosyan wrote:
>>>>>>>>> But I revised my source code and found many LOGICAL mistakes because
>>>>>>>>> of which my source routine didn't work at all. Yes it run but it
>>>>>>>>> didn't take beam from data file. So.... I corrected my mistakes and
>>>>>>>>> now it works as I want.
>>>>>>>>>
>>>>>>>>> But I have SMALL Problem! Can you help me please?
>>>>>>>>> I have DATA FILE in this format: 3 0.2 0.3 -0.9 -0.2
>>>>>>>>> -0.4 -0.9 0.003
>>>>>>>>> but when I run it crashes with ERROR: "Floating point exception
>>>>>>>>> (core
>>>>>>>>> dumped)"
>>>>>>>>> I read the the lecture
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Where it SAYS:
>>>>>>>>> "The code works under IMPLICIT DOUBLE PRECISION for variables in the
>>>>>>>>> range (A-H,O-Z). Don?t forget ..D+/-xx (eg
>>>>>>>>> 2.3D+00, 7.8D-03) in all numerical settings in user routines, and be
>>>>>>>>> careful in passing variables to/from Fluka"
>>>>>>>>> ie passed number should be in this form "2.3D+00".
>>>>>>>>> So...... I manually crated DATA FILE with this format: 1 20D-01
>>>>>>>>> 1D-02 -1D+00 -1D-01 1D-01 1D-01 1D-04
>>>>>>>>> and my code worked as I expected.
>>>>>>>>> ..................
>>>>>>>>> I tried to use DBLE() function in order to convert my array elements
>>>>>>>>> to DOUBlE PRECISION when I assign it to the FLUKA variables but it
>>>>>>>>> doesn't help...... again the same error appears.
>>>>>>>>> ....I do like this....
>>>>>>>>> TXFLK (NPFLKA) = DBLE(COSX(I))
>>>>>>>>> .....................
>>>>>>>>> When I use another DATA FILE where numbers are like this "2.3D+00"
>>>>>>>>> format My code WORKS JUST FINE!!!
>>>>>>>>>
>>>>>>>>> Now I try to convert data in form "2.3D+00" myself using this doc.
>>>>>>>>> http://docs.oracle.com/cd/E19957-01/805-4939/z40007437a2e/index.html
>>>>>>>>> but can't implement.... the same error appears.....
>>>>>>>>> So question how can I convert my DATA file numbers to this "2.3D+00"
>>>>>>>>> format using FORTRAN77?
>>>>>>>>>
>>>>>>>>> Thank You!
>>>>>>>>>
>>>>>>>>> On 11/8/2013 10:47 PM,nozarm_at_triumf.ca wrote:
>>>>>>>>>> Hello Vahan,
>>>>>>>>>>
>>>>>>>>>> I just tried compiling and running the executable and it worked
>>>>>>>>>> just
>>>>>>>>>> fine.
>>>>>>>>>> I defined a new run in your flair project, named testroutine-A with
>>>>>>>>>> 1000
>>>>>>>>>> primaries per cycle and 5 cycles.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Cmd: /usr/bin/nohup
>>>>>>>>>> /triumfcs/linux/fluka/fluka/default/flutil/rfluka
>>>>>>>>>> -M 5
>>>>>>>>>> testroutine-A
>>>>>>>>>>
>>>>>>>>>> produced:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> -rw-rw-r-- 1 nozarm nozarm 4000238 Nov 8 10:39stroutine-A001.log
>>>>>>>>>> -rw-rw-r-- 1 nozarm nozarm 4000238 Nov 8 10:39
>>>>>>>>>> testroutine-A001_fort.32
>>>>>>>>>> -rw-rw-r-- 1 nozarm nozarm 114352 Nov 8 10:39
>>>>>>>>>> testroutine-A001.out
>>>>>>>>>> -rw-rw-r-- 1 nozarm nozarm 22470 Nov 8 10:39
>>>>>>>>>> testroutine-A001.err
>>>>>>>>>>
>>>>>>>>>> and similar files for A002 through A005.
>>>>>>>>>>
>>>>>>>>>> I even looked at your usrbin plot and it looks fine.
>>>>>>>>>>
>>>>>>>>>> I am attaching the flair project file with the run definition. I
>>>>>>>>>> think
>>>>>>>>>> your problem was with the way you were running fluka at the end.
>>>>>>>>>>
>>>>>>>>>> Best wishes,
>>>>>>>>>> Mina
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> Hi everyone!
>>>>>>>>>>> I am wrtitting a custom SOURCE routine that generates beam with
>>>>>>>>>>> mixture
>>>>>>>>>>> of particles for example electrons and protons from DATA FILE.
>>>>>>>>>>> I read the FLUKA help part 13.2.19 and fluka discuss thread from
>>>>>>>>>>> Alberto
>>>>>>>>>>> Fasso
>>>>>>>>>>> http://www.fluka.org/web_archive/earchive/new-fluka-discuss/2887.html.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I was able to write the routine and compile it with success!!! But
>>>>>>>>>>> when
>>>>>>>>>>> I run FLUKA It starts to work in a moment and crashes with
>>>>>>>>>>> "Finished
>>>>>>>>>>> with ERRORS".
>>>>>>>>>>> In my source.f routine:
>>>>>>>>>>> 1) I read file using OPEN command
>>>>>>>>>>> 2) I use READ command inside DO loop in order to fill arrays of
>>>>>>>>>>> particle-ID, coordinates, cosines and energy.
>>>>>>>>>>> 3) I put particle intanialization from input file in DO loop.
>>>>>>>>>>> DO 20 I = 1, NLINES
>>>>>>>>>>> NPFLKA = NPFLKA + 1
>>>>>>>>>>> WTFLK (NPFLKA) = ONEONE
>>>>>>>>>>> WEIPRI = WEIPRI + WTFLK (NPFLKA)
>>>>>>>>>>> IJBEAM = PARTID(I)
>>>>>>>>>>> TXFLK (NPFLKA) = COSX(I)
>>>>>>>>>>> TYFLK (NPFLKA) = COSX(I)
>>>>>>>>>>>
>>>>>>>>>>> ****** etc. ******
>>>>>>>>>>> 20 CONTINUE
>>>>>>>>>>> RETURN
>>>>>>>>>>> CALL SOEVSV
>>>>>>>>>>>
>>>>>>>>>>> I can't undertand why it happens because in my nohup.out file
>>>>>>>>>>> there is
>>>>>>>>>>> only one single line
>>>>>>>>>>>
>>>>>>>>>>> ======================= Running FLUKA for cycle # 1
>>>>>>>>>>> =======================
>>>>>>>>>>> /usr/local/fluka/flutil/rfluka: line 358: 1926 Aborted
>>>>>>>>>>> (core dumped) "\${EXE}" < "\$INPN" 2> "\$LOGF" > "\$LOGF"
>>>>>>>>>>>
>>>>>>>>>>> If someone has time PLEASE take a look and say why my SOURCE
>>>>>>>>>>> doesn't
>>>>>>>>>>> work.......
>>>>>>>>>>> I am attached files that I got after run.
>>>>>>>>>>>
>>>>>>>>>>> Thank You.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>
>
Received on Thu Nov 14 2013 - 22:54:52 CET

This archive was generated by hypermail 2.3.0 : Thu Nov 14 2013 - 22:54:55 CET