/[MITgcm]/MITgcm/model/src/rotate_spherical_polar_grid.F
ViewVC logotype

Contents of /MITgcm/model/src/rotate_spherical_polar_grid.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download)
Sun Dec 25 22:24:35 2011 UTC (12 years, 4 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, HEAD
Changes since 1.3: +5 -96 lines
- rename S/R CALC_ANGLES to CALC_GRID_ANGLES and move it outside
  rotate_spherical_polar_grid.F into specific file calc_grid_angles.F

1 C $Header: /u/gcmpack/MITgcm/model/src/rotate_spherical_polar_grid.F,v 1.3 2011/02/21 17:57:36 jmc Exp $
2 C $Name: $
3
4 #include "CPP_OPTIONS.h"
5
6 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
7 CBOP
8 C !ROUTINE: ROTATE_SPHERICAL_POLAR_GRID
9 C !INTERFACE:
10 SUBROUTINE ROTATE_SPHERICAL_POLAR_GRID(
11 U X, Y,
12 I myThid )
13
14 C !DESCRIPTION: \bv
15 C *===================================================================*
16 C | SUBROUTINE ROTATE_SPHERICAL_POLAR_GRID
17 C | o rotate the model coordinates on the input arrays to
18 C | geographical coordinates
19 C | o this is useful when a rotated spherical grid is used,
20 C | e.g., in order to avoid the pole singularity.
21 C | The three Euler angles PhiEuler, ThetaEuler, and PsiEuler
22 C | define the rotation about the original z-axis (of an sphere
23 C | centered cartesian grid), the new x-axis, and the new z-axis,
24 C | respectively.
25 C | The input coordinates X, Y are assumed to be the model coordinates
26 C | on a rotated grid defined by the Euler angles. In this S/R they
27 C | are rotated *BACK* to the geographical coordinate; that is why
28 C | all rotation matrices are the inverses of the original matrices.
29 C | On exit X and Y are the geographical coordinates, that are
30 C | used to compute the Coriolis parameter and also to interpolate
31 C | forcing fields to as in pkg/exf/exf_interf.F
32 C | Naturally, this feature does not work with all packages, so the
33 C | some combinations are prohibited in config_summary (flt,
34 C | flt_zonal, ecco, profiles), because there the coordinates are
35 C | assumed to be regular spherical grid coordinates.
36 C *===================================================================*
37 C \ev
38
39 C !USES:
40 IMPLICIT NONE
41 C === Global variables ===
42 #include "SIZE.h"
43 #include "EEPARAMS.h"
44 #include "PARAMS.h"
45
46 C !INPUT/OUTPUT PARAMETERS:
47 C == Routine arguments ==
48 C X, Y :: on entry: model coordinate location
49 C :: on exit: geographical coordinate location
50 C myThid :: my Thread Id Number
51 _RS X(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
52 _RS Y(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
53 INTEGER myThid
54 CEOP
55
56 C !LOCAL VARIABLES:
57 C == Local variables ==
58 C bi,bj :: Tile indices
59 C i, j :: Loop counters
60 INTEGER bi, bj
61 INTEGER I, J, iA, jA, kA
62 C Euler angles in radians
63 _RL phiRad, thetaRad, psiRad
64 C inverted rotation matrix
65 _RL Ainv(3,3), Binv(3,3), Cinv(3,3), Dinv(3,3), CB(3,3)
66 C cartesian coordinates
67 _RL XYZgeo(3), XYZrot(3)
68 C some auxilliary variables
69 _RL hypotxy
70 CEOP
71
72 C convert to radians
73 phiRad = phiEuler *deg2rad
74 thetaRad = thetaEuler*deg2rad
75 psiRad = psiEuler *deg2rad
76
77 C create inverse of full rotation matrix
78 Dinv(1,1) = COS(phiRad)
79 Dinv(1,2) = -SIN(phiRad)
80 Dinv(1,3) = 0. _d 0
81 C
82 Dinv(2,1) = SIN(phiRad)
83 Dinv(2,2) = COS(phiRad)
84 Dinv(2,3) = 0. _d 0
85 C
86 Dinv(3,1) = 0. _d 0
87 Dinv(3,2) = 0. _d 0
88 Dinv(3,3) = 1. _d 0
89 C
90 Cinv(1,1) = 1. _d 0
91 Cinv(1,2) = 0. _d 0
92 Cinv(1,3) = 0. _d 0
93 C
94 Cinv(2,1) = 0. _d 0
95 Cinv(2,2) = COS(thetaRad)
96 Cinv(2,3) = -SIN(thetaRad)
97 C
98 Cinv(3,1) = 0. _d 0
99 Cinv(3,2) = SIN(thetaRad)
100 Cinv(3,3) = COS(thetaRad)
101 C
102 Binv(1,1) = COS(psiRad)
103 Binv(1,2) = -SIN(psiRad)
104 Binv(1,3) = 0. _d 0
105 C
106 Binv(2,1) = SIN(psiRad)
107 Binv(2,2) = COS(psiRad)
108 Binv(2,3) = 0. _d 0
109 C
110 Binv(3,1) = 0. _d 0
111 Binv(3,2) = 0. _d 0
112 Binv(3,3) = 1. _d 0
113 C Ainv = Binv*Cinv*Dinv (matrix multiplications)
114 DO jA=1,3
115 DO iA=1,3
116 Ainv(iA,jA) = 0. _d 0
117 CB (iA,jA) = 0. _d 0
118 ENDDO
119 ENDDO
120 DO jA=1,3
121 DO iA=1,3
122 DO kA=1,3
123 CB (iA,jA) = CB (iA,jA) + Cinv(iA,kA)*Binv(kA,jA)
124 ENDDO
125 ENDDO
126 ENDDO
127 DO jA=1,3
128 DO iA=1,3
129 DO kA=1,3
130 Ainv(iA,jA) = Ainv(iA,jA) + Dinv(iA,kA)*CB(kA,jA)
131 ENDDO
132 ENDDO
133 ENDDO
134 C
135
136 C For each tile ...
137 DO bj = myByLo(myThid), myByHi(myThid)
138 DO bi = myBxLo(myThid), myBxHi(myThid)
139
140 C loop over grid points
141 DO J = 1-OLy,sNy+OLy
142 DO I = 1-OLx,sNx+OLx
143 C transform spherical coordinates with unit radius
144 C to sphere centered cartesian coordinates
145 XYZrot(1) =
146 & COS( Y(I,J,bi,bj)*deg2rad )*COS( X(I,J,bi,bj)*deg2rad )
147 XYZrot(2) =
148 & COS( Y(I,J,bi,bj)*deg2rad )*SIN( X(I,J,bi,bj)*deg2rad )
149 XYZrot(3) = SIN( Y(I,J,bi,bj)*deg2rad )
150 C rotate cartesian coordinate (matrix multiplication)
151 DO iA=1,3
152 XYZgeo(iA) = 0. _d 0
153 ENDDO
154 DO iA=1,3
155 DO jA=1,3
156 XYZgeo(iA) = XYZgeo(iA) + Ainv(iA,jA)*XYZrot(jA)
157 ENDDO
158 ENDDO
159 C tranform cartesian coordinates back to spherical coordinates
160 hypotxy = SQRT( ABS(XYZgeo(1))*ABS(XYZgeo(1))
161 & + ABS(XYZgeo(2))*ABS(XYZgeo(2)) )
162 IF(XYZgeo(1) .EQ. 0. _d 0 .AND. XYZgeo(2) .EQ. 0. _d 0)THEN
163 C happens exactly at the poles
164 X(I,J,bi,bj) = 0. _d 0
165 ELSE
166 X(I,J,bi,bj) = ATAN2(XYZgeo(2),XYZgeo(1))/deg2rad
167 IF ( X(I,J,bi,bj) .LT. 0. _d 0 )
168 & X(I,J,bi,bj) = X(I,J,bi,bj) + 360. _d 0
169 ENDIF
170 IF(hypotxy .EQ. 0. _d 0 .AND. XYZgeo(3) .EQ. 0. _d 0)THEN
171 C this can not happen for a sphere with unit radius
172 Y(I,J,bi,bj) = 0. _d 0
173 ELSE
174 Y(I,J,bi,bj) = ATAN2(XYZgeo(3),hypotxy)/deg2rad
175 ENDIF
176 ENDDO
177 ENDDO
178 C bi,bj-loops
179 ENDDO
180 ENDDO
181
182 RETURN
183 END

  ViewVC Help
Powered by ViewVC 1.1.22