forked from valentastanislav/dicebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fce_global.f90
1727 lines (1692 loc) · 61.6 KB
/
fce_global.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!TODO gilbert cameron and spin distribution of initial states email jutta escher
!gamma_multiplicita make
module vsechno
use lokalni_fce
use spolecne
implicit none
integer:: NEVENTS,NREAL,NSUB,NDDD,NOPTFL,NLINc,ipinc,nfilev,NSTEPS,NENT,NENK,NEN_IPF,&
KpopGS,ISWWR,ISWBN,ISWEL,ISWSP,ISWPA,ISWIC,ISWMX,ISWWI,ISWLS,NOPTCS,&
N_MSC_FS,MIN_MULTIPLICITA,MAX_MULTIPLICITA,TRGT_PI
real:: eall,EIN,EFI,ecrit,xrayk,xrayl,max_spin,factnrm,SUMNO,BIN_WIDTH,&
D0,TRGT_SPIN
integer, dimension(1:199):: ilowip
integer, dimension(0:49,0:1):: levdis
integer, dimension(1:20,0:49,0:1):: dekod
integer,dimension(:,:),allocatable:: isbspin
real, dimension(:),allocatable:: MSC_FS
real, dimension(1:2):: CAPFR,spinc
real, dimension(1:100):: elent,elenk,ELEN_IPF
real, dimension(1:199):: elowlev,elowsp
real, dimension(1:199,0:20):: p_conv,p_conv_K,p_conv_IPF !TODO somehow smart determine the maximum number of decays in DIS and make these allocatable
real, dimension(1:199,1:20):: deltx
real, dimension(0:1,1:5,1:100):: CONVt,CONVk,CONV_IPF
contains
!***********************************************************************
SUBROUTINE READ_EV(NAME,lopopgs,KONTROLMATRIX)
! reading of the input file
INTEGER,PARAMETER:: MAXJC = 49
CHARACTER(80):: TITLE1,TITLE2,TITLE3
character(80):: NAME
logical:: lopopgs
integer,dimension(:,:),allocatable:: KONTROLMATRIX
INTEGER:: I,J,K,NMU,ipfi,ipar,control
REAL:: enrg,spfi,enrgf,desp,dlt,alphak,alphaIPF,SPACRES,dummy,FSPAC,corrAlpha,corrDelta
OPEN (UNIT=5,FILE=NAME,STATUS='OLD')
! User's alphanumeric titles:
READ (5,100) TITLE1
READ (5,100) TITLE2
READ (5,100) TITLE3
100 FORMAT (A80)
! The regime of run:
READ (5,*)
READ (5,*) ISWWR,ISWBN,ISWEL,ISWSP,ISWPA,ISWIC,ISWMX,ISWWI,ISWLS
READ (5,*)
Read (5,*) Nreal, NEVENTS, NSUB
if (.not.allocated(KONTROLMATRIX)) then
allocate(KONTROLMATRIX(1:4,1:NREAL))
endif
READ (5,*)
READ (5,*) NBIN,(KONTROLMATRIX(I,1),I=1,4)
READ (5,*)
READ (5,*) NOPTFL,NOPTE1,NOPTM1,NOPTE2,NOPTDE,LMODE,LDENP,LDSTAG
READ (5,*)
READ (5,*) N_MSC_FS, BIN_WIDTH
if (N_MSC_FS.GE.1) then
allocate (MSC_FS(1:N_MSC_FS))
DO I=1,N_MSC_FS
READ (5,*) MSC_FS(I)
ENDDO
endif
MIN_MULTIPLICITA=1
MAX_MULTIPLICITA=7
!
! Giant Resonaces:
!
NLOWLOR=0
READ (5,*)
IF((NOPTE1.EQ.66).OR.(NOPTE1.EQ.77)) THEN
READ (5,*) NGIGE, NLOWLOR
DO I=1, NGIGE+NLOWLOR
READ (5,*) ER(I),W0(I),SIG(I)
ENDDO
ELSE
READ (5,*) NGIGE
DO I=1, NGIGE
READ (5,*) ER(I),W0(I),SIG(I)
ENDDO
ENDIF
READ (5,*)
READ (5,*) NGIGM
DO I=1, NGIGM
READ (5,*) ERM(I),WM0(I),SIGM(I)
ENDDO
READ (5,*)
READ (5,*) NGIGE2
DO I=1, NGIGE2
READ (5,*) ERE(I),WE0(I),SIGE(I)
ENDDO
!
! Other data needed for photon strength:
READ (5,*)
READ (5,*) DEG,DMG,QEL
READ (5,*)
READ (5,*) FERMC, TCONST, PAIR_PSF
READ (5,*)
READ (5,*) EK0,EGZERO
READ (5,*)
READ (5,*) (PAR_E1(I),I=1,3) ! DIPELO,DIPEHI,DIPSUP
DIPSLP=(1.0-PAR_E1(3))/(PAR_E1(2)-PAR_E1(1))
DIPZER=1.0-DIPSLP*PAR_E1(2)
READ (5,*)
READ (5,*) (PAR_M1(I),I=1,4)
!
! Data needed for level density formulas:
!
READ (5,*)
READ (5,*) EZERO,DEL,TEMPER,ASHELL,AMASS,ZNUM,PAIRING
READ (5,*)
READ (5,*) ASHELL09,DEL09,TEMPER09,EZERO09,PAIRING09,SIG_CUSTOM
READ (5,*)
READ (5,*) DENPPC,DENPA0,DENPA1,DENPA2 !see PRC67, 015803
IF ((LDENP.GT.0).AND.(DENPPC.LT.0.)) THEN
WRITE(*,*) 'Negative DENPPC means parity asymmetry is appearing with excitation energy',&
' while oposite is usually the case. Are You sure about the DENPPC = ',DENPPC,' ?'
ENDIF
READ (5,*)
READ (5,*) DENLO,DENHI,DENPA,DENPB,DENPC,DENPD
IF (LDSTAG.NE.0) THEN
IF ((MOD(INT(AMASS+0.25),2).NE.0).OR.(MOD(INT(ZNUM+0.25),2).NE.0)) THEN
WRITE(*,*) 'Are You sure You want to use staggering in isotope which is not even-even?!'
ENDIF
WRITE(*,*) 'Effect of staggering linearly decrasing from energy of ',DENLO,' MeV to ',DENHI,' MeV'
ENDIF
!
! Data relating to the (thermal) neutron capturing state:
!
READ (5,*)
READ (5,*) BN,SPINc(1),IPINC,TRGT_SPIN,TRGT_PI
NOPTCS=1
NLINc=1
CAPFR(1)=1.
!
! Now read the tables of ICC-coefficients and other information
! on electron conversion. The used notation:
!
! XRAYK,XRAYL -- electron binding energy for K-shell
! (and L-shell) expressed in MeV
! NENT,NENK -- the number of electron energy points
! NMU -- the highest multipolarity, e.g. 3 for
! octupole (electric and magnetic)
! CONVK(I,MU,K) -- K-shell ICC for I-th type of radiation
! (0 for electric, 1 for magnetic),
! multipolarity MU and K-th electron
! energy value
! CONVT(I,M,K) -- total ICC ... (as the CONVK)
! ELENT(K),ELENK(K) -- K-th value of electron energy
!
READ (5,*)
READ (5,*) xrayk,xrayl
READ (5,*) NMU
READ (5,*) NENT
READ (5,*) (ELENT(K),K=1,NENT)
READ (5,*) (((CONVT(I,J,K),I=0,1),J=1,NMU),K=1,NENT)
READ (5,*) NENK
READ (5,*) (ELENK(K),K=1,NENK)
READ (5,*) (((CONVK(I,J,K),I=0,1),J=1,NMU),K=1,NENK)
READ (5,*) NEN_IPF
READ (5,*) (ELEN_IPF(K),K=1,NEN_IPF)
READ (5,*) (((CONV_IPF(I,J,K),I=0,1),J=1,3),K=1,NEN_IPF)
!
! Data related to the discrete levels (J, pi, Eexc, primary intensities
! and branchings):
!
READ (5,*)
READ (5,*) ECRIT
EALL=ECRIT
read (5,*)
LOpopGS=.false.
DO J=0,MAXJC
DO K=0,1
NDIS(J,K)=0
ENDDO
ENDDO
max_decays=0
max_spin=0.
READ (5,*) numlev
if (.not.allocated(ityp)) then
allocate (ityp(1:numlev,1:2))
endif
if (.not.allocated(isbspin)) then
allocate (isbspin(1:numlev,1:2))
endif
DO i=1,numlev
READ (5,*) enrg,spfi,ipfi,denum(i),dummy,dummy,LVL_CLASS(i)
write(*,*) 'reading lvl # ',i,' at energy ',enrg
IF((ipfi.NE.0).AND.(ipfi.NE.1)) THEN
WRITE(*,*) 'parity can be either 0 (+) or 1 (-)'
STOP
ENDIF
LVL_ENERGY(i)=enrg
ndis(ISUBSC(spfi),ipfi)=ndis(ISUBSC(spfi),ipfi)+1
endis(ndis(ISUBSC(spfi),ipfi),ISUBSC(spfi),ipfi)=enrg
dekod(ndis(ISUBSC(spfi),ipfi),ISUBSC(spfi),ipfi)=i
IF (denum(i).GT.0) then
DO k=1,denum(i)
! write(*,*) i,k,enrg
READ (5,*) enrgf,sal(i,k),errsal(i,k),desp,ipar,dlt,alpha(i,k)
IF((ipar.NE.0).AND.(ipar.NE.1)) THEN
WRITE(*,*) 'parity can be either 0 (+) or 1 (-)'
STOP
ENDIF
control=0
DO j=1,ndis(ISUBSC(desp),ipar)
IF(elowlev(dekod(j,ISUBSC(desp),ipar)).NE.enrgf) control=control+1
ENDDO
IF ((enrgf.GT.enrg).OR.(control.EQ.ndis(ISUBSC(desp),ipar))) THEN
WRITE(*,*) 'wrong decay pattern at level',enrg,'to level',enrgf,desp,ipar
STOP
ENDIF
DO j=1,ndis(ISUBSC(desp),ipar)
IF (endis(j,ISUBSC(desp),ipar).EQ.enrgf) THEN
delev(i,k)=j
despin(i,k)=desp
deparity(i,k)=ipar
deltx(i,k)=dlt
if (alpha(i,k).LE.1e-6) alpha(i,k)=ALPH_TOT(enrg,spfi,ipfi,enrgf,desp,ipar,dlt**2,nent,elent,convt)
alphak=ALPH_TOT(enrg,spfi,ipfi,enrgf,desp,ipar,dlt**2,nenk,elenk,convk)
alphaIPF=ALPH_TOT(enrg,spfi,ipfi,enrgf,desp,ipar,dlt**2,NEN_IPF,ELEN_IPF,CONV_IPF)
if (alphak.GT.alpha(i,k)) alphak=alpha(i,k)
p_conv(i,k)=alpha(i,k)/(1+alpha(i,k))
p_conv_K(i,k)=alphak/(1+alpha(i,k))
p_conv_IPF(i,k)=(alphaIPF+alphak)/(1+alpha(i,k))
ENDIF
ENDDO
ENDDO
ENDIF
elowlev(i)=enrg
IF(elowlev(i).EQ.0.) THEN
LOpopGS=.TRUE.
KpopGS=i
ENDIF
elowsp(i)=spfi
ilowip(i)=ipfi
IF(denum(i).GT.max_decays) max_decays=denum(i)
IF(elowsp(i).GT.max_spin) max_spin=elowsp(i)
!
DO j=1,NLINc
isbspin(i,j)=NINT(spfi+.25)-NINT(spinc(j)+.25)
ityp(i,j)=ITYPE(spinc(j),ipinc,spfi,ipfi)
ENDDO
IF (NLINc.EQ.1) ityp(i,2)=0
ENDDO !i over numlev
!
DO ipfi=0,1
DO j = 0,ISUBSC(max_spin)
spfi = spinc(1)-int(spinc(1)+.25) + float(j)
levdis(ISUBSC(spfi),ipfi)=nddd+ndis(ISUBSC(spfi),ipfi)
nddd=levdis(ISUBSC(spfi),ipfi)
ENDDO
ENDDO
!
CLOSE (UNIT=5,STATUS='KEEP')
WRITE(*,*) 'nddd ',nddd,' numlev ',numlev
IF ((NOPTDE.EQ.8).OR.(NOPTDE.EQ.9)) THEN
IF (MOD(INT(AMASS+0.25),2).EQ.0) THEN
IF (MOD(INT(ZNUM+0.25),2).EQ.0) THEN
WRITE(*,*) 'beware, LD model is going to use staggering!'
ENDIF
ENDIF
ENDIF
!
! Tabulated level density (Kawano)
!
IF (NOPTDE.EQ.12) THEN
NAME = "LDTAB_K.DAT"
OPEN (UNIT=5,FILE=NAME,STATUS='OLD')
READ(5,*)
READ(5,*) NLD
READ(5,*)
DO I = NLD, 1, -1
READ(5,*) TABENLD(I),DUMMY,(TABLD(I,J,0),J=0,9)
ENDDO
DO I = 1, NLD
DO J = 0, 9
TABLD(I,J,0) = TABLD(I,J,0) / 2.0 ! Kawano gives total NLD (p-independent)
TABLD(I,J,1) = TABLD(I,J,0)
ENDDO
DO J = 10, MAXJC
TABLD(I,J,0) = 0.0
TABLD(I,J,1) = 0.0
ENDDO
ENDDO
CLOSE (UNIT=5,STATUS='KEEP')
IF (TABENLD(NLD).LT.BN) THEN
WRITE(*,*) 'tabulated LD does not span up to the initial state: ',TABENLD(NLD),' vs ',BN
STOP
ENDIF
ENDIF
!
! Tabulated level density (Goriely)
!
IF (NOPTDE.EQ.11) THEN
NAME = "LDTAB.DAT"
OPEN (UNIT=5,FILE=NAME,STATUS='OLD')
READ(5,*)
READ(5,*) NLD, SPACRES,spfi,ipfi,corrAlpha,corrDelta
READ(5,*)
DO I = 1, NLD
READ(5,*) TABENLD(I),DUMMY,DUMMY,DUMMY,DUMMY,(TABLD(I,J,0),J=0,MAXJC)
ENDDO
READ(5,*)
READ(5,*)
READ(5,*)
DO I = 1, NLD
READ(5,*) TABENLD(I),DUMMY,DUMMY,DUMMY,DUMMY,(TABLD(I,J,1),J=0,MAXJC)
ENDDO
IF (TABENLD(NLD).LT.BN) THEN
WRITE(*,*) 'tabulated LD does not span up to the initial state: ',TABENLD(NLD),' vs ',BN
STOP
ENDIF
!
! "Normalization to experimental level spacing" - spfi/ipfi needed
!
IF (spfi.EQ.0.0) THEN !matching the s-wave spacing for even-even target with gs spin 0
FSPAC = (1.0 / SPACRES * 1e6) / DENSITY(BN,spfi+0.5,ipfi)
corrAlpha=0.0
corrDelta=0.0
write(*,*) 'using tabulated NLD matched to s-wave resonance spacing of ',SPACRES
ELSEIF (spfi.EQ.-1.0) THEN !constant renormalization by one common factor
write(*,*) 'using tabulated NLD with renormalization by one given factor of ',SPACRES
FSPAC = SPACRES
corrAlpha=0.0
corrDelta=0.0
ELSEIF (spfi.EQ.-2.0) THEN !renormalization by Goriely PRC 78 064307 (2008): \rho(u,J,p)=\exp(alpha x \sqrt(U-delta)) * \rho(U-delta,J,p)
write(*,*) 'using tabulated NLD with renormalization by Goriely PRC 78 064307 (2008) from ',TABENLD(1),&
' to ', TABENLD(NLD),' with alpha ',corrAlpha,' and delta ',corrDelta
FSPAC = 1
ELSE !matching the s-wave spacing for target with nonzero spin
FSPAC = (1.0 / SPACRES * 1e6) /(DENSITY(BN,spfi-0.5,ipfi) + DENSITY(BN,spfi+0.5,ipfi))
corrAlpha=0.0
corrDelta=0.0
write(*,*) 'tabulated NLD gives s-wave resonance spacing of ',1e6/(DENSITY(BN,spfi-0.5,ipfi) + DENSITY(BN,spfi+0.5,ipfi))
write(*,*) 'using tabulated NLD matched to s-wave resonance spacing of ',SPACRES,' by a factor ',FSPAC
ENDIF
DO I = 1, NLD !Standa's version
TABENLD(I)=TABENLD(I)+corrDelta
DO J = 0, MAXJC
DO K = 0, 1
if (corrAlpha.eq.0.0) then
TABLD(I,J,K) = TABLD(I,J,K) * FSPAC
else
TABLD(I,J,K) = TABLD(I,J,K) * FSPAC * exp(corrAlpha*sqrt(TABENLD(I)-corrDelta))
endif
ENDDO
ENDDO
ENDDO
write(*,*) 'normalization of tabulated NLD done'
CLOSE (UNIT=5,STATUS='KEEP')
ENDIF
IF (TRGT_SPIN.EQ.0.0) THEN
D0=1e6/DENSITY(BN,TRGT_SPIN+0.5,TRGT_PI)
ELSE
D0=1e6/(DENSITY(BN,TRGT_SPIN-0.5,TRGT_PI) + DENSITY(BN,TRGT_SPIN+0.5,TRGT_PI))
ENDIF
!
! Tabulated PSF
!
IF ((NOPTE1.EQ.11).OR.(NOPTE1.EQ.50)) THEN
NAME = "PSFE1.DAT"
OPEN (UNIT=5,FILE=NAME,STATUS='OLD')
READ(5,*)
READ(5,*) NPSF(1), dummy
READ(5,*)
TABPSF(1,0)=0.
DO I = 1, NPSF(1)
READ(5,*) TABENPSF(1,I),TABPSF(1,I)
TABPSF(1,I)=dummy*TABPSF(1,I)
ENDDO
CLOSE(5)
IF (TABENPSF(1,NPSF(1)).LT.BN) THEN
WRITE(*,*) 'tabulated E1 does not span up to the initial state: ',TABENPSF(1,NPSF(1)),' vs ',BN
STOP
ENDIF
ENDIF
IF (NOPTM1.EQ.11) THEN
NAME = "PSFM1.DAT"
OPEN (UNIT=5,FILE=NAME,STATUS='OLD')
READ(5,*)
READ(5,*) NPSF(2), dummy
READ(5,*)
TABPSF(2,0)=0.
DO I = 1, NPSF(2)
READ(5,*) TABENPSF(2,I),TABPSF(2,I)
TABPSF(2,I)=dummy*TABPSF(2,I)
ENDDO
CLOSE(5)
IF (TABENPSF(2,NPSF(2)).LT.BN) THEN
WRITE(*,*) 'tabulated M1 does not span up to the initial state: ',TABENPSF(2,NPSF(2)),' vs ',BN
STOP
ENDIF
ENDIF
IF (NOPTE2.EQ.11) THEN
NAME = "PSFE2.DAT"
OPEN (UNIT=5,FILE=NAME,STATUS='OLD')
READ(5,*)
READ(5,*) NPSF(3), dummy
READ(5,*)
TABPSF(1,0)=0.
DO I = 1, NPSF(3)
READ(5,*) TABENPSF(3,I),TABPSF(3,I)
TABPSF(3,I)=dummy*TABPSF(3,I)
ENDDO
CLOSE(5)
IF (TABENPSF(3,NPSF(3)).LT.BN) THEN
WRITE(*,*) 'tabulated E2 does not span up to the initial state: ',TABENPSF(3,NPSF(3)),' vs ',BN
STOP
ENDIF
ENDIF
!
DELTA=(BN-ECRIT)/FLOAT(NBIN)
WRITE(*,*) ' Inputs have been successfully loaded.'
RETURN
END SUBROUTINE READ_EV
!***********************************************************************
SUBROUTINE GERMS(IR,NTOTAL,NDDD,IRCONc,IRCON) !should be OK
!
! This subroutine generates a random-generator random seed for
! each individual level. The seeds obtained are stored in IRCON(K).
! For a level of interest, characterized by {IP,SP,IB,IL}, the
! corresponding seed can be fetched in a simple way. This is evident
! from the body of the functio SEED that performs such an operation.
!
!***********************************************************************
! vstup(NTOTAL_tp,NDDD_c,NOPTCS_c) vystup(IRCON,IRCONc)
INTEGER:: I,IG,K,N,NOLD,NDIF,KAUX,JAUX
INTEGER,dimension(:),allocatable:: IAUX
REAL:: dummy
integer:: IR,NTOTAL,NDDD
integer,dimension(:),allocatable:: IRCONc,IRCON
!globalni NLINc
if (allocated(IRCON)) then
deallocate(IRCON)
endif
allocate(IRCON(1:NTOTAL+NDDD))
if (allocated(IRCONc)) then
deallocate(IRCONc)
endif
allocate(IRCONc(1:NLINc))
! Seed for 1st capturing state
NOLD = 0
NDIF = 0
IRCONc(1)=IR
! Initialization of IRCON
DO K=1,NTOTAL+NDDD
IRCON(K)=0
ENDDO
! IRCON(.) is seeded in a random fashion by seeds IR produced
! consecutively by repeated calls of RAN0(IR), see the body of the
! routine. If two or more seeds are falling to the same word of
! IRCON(.), then only the last of them is kept there.
4 DO IG=1,NTOTAL+NDDD
dummy=RAN0(IR)
K=CEILING(DBLE(NTOTAL+NDDD)*dummy) !obcas dela problem predelano by SV
IF (K.GT.(NTOTAL+NDDD)) write(*,*) dummy, NTOTAL+NDDD, DBLE((NTOTAL+NDDD)*dummy)
dummy=RAN0(IR)
IRCON(K)=IR
ENDDO
! Determine the number of not seeded IRCON(K)
N=0
DO K=1,NTOTAL+NDDD
IF (IRCON(K).EQ.0) N=N+1
ENDDO
NDIF = ABS(NOLD - N)
NOLD = N
IF ((NOLD.GT.2000).AND.(NDIF.GT.1000)) GOTO 4
IF (NOLD.EQ.0) GOTO 7
allocate(IAUX(1:NOLD))
! If every site of the IRCON(.) is seeded, the possible seeding of 2nd capture state
! and RETURN follows. If not, ONLY EMPTY positions are additionally
! seeded. Hopefully, seeds are again being distributed randomly.
! This new seeding to a restricted area ensures that ALL
! positions are seeded. After that the (2nd CS &) RETURN follows.
N=0
DO K=1,NTOTAL+NDDD
IF (IRCON(K).EQ.0) THEN
N=N+1
IAUX(N)=K
ENDIF
ENDDO
IF (N.NE.NOLD) WRITE(*,*) 'pruser velikost' !debug line
DO KAUX=1,NOLD
I=INT(FLOAT(N)*RAN0(IR))+1
dummy=RAN0(IR)
IRCON(IAUX(I))=IR
DO JAUX=I+1,N
IAUX(JAUX-1)=IAUX(JAUX)
ENDDO
N=N-1
ENDDO
IF (N.NE.0) WRITE(*,*) 'pruser nenulovost' !debug line
7 IF (NLINc.NE.1) THEN
dummy=RAN0(IR)
IRCONc(2)=IR ! 2nd capture state is now seeded
ENDIF
if (allocated(IAUX)) then
deallocate(IAUX)
endif
RETURN
END SUBROUTINE GERMS
!***********************************************************************
FUNCTION SEEDS(MODE,SP,IP,IL,IB,LEVCON,IRCON,IRCONc) !should be OK
! This functio yields the seed that is needed for the intrinsic
! functio RAN inside the subroutine WIDTHS immediately before
! this subroutine starts to generate the values of the subscripted
! variable STCON.
!***********************************************************************
INTEGER:: SEEDS
integer:: MODE,IP,IL,IB
real:: SP
integer,dimension(:),allocatable:: IRCONc,IRCON
integer,dimension(:,:,:),allocatable::LEVCON
!no globals, pro-ly strictly threadprivate
IF (MODE.GT.0) THEN
SEEDS=IRCONc(MODE)
ELSE
SEEDS=IRCON(LEVCON(IB-1,ISUBSC(SP),IP)+IL)
ENDIF
RETURN
END FUNCTION SEEDS
!***********************************************************************
!should be OK, just TODOs for chi2 random number generation
SUBROUTINE WIDTHS_R (MODE,IPIN,SPIN,IBIN,ILIN,TOTCON,STCON,GACON,ISCON,TOTDIS,STDIS,GADIS,ISDIS,LEVCON,&
IRCON,IRCONc,IFLAG,U,IREGI,EIN,EFI)
!***********************************************************************
double precision,dimension(0:2,-2:2,0:1):: GACON
double precision,dimension(:,:,:,:),allocatable:: STCON
double precision,dimension(0:2):: TOTCON
integer,dimension(:,:,:,:),allocatable:: ISCON
real, dimension(0:2,0:20,-2:2,0:1):: STDIS
real, dimension(0:2,-2:2,0:1):: GADIS
real, dimension(0:2):: TOTDIS
real:: U,SPIN,EIN,EFI
integer:: MODE,IPIN,IBIN,ILIN,IFLAG,IREGI
integer,dimension(:),allocatable:: IRCONc,IRCON
integer,dimension(:,:,:),allocatable::LEVCON
integer,dimension(:,:,:,:),allocatable::ISDIS
INTEGER:: IPFI,ISPFI,ISP,IP,IS,I,NLEV,ISEED,ISEEDGS,ISEEDORIG,ISBS,IT,IT1,IT2,ITT,IL,NL,ICOR
REAL:: SPFI,Q,SPAC,GGS,SP,EG,Z,GSQ,G,CLEB
REAL,dimension(1:2):: SIMPL
!globalni NOPTFL,DELTA,corri,re2res,im2res,NDIS,ENDIS,BN,NBIN
!
! If you use MODE=1 or 2 you have to set IBIN=1 and ILIN=1 !
!
IF (IREGI.EQ.0) THEN
IF (MODE.NE.0) THEN
EIN=BN
Q=0.0
ELSE
NLEV=LEVCON(IBIN,ISUBSC(SPIN),IPIN)-LEVCON(IBIN-1,ISUBSC(SPIN),IPIN)
Q=1.-FLOAT(2*ILIN-1)/FLOAT(2*NLEV)
EIN=BN-(FLOAT(IBIN)-Q)*DELTA
ENDIF
IF (NOPTFL.GE.1) ISEED=SEEDS(MODE,SPIN,IPIN,ILIN,IBIN,LEVCON,IRCON,IRCONc) !originaly .EQ.
ELSE
EIN=EFI
ENDIF
SPAC=1./DENSITY(EIN,SPIN,IPIN)
IF (SPAC.LE.0.0) SPAC=0.0000001 !nikdy byt nemusi
TOTCON(MODE)=0.D+0
TOTDIS(MODE)=0.
!
DO IS=-2,2
DO IP=0,1
DO I=0,NBIN
STCON(MODE,I,IS,IP)=0.D+0
ENDDO
! IF (MODE.EQ.0) THEN !what the hell
DO I=0,20
STDIS(MODE,I,IS,IP)=0.
ENDDO
! ENDIF
GACON(MODE,IS,IP)=0.D+0
GADIS(MODE,IS,IP)=0.
ENDDO
ENDDO
!
SP = SPIN - INT(SPIN + .25)
ISP = INT(SPIN + .25)
DO IPFI=0,1
DO ISPFI= ISP-2, ISP+2
SPFI = SP + FLOAT(ISPFI)
ISBS=NINT(SPFI+.25)-NINT(SPIN+.25)
IT=ITYPE(SPIN,IPIN,SPFI,IPFI)
IF (IT.EQ.0) GOTO 1
IF (IT.EQ.2) THEN
IT1=3
IT2=4
ELSE
IT1=IT
IT2=IT
ENDIF
STCON(MODE,IBIN,ISBS,IPFI)=0.D+0
IF (iregi.eq.1) then
ISEED=SEEDS(mode,spin,ipin,ilin,ibin,LEVCON,IRCON,IRCONc)
GOTO 24
ENDIF
!
DO I=IBIN+1,NBIN
NL=LEVCON(I,ISUBSC(SPFI),IPFI)-LEVCON(I-1,ISUBSC(SPFI),IPFI)
EG=(FLOAT(I-IBIN-1)+Q+.5)*DELTA ! Q=0.5 ... fixed; trans. between mid-bins
Z=0.
DO ITT=IT1,IT2
SIMPL(ITT-IT1+1)=SGAMMA(EG,EIN,ITT)
ENDDO
IF (NOPTFL.LT.1) THEN !originaly .NE.
DO ITT=IT1,IT2
Z=Z+FLOAT(NL)*SIMPL(ITT-IT1+1)
ENDDO
ELSE !TODO modify for chi2 with more DOF
ISCON(MODE,I,ISBS,IPFI)=ISEED
IFLAG=0
IF (MODE.EQ.0) THEN
DO IL=1,NL !neprobehne kdyz NL je 0, coz ma za nasledek nulovou intenzitu do prazdnych binu
DO ITT=IT1,IT2
G=GAUSS(ISEED,U,IFLAG)
Z=Z+G*G*SIMPL(ITT-IT1+1)
ENDDO
ENDDO !IL
ELSE ! Primary transitions (the same fluctuation)
DO IL=1,NL
DO ITT=IT1,IT2
GSQ=CHISQR(NOPTFL,ISEED,U,IFLAG) !originaly GSQ=GAUSS(ISEED,U,IFLAG)
Z=Z+GSQ*SIMPL(ITT-IT1+1)
ENDDO
ENDDO !IL
ENDIF
ENDIF
!
! fix equivalent to NL.EQ.0 cause of construction of Z
IF (DENSITY(EIN,SPIN,IPIN).GT.0.0) THEN
STCON(MODE,I,ISBS,IPFI)=STCON(MODE,I-1,ISBS,IPFI)+DBLE(Z*SPAC)
ELSE
STCON(MODE,I,ISBS,IPFI)=STCON(MODE,I-1,ISBS,IPFI)
ENDIF
! IF (IT.EQ.1) THEN
! GE1=GE1+Z
! ELSEIF (IT.EQ.3) THEN
! GM1=GM1+Z
! ELSEIF (IT.EQ.4) THEN
! GE2=GE2+Z
! ELSEIF (IT.EQ.2) THEN ! This is not fully correct (strength fluctuate)
! GM1=GM1+Z*SIMPL(1)/(SIMPL(1)+SIMPL(2)) ! But it is acceptable approximation
! GE2=GE2+Z*SIMPL(2)/(SIMPL(1)+SIMPL(2))
! ENDIF
ENDDO !I=IBIN+1,NBIN
!
! For primary transitions it is assumed that MODE=0. In such
! a case it is understood that the values of the ACTUAL
! subscripted variable that replaces the FICTIVE variable STDIS
! are simply derived from input data without the need of Monte
! Carlo simulation.
!
! IF (MODE.NE.0) GOTO 22 !!!!!!!! Compare to WIDTHS()
24 CONTINUE
DO I=1,NDIS(ISUBSC(SPFI),IPFI)
EG=EIN-ENDIS(I,ISUBSC(SPFI),IPFI)
IF (NOPTFL.GE.1) ISDIS(MODE,I,ISUBSC(SPFI),IPFI)=ISEED !originaly .EQ.
IFLAG=0
Z=0.
DO ITT=IT1,IT2
SIMPL(ITT-IT1+1)=SGAMMA(EG,EIN,ITT)
ENDDO
IF (NOPTFL.GE.1) THEN !originaly .EQ.
IF (MODE.EQ.0) THEN
DO ITT=IT1,IT2
G=GAUSS(ISEED,U,IFLAG)
Z=Z+G*G*SIMPL(ITT-IT1+1)
ENDDO
ELSE ! Primary transitions (the same fluctuation)
DO ITT=IT1,IT2
! G1=GAUSS(ISEED)
! G2=GAUSS(ISEED)+CORRI(MODE)*G1
! GSQ=(Re2Res(mode)*G2*G2/(1+CORRI(mode)**2)+
! * Im2Res(mode)*G1*G1)/(Re2Res(mode)+Im2Res(mode))
GSQ=CHISQR(NOPTFL,ISEED,U,IFLAG) !originaly GSQ=GAUSS(ISEED,U,IFLAG)
Z=Z+GSQ*SIMPL(ITT-IT1+1)
ENDDO
ENDIF
ELSE
DO ITT=IT1,IT2
Z=Z+SIMPL(ITT-IT1+1)
ENDDO
ENDIF
!
! IF (IT.EQ.1) THEN
! GE1=GE1+Z
! ELSEIF (IT.EQ.3) THEN
! GM1=GM1+Z
! ELSEIF (IT.EQ.4) THEN
! GE2=GE2+Z
! ELSEIF (IT.EQ.2) THEN ! This is not fully correct (strength fluctuate)
! GM1=GM1+Z*SIMPL(1)/(SIMPL(1)+SIMPL(2)) ! But it is acceptable approximation
! GE2=GE2+Z*SIMPL(2)/(SIMPL(1)+SIMPL(2))
! ENDIF
!
IF (DENSITY(EIN,SPIN,IPIN).GT.0.0) THEN
! WRITE(*,*) MODE,I,ISBS,IPFI,STDIS(MODE,I-1,ISBS,IPFI)
! write(*,*) 'stdis',stdis(mode,0,isbs,ipfi)
STDIS(MODE,I,ISBS,IPFI)=STDIS(MODE,I-1,ISBS,IPFI)+Z*SPAC
ELSE
STDIS(MODE,I,ISBS,IPFI)=STDIS(MODE,I-1,ISBS,IPFI)
ENDIF
ENDDO !I=1,NDIS
22 TOTCON(MODE)=TOTCON(MODE)+STCON(MODE,NBIN,ISBS,IPFI)
GACON(MODE,ISBS,IPFI)=TOTCON(MODE)
TOTDIS(MODE)=TOTDIS(MODE)+STDIS(MODE,NDIS(ISUBSC(SPFI),IPFI),ISBS,IPFI)
GADIS(MODE,ISBS,IPFI)=TOTDIS(MODE)
! WRITE(*,*) TOTDIS(MODE),STDIS(MODE,NDIS(ISUBSC(SPFI),IPFI),ISBS,IPFI),Z,SPAC
!
1 CONTINUE
ENDDO
ENDDO
RETURN
END SUBROUTINE WIDTHS_R
!***********************************************************************
SUBROUTINE ONESTEP(MODE,IPIN,SPIN,IBIN,ILIN,TOTCON,STCON,GACON,ISCON,TOTDIS,STDIS,GADIS,ISDIS,IPFI,&
SPFI,IBFI,ILFI,DMIX2,SIGN,IR,IRX,LEVCON,sall,U,IFLAG,EIN,EFI,IREGI,IC_type,IRCON,IRCONc)
!should be OK, changes EIN,EFI, outputs DMIX2,IC_type,sign
!***********************************************************************
REAL:: SP,SPF,ALPHA,ALPHAK,ALPHAIPF,SPAC,EG,Z,G1,G2,GSQ,Q1,dummy,RN,G
DOUBLE PRECISION:: AUX0,DRN,GAC
INTEGER:: IPF,ISPF,ISEED,ISEEDEN,deaux,ISP,ISBS,IT,I,NL,IL,ITT,IT1,IT2,NLEV1
REAL,dimension(1:2):: SIMPL,GG
real:: U,SPIN,EIN,EFI,SPFI,DMIX2,SIGN
integer:: MODE,IPIN,IBIN,ILIN,IFLAG,IREGI,IPFI,IBFI,ILFI,IR,IRX,IC_type
double precision,dimension(0:2,-2:2,0:1):: GACON
double precision,dimension(:,:,:,:),allocatable:: STCON
double precision,dimension(0:2):: TOTCON
integer,dimension(:,:,:,:),allocatable:: ISCON
real, dimension(0:2,0:20,-2:2,0:1):: STDIS
real, dimension(0:2,-2:2,0:1):: GADIS
real, dimension(0:2):: TOTDIS
integer,dimension(:),allocatable:: IRCONc,IRCON
integer,dimension(:,:,:),allocatable::LEVCON
real,dimension(:,:),allocatable:: sall
integer,dimension(:,:,:,:),allocatable::ISDIS
!globalni NBIN,BN,DELTA,NOPTFL,CORRI,Re2Res,Im2Res,ecrit,NENT,ELENT,CONVT,NENK,ELENK,CONVK,NEN_IPF,ELEN_IPF,CONV_IPF,NDIS,dekod,delev,despin,deparity,deltx
IF (iregi.eq.2) GOTO 23
SPAC=1./DENSITY(EIN,SPIN,IPIN)
IF (SPAC.LE.0.0) SPAC=0.00001
!
5 DRN=(DBLE(INT(DBLE(RAN0(IR))/1.D-4))+DBLE(RAN0(IR)))*1.D-4*(TOTCON(MODE)+DBLE(TOTDIS(MODE)))
! WRITE(*,*) MODE,TOTDIS(MODE),TOTCON(MODE)
! READ(*,*) MODE
IF (DRN-TOTCON(MODE)) 1,2,2
!
! Label #1 means that the transition ends in the continuum; this
! can be learnt from IREGI=0.
!
1 IREGI=0
SP = SPIN - INT(SPIN + .25)
ISP = INT(SPIN + .25)
DO IPF=0,1
DO ISPF = ISP-2, ISP+2
SPF = SP + FLOAT(ISPF)
ISBS=NINT(SPF+.25)-NINT(SPIN+.25)
IT=ITYPE(SPIN,IPIN,SPF,IPF)
IF (IT.NE.0) THEN
GAC=GACON(MODE,ISBS,IPF)
IF(DRN.LT.GAC) GOTO 4
ENDIF
ENDDO !ISPF
ENDDO !IPF
!
! GOTO 5 statements are here for security reasons
!
GOTO 5
!
! Now IPFI,SPFI (& ISBS) are already determined:
!
4 IPFI=IPF
SPFI=SPF
DRN=DRN-GAC+STCON(MODE,NBIN,ISBS,IPFI)
IF (IT.EQ.2) THEN
IT1=3
IT2=4
ELSE
IT1=IT
IT2=IT
ENDIF
!
! A DO-loop that follows should be later replaced by a faster
! algorithm
!
DO I=IBIN+1,NBIN
IF (STCON(MODE,I,ISBS,IPFI).GT.DRN) GOTO 7
ENDDO
GOTO 5
7 IBFI=I
!
! Now even IBFI is known. It remains to determine ILFI.
!
ISEED=ISCON(MODE,IBFI,ISBS,IPFI)
IFLAG=0
!
! The appropriate ISEED is now fetched and IFLAG reset.
! The algorithm for finding ILFI can start.
!
EG=EIN-BN+(FLOAT(IBFI)-0.5)*DELTA
! EG=(FLOAT(IBFI-IBIN))*DELTA !Energies between mid-bins
NL=LEVCON(IBFI,ISUBSC(SPFI),IPFI)-LEVCON(IBFI-1,ISUBSC(SPFI),IPFI)
AUX0=STCON(MODE,IBFI-1,ISBS,IPFI)
Z=0.
DO ITT=IT1,IT2
SIMPL(ITT-IT1+1)=SGAMMA(EG,EIN,ITT)
ENDDO
DO IL=1,NL
DO ITT=IT1,IT2
IF (NOPTFL.GE.1) THEN !originaly .EQ.
IF (MODE.EQ.0) THEN
G=GAUSS(ISEED,U,IFLAG)
Z=Z+G*G*SIMPL(ITT-IT1+1)
GG(ITT-IT1+1)=G
ELSE !Primary transitions
! G1=GAUSS(ISEED)
! G2=GAUSS(ISEED)+CORRI(MODE)*G1
! GSQ=(Re2Res(mode)*G2*G2/(1+CORRI(mode)**2)+
! * Im2Res(mode)*G1*G1)/(Re2Res(mode)+Im2Res(mode))
GSQ=CHISQR(NOPTFL,ISEED,U,IFLAG) !originaly GSQ=GAUSS(ISEED,U,IFLAG)
Z=Z+GSQ*SIMPL(ITT-IT1+1)
! GG(ITT-IT1+1)=sqrt(GSQ)
! IF (G1.LT.0) GG(ITT-IT1+1)=-1.*GG(ITT-IT1+1)
GG(ITT-IT1+1)=SQRT(GSQ)
ENDIF
ELSE
Z=Z+SIMPL(ITT-IT1+1)
ENDIF
ENDDO !ITT
IF ((AUX0+DBLE(Z*SPAC)).GT.DRN) GOTO 9
ENDDO !IL
GO TO 5
!
! The resulting ILFI:
!
9 ILFI=IL
!
NLEV1=LEVCON(IBFI,ISUBSC(SPFI),IPFI)-LEVCON(IBFI-1,ISUBSC(SPFI),IPFI)
Q1=1.-FLOAT(2*ILFI-1)/FLOAT(2*NLEV1)
! ISEEDEN=SEEDS(0,SPFI,IPFI,ILFI,IBFI,LEVCON,IRCON,IRCONc)
! Q1=RAN0(ISEEDEN) ! Energy of the final level random in bin
EFI=BN-(FLOAT(IBFI)-Q1)*DELTA
IF (efi.le.ecrit) IREGI=2
!
! delta**2 and conversion
!
IF (NOPTFL.LT.1) THEN !NOTE originaly .NE.
GG(1)=1.
GG(2)=1.
ENDIF
IF (IT.EQ.2) THEN
IF (GG(1).NE.0.) THEN
DMIX2=GG(2)**2*SIMPL(2)/GG(1)**2/SIMPL(1)
IF (GG(1).GT.0) THEN
SIGN=1.
ELSE
SIGN=-1.
ENDIF
ELSE
DMIX2=1.E+6
SIGN=1.
ENDIF
ELSE
DMIX2=0.
SIGN=1.
ENDIF
dummy=RAN0(IRX)
ALPHA=ALPH_TOT(EIN,SPIN,IPIN,EFI,SPFI,IPFI,DMIX2,NENT,ELENT,CONVT)
IF (dummy.GT.(ALPHA/(1+ALPHA))) THEN
IC_type=0
ELSE
ALPHAK=ALPH_TOT(EIN,SPIN,IPIN,EFI,SPFI,IPFI,DMIX2,NENK,ELENK,CONVK)
ALPHAIPF=ALPH_TOT(EIN,SPIN,IPIN,EFI,SPFI,IPFI,DMIX2,NEN_IPF,ELEN_IPF,CONV_IPF)+ALPHAK
IF (dummy.LE.(ALPHAK/(1+ALPHA))) THEN
IC_type=1
ELSEIF (dummy.LE.(ALPHAIPF/(1+ALPHA))) THEN
IC_type=3
ELSE
IC_type=2
ENDIF
ENDIF
RETURN
!
2 IREGI=1
RN=SNGL(DRN-TOTCON(MODE))
SP = SPIN - INT(SPIN + .25)
ISP = INT(SPIN + .25)
DO IPF=0,1
DO ISPF = ISP-2, ISP+2
SPF = SP + FLOAT(ISPF)
ISBS=NINT(SPF+.25)-NINT(SPIN+.25)
IT=ITYPE(SPIN,IPIN,SPF,IPF)
IF (IT.NE.0) THEN
IF (RN.LT.GADIS(MODE,ISBS,IPF)) GOTO 11
ENDIF
ENDDO !SPF
ENDDO !IPF
GOTO 5
11 SPFI=SPF
IPFI=IPF
!
RN=RN-GADIS(MODE,ISBS,IPFI)+STDIS(MODE,NDIS(ISUBSC(SPFI),IPFI),ISBS,IPFI)
DO I=1,NDIS(ISUBSC(SPFI),IPFI)
IF (RN.LT.STDIS(MODE,I,ISBS,IPFI)) GOTO 15
ENDDO
GOTO 5
15 ILFI=I
ibin=0 !!!!Why
EFI=ENDIS(ILFI,ISUBSC(SPFI),IPFI)
IF (EFI.LE.ecrit) IREGI=2
!
! delta**2 and conversion
!
ISEED=ISDIS(MODE,ILFI,ISUBSC(SPFI),IPFI)
IFLAG=0
IF (IT.EQ.2) THEN
IT1=3
IT2=4
ELSE
IT1=IT
IT2=IT
ENDIF
EG=EIN-EFI
DO ITT=IT1,IT2
SIMPL(ITT-IT1+1)=SGAMMA(EG,EIN,ITT)
ENDDO
IF (NOPTFL.GE.1) THEN !originaly .EQ. ,TODO modify for chi2 with more DOF
IF (MODE.EQ.0) THEN
DO ITT=IT1,IT2
G=GAUSS(ISEED,U,IFLAG)
GG(ITT-IT1+1)=G
ENDDO
ELSE !Primary transitions
DO ITT=IT1,IT2
! G1=GAUSS(ISEED)
! G2=GAUSS(ISEED)+CORRI(MODE)*G1
! GSQ=(Re2Res(mode)*G2*G2/(1+CORRI(mode)**2)+
! * Im2Res(mode)*G1*G1)/(Re2Res(mode)+Im2Res(mode))
! GG(ITT-IT1+1)=sqrt(GSQ)
! IF (G1.LT.0) GG(ITT-IT1+1)=-1.*GG(ITT-IT1+1)
G=CHISQR(NOPTFL,ISEED,U,IFLAG) !originaly G=GAUSS(ISEED,U,IFLAG)
GG(ITT-IT1+1)=SQRT(G)
ENDDO
ENDIF
ENDIF
IF (NOPTFL.LT.1) THEN !originaly .NE.
GG(1)=1.
GG(2)=1.
ENDIF
IF (IT.EQ.2) THEN
IF (GG(1).NE.0.) THEN
DMIX2=GG(2)**2*SIMPL(2)/GG(1)**2/SIMPL(1)
IF (GG(1).GT.0) THEN
SIGN=1.
ELSE
SIGN=-1.
ENDIF
ELSE
DMIX2=1.E+6
SIGN=1.
ENDIF
ELSE
DMIX2=0.
SIGN=1.
ENDIF
dummy=RAN0(IRX)
ALPHA=ALPH_TOT(EIN,SPIN,IPIN,EFI,SPFI,IPFI,DMIX2,NENT,ELENT,CONVT)
IF (dummy.GT.(ALPHA/(1+ALPHA))) THEN
IC_type=0
ELSE
ALPHAK=ALPH_TOT(EIN,SPIN,IPIN,EFI,SPFI,IPFI,DMIX2,NENK,ELENK,CONVK)
ALPHAIPF=ALPH_TOT(EIN,SPIN,IPIN,EFI,SPFI,IPFI,DMIX2,NEN_IPF,ELEN_IPF,CONV_IPF)+ALPHAK
IF (dummy.LE.(ALPHAK/(1+ALPHA))) THEN
IC_type=1
ELSEIF (dummy.LE.(ALPHAIPF/(1+ALPHA))) THEN
IC_type=3
ELSE
IC_type=2
ENDIF
ENDIF
RETURN
!
!
! Note that this time ILFI means order number of an actual
! level, not the order number of a level in an energy bin of
! the energy continuum.
!
! End in a part, where one knows every branching ratios
!