RE: problem when reading source from a file

From: Fasso, Alberto <fasso_at_SLAC.Stanford.EDU>
Date: Thu, 1 Jul 2010 03:13:49 -0700

Dear Yuanjie,

all the statements located between IF(LFIRST) and END IF (*** User initializatio
n ***) are executed
only once, the first time the source routine is called.
Move READ(98,*) X,Y,Z,PX,PY,PZ after the user initialization, i.e. af
ter the END IF.

Apart from that, three remarks:

1) XBEAM=X/10
         YBEAM=Y/10
         ZBEAM=Z/10
  10 is an integer, you shoud use a double precision number:
         XBEAM=X/10.D0
         YBEAM=Y/10.D0
         ZBEAM=Z/10.D0

2) SQRT(PX*PX+PY*PY+PZ*PZ) : this expression, used several times, contains a sq
uare root which is very expensive in CPU time. Probably the compiler optimizer will take c
are of evaluating it only once, but it is better to do that yourself:
      TEMP = SQRT(PX*PX+PY*PY+PZ*PZ)
      UBEAM = PX/TEMP
      VBEAM = PY/TEMP
      WBEAM = PZ/TEMP

3) PBEAM=SQRT(PX*PX+PY*PY+PZ*PZ)* AM (IONID)
      Why the multiplication by AM (IONID)? The momentum is just the vectorial s
um of PX, PY, PZ

Alberto
________________________________________
>From: owner-fluka-discuss_at_mi.infn.it [owner-fluka-discuss_at_mi.infn.it] On Behalf
>Of ±ΟΤΆ½ά [biyuanjie_at_tsinghua.org.cn]
>Sent: Tuesday, June 29, 2010 7:30 PM
>To: fluka-discuss_at_fluka.org
>Subject: problem when reading source from a file
>
>Dear everyone
>
>I read in the source from a file which includes 1e6 particles.
>I do the following in source.f :
>
>* | *** User initialization ***
> OPEN(98,FILE='../loss.txt',STATUS='OLD',FORM='FORMATTED')
> READ(98,*) X,Y,Z,PX,PY,PZ
>*
>...................
>
>*... to this point: don't change anything
> XBEAM=X/10
>
> YBEAM=Y/10
>
> ZBEAM=Z/10
>
>
> UBEAM=PX/SQRT(PX*PX+PY*PY+PZ*PZ)
>
> VBEAM=PY/SQRT(PX*PX+PY*PY+PZ*PZ)
>
> WBEAM=PZ/SQRT(PX*PX+PY*PY+PZ*PZ)
>
>
> PBEAM=SQRT(PX*PX+PY*PY+PZ*PZ)* AM (IONID)
>
>Now the question is:
>Everytime when calling source.f, only the first line in loss.txt is readed in.
>How could I solve it?
>Thanks very much!

>Best wishes
>Yuanjie
Received on Thu Jul 01 2010 - 13:07:54 CEST

This archive was generated by hypermail 2.2.0 : Thu Jul 01 2010 - 13:07:54 CEST