-
Notifications
You must be signed in to change notification settings - Fork 1
/
mimosa_model0.f90
1455 lines (1191 loc) · 38.2 KB
/
mimosa_model0.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
!
!|************************************************************************
!| FILE: ii_skyimage_model0.F90
!| VERSION: 2.8 Aleksandra Gros
!| COMPONENT: ii_skyimage_extract
!| DeveloperS: Aleksandra Gros SAp/CEA-Saclay
!| Notes: This file contains analytic source model creation subroutine
!|***********************************************************************
!| MODULES :1. MODEL0_VALS - global constants and variables
!| 2. MODEL0_AUX - auxiliary subroutines
!| 3. MODEL_PROC- auxiliary subroutines
!| 4. SOURCE_MODEL - main subroutine
!|************************************************************************
!**************************
!**************************
MODULE MODEL0_VALS
!**************************
! effective start and stop of mask pattern in the array
INTEGER,parameter :: iMaskStart = 33,iMaskStop = 127,&
jMaskStart = 33,jMaskStop = 127
REAL (kind=8),parameter :: FigSurfMinTol= 1.E-3,FigTol = 1.E-4
LOGICAL ,save :: MaskDetRotationFlag =.false.
REAL (kind=8) :: xsoushift,ysoushift
REAL (kind=8) :: relpi,theta,thetarad,tgtheta
REAL (kind=8) :: cost,sent,alpha,alphax,alphay
REAL (kind=8) :: xmaskcentre,ymaskcentre
REAL (kind=8) :: xdetcentre,ydetcentre
REAL (kind=8),dimension(4,2) :: xyCorner
INTEGER,dimension(4,2) :: ijCorner
INTEGER,dimension(4,2),save :: wzor
INTEGER,parameter :: pktmax=20
TYPE line
REAL (kind=8) :: a,b
REAL (kind=8),dimension(pktmax,2) :: pkty
INTEGER,dimension(pktmax) :: inlist
INTEGER :: ilepktow
INTEGER :: fill_gap_dummy
END TYPE line
INTEGER,parameter :: pktmax1=20
TYPE cors
REAL (kind=8) :: a,b
REAL (kind=8),dimension(pktmax,2) :: pkty
INTEGER,dimension(pktmax) :: inlist
INTEGER :: ilepktow
INTEGER :: fill_gap_dummy
END TYPE cors
TYPE(line),dimension(4) :: PixLines
TYPE(cors) :: PixCorners
INTEGER,parameter :: mpsize = 40
! list of singular points of the projected mask pixel
REAL (kind=8),dimension(mpsize,2) :: points
! list of int singular points of the projected mask pixel
INTEGER,dimension(mpsize,2) :: intpoints
INTEGER,dimension(mpsize) :: typepoints
! list of point belonging to the given det pixel
INTEGER,parameter :: MaxFigCorners=10
REAL (kind=8),dimension(MaxFigCorners,2) :: Figure
! figure point order
INTEGER,dimension(MaxFigCorners) :: vertex ,vertex1
! mask pixel surface fraction projected onto given det pixel
REAL (kind=8),dimension(mpsize,mpsize) :: DetPixFraction
!**************************
END MODULE MODEL0_VALS
!**************************
!***************************
MODULE MODEL0_AUX
!***************************
INTERFACE
SUBROUTINE AddPoint_MODEL0(x,y,point)
!-------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: point
REAL (kind=8) :: x,y
END SUBROUTINE AddPoint_MODEL0
SUBROUTINE FigVerif_MODEL0(ile,surface,Status)
!--------------------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: ile,Status
REAL (kind=8) :: surface
END SUBROUTINE FigVerif_MODEL0
SUBROUTINE Triangle_MODEL0(surface)
!----------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
END SUBROUTINE Triangle_MODEL0
SUBROUTINE Quad_MODEL0(surface)
!--------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
END SUBROUTINE Quad_MODEL0
SUBROUTINE Penta_MODEL0(surface)
!--------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
END SUBROUTINE Penta_MODEL0
SUBROUTINE Hexa_MODEL0(surface)
!--------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
END SUBROUTINE Hexa_MODEL0
SUBROUTINE MAKEVERTEX_MODEL0(ile)
!--------------------------
IMPLICIT NONE
! INPUT/OUTPUT VARIABLES
INTEGER :: ile
END SUBROUTINE MAKEVERTEX_MODEL0
END INTERFACE
!***************************
END MODULE MODEL0_AUX
!***************************
!**************************
MODULE MODEL0_PROC
!**************************
INTERFACE
SUBROUTINE DetMaskPos_MODEL0(idetpix,jdetpix,&
xmaskpos,ymaskpos,imaskpix,jmaskpix)
!----------------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: idetpix,jdetpix,imaskpix,jmaskpix
REAL(kind=8) :: xmaskpos,ymaskpos
END SUBROUTINE DetMaskPos_MODEL0
SUBROUTINE MaskDetPos_MODEL0(imaskpix,jmaskpix,&
xdetpos,ydetpos,idetpix,jdetpix)
!-----------------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: imaskpix,jmaskpix,idetpix,jdetpix
REAL(kind=8) :: xdetpos,ydetpos
END SUBROUTINE MaskDetPos_MODEL0
SUBROUTINE MinMaxMaskPixel_MODEL0(i1,j1,i2,j2,&
imin,imax,jmin,jmax)
!---------------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: i1,j1,i2,j2,imin,imax,jmin,jmax
END SUBROUTINE MinMaxMaskPixel_MODEL0
!!$SUBROUTINE MaskBlok_MODEL0(MASKP,iMaskPix,jMaskPix,jMaskMax,ile)
!!$!--------------------------------------------------------
!!$IMPLICIT NONE
!!$
!!$!INPUT/OUTPUT VARIABLES
!!$REAL (kind=8), dimension(:,:), pointer :: MASKP
!!$INTEGER ::iMaskPix,jMaskPix,jMaskMax,ile
!!$END SUBROUTINE MaskBlok_MODEL0
SUBROUTINE MaskDetDefLines_MODEL0(imin,imax,jmin,jmax)
!-------------------------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER ::imin,imax,jmin,jmax
END SUBROUTINE MaskDetDefLines_MODEL0
SUBROUTINE DetPixChoice_MODEL0(i1,i2,j1,j2,Status)
!-----------------------------
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: i1,i2,j1,j2,Status
END SUBROUTINE DetPixChoice_MODEL0
SUBROUTINE SET_DET_MODEL0(idetpix,jdetpix,Det,MASKP,&
imaskpix,jmaskpix,coeff)
!--------------------------------------
IMPLICIT NONE
! INPUT/OUTPUT VARIABLES
INTEGER :: idetpix,jdetpix,imaskpix,jmaskpix
REAL (kind=8), dimension(:,:),pointer :: DET,MASKP
REAL (kind=8) :: coeff
END SUBROUTINE SET_DET_MODEL0
END INTERFACE
!**************************
END MODULE MODEL0_PROC
!**************************
!**************************
MODULE MODEL0_DECLARATIONS
!**************************
INTERFACE
SUBROUTINE Model0(MASKP,DET,xsou,ysou,status)
!---------------------------------------------
IMPLICIT NONE
! INTERFACE variables
REAL (kind=8), dimension(:,:), pointer :: DET,MASKP
REAL (kind=8) :: xsou,ysou
INTEGER :: status
END SUBROUTINE Model0
END INTERFACE
!**************************
END MODULE MODEL0_DECLARATIONS
!**************************
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
! SUBROUTINES
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
!##################################
! subroutines from MODEL0_AUX
!##################################
!===================================
SUBROUTINE AddPoint_MODEL0(x,y,point)
!===================================
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: point
REAL (kind=8) :: x,y
!LOCAL VARIABLES
REAL (kind=8) :: xi,yi
xi = aint(x)
yi = aint(y)
points(point,1) = x
points(point,2) = y
intpoints(point,1) = xi
intpoints(point,2) = yi
if(xi.ne.x)then
!not on vertical line
if(yi.eq.y)then
! only on horizonthal line
typepoints(point) = 2
endif
else
!on vertical line
if(yi.eq.y)then
! on vertical and horizonthal line
typepoints(point) = 4
else
! only on vertical line
typepoints(point) = 1
endif
endif
!=======================
END SUBROUTINE AddPoint_MODEL0
!=======================
!============================================
SUBROUTINE FigVerif_MODEL0(ile,surface,Status)
!============================================
USE ISDC
USE MIMOSA_CONTROL_MODULE
!!!!!!!!USE II_SKYIMAGE_GLOBVAR_MODULE
!!!!!!!!USE II_SKYIMAGE_USE_MODULE
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: ile,Status
REAL (kind=8) :: surface
!LOCAL VARIABLES
INTEGER :: ki,kj
REAL (kind=8) :: x1,x2,y1,y2
INTEGER,dimension(10) :: tab
INTEGER,dimension(1) :: tt1
CHARACTER(len=100) :: str100
CHARACTER(len=20) :: procName
Status = ISDC_OK
procName = 'FigVerif_MODEL0'
if(ile > 2)then
!figure size verif
x1 = minval(figure(1:ile,1))
x2 = maxval(figure(1:ile,1))
y1 = minval(figure(1:ile,2))
y2 = maxval(figure(1:ile,2))
surface = (x2-x1)*(y2-y1)
if(surface.lt.FigSurfMinTol)then
ile=0
else ! not too small figure
! same points searching
!numbers will be marked as 0 in the table tab
tab(1:ile) = 1
do ki=1,ile ! first point
if(tab(ki) > 0)then ! not excluded
do kj=ki+1,ile ! second point
if(tab(kj) > 0)then
if(abs(figure(ki,1)-figure(kj,1)) < figtol)then
if(abs(figure(ki,2)-figure(kj,2))< figtol)then
tab(kj) = 0
endif
endif
endif
enddo
endif
enddo
if(sum(tab(1:ile)) < ile)then ! same points found
do while(tab(ile)==0) ! ostatnie podwojne pkty usuniete
ile = ile-1
enddo
if(ile==0)then
write(str100,*)' figure verif problem 1'
call MESSAGE(procName,str100, AnalModelError,Status)
return
endif
do while(minval(tab(1:ile))==0) ! deleting duplicated
tt1=minloc(tab(1:ile))
ki= tt1(1)
! point no ki duplicated - deleting - but not the last one
kj=ile ! point to be placed on ki place
do while((tab(kj)==0).and.(kj > 0))
kj = kj-1
enddo
if(kj==0)then
write(str100,*)' figure verif problem 2'
call MESSAGE(procName,str100, AnalModelError,Status)
return
endif
! kj - point to be put on the ki place
figure(ki,1:2) = figure(kj,1:2)
if(kj==ile)then
ile=ile-1
else
! point ile to be put at kj place
figure(kj,1:2)=figure(ile,1:2)
ile=ile-1
endif
tab(ki) = 1
do while(tab(ile)==0) ! ostatnie podwojne pkty usuniete
ile = ile-1
enddo
enddo
endif ! same points found - deleting
endif ! not too small figure
endif ! ile > 2
!==========================
END SUBROUTINE FigVerif_MODEL0
!==========================
!==================================
SUBROUTINE Triangle_MODEL0(surface)
!==================================
!calculates Triangle_MODEL0 surface
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
!LOCAL VARIABLES
REAL (kind=8),dimension(3) :: bok
REAL (kind=8) :: p
surface = 0.
bok = 0.
bok(1) = sqrt((figure(vertex(1),1)-figure(vertex(2),1))**2+&
(figure(vertex(1),2)-figure(vertex(2),2))**2 )
bok(2) = sqrt((figure(vertex(2),1)-figure(vertex(3),1))**2+&
(figure(vertex(2),2)-figure(vertex(3),2))**2 )
bok(3) = sqrt((figure(vertex(3),1)-figure(vertex(1),1))**2+&
(figure(vertex(3),2)-figure(vertex(1),2))**2 )
p = 0.5*(bok(1)+bok(2)+bok(3))
surface = p*(p-bok(1))*(p-bok(2))*(p-bok(3))
surface = sqrt(surface)
!=======================
END SUBROUTINE Triangle_MODEL0
!========================
!==================================
SUBROUTINE Quad_MODEL0(surface)
!==================================
!calculates Quad_MODEL0rilateral surface
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
!LOCAL VARIABLES
REAL (kind=8),dimension(5) :: bok
REAL (kind=8) :: p1,p2,s1,s2
surface = 0.
bok = 0.
bok(1) = sqrt((figure(vertex(1),1)-figure(vertex(2),1))**2+&
(figure(vertex(1),2)-figure(vertex(2),2))**2 )
bok(2) = sqrt((figure(vertex(2),1)-figure(vertex(3),1))**2+&
(figure(vertex(2),2)-figure(vertex(3),2))**2 )
bok(3) = sqrt((figure(vertex(3),1)-figure(vertex(4),1))**2+&
(figure(vertex(3),2)-figure(vertex(4),2))**2 )
bok(4) = sqrt((figure(vertex(4),1)-figure(vertex(1),1))**2+&
(figure(vertex(4),2)-figure(vertex(1),2))**2 )
bok(5) = sqrt((figure(vertex(1),1)-figure(vertex(3),1))**2+&
(figure(vertex(1),2)-figure(vertex(3),2))**2 )
p1 = 0.5*(bok(1)+bok(2)+bok(5))
p2= 0.5*(bok(3)+bok(4)+bok(5))
s1 = p1*(p1-bok(1))*(p1-bok(2))*(p1-bok(5))
s1 = sqrt(s1)
s2 = p2*(p2-bok(3))*(p2-bok(4))*(p2-bok(5))
s2 = sqrt(s2)
surface = s1+s2
!=======================
END SUBROUTINE Quad_MODEL0
!========================
!==================================
SUBROUTINE Penta_MODEL0(surface)
!==================================
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
!LOCAL VARIABLES
REAL (kind=8),dimension(7) :: bok
REAL (kind=8) :: p1,p2,p3,s1,s2,s3
surface = 0.
bok = 0.
bok(1) = sqrt((figure(vertex(1),1)-figure(vertex(2),1))**2+&
(figure(vertex(1),2)-figure(vertex(2),2))**2 )
bok(2) = sqrt((figure(vertex(2),1)-figure(vertex(3),1))**2+&
(figure(vertex(2),2)-figure(vertex(3),2))**2 )
bok(3) = sqrt((figure(vertex(3),1)-figure(vertex(4),1))**2+&
(figure(vertex(3),2)-figure(vertex(4),2))**2 )
bok(4) = sqrt((figure(vertex(4),1)-figure(vertex(5),1))**2+&
(figure(vertex(4),2)-figure(vertex(5),2))**2 )
bok(5) = sqrt((figure(vertex(5),1)-figure(vertex(1),1))**2+&
(figure(vertex(5),2)-figure(vertex(1),2))**2 )
bok(6) = sqrt((figure(vertex(1),1)-figure(vertex(3),1))**2+&
(figure(vertex(1),2)-figure(vertex(3),2))**2 )
bok(7) = sqrt((figure(vertex(1),1)-figure(vertex(4),1))**2+&
(figure(vertex(1),2)-figure(vertex(4),2))**2 )
p1 = 0.5*(bok(1)+bok(2)+bok(6))
p2= 0.5*(bok(6)+bok(3)+bok(7))
p3= 0.5*(bok(7)+bok(4)+bok(5))
s1 = p1*(p1-bok(1))*(p1-bok(2))*(p1-bok(6))
s1 = sqrt(s1)
s2 = p2*(p2-bok(6))*(p2-bok(3))*(p2-bok(7))
s2 = sqrt(s2)
s3 = p3*(p3-bok(7))*(p3-bok(4))*(p3-bok(5))
s3 = sqrt(s3)
surface = s1+s2+s3
!=======================
END SUBROUTINE Penta_MODEL0
!========================
!==================================
SUBROUTINE Hexa_MODEL0(surface)
!==================================
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
REAL (kind=8) :: surface
!LOCAL VARIABLES
REAL (kind=8),dimension(9) :: bok
REAL (kind=8) :: p1,p2,p3,p4,s1,s2,s3,s4
surface = 0.
bok = 0.
bok(1) = sqrt((figure(vertex(1),1)-figure(vertex(2),1))**2+&
(figure(vertex(1),2)-figure(vertex(2),2))**2 )
bok(2) = sqrt((figure(vertex(2),1)-figure(vertex(3),1))**2+&
(figure(vertex(2),2)-figure(vertex(3),2))**2 )
bok(3) = sqrt((figure(vertex(3),1)-figure(vertex(4),1))**2+&
(figure(vertex(3),2)-figure(vertex(4),2))**2 )
bok(4) = sqrt((figure(vertex(4),1)-figure(vertex(5),1))**2+&
(figure(vertex(4),2)-figure(vertex(5),2))**2 )
bok(5) = sqrt((figure(vertex(5),1)-figure(vertex(6),1))**2+&
(figure(vertex(5),2)-figure(vertex(6),2))**2 )
bok(6) = sqrt((figure(vertex(6),1)-figure(vertex(1),1))**2+&
(figure(vertex(6),2)-figure(vertex(1),2))**2 )
bok(7) = sqrt((figure(vertex(1),1)-figure(vertex(3),1))**2+&
(figure(vertex(1),2)-figure(vertex(3),2))**2 )
bok(8) = sqrt((figure(vertex(1),1)-figure(vertex(4),1))**2+&
(figure(vertex(1),2)-figure(vertex(4),2))**2 )
bok(9) = sqrt((figure(vertex(1),1)-figure(vertex(5),1))**2+&
(figure(vertex(1),2)-figure(vertex(5),2))**2 )
p1 = 0.5*(bok(1)+bok(2)+bok(7))
p2= 0.5*(bok(7)+bok(3)+bok(8))
p3= 0.5*(bok(8)+bok(4)+bok(9))
p4= 0.5*(bok(9)+bok(5)+bok(6))
s1 = p1*(p1-bok(1))*(p1-bok(2))*(p1-bok(7))
s1 = sqrt(s1)
s2 = p2*(p2-bok(7))*(p2-bok(3))*(p2-bok(8))
s2 = sqrt(s2)
s3 = p3*(p3-bok(8))*(p3-bok(4))*(p3-bok(9))
s3 = sqrt(s3)
s4 = p4*(p4-bok(9))*(p4-bok(5))*(p4-bok(6))
s4 = sqrt(s4)
surface = s1+s2+s3+s4
!=======================
END SUBROUTINE Hexa_MODEL0
!========================
!=======================
SUBROUTINE MAKEVERTEX_MODEL0(ile)
!=======================
USE MODEL0_VALS
IMPLICIT NONE
! INPUT/OUTPUT VARIABLES
INTEGER :: ile
!LOCAL VARIABLES
REAL (kind=8) :: x1,x2,a,b,y1,y2
INTEGER :: i,j,i1,i2,gora,dol,maxi,ival
REAL (kind=8) :: val
INTEGER ,dimension(4) :: gorny,dolny
!REAL(kind=8) ,dimension(2) :: tab
gora = 0
dol = 0
x1 = minval(figure(1:ile,1))
x2 = maxval(figure(1:ile,1))
do i=1,ile
if(figure(i,1) == x1)i1=i
if(figure(i,1) == x2) i2=i
enddo
y1 = figure(i1,2)
y2 = figure(i2,2)
a = (y2-y1)/(x2-x1)
b = (y1+y2-a*(x1+x2))/2.
do i=1,ile
if((i.ne.i1).and.(i.ne.i2))then
if(a*figure(i,1)+b.lt.figure(i,2))then
gora = gora+1
gorny(gora) = i
else
dol = dol+1
dolny(dol) = i
endif
endif
enddo
do i=1,gora ! sortowanie gory wedlug rosnacych x-ow
maxi = 0
val = 10000000.
do j=i,gora
if(figure(gorny(j),1).lt.val)then
val =figure(gorny(j),1)
maxi = j
endif
enddo
if(maxi.ne.i)then ! zamiana
! tab = figure(gorny(maxi),1:2)
! figure(gorny(maxi),1:2) = figure(gorny(i),1:2)
! figure(gorny(i),1:2) = tab
ival = gorny(maxi)
gorny(maxi) = gorny(i)
gorny(i) = ival
endif
enddo
do i=1,dol ! sortowanie dolu wedlug malejacych x-ow
maxi = 0
val = 0.
do j=i,dol
if(figure(dolny(j),1).gt.val)then
val =figure(dolny(j),1)
maxi = j
endif
enddo
if(maxi.ne.i)then ! zamiana
! tab = figure(dolny(maxi),1:2)
! figure(dolny(maxi),1:2) = figure(dolny(i),1:2)
! figure(dolny(i),1:2) = tab
ival =dolny(maxi)
dolny(maxi) = dolny(i)
dolny(i) = ival
endif
enddo
vertex(1) = i1
do i=1,gora
vertex(1+i)= gorny(i)
enddo
vertex(2+gora) = i2
do i=1,dol
vertex(2+gora+i) = dolny(i)
enddo
!==========================
END SUBROUTINE MAKEVERTEX_MODEL0
!==========================
!##################################
! subroutines from MODEL0_PROC
!##################################
!=========================================
SUBROUTINE DetMaskPos_MODEL0(idetpix,jdetpix,&
xmaskpos,ymaskpos,imaskpix,jmaskpix)
!=========================================
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: idetpix,jdetpix,imaskpix,jmaskpix
REAL(kind=8) :: xmaskpos,ymaskpos
!LOCAL VARIABLES
REAL(kind=8) :: xdp,ydp,xm,ym
xdp=idetpix+xsoushift
ydp=jdetpix+ysoushift
! Mask coordinates
if(theta .ne. 0.)then
xm=xdp*cost-ydp*sent
ym=xdp*sent+ydp*cost
xm=xm/relpi
ym=ym/relpi
else
xm=xdp/relpi
ym=ydp/relpi
endif
xmaskpos = xm+xmaskcentre
ymaskpos = ym+ymaskcentre
imaskpix=int(xmaskpos)+1
jmaskpix=int(ymaskpos)+1
!==========================
END SUBROUTINE DetMaskPos_MODEL0
!==========================
!=========================================
SUBROUTINE MaskDetPos_MODEL0(imaskpix,jmaskpix,&
xdetpos,ydetpos,idetpix,jdetpix)
!=========================================
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: imaskpix,jmaskpix,idetpix,jdetpix
REAL(kind=8) :: xdetpos,ydetpos
!LOCAL VARIABLES
REAL(kind=8) :: xdp,ydp,xm,ym
xdp=imaskpix -xmaskcentre
ydp=jmaskpix -ymaskcentre
! detector coordinates
if(theta .ne. 0.)then
xm= xdp*cost + ydp*sent
ym=-xdp*sent + ydp*cost
xm=xm*relpi
ym=ym*relpi
else
xm=xdp*relpi
ym=ydp*relpi
endif
xdetpos = xm-xsoushift
ydetpos = ym-ysoushift
idetpix=int(xdetpos)+1
jdetpix=int(ydetpos)+1
!==========================
END SUBROUTINE MaskDetPos_MODEL0
!==========================
!=========================================
SUBROUTINE MinMaxMaskPixel_MODEL0(i1,j1,i2,j2,&
imin,imax,jmin,jmax)
!=========================================
USE MODEL0_VALS
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: i1,j1,i2,j2,imin,imax,jmin,jmax
!LOCAL VARIABLES
INTEGER,dimension(4) :: ipix,jpix
REAL(kind=8) :: xm,ym
call DetMaskPos_MODEL0(i1-1,j1-1,xm,ym,ipix(1),jpix(1))
call DetMaskPos_MODEL0(i2+1,j2+1,xm,ym,ipix(2),jpix(2))
call DetMaskPos_MODEL0(i2+1,j1-1,xm,ym,ipix(3),jpix(3))
call DetMaskPos_MODEL0(i1-1,j2+1,xm,ym,ipix(4),jpix(4))
imin = int(minval(ipix))
imax = int(maxval(ipix))
jmin = int(minval(jpix))
jmax = int(maxval(jpix))
imin = max(iMaskStart,imin)
imax = min(iMaskStop,imax)
jmin = max(jMaskStart,jmin)
jmax = min(jMaskStop,jmax)
!=========================================
END SUBROUTINE MinMaxMaskPixel_MODEL0
!=========================================
!!$!===============================================
!!$SUBROUTINE MaskBlok_MODEL0(MASKP,iMaskPix,jMaskPix,jMaskMax,ile)
!!$!===============================================
!!$
!!$USE MODEL0_VALS
!!$USE MODEL0_AUX
!!$USE II_SKYIMAGE_GLOBVAR_MODULE
!!$USE II_SKYIMAGE_CONTROL_MODULE
!!$USE II_SKYIMAGE_USE_MODULE
!!$IMPLICIT NONE
!!$
!!$!INPUT/OUTPUT VARIABLES
!!$REAL (kind=8), dimension(:,:), pointer :: MASKP
!!$INTEGER ::iMaskPix,jMaskPix,jMaskMax,ile
!!$!LOCAL VARIABLES
!!$INTEGER :: k,type
!!$
!!$type = MASKP(imaskpix,jmaskpix)
!!$ile=0
!!$k=jmaskpix+1
!!$do while((jmaskpix .le.jMaskMax).and.&
!!$ (type.eq.MASKP(imaskpix,k)))
!!$ k = k+1
!!$ ile = ile+1
!!$enddo
!!$ile = min(ile,4)
!!$!=========================
!!$END SUBROUTINE MaskBlok_MODEL0
!!$!=========================
!===============================================
SUBROUTINE MaskDetDefLines_MODEL0(imin,imax,jmin,jmax)
!================================================
USE MODEL0_VALS
USE MODEL0_AUX
IMPLICIT NONE
!INPUT/OUTPUT VARIABLES
INTEGER :: imin,imax,jmin,jmax
!LOCAL VARIABLES
INTEGER :: lnum,pocz,kon,j1,j2,i1,i2,veri,horj,ipktow
REAL(kind=8) :: x1,x2,y1,y2,dx,dy,x,y,a,b
!Calculates cuts points
!-------------------------------
do lnum=1,4 !line loop
!-------------------------------
PixLines(lnum)%inlist(:) = 1 ! different point list
select case(lnum)
case(2,3)
PixLines(lnum)%inlist(1) = 0
case(4)
PixLines(lnum)%inlist(1:2) = 0
end select
pocz = wzor(lnum,1) ! numer poczatku i konca boku
kon = wzor(lnum,2)
PixLines(lnum)%ilepktow = 2 ! min number of singular points on the line
ipktow = 2
x1 = xycorner(pocz,1)
y1 = xycorner(pocz,2)
PixLines(lnum)%pkty(1,1) = x1
PixLines(lnum)%pkty(1,2) = y1
x2 = xycorner(kon,1)
y2 = xycorner(kon,2)
PixLines(lnum)%pkty(2,1) = x2
PixLines(lnum)%pkty(2,2) = y2
i1 =int(min(x1,x2))
i2 = int(max(x1,x2))
j1 = int(min(y1,y2))
j2 = int(max(y1,y2))
!---------------------------------------------
if(.not.MaskDetRotationFlag)then !no rotation
!---------------------------------------------
! line coeffs - not defined in this case
if(i1.ne.i2)then
! projected mask pixel side is a horizonthal line
!vertical lines cut it
do veri=i1+1,i2
ipktow = ipktow+1
PixLines(lnum)%pkty(ipktow,1) = real(veri)
PixLines(lnum)%pkty(ipktow,2) = xycorner(pocz,2)
enddo
else
! projected mask pixel side is a vertical line
! horizonthal lines cut it
if(j1.ne.j2)then
do horj = j1+1,j2
ipktow = ipktow +1
PixLines(lnum)%pkty(ipktow,1) = xycorner(pocz,1)
PixLines(lnum)%pkty(ipktow,2) =real(horj)
enddo
endif
endif
!------------------------------------------
else ! rotation between mask/detector plane
!------------------------------------------
! line coeffs
a = (y2-y1)/(x2-x1)
b = (y1+y2-a*(x1+x2))/2.
PixLines(lnum)%a = a
PixLines(lnum)%b = b
if(i1.ne.i2)then
! vertical lines cut this side
do veri=i1+1,i2
!y1 = a*real(veri)+b
y = y2-(x2-real(veri))*a
ipktow = ipktow+1
PixLines(lnum)%pkty(ipktow,1) = real(veri)
PixLines(lnum)%pkty(ipktow,2) =y
enddo
endif
if(j1.ne.j2)then
! horizonthal lines cut this side
do horj=j1+1,j2
! x1 = (real(horj)-b)/a
x = x2-(y2-real(horj))/a
if(aint(x).ne.x)then
! not the vertical cut at the same time
ipktow = ipktow+1
PixLines(lnum)%pkty(ipktow,1) = x
PixLines(lnum)%pkty(ipktow,2) =real(horj)
endif
enddo
endif
endif ! rotation
PixLines(lnum)%ilepktow = ipktow
!---------------------
enddo !line loop
!---------------------
PixCorners%ilepktow = 0
PixCorners%inlist(:) = 1
!counting of internal det pixel vertex
ipktow = 0
if((imin < imax).and.( jmin < jmax)) then
!---------------------------------------------
if(.not.MaskDetRotationFlag)then ! no rotation
!---------------------------------------------
do veri=imin+1,imax
do horj=jmin+1,jmax
ipktow = ipktow +1
PixCorners%pkty(ipktow,1)= veri
PixCorners%pkty(ipktow,2)= horj
enddo
enddo
!---------------------------------------------
else !rotation between mask and detector plane
!---------------------------------------------
if(theta.gt.0)then ! anticlockwise rotation
do veri=imin+1,imax
do horj=jmin+1,jmax
dx = dble(veri)
dy = dble(horj)
if(PixLines(2)%a*dx + PixLines(2)%b .gt. dy)then
! below 2 pixel line
if(PixLines(4)%a*dx + PixLines(4)%b .lt. dy)then
!above 4 line
if(PixLines(1)%a*dx + PixLines(1)%b .gt. dy)then
! above 1 line
if(PixLines(3)%a*dx + PixLines(3)%b .lt. dy)then
!below 3 line
ipktow = ipktow + 1
PixCorners%pkty(ipktow,1)= dx
PixCorners%pkty(ipktow,2)= dy
endif
endif
endif
endif
enddo
enddo
else !clockwise rotation
do veri=imin+1,imax
do horj=jmin+1,jmax
dx = dble(veri)
dy = dble(horj)
if(PixLines(2)%a*dx + PixLines(2)%b .gt.dy)then
! below 2 line
if(PixLines(4)%a*dx + PixLines(4)%b .lt.dy)then
!above 4 line
if(PixLines(1)%a*dx + PixLines(1)%b .lt. dy)then
! below 1 line
if(PixLines(3)%a*dx + PixLines(3)%b .gt. dy)then
!above 3 line
ipktow = ipktow + 1