COSMOS v7.655  COSMOSv7655
(AirShowerMC)
cgetRotMat4.f
Go to the documentation of this file.
1 !c to test cgetRotMat4, cinvRotMat4, cmultRotMat4, capplyRot4
2 !c cgetRotMat4: get rotation matrix of x/y/z axis
3 !c cinvRotMat4: invert a rotation matrix
4 !c cmultRotMat4: multiply two rotation matrix
5 !c capplyRot4: applay a rotation on a 3d vector.
6 !c
7 ! implicit none
8 ! include '../Zptcl.h'
9 ! type(fmom):: vn, v
10 ! real*8 rm(4, 4), rmn(4,4), rmm(4,4)
11 ! real*8 Torad
12 ! integer i, j, m
13 ! v.x =1.
14 ! v.y =0.
15 ! v.z =1.
16 !c
17 ! do i=1, 4
18 ! do j=1, 4
19 ! rm(i, j)=1.d30
20 ! rmn(i, j)=-1.d30
21 ! rmm(i, j)=1.d15
22 ! enddo
23 ! enddo
24 ! do i=1, 3
25 ! vn.p(i)= 1.e50
26 ! enddo
27 ! Torad=asin(1.d0)/90.d0
28 ! m=3
29 ! call cgetRotMat4(m, 45.*Torad, rm)
30 ! call cinvRotMat4(rm, rmn)
31 ! call cgetRotMat4(m, -45.*Torad, rmm)
32 ! write(*, *) ' rotation matrix around m=', m
33 ! do 10 i=1, 4
34 ! write(*,*) (rm(i,j),j=1, 4)
35 ! 10 continue
36 ! write(*,*) "-----inverse of the above--"
37 ! do 20 i=1, 4
38 ! write(*,*) (rmn(i,j),j=1, 4)
39 ! 20 continue
40 ! write(*,*) "-----should be the same as above--"
41 ! do 30 i=1, 4
42 ! write(*,*) (rmm(i,j),j=1, 4)
43 ! 30 continue
44 ! write(*,*) "-------"
45 ! call capplyRot4(rm, v, vn)
46 ! write(*, *) ' v is rotated by rm'
47 ! write(*,*) vn.p
48 ! call cmultRotMat4(rm, rmn, rmm)
49 ! write(*, *)' unit matrix should be seen'
50 ! write(*, *) rmm
51 ! call capplyRot4(rmm, v, vn)
52 ! write(*, *) " no change from v"
53 ! write(*,*) vn.p
54 ! end
55 ! **************************************************************
56 ! *
57 ! * cgetRotMat4: make rotation matrix of 3-d coordinate axes.
58 ! *
59 ! **************************************************************
60 ! /usage/ call cgetRotMat4(m, ang, rm)
61 !
62 ! m: input. integer 1--> rotaion of coordinate around x axis
63 ! 2--> // y
64 ! 3--> // z
65 ! rotation is made anticlock wise (e.g,
66 ! if m=3,
67 ! !y / new x
68 ! $ new y ! /
69 ! $ ! / *
70 ! $ ! / * ang ( if > 0)
71 ! $ ! / *
72 ! ~~~~~~~~~~~~~~~~~ x
73 ! z is directed to the eyes.
74 ! ang: input. real*8. rotation angle in radian.
75 ! rm(4,4): output. real*8 rotation matrix. v'=rm*v is the new coordinate
76 ! of a vector v(see capplyRot4)
77 !
78  subroutine cgetrotmat4(m, ang, rm)
79  implicit none
80 !
81  integer m
82  real*8 ang
83  real*8 rm(4, 4)
84 !
85  integer i, j, m1, m2
86  real*8 c, s
87 !
88  if(m .ge. 1 .and. m .le. 3) then
89  do i=1, 4
90  do j=1, 4
91  rm(i, j)= 0.d0
92  enddo
93  enddo
94  rm(4,4)=1.d0
95  rm(m, m)=1.d0
96  m1=mod(m,3)+1
97  m2=mod(m1,3)+1
98  c=cos(ang)
99  s=sin(ang)
100  rm(m1,m1)=c
101  rm(m2,m2)=c
102  rm(m1,m2)=s
103  rm(m2,m1)=-s
104  else
105  write(*,*) ' invalid m=',m,' to cgetRotMat4 '
106  stop 9999
107  endif
108  end
109  subroutine cinvrotmat4(rm, rmn)
110 ! Invert rotation matrix rm and put into rmn.
111 ! rm should be a roation matrix made by calling
112 ! cgetRotMat4 (with ang). rmn can be made by calling
113 ! cgetRotMat4 with -ang, too. this one is to avoid
114 ! computing the cos and sin for reducing time.
115 ! rmn cannot be the same arrays as rm.
116 ! rmn is nothing but the transposed matrix of rm.
117  implicit none
118  real*8 rm(4,4), rmn(4,4)
119  integer i, j
120  do i=1,4
121  do j=i+1, 4
122  rmn(i,j)=rm(j, i)
123  rmn(j,i)=rm(i, j)
124  enddo
125  enddo
126  do i=1, 4
127  rmn(i,i)=rm(i, i)
128  enddo
129  end
130  subroutine cmultrotmat4(a, b, c)
131 ! 3-d matrix product c=a*b
132 ! c cannot be either of a or b.
133  implicit none
134  real*8 a(4,4), b(4,4), c(4,4)
135  integer i, j, k
136  real*8 ab
137  do i=1, 4
138  do j=1, 4
139  ab=0.
140  do k=1, 4
141  ab=ab+ a(i,k)*b(k,j)
142  enddo
143  c(i,j)=ab
144  enddo
145  enddo
146  end
147  subroutine capplyrot4(a, v, vn)
148 ! 3-d transformation matrix a is multiplied by
149 ! a vector v to obtain a new vector vn.
150 ! vn can be v.
151 !
152  implicit none
153 !---- include '../Zptcl.h'
154 #include "Zptcl.h"
155  type(fmom):: v, vn
156  real*8 a(4,4)
157  type(fmom):: tmp
158 !
159  real*8 sum
160  integer i, j
161 !
162  do i=1, 3
163  sum=0.
164  do j=1, 4
165  sum=sum + a(i, j)*v%p(j)
166  enddo
167  tmp%p(i)=sum
168  enddo
169  vn = tmp
170  end
171 
subroutine cmultrotmat4(a, b, c)
Definition: cgetRotMat4.f:131
! for length to thickness conversion or v v ! integer maxnodes real Hinf ! This is used when making table for dim simulation ! The slant length for vertical height to km is ! divided by LenStep m steps ! It can cover the slant length of about km for cos
Definition: Zatmos.h:8
subroutine cinvrotmat4(rm, rmn)
Definition: cgetRotMat4.f:110
subroutine cgetrotmat4(m, ang, rm)
Definition: cgetRotMat4.f:79
Definition: Zptcl.h:72
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine capplyrot4(a, v, vn)
Definition: cgetRotMat4.f:148