-
Notifications
You must be signed in to change notification settings - Fork 0
/
complicated_guide.for
executable file
·2738 lines (2628 loc) · 83 KB
/
complicated_guide.for
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
PROGRAM complicated_guide
c Monte Carlo calculation of guide divergence for arbitrary guide geometry.
c
c last modified 26/9/10
INCLUDE 'parameters.inc'
INCLUDE 'common.inc'
INCLUDE 'c_guide.inc'
INCLUDE 'c_bin.inc'
INCLUDE 'c_plot.inc'
REAL*8 Lguide(msections), Lexit, L, Lap, Lend, Lmon, rtime,
&nsigmaS, lambdamin, lambdamax, dlambda, lambda_arr(mlambda),
&lambda0
DIMENSION nthrough(msections,2), nmon(2), ncentral(3,2),
&dLguide(msections), dvar(mvars), iusevars(mvars),
&nUCN(2), PsumUCN(2), xloss(2,2), array(marray),
&Rguide0(msections,4),
&scan_arr(mscan), iscan_nmultiple(msections),
&iscan_gmultiple(msections), iscan_dLguide(msections),
&iscan_Wguide(msections,2), iscan_Hguide(msections,2),
&iscan_Lguide(msections), iscan_Rguide(msections,4),
&iscan_mnumber(msections,5), iscan_refl0(msections,5),
&iscan_reflm(msections,5), iscan_Wwav(msections,5),
&iscan_tilt(msections,5), iscan_gshift(msections,5),
&iscan_chamfer(msections,5)
REAL*4 xmin, xmax, ymin, ymax, zmin, zmax, xp(101), yp(101),
&zp(101), xplot(2*nbin+1), yplot(2*nbin+1), eplot(2*nbin+1),
&yyr, zzr, phiyyr, phizzr, rlambda, random
CHARACTER vname(mvars,2)*12, vblurb(mvars)*50, filename*50,
&Answer*1, blurb*50, title*80, input_file*50,
&string*50, out_file*50, ctime*8, source_file*50, cpol*1,
&line*(nline), charr(marray)*40, scanvarname*10, FMT*40, LFMT*120,
&line0*(nline)
LOGICAL through, binit, printrays, OK, exist,
&saveneutrons, batchjob, hitmon, saveresults,
&keepgoing, polarised, saveplot, usesavedneutrons,
&cylindrical(msections), UCN, intube, looplambda,
&saveplots, plot, showplots, circular_source,
&cylindrical_source,
&collimated_source, in, hparabolic(msections),
&vparabolic(msections), curved(msections), refl_file, scan,
&wrange, cavity(msections), polarised_in, newneutron,
&screeninput, nooutput
DATA pi/3.141592654/, g/9.82E-03/, const/3956./, ! in units of mm and ms
&vblurb(2*msections+1)/'Hor pos at exit of last segment'/,
&vname(2*msections+1,1)/'_yexit_'/,
&dvar(2*msections+1)/1.0/,
&vname(2*msections+1,2)/'Neutrons/bin'/,
&vblurb(2*msections+2)/'Ver pos at exit of last segment'/,
&vname(2*msections+2,1)/'_zexit_'/,
&dvar(2*msections+2)/1.0/,
&vname(2*msections+2,2)/'Neutrons/bin'/,
&vblurb(2*msections+3)/'Horizontal divergence on monitor'/,
&vname(2*msections+3,1)/'phiHsam'/,
&dvar(2*msections+3)/0.01/,
&vname(2*msections+3,2)/'Neutrons/bin'/,
&vblurb(2*msections+4)/'Vertical divergence on monitor'/,
&vname(2*msections+4,1)/'phiVsam'/,
&dvar(2*msections+4)/0.01/,
&vname(2*msections+4,2)/'Neutrons/bin'/,
&vblurb(2*msections+5)/'Horizontal position at monitor'/,
&vname(2*msections+5,1)/'ysample'/,
&dvar(2*msections+5)/.50/,
&vname(2*msections+5,2)/'Neutrons/bin'/,
&vblurb(2*msections+6)/'Vertical position at monitor'/,
&vname(2*msections+6,1)/'_zexit_'/,
&dvar(2*msections+6)/.50/,
&vname(2*msections+6,2)/'Neutrons/bin'/,
&vblurb(2*msections+7)/'Total flight path'/,
&vname(2*msections+7,1)/'Ltotal_'/,
&vname(2*msections+7,2)/'Neutrons/bin'/,
&vblurb(2*msections+8)/'Total number of reflections'/,
&vname(2*msections+8,1)/'_Nrefl_'/,
&dvar(2*msections+8)/1.0/,
&vname(2*msections+8,2)/'Neutrons/bin'/,
&vblurb(2*msections+9)/'Neutron losses in guide gaps'/,
&vname(2*msections+9,1)/'xloss0_'/,
&dvar(2*msections+9)/100.0/,
&vname(2*msections+9,2)/'Neutrons/bin'/,
&vblurb(2*msections+10)/'Neutron losses on face 1'/,
&vname(2*msections+10,1)/'xloss1_'/,
&dvar(2*msections+10)/100.0/,
&vname(2*msections+10,2)/'Neutrons/bin'/,
&vblurb(2*msections+11)/'Neutron losses on face 2'/,
&vname(2*msections+11,1)/'xloss2_'/,
&dvar(2*msections+11)/100.0/,
&vname(2*msections+11,2)/'Neutrons/bin'/,
&vblurb(2*msections+12)/'Neutron losses on face 3'/,
&vname(2*msections+12,1)/'xloss3_'/,
&dvar(2*msections+12)/100.0/,
&vname(2*msections+12,2)/'Neutrons/bin'/,
&vblurb(2*msections+13)/'Neutron losses on face 4'/,
&vname(2*msections+13,1)/'xloss4_'/,
&dvar(2*msections+13)/100.0/,
&vname(2*msections+13,2)/'Neutrons/bin'/,
&vblurb(2*msections+14)/'Neutron losses on face 5'/,
&vname(2*msections+14,1)/'xloss5_'/,
&dvar(2*msections+14)/100.0/,
&vname(2*msections+14,2)/'Neutrons/bin'/,
&vblurb(2*msections+15)/'Neutron losses on face 6'/,
&vname(2*msections+15,1)/'xloss6_'/,
&dvar(2*msections+15)/100.0/,
&vname(2*msections+15,2)/'Neutrons/bin'/,
&Si_lambda/0.0,0.20229,0.40457,0.52230,0.63968,0.90465,
&1.0813,1.2794,1.4304,1.6517,2.0229,2.8607,3.4192,
&4.0457,4.5232,5.2230,6.3968,9.0465,100.0/, ! wavelength in Å
&Si_mu/0.12,0.1125,0.0925,0.0750,0.0625,0.0420,0.0325,
&0.0265,0.0250,0.0215,0.0200,0.0205,0.0215,0.0250,
&0.0275,0.0310,0.0365,0.0510,0.5/ ! attenuation length in cm^-1
scanvarname='xxx'
iscan_Wmod=0
iscan_Hmod=0
iscan_Lap=0
iscan_Wap=0
iscan_Hap=0
iscan_Hsourcem=0
iscan_Vsourcem=0
DO i=1,msections
IF (i.LT.10) THEN
WRITE(vblurb(2*i-1),811) i
811 FORMAT(' Horizontal divergence at exit of segment ',I1)
WRITE(vname(2*i-1,1),812) i
812 FORMAT(' phiH',I1)
WRITE(vblurb(2*i),813) i
813 FORMAT(' Vertical divergence at exit of segment ',I1)
WRITE(vname(2*i,1),814) i
814 FORMAT(' phiV',I1)
ELSE
WRITE(vblurb(2*i-1),821) i
821 FORMAT(' Horizontal divergence at exit of segment ',I2)
WRITE(vname(2*i-1,1),822) i
822 FORMAT(' phiH',I2)
WRITE(vblurb(2*i),823) i
823 FORMAT(' Vertical divergence at exit of segment ',I2)
WRITE(vname(2*i,1),824) i
824 FORMAT(' phiV',I2)
END IF
dvar(2*i-1)=0.02
vname(2*i-1,2)='Neutrons/bin'
dvar(2*i)=0.02
vname(2*i,2)='Neutrons/bin'
iscan_nmultiple(i)=0
iscan_gmultiple(i)=0
iscan_dLguide(i)=0
iscan_Lguide(i)=0
DO j=1,2
iscan_Wguide(i,j)=0
iscan_Hguide(i,j)=0
iscan_Rguide(i,2*j-i)=0
END DO
DO j=1,5
iscan_mnumber(i,j)=0
iscan_refl0(i,j)=0
iscan_reflm(i,j)=0
iscan_Wwav(i,j)=0
iscan_tilt(i,j)=0
iscan_gshift(i,j)=0
iscan_chamfer(i,j)=0
END DO
END DO
UCN=.FALSE.
c UCN=.TRUE. ! calculation for UCN production
c show=.TRUE.
polarised_in=.FALSE.
polarised=.FALSE.
IF (UCN) THEN
density=2.185E+22 ! He number density (cm^-3)
sigmaS=3.48E-02 ! Total scattering cross-section for 8.9A neutrons (barns)
sigmaU=5.45E-05 ! UCN-creation cross-section for 8.9A neutrons (barns)
nsigmaS=density*sigmaS*1.E-25 ! in mm^-1 (1 barn = 10^-24 cm2)
dvar(2*msections+7)=5.
ELSE
sigmaS=0.
sigmaU=0.
nsigmaS=0.
dvar(2*msections+7)=0.2
END IF
screeninput=.FALSE. ! normal running mode
c screeninput=.TRUE. ! all input/output is from screen
ierror=0
IF (screeninput) THEN
in_unit=5
input_file='lardon.in'
ELSE
in_unit=10
4 WRITE(*,5)
5 FORMAT(' Enter input file : ',$) ! filename must end in .in
READ(*,'(A50)') input_file
IF (input_file.EQ.' ') input_file='testfile.in'
OPEN(in_unit,FILE=input_file,STATUS='OLD',ERR=6)
GOTO 7
6 PRINT*,'Error - cannot open input file'
GOTO 4
7 CONTINUE
END IF
c****************************************
c Read from input unit
ierror=ierror+1
10 READ(in_unit,'(A80)') line
CALL read_char_line(line,charr,ncharr)
IF (charr(1)(1:1).EQ.'!') GOTO 10
IF (charr(1).NE.'SOURCE') GOTO 100
usesavedneutrons=.FALSE.
circular_source=.FALSE.
cylindrical_source=.FALSE.
collimated_source=.FALSE.
Hsourcem=0.
Vsourcem=0.
Lap=0.
Wap=0.
Hap=0.
halo=0.
IF (charr(2).EQ.'RECTANGULAR') THEN
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.100) GOTO 100
IF (narray.LT.5 .OR. narray.GT.6) GOTO 100
Wmod=array(1)
Hmod=array(2)
Lap=array(3)
Wap=array(4)
Hap=array(5)
IF (narray.EQ.6) halo=array(6)
ELSE IF(charr(2).EQ.'CIRCULAR') THEN
circular_source=.TRUE.
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.100) GOTO 100
IF (narray.LT.4 .OR. narray.GT.5) GOTO 100
Wmod=array(1)
Hmod=Wmod
Lap=array(2)
Wap=array(3)
Hap=array(4)
IF (narray.EQ.5) halo=array(5)
ELSE IF(charr(2).EQ.'CYLINDRICAL') THEN
cylindrical_source=.TRUE.
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.100) GOTO 100
IF (narray.LT.5 .OR. narray.GT.6) GOTO 100
Wmod=array(1)
Hmod=array(2)
Lap=array(3)
Wap=array(4)
Hap=array(5)
IF (narray.EQ.6) halo=array(6)
ELSE IF (charr(2).EQ.'FILE') THEN
usesavedneutrons=.TRUE.
READ(in_unit,'(A50)',ERR=100) source_file ! filename must end in .dat
ELSE IF (charr(2).EQ.'RECTANGULAR_COLLIMATED') THEN
collimated_source=.TRUE.
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.100) GOTO 100
IF (narray.LT.4 .OR. narray.GT.5) GOTO 100
Wmod=array(1)
Hmod=array(2)
Hsourcem=array(3) ! horizontal and vertical
Vsourcem=array(4) ! m-number
IF (narray.EQ.5) halo=array(5)
ELSE IF (charr(2).EQ.'CIRCULAR_COLLIMATED') THEN
circular_source=.TRUE.
collimated_source=.TRUE.
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.100) GOTO 100
IF (narray.LT.3 .OR. narray.GT.4) GOTO 100
Wmod=array(1)
Hmod=Wmod
Hsourcem=array(2)
Vsourcem=array(3)
IF (narray.EQ.4) halo=array(4)
ELSE IF (charr(2).EQ.'CYLINDRICAL_COLLIMATED') THEN
cylindrical_source=.TRUE.
collimated_source=.TRUE.
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.100) GOTO 100
IF (narray.LT.4 .OR. narray.GT.5) GOTO 100
Wmod=array(1)
Hmod=array(2)
Hsourcem=array(3) ! horizontal and vertical
Vsourcem=array(4) ! m-number
IF (narray.EQ.5) halo=array(5)
END IF
IF (Wmod.EQ.-999.) iscan_Wmod=1
IF (Hmod.EQ.-999.) iscan_Hmod=1
IF (Lap.EQ.-999.) iscan_Lap=1
IF (Wap.EQ.-999.) iscan_Wap=1
IF (Hap.EQ.-999.) iscan_Hap=1
IF (Hsourcem.EQ.-999.) iscan_Hsourcem=1
IF (Vsourcem.EQ.-999.) iscan_Vsourcem=1
nsections=0
DO i=1,msections
ierror=ierror+1
20 READ(in_unit,'(A80)') line
CALL read_char_line(line,charr,ncharr)
IF (charr(1)(1:1).EQ.'!') GOTO 20
IF (charr(1).EQ.'END') GOTO 60 ! no more guide sections
IF (charr(1).EQ.'GUIDE') THEN
nsections=nsections+1
curved(i)=.FALSE.
cylindrical(i)=.FALSE.
hparabolic(i)=.FALSE.
vparabolic(i)=.FALSE.
cavity(i)=.FALSE.
tilted(i)=.FALSE.
nmultiple(i)=1
gmultiple(i)=0.
ivcavity(i)=0
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (charr(2).EQ.'STRAIGHT' .OR.
&charr(2).EQ.'CONVERGING' .OR. charr(2).EQ.'DIVERGING') THEN
IF (charr(3).EQ.'MULTIPLE') THEN
IF (narray.NE.2) GOTO 100
nmultiple(i)=NINT(array(1))
gmultiple(i)=array(2)
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
END IF
IF (narray.EQ.100 .OR. narray.LT.4) GOTO 100
dLguide(i)=array(1)
Wguide(i,1)=array(2)
Hguide(i,1)=array(3)
Lguide(i)=array(4)
Rguide0(i,1)=0.
IF (narray.EQ.4) THEN
Wguide(i,2)=Wguide(i,1)
Hguide(i,2)=Hguide(i,1)
ELSE IF (narray.EQ.6) THEN
Wguide(i,2)=array(5)
Hguide(i,2)=array(6)
ELSE
GOTO 100
END IF
ELSE IF (charr(2).EQ.'CURVED' .OR.
&charr(2).EQ.'CURVED_CONVERGING' .OR.
&charr(2).EQ.'CONVERGING_CURVED' .OR.
&charr(2).EQ.'CURVED_DIVERGING' .OR.
&charr(2).EQ.'DIVERGING_CURVED') THEN
IF (charr(3).EQ.'MULTIPLE') THEN
IF (narray.NE.2) GOTO 100
nmultiple(i)=array(1)
gmultiple(i)=array(2)
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
END IF
IF (narray.EQ.100 .OR. narray.LT.5) GOTO 100
curved(i)=.TRUE.
dLguide(i)=array(1)
Wguide(i,1)=array(2)
Hguide(i,1)=array(3)
Lguide(i)=array(4)
Rguide0(i,1)=array(5)
Rguide0(i,3)=0.
IF (narray.EQ.5) THEN
Wguide(i,2)=Wguide(i,1)
Hguide(i,2)=Hguide(i,1)
ELSE IF (narray.EQ.7) THEN
Wguide(i,2)=array(6)
Hguide(i,2)=array(7)
ELSE
GOTO 100
END IF
ELSE IF (charr(2).EQ.'CYLINDRICAL') THEN
IF (charr(3).EQ.'MULTIPLE') THEN
IF (narray.NE.2) GOTO 100
nmultiple(i)=array(1)
gmultiple(i)=array(2)
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
END IF
IF (narray.NE.3) GOTO 100
cylindrical(i)=.TRUE.
dLguide(i)=array(1)
Wguide(i,1)=array(2)
Hguide(i,1)=Wguide(i,1)
Lguide(i)=array(3)
Wguide(i,2)=Wguide(i,1)
Hguide(i,2)=Hguide(i,1)
Rguide0(i,1)=0.
ELSE IF (charr(2).EQ.'PARABOLIC' .OR.
&charr(2).EQ.'HORIZONTALLY_PARABOLIC' .OR.
&charr(2).EQ.'VERTICALLY_PARABOLIC') THEN
IF (charr(3).EQ.'MULTIPLE') THEN
IF (narray.NE.2) GOTO 100
nmultiple(i)=array(1)
gmultiple(i)=array(2)
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
END IF
IF (narray.NE.6) GOTO 100
dLguide(i)=array(1)
Wguide(i,1)=array(2)
Hguide(i,1)=array(3)
Lguide(i)=array(4)
Wguide(i,2)=array(5)
Hguide(i,2)=array(6)
IF (charr(2).EQ.'VERTICALLY_PARABOLIC') THEN
vparabolic(i)=.TRUE.
IF (Hguide(i,1).LE.Hguide(i,2)) THEN
PRINT*,'Entrance height must be > ',
&'Exit height for vertically parabolic guide'
GOTO 100
END IF
ELSE
hparabolic(i)=.TRUE.
IF (Wguide(i,1).LE.Wguide(i,2)) THEN
PRINT*,'Entrance width must be > ',
&'Exit width for horizontally parabolic guide'
GOTO 100
END IF
END IF
ELSE IF (charr(2).EQ.'TRANSMISSION_MIRROR') THEN
IF (charr(3).EQ.'MULTIPLE') THEN
IF (narray.NE.2) GOTO 100
nmultiple(i)=array(1)
gmultiple(i)=array(2)
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
END IF
IF (narray.EQ.100 .OR. narray.LT.5) GOTO 100
cavity(i)=.TRUE.
dLguide(i)=array(1)
Wguide(i,1)=array(2)
Hguide(i,1)=array(3)
Lguide(i)=array(4)
cthickness(i)=array(5)
IF (narray.EQ.5) THEN
Wguide(i,2)=Wguide(i,1)
Hguide(i,2)=Hguide(i,1)
ELSE IF (narray.EQ.7) THEN
Wguide(i,2)=array(6)
Hguide(i,2)=array(7)
ELSE
GOTO 100
END IF
ELSE
GOTO 100
END IF
ELSE
GOTO 100
END IF
IF (nmultiple(i).EQ.-999) iscan_nmultiple(i)=1
IF (gmultiple(i).EQ.-999.) iscan_gmultiple(i)=1
IF (dLguide(i).EQ.-999.) iscan_dLguide(i)=1
DO j=1,2
IF (Wguide(i,j).EQ.-999.) iscan_Wguide(i,j)=1
IF (Hguide(i,j).EQ.-999.) iscan_Hguide(i,j)=1
IF (Rguide0(i,2*j-1).EQ.-999.) iscan_Rguide(i,2*j-i)=1
END DO
IF (Lguide(i).EQ.-999.) iscan_Lguide(i)=1
Rguide0(i,1)=Rguide0(i,1)*1.E+03
Rguide0(i,3)=Rguide0(i,3)*1.E+03
ierror=ierror+1
30 READ(in_unit,'(A80)') line
CALL read_char_line(line,charr,ncharr)
IF (charr(1)(1:1).EQ.'!') GOTO 30
DO j=1,4 ! default values
mnumber(i,j)=1.
refl0(i,j)=1. ! R=1.0 up to m=1, then decreasing
reflm(i,j)=1.
Wwav(i,j)=0.
tilt(i,j)=0.
gshift(i,j)=0.
chamfer(i,j)=0.
END DO
IF (charr(1).EQ.'FACE') THEN
READ(charr(2),*,ERR=100) iface
nfaces=4
IF (cavity(i)) nfaces=5
ELSE IF (charr(1).EQ.'ALL' .AND. charr(2).EQ.'FACES') THEN
nfaces=1
ELSE
PRINT*,'Syntax error - faces not specified'
GOTO 100
END IF
DO iface=1,nfaces
IF (iface.NE.1) THEN
35 READ(in_unit,'(A80)') line
CALL read_char_line(line,charr,ncharr)
IF (charr(1)(1:1).EQ.'!') GOTO 35
READ(charr(2),*,ERR=100) ifac
IF (ifac.NE.iface) GOTO 100
END IF
refl_file=.FALSE.
IF (ncharr.GE.3) THEN
IF (charr(3).EQ.'FILE') refl_file=.TRUE.
END IF
IF (iface.EQ.5) THEN ! transmission mirror
nsides(i)=0
IF (ncharr.GE.4) THEN
IF (charr(3).EQ.'SINGLE_SIDED') nsides(i)=1
IF (charr(3).EQ.'DOUBLE_SIDED') nsides(i)=2
IF (charr(4).EQ.'V-') ivcavity(i)=-2
IF (charr(4).EQ.'LEFT') ivcavity(i)=-1
IF (charr(4).EQ.'RIGHT') ivcavity(i)=1
IF (charr(4).EQ.'V+') ivcavity(i)=2
END IF
IF (nsides(i).EQ.0 .OR. ivcavity(i).EQ.0) THEN
PRINT*,'Syntax error - face 5 not properly defined'
GOTO 100
END IF
IF (ncharr.GE.5) THEN
IF (charr(5).EQ.'FILE') refl_file=.TRUE.
END IF
END IF
40 READ(in_unit,'(A80)') line
CALL read_char_line(line,charr,ncharr)
IF (charr(1)(1:1).EQ.'!') GOTO 40
IF (refl_file) THEN
refl0(i,iface)=-1.
reflfile(i,iface)=charr(1)
OPEN(15,FILE=reflfile(i,iface),STATUS='OLD',ERR=41)
READ(15,'(A80)') line0
CALL read_real_line(line0,array,narray)
c Qarr(i,iside,ipol,i)=4.*pi*SIN(array(1)*pi/180.)/7.5 ! T3 data
Qarr(i,iface,1)=array(1)
Parr(i,iface,1,1)=array(2)
IF (narray.EQ.2) THEN
DO iQ=2,mQ
READ(15,*,END=42) Q, P
Qarr(i,iface,iQ)=Q
Parr(i,iface,1,iQ)=P
Parr(i,iface,2,iQ)=P
END DO
ELSE
polarised=.TRUE.
mnumber(i,iface)=-1.
Parr(i,iface,2,1)=array(3)
DO iQ=2,mQ
READ(15,*,END=42) Q, P1, P2
Qarr(i,iface,iQ)=Q
Parr(i,iface,1,iQ)=P1
Parr(i,iface,2,iQ)=P2
END DO
END IF
GOTO 42
41 PRINT*,'Error - cannot open file ',reflfile(i,iface)
GOTO 1000
42 nQ(i,iface)=iQ-1
CLOSE(15)
DO il=1,nline-1
IF (line(il:il).NE.' ' .AND.
&line(il+1:il+1).EQ.' ') GOTO 45
END DO
45 nl=il
DO il=1,nl
line(il:il)=' '
END DO
CALL read_real_line(line,array,narray)
IF (narray.GT.4) GOTO 100
IF (narray.GE.1) Wwav(i,iface)=array(1)
IF (narray.GE.2) tilt(i,iface)=array(2)
IF (tilt(i,iface).NE.0.) tilted(i)=.TRUE.
IF (narray.GE.3) gshift(i,iface)=array(3)
IF (narray.GE.4) chamfer(i,iface)=array(4)
ELSE
CALL read_real_line(line,array,narray)
IF (narray.GT.7) GOTO 100
mnumber(i,iface)=array(1)
IF (narray.GE.2) refl0(i,iface)=array(2)
IF (narray.GE.3) THEN
reflm(i,iface)=array(3)
ELSE
IF (mnumber(i,iface).GT.1.)
&reflm(i,iface)=refl0(i,iface)-0.1*(mnumber(i,iface)-1.)
IF (mnumber(i,iface).GT.1.119 .AND. ! make an exception for Ni-58
&mnumber(i,iface).LT.1.201) reflm(i,iface)=1.0
END IF
IF (narray.GE.4) Wwav(i,iface)=array(4)
IF (narray.GE.5) tilt(i,iface)=array(5)
IF (tilt(i,iface).NE.0.) tilted(i)=.TRUE.
IF (narray.GE.6) gshift(i,iface)=array(6)
IF (narray.GE.7) chamfer(i,iface)=array(7)
IF (show) PRINT*,'m =',REAL(mnumber(i,iface)),
&' R0 =',REAL(refl0(i,iface)),' Rm =',REAL(reflm(i,iface)),
&' Wwav =',REAL(Wwav(i,iface)),' tilt=',REAL(tilt(i,iface)),
&' shift =',REAL(gshift(i,iface)),
&' chamfer=',REAL(chamfer(i,iface))
IF (mnumber(i,iface).LT.0.) polarised=.TRUE.
50 CONTINUE
END IF ! reflectivity file or parameter input
IF (show) PRINT*,'polarised=',polarised
IF (mnumber(i,iface).EQ.-999.) iscan_mnumber(i,iface)=1
IF (refl0(i,iface).EQ.-999.) iscan_refl0(i,iface)=1
IF (reflm(i,iface).EQ.-999.) iscan_reflm(i,iface)=1
IF (Wwav(i,iface).EQ.-999.) iscan_Wwav(i,iface)=1
IF (tilt(i,iface).EQ.-999.) iscan_tilt(i,iface)=1
IF (gshift(i,iface).EQ.-999.) iscan_gshift(i,iface)=1
IF (chamfer(i,iface).EQ.-999.) iscan_chamfer(i,iface)=1
Wwav(i,iface)=Wwav(i,iface)*pi/180.
tilt(i,iface)=tilt(i,iface)*pi/180.
END DO ! iface=1,nfaces
IF (nfaces.EQ.1 .AND. .NOT.cylindrical(i)) THEN
DO iface=2,4
mnumber(i,iface)=mnumber(i,1)
IF (iscan_mnumber(i,1).EQ.1) iscan_mnumber(i,iface)=1
refl0(i,iface)=refl0(i,1)
IF (iscan_refl0(i,1).EQ.1) iscan_refl0(i,iface)=1
reflm(i,iface)=reflm(i,1)
IF (iscan_reflm(i,1).EQ.1) iscan_reflm(i,iface)=1
Wwav(i,iface)=Wwav(i,1)
IF (iscan_Wwav(i,1).EQ.1) iscan_Wwav(i,iface)=1
chamfer(i,iface)=chamfer(i,1)
IF (iscan_chamfer(i,1).EQ.1) iscan_chamfer(i,iface)=1
IF (iface.EQ.2) THEN
tilt(i,iface)=tilt(i,1)
IF (iscan_tilt(i,1).EQ.1) iscan_tilt(i,iface)=1
gshift(i,iface)=gshift(i,1)
IF (iscan_gshift(i,1).EQ.1) iscan_gshift(i,iface)=1
END IF
IF (refl0(i,1).LT.0.) THEN ! reflectivity from input file
refl0(i,iface)=-1.
nQ(i,iface)=nQ(i,1)
DO iQ=1,nQ(i,iface)
Qarr(i,iface,iQ)=Qarr(i,1,iQ)
Parr(i,iface,1,iQ)=Parr(i,1,1,iQ)
Parr(i,iface,2,iQ)=Parr(i,1,2,iQ)
END DO
END IF
END DO
END IF
END DO ! i=1,msections
60 CONTINUE
IF (show) PRINT*,'No more guide sections'
c PRINT*,'Hit return to continue'
c READ(*,'(A1)') Answer
gravity=.FALSE.
sideways=.FALSE.
scan=.FALSE.
wrange=.FALSE.
lambda=0.
divlimit=0.50 ! +/- divlimit is useful divergence
ierror=ierror+1
70 IF (charr(1)(1:3).EQ.'END' .AND. charr(2)(1:5).EQ.'GUIDE') THEN
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
Lend=array(1)
Wmon=array(2)
Hmon=array(3)
IF (narray.EQ.3) THEN
Hmonshift=0.
Vmonshift=0.
ELSE IF (narray.EQ.5) THEN
Hmonshift=array(4)
Vmonshift=array(5)
ELSE
PRINT*,'Error - narray should be 3 or 5. It is =',narray
END IF
IF (Lend.EQ.-999.) iscan_Lend=1
IF (Wmon.EQ.-999.) iscan_Wmon=1
IF (Hmon.EQ.-999.) iscan_Hmon=1
IF (Hmonshift.EQ.-999.) iscan_Hmonshift=1
IF (Vmonshift.EQ.-999.) iscan_Vmonshift=1
ELSE IF (charr(1).EQ.'GRAVITY' .AND. ncharr.GE.2) THEN
IF (charr(2).EQ.'SIDEWAYS' .OR.
&(ncharr.EQ.3 .AND. charr(3).EQ.'SIDEWAYS')) sideways=.TRUE.
IF (sideways) gravity=.TRUE.
IF (charr(2).EQ.'OFF' .OR.
&(ncharr.EQ.3 .AND. charr(3).EQ.'OFF')) gravity=.FALSE.
IF (charr(2).EQ.'ON' .OR.
&(ncharr.EQ.3 .AND. charr(3).EQ.'ON')) gravity=.TRUE.
ELSE IF (charr(1)(1:10).EQ.'WAVELENGTH') THEN
READ(in_unit,'(A80)') line
IF (ncharr.GE.2 .AND. charr(2)(1:4).EQ.'FILE') THEN
INQUIRE(FILE=line,EXIST=exist)
IF (.NOT.exist) PRINT*,'Error - file does not exist: ',line
OPEN(11,FILE=line,STATUS='OLD')
DO ilambda=1,mlambda
READ(11,*,END=240) lambda_arr(ilambda)
END DO
240 CLOSE(11)
nlambda=ilambda-1
IF (nlambda.LE.0) PRINT*,
&'Error - no wavelengths found in file: ',line
WRITE(*,244) nlambda
244 FORMAT(I6,' wavelengths :')
WRITE(*,245) (i, lambda_arr(i), i=1,nlambda)
245 FORMAT(' Wavelength',I2,' ='F6.2,' A')
looplambda=.TRUE.
ilambda=0
ELSE IF (ncharr.GE.2 .AND. charr(2)(1:4).EQ.'SCAN') THEN
CALL read_real_line(line,array,narray)
IF (narray.EQ.3) THEN
lambdamin=array(1)
dlambda=array(2)
lambdamax=array(3)
ELSE
PRINT*,'Error: narray should be 3. It is =',narray
END IF
nlambda=NINT((lambdamax-lambdamin)/dlambda)+1
WRITE(*,260) nlambda, lambdamin, dlambda,
&lambdamin+REAL(nlambda-1)*dlambda
260 FORMAT(I6,' wavelengths:',F6.2,' (',F4.2,')',F6.2)
DO i=1,nlambda
lambda_arr(i)=lambdamin+REAL(i-1)*dlambda
END DO
looplambda=.TRUE.
ilambda=0
ELSE IF (ncharr.GE.2 .AND. charr(2)(1:5).EQ.'RANGE') THEN
CALL read_real_line(line,array,narray)
IF (narray.EQ.2) THEN
lambdamin=array(1)
lambdamax=array(2)
ELSE
PRINT*,'Error: narray should be 2. It is =',narray
END IF
wrange=.TRUE.
ELSE
CALL read_real_line(line,array,narray)
IF (narray.EQ.1) THEN
lambda=array(1)
ELSE
PRINT*,'Error: narray should be 1. It is =',narray
END IF
looplambda=.FALSE.
END IF
ELSE IF (charr(1)(1:4).EQ.'SCAN' .AND. ncharr.EQ.2) THEN
READ(in_unit,'(A80)') line
IF (ncharr.GE.2 .AND. charr(2)(1:4).EQ.'FILE') THEN
INQUIRE(FILE=line,EXIST=exist)
IF (.NOT.exist) PRINT*,'Error - file does not exist: ',line
OPEN(11,FILE=line,STATUS='OLD')
DO iscan=1,mscan
READ(11,*,END=830) scan_arr(iscan)
END DO
830 CLOSE(11)
nscan=iscan-1
IF (nscan.LE.0) PRINT*,
&'Error - no scan points found in file: ',line
IF (.NOT.screeninput) WRITE(*,831) nscan
831 FORMAT(I6,' scan points :')
IF (.NOT.screeninput) WRITE(*,832)
&(i, scan_arr(i), i=1,nscan)
832 FORMAT(' Scan point',I3,' ='F9.3)
scan=.TRUE.
iscan=0
ELSE IF (charr(2).EQ.'ON') THEN
CALL read_real_line(line,array,narray)
IF (narray.EQ.3) THEN
scanmin=array(1)
dscan=array(2)
scanmax=array(3)
ELSE
PRINT*,'Error: narray should be 3. It is =',narray
END IF
nscan=NINT((scanmax-scanmin)/dscan)+1
IF (.NOT.screeninput) WRITE(*,833) nscan,
&scanmin, dscan, scanmin+REAL(nscan-1)*dscan
833 FORMAT(I6,' scan points:',F9.3,' (',F6.3,')',F9.3)
DO i=1,nscan
scan_arr(i)=scanmin+REAL(i-1)*dscan
END DO
scan=.TRUE.
iscan=0
END IF
ELSE IF (charr(1)(1:8).EQ.'NEUTRONS') THEN
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.2) THEN
neutrons=NINT(array(1))
iseed=NINT(array(2))
ELSE
PRINT*,'Error: narray should be 2. It is =',narray
END IF
ELSE IF (charr(1)(1:6).EQ.'OUTPUT') THEN
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.2) THEN
iresults=NINT(array(1))
idebug=NINT(array(2))
nooutput=.FALSE.
IF (idebug.EQ.-2) nooutput=.TRUE.
ELSE
PRINT*,'Error: narray should be 2. It is =',narray
END IF
ELSE IF (charr(1)(1:3).EQ.'END' .AND.
&charr(2)(1:5).EQ.'INPUT') THEN
GOTO 90
ELSE IF (charr(1)(1:10).EQ.'ACCEPTANCE') THEN
READ(in_unit,'(A80)') line
CALL read_real_line(line,array,narray)
IF (narray.EQ.1) THEN
divlimit=array(1)
ELSE
PRINT*,'Error: narray should be 1. It is =',narray
END IF
END IF
READ(in_unit,'(A80)') line
CALL read_char_line(line,charr,ncharr)
GOTO 70
90 IF (.NOT.screeninput) CLOSE(in_unit)
IF (lambda.EQ.0. .AND.
&.NOT.(looplambda.OR.usesavedneutrons.OR.wrange)) THEN
PRINT*,'Error - wavelength has not been specified'
END IF
IF (scan) THEN
IF (iscan_Wmod.EQ.1) scanvarname='Wmod'
IF (iscan_Hmod.EQ.1) scanvarname='Hmod'
IF (iscan_Lap.EQ.1) scanvarname='Lap'
IF (iscan_Wap.EQ.1) scanvarname='Wap'
IF (iscan_Hap.EQ.1) scanvarname='Hap'
IF (iscan_Hsourcem.EQ.1) scanvarname='Hsourcem'
IF (iscan_Vsourcem.EQ.1) scanvarname='Hsourcem'
DO i=1,nsections
IF (iscan_nmultiple(i).EQ.1) scanvarname='nmultiple'
IF (iscan_gmultiple(i).EQ.1) scanvarname='gmultiple'
IF (iscan_dLguide(i).EQ.1) scanvarname='dLguide'
IF (iscan_Lguide(i).EQ.1) scanvarname='Lguide'
DO j=1,2
IF (iscan_Rguide(i,2*j-1).EQ.1) scanvarname='Rguide'
IF (iscan_Wguide(i,j).EQ.1) scanvarname='Wguide'
IF (iscan_Hguide(i,j).EQ.1) scanvarname='Hguide'
END DO
DO iface=1,4
IF (iscan_mnumber(i,iface).EQ.1) scanvarname='mnumber'
IF (iscan_refl0(i,iface).EQ.1) scanvarname='refl0'
IF (iscan_reflm(i,iface).EQ.1) scanvarname='reflm'
IF (iscan_Wwav(i,iface).EQ.1) scanvarname='Wwav'
IF (iscan_tilt(i,iface).EQ.1) scanvarname='tilt'
IF (iscan_gshift(i,iface).EQ.1) scanvarname='gshift'
IF (iscan_chamfer(i,iface).EQ.1) scanvarname='chamfer'
END DO
END DO
IF (iscan_Lend.EQ.1) scanvarname='Lend'
IF (iscan_Wmon.EQ.1) scanvarname='Wmon'
IF (iscan_Hmon.EQ.1) scanvarname='Hmon'
IF (iscan_Hmonshift.EQ.1) scanvarname='Hmonshift'
IF (iscan_Vmonshift.EQ.1) scanvarname='Vmonshift'
IF (scanvarname.EQ.'xxx') THEN
PRINT*,'Error - scan set up with no scan variable'
GOTO 1000
END IF
PRINT*,'scanvarname=',scanvarname
END IF
GOTO 101
100 PRINT*,'Error in reading from input_file'
PRINT*,'line =',line
PRINT*,'ncharr =',ncharr,' narray =',narray,' ierror =',ierror
CLOSE(10)
GOTO 1000
101 CONTINUE
c step up scan variable if there is one
IF (scan) THEN
iscan=iscan+1
scanvar=scan_arr(iscan)
IF (.NOT.nooutput) WRITE(*,102) scanvarname, scanvar
102 FORMAT(' scan variable : ',A10,' =',F9.3)
IF (iscan_Wmod.EQ.1) Wmod=scanvar
IF (iscan_Hmod.EQ.1) Hmod=scanvar
IF (iscan_Lap.EQ.1) Lap=scanvar
IF (iscan_Wap.EQ.1) Wap=scanvar
IF (iscan_Hap.EQ.1) Hap=scanvar
IF (iscan_Hsourcem.EQ.1) Hsourcem=scanvar
IF (iscan_Vsourcem.EQ.1) Vsourcem=scanvar
DO i=1,nsections
IF (iscan_nmultiple(i).EQ.1) nmultiple(i)=NINT(scanvar)
IF (iscan_gmultiple(i).EQ.1) gmultiple(i)=scanvar
IF (iscan_dLguide(i).EQ.1) dLguide(i)=scanvar
IF (iscan_Lguide(i).EQ.1) Lguide(i)=scanvar
DO j=1,2
IF (iscan_Rguide(i,2*j-1).EQ.1)
&Rguide0(i,2*j-1)=scanvar*1.E+03
IF (iscan_Wguide(i,j).EQ.1) Wguide(i,j)=scanvar
IF (iscan_Hguide(i,j).EQ.1) Hguide(i,j)=scanvar
END DO
DO iface=1,4
IF (iscan_mnumber(i,iface).EQ.1) mnumber(i,iface)=scanvar
IF (iscan_refl0(i,iface).EQ.1) refl0(i,iface)=scanvar
IF (iscan_reflm(i,iface).EQ.1) reflm(i,iface)=scanvar
IF (iscan_Wwav(i,iface).EQ.1) Wwav(i,iface)=scanvar*pi/180.
IF (iscan_tilt(i,iface).EQ.1) tilt(i,iface)=scanvar*pi/180.
IF (iscan_gshift(i,iface).EQ.1) gshift(i,iface)=scanvar
IF (iscan_chamfer(i,iface).EQ.1) chamfer(i,iface)=scanvar
END DO
END DO
IF (iscan_Lend.EQ.1) Lend=scanvar
IF (iscan_Wmon.EQ.1) Wmon=scanvar
IF (iscan_Hmon.EQ.1) Hmon=scanvar
IF (iscan_Hmonshift.EQ.1) Hmonshift=scanvar
IF (iscan_Vmonshift.EQ.1) Vmonshift=scanvar
c DO iface=1,4 ! bodge for D17 S-bender
c IF (iscan_tilt(3,iface).EQ.1 .AND.
c &iscan_tilt(6,iface).EQ.1) tilt(6,iface)=-tilt(3,iface)
c END DO
END IF
c****************************************
c Recalculate and show parameters from input file
IF (.NOT.nooutput) THEN
IF (usesavedneutrons) THEN
PRINT*,' Source file : ',source_file
ELSE IF (collimated_source) THEN
IF (circular_source) THEN
WRITE(*,106) NINT(Wmod), NINT(halo),
&Hsourcem, Vsourcem
106 FORMAT(
&' Diameter of source, halo, Hor and Ver m-number'/,
&2I5,2F6.2,5X,'- circular collimated source')
ELSE IF (cylindrical_source) THEN
WRITE(*,107) NINT(Wmod), NINT(Hmod), NINT(halo),
&Hsourcem, Vsourcem
107 FORMAT(
&' W, H of source, halo, Hor and Ver m-number'/,
&3I5,2F6.2,5X,'- cylindrical collimated source')
ELSE
WRITE(*,108) NINT(Wmod), NINT(Hmod), NINT(halo),
&Hsourcem, Vsourcem
108 FORMAT(
&' W, H of source, halo, Hor and Ver m-number'/,
&3I5,2F6.2,5X,'- rectangular collimated source')
END IF
ELSE
IF (circular_source) THEN
WRITE(*,109) NINT(Wmod), NINT(halo),
&NINT(Lap), NINT(Wap), NINT(Hap)
109 FORMAT(
&' Diameter of source, halo, Distance to and W, H',
&' of virtual aperture'/,2I5,I6,2I5,5X,'- circular source')
ELSE IF (cylindrical_source) THEN
WRITE(*,110) NINT(Wmod), NINT(Hmod), NINT(halo),
&NINT(Lap), NINT(Wap), NINT(Hap)
110 FORMAT(
&' W, H of source, halo, Distance to and W, H',
&' of virtual aperture'/3I5,I6,2I5,5X,'- cylindrical source')
ELSE
WRITE(*,111) NINT(Wmod), NINT(Hmod), NINT(halo),
&NINT(Lap), NINT(Wap), NINT(Hap)
111 FORMAT(
&' W, H of source, halo, Distance to and W, H',
&' of virtual aperture'/3I5,I6,2I5,5X,'- rectangular source')
END IF
END IF
WRITE(*,115) nsections
115 FORMAT(I5,' guide sections')
END IF
DO i=1,nsections
nfaces=4
string='straight'
R=0.
IF (curved(i)) THEN
string='curved'
R=Rguide0(i,1)*1.E-03
ELSE IF (cavity(i)) THEN
nfaces=5
string='cavity'
ELSE IF (cylindrical(i)) THEN
nfaces=1
string='cylindrical'
tilt(i,2)=tilt(i,1)
ELSE IF (hparabolic(i)) THEN
string='hparabolic'
ELSE IF (vparabolic(i)) THEN
string='vparabolic'
END IF
IF (tilted(i)) THEN
IF (cylindrical(i)) THEN
Hshift(i)=gshift(i,1)
Vshift(i)=0.
ELSE