COSMOS v7.655  COSMOSv7655
(AirShowerMC)
cgetRotMat3.f
Go to the documentation of this file.
1 !c to test cgetRotMat3, cinvRotMat3, cmultRotMat3, capplyRot3
2 !c cgetRotMat3: get rotation matrix of x/y/z axis
3 !c cinvRotMat3: invert a rotation matrix
4 !c cmultRotMat3: multiply two rotation matrix
5 !c capplyRot3: applay a rotation on a 3d vector.
6 !c
7 ! implicit none
8 ! real*8 rm(3, 3), rmn(3,3), rmm(3, 3)
9 ! real*8 Torad, vn(3), v(3)
10 ! integer i, j, m
11 ! v(1) =1.
12 ! v(2) =0.
13 ! v(3) = 1.
14 !
15 ! do i=1, 3
16 ! do j=1, 3
17 ! rm(i, j)=1.d30
18 ! rmn(i, j)=-1.d30
19 ! rmm(i, j)=1.d15
20 ! enddo
21 ! enddo
22 ! do i=1, 3
23 ! vn(i)= 1.e50
24 ! enddo
25 ! Torad=asin(1.d0)/90.d0
26 ! m=3
27 ! call cgetRotMat3(m, 1.d0, 0.d0, rm)
28 ! write(*,*) rm
29 ! call cgetRotMat3(m, cos(45.*Torad), -sin(45.*Torad), rm)
30 ! call cinvRotMat3(rm, rmn)
31 ! call cgetRotMat3(m,cos(-45.*Torad), -sin(-45.*Torad), rmm)
32 ! write(*, *) ' rotation matrix around m=', m
33 ! do i=1, 3
34 ! write(*,*) (rm(i,j),j=1, 3)
35 ! enddo
36 ! write(*,*) "-----inverse of the above--"
37 ! do i=1, 3
38 ! write(*,*) (rmn(i,j),j=1, 3)
39 ! enddo
40 ! write(*,*) "-----should be the same as above--"
41 ! do i=1, 3
42 ! write(*,*) (rmm(i,j),j=1, 3)
43 ! enddo
44 ! write(*,*) "-------"
45 ! call capplyRot3(rm, v, vn)
46 ! write(*, *) ' v is rotated by rm'
47 ! write(*,*) vn
48 ! call cmultRotMat3(rm, rmn, rmm)
49 ! write(*, *)' unit matrix should be seen'
50 ! write(*, *) rmm
51 ! call capplyRot3(rmm, v, vn)
52 ! write(*, *) " no change from v"
53 ! write(*,*) vn
54 ! end
55 ! **************************************************************
56 ! *
57 ! * cgetRotMat3: make rotation matrix of 3-d coordinate axes.
58 ! *
59 ! **************************************************************
60 ! /usage/ call cgetRotMat3(m, cosa, sina, 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.r(1)
68 ! $ new.r(2) ! /
69 ! $ ! / *
70 ! $ ! / * ang ( if > 0)
71 ! $ ! / *
72 ! ~~~~~~~~~~~~~~~~~ x
73 ! z is directed to the eyes.
74 ! cosa: input. real*8. cos of rotation angle.
75 ! sina: input. // sin //
76 ! rm(3,3): output. real*8 rotation matrix. v'=rm*v is the new coordinate
77 ! of a vector v(see capplyRot3)
78 !
79  subroutine cgetrotmat3(m, cosa, sina, rm)
80  implicit none
81 !
82  integer m
83  real*8 cosa, sina
84  real*8 rm(3, 3)
85 !
86  integer i, j, m1, m2
87  character*70 msg
88 !
89  if(m .ge. 1 .and. m .le. 3) then
90  do i=1, 3
91  do j=1, 3
92  rm(i, j)= 0.d0
93  enddo
94  enddo
95  rm(m, m)=1.d0
96  m1=mod(m,3)+1
97  m2=mod(m1,3)+1
98  rm(m1,m1)=cosa
99  rm(m2,m2)=cosa
100  rm(m1,m2)=sina
101  rm(m2,m1)=-sina
102  else
103  write(msg, *) ' invalid m=',m,' to cgetRotMat3 '
104  call cerrormsg(msg,0)
105  endif
106  end
107  subroutine cinvrotmat3(rm, rmn)
108 ! Invert rotation matrix rm and put into rmn.
109 ! rm should be a roation matrix made by calling
110 ! cgetRotMat3 (with cosa, sina). rmn can be made by calling
111 ! cgetRotMat3 with cosa, -sina, too.
112 ! rmn cannot be the same arrays as rm.
113 ! rmn is nothing but the transposed matrix of rm.
114  implicit none
115  real*8 rm(3,3), rmn(3,3)
116  integer i, j
117  do i=1,3
118  do j=i+1, 3
119  rmn(i,j)=rm(j, i)
120  rmn(j,i)=rm(i, j)
121  enddo
122  enddo
123  do i=1, 3
124  rmn(i,i)=rm(i, i)
125  enddo
126  end
127  subroutine cmultrotmat3(a, b, c)
128 ! 3-d matrix product c=a*b
129 ! c cannot be either of a or b.
130  implicit none
131  real*8 a(3,3), b(3,3), c(3,3)
132  integer i, j, k
133  real*8 ab
134  do i=1, 3
135  do j=1, 3
136  ab=0.
137  do k=1, 3
138  ab=ab+ a(i,k)*b(k,j)
139  enddo
140  c(i,j)=ab
141  enddo
142  enddo
143  end
144  subroutine capplyrot3(a, v, vn)
145 ! 3-d transformation matrix a is multiplied by
146 ! a vector v to obtain a new vector vn.
147 ! vn can be v.
148 !
149  implicit none
150  real*8 a(3,3), v(3), vn(3)
151 
152 !
153  real*8 sum
154  integer i, j
155 !
156  do i=1, 3
157  sum=0.
158  do j=1, 3
159  sum=sum + a(i, j)*v(j)
160  enddo
161  vn(i)=sum
162  enddo
163  end
subroutine cerrormsg(msg, needrtn)
Definition: cerrorMsg.f:4
subroutine cinvrotmat3(rm, rmn)
Definition: cgetRotMat3.f:108
subroutine cgetrotmat3(m, cosa, sina, rm)
Definition: cgetRotMat3.f:80
subroutine cmultrotmat3(a, b, c)
Definition: cgetRotMat3.f:128
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine capplyrot3(a, v, vn)
Definition: cgetRotMat3.f:145