source: trunk/SRC/Interpolation/angle.pro @ 241

Last change on this file since 241 was 238, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1;+
2;
3; @file_comments
4; north stereographic polar projection
5;
6; @categories
7; Interpolation
8;
9; @param plam {in}{required}
10; longitude position
11;
12; @param pphi {in}{required}
13; latitude position
14;
15; @keyword DOUBLE {default=0}
16; use double precision (default is float)
17;
18; @returns
19; structure: {x:x, y:y} containing the point position in north stereographic polar projection
20;
21; @hidden
22;
23;-
24;
25FUNCTION fsnspp, plam, pphi, DOUBLE = double
26;
27  compile_opt idl2, strictarrsubs
28;
29  IF keyword_set(double) THEN BEGIN
30    a = 2.d * tan( !dpi/4.d - !dpi/180.d*pphi/2.d )
31    x = cos( !dpi/180.d*plam ) * a
32    y = sin( !dpi/180.d*plam ) * a
33  ENDIF ELSE BEGIN
34    a = 2. * tan( !pi/4. - !pi/180.*float(pphi)/2. )
35    x = cos( !pi/180.*float(plam) ) * a
36    y = sin( !pi/180.*float(plam) ) * a
37  ENDELSE
38  RETURN, {x:x, y:y}
39END
40;+
41;
42; @file_comments
43; Compute angles between grid lines and direction of the North pole
44;(fom angle.F,v 2.2 in OPA8.2)
45;
46; @categories
47; Interpolation
48;
49; @param fileocemesh {in}{required}{type=scalar string}
50; a netcdf file that contains (at least) the following variables:
51;        glamu, gphiu: longitudes and latitudes at U-points
52;        glamv, gphiv: longitudes and latitudes at V-points
53;        glamf, gphif: longitudes and latitudes at F-points
54;
55; @param gcosu {out}{type=2d array}
56; cosinus of the angle between grid lines at U points and direction of the North pole
57;
58; @param gsinu {out}{type=2d array}
59; sinus of the angle between grid lines at U points and direction of the North pole
60;
61; @param gcosv {out}{type=2d array}
62; cosinus of the angle between grid lines at V points and direction of the North pole
63;
64; @param gsinv {out}{type=2d array}
65; sinus of the angle between grid lines at V points and direction of the North pole
66;
67; @param gcost {out}{type=2d array}
68; cosinus of the angle between grid lines at T points and direction of the North pole
69;
70; @param gsint {out}{type=2d array}
71; sinus of the angle between grid lines at T points and direction of the North pole
72;
73; @keyword IODIRECTORY {type=scalar string}{default=''}
74; the directory path where is located fileocemesh
75;
76; @keyword DOUBLE {type=1 ou 2}{default=0}
77; put 1 to use double precision (default is float)
78;
79; @restrictions
80; to compute the lateral boundary conditions, we assume that:
81;     (1) the first line is similar to the second line
82;       =>    gcosu[*, 0] = gcosu[*, 1]
83;       =>    gsinu[*, 0] = gsinu[*, 1]
84;     (2) the grid follows OPA x periodicity rule, first column is
85;     equal to the next to last column
86;       =>    gcosv[0, *] = gcosv[jpj-2, *]
87;       =>    gsinv[0, *] = gsinv[jpj-2, *]
88;
89; @history
90;       Original :  96-07 (O. Marti)
91;                   98-06 (G. Madec)
92;       Feb 2005: IDL adaptation S. Masson
93;
94; @version
95; $Id$
96;
97;-
98;
99PRO angle, fileocemesh, gcosu, gsinu, gcosv, gsinv, gcost, gsint $
100           , IODIRECTORY = iodirectory, DOUBLE = double
101;
102  compile_opt idl2, strictarrsubs
103;
104; 0. read oceanic grid parameters
105; ================================
106;
107  IF keyword_set(IODIRECTORY) THEN BEGIN
108    IF  strpos(iodirectory,'/',/reverse_search) NE (strlen(iodirectory)-1) THEN $
109      iodirectory = iodirectory+'/'
110  ENDIF ELSE iodirectory = ''
111  fileoce = iodirectory+fileocemesh
112;
113  fileoce = findfile(fileoce, count = okfile)
114  IF okfile NE 1 THEN BEGIN
115    ras = report('the file '+fileoce+' is not found... we stop')
116    stop
117  ENDIF
118;
119  cdfido = ncdf_open(fileoce[0])
120  ncdf_varget, cdfido, 'glamt', glamt
121  ncdf_varget, cdfido, 'glamu', glamu
122  ncdf_varget, cdfido, 'glamv', glamv
123  ncdf_varget, cdfido, 'glamf', glamf
124  ncdf_varget, cdfido, 'gphit', gphit
125  ncdf_varget, cdfido, 'gphiu', gphiu
126  ncdf_varget, cdfido, 'gphiv', gphiv
127  ncdf_varget, cdfido, 'gphif', gphif
128  ncdf_close, cdfido
129;
130  glamt = reform(glamt, /over)
131  glamu = reform(glamu, /over)
132  glamv = reform(glamv, /over)
133  glamf = reform(glamf, /over)
134  gphit = reform(gphit, /over)
135  gphiu = reform(gphiu, /over)
136  gphiv = reform(gphiv, /over)
137  gphif = reform(gphif, /over)
138  jpj = (size(glamf, /dimension))[1]
139;
140; I. Compute the cosinus and sinus
141; ================================
142; (computation done on the north stereographic polar plan
143;
144;   ... north pole direction & modulous (at t-point)
145  znpt = fsnspp( glamt, gphit, DOUBLE = double )
146  glamt = -1 & gphit = -1; free memory
147  znpt.x = - znpt.x
148  znpt.y = - znpt.y
149  znnpt = znpt.x*znpt.x + znpt.y*znpt.y
150;   ... north pole direction & modulous (at u-point)
151  znpu = fsnspp( glamu, gphiu, DOUBLE = double )
152  glamu = -1 & gphiu = -1; free memory
153  znpu.x = - znpu.x
154  znpu.y = - znpu.y
155  znnpu = znpu.x*znpu.x + znpu.y*znpu.y
156;   ... north pole direction & modulous (at v-point)
157  znpv = fsnspp( glamv, gphiv, DOUBLE = double )
158  znpv00 = znpv
159  znpv01 = fsnspp( shift(glamv, 0, 1), shift(gphiv, 0, 1), DOUBLE = double )
160  glamv = -1 & gphiv = -1; free memory
161  znpv.x = - znpv.x
162  znpv.y = - znpv.y
163  znnpv = znpv.x*znpv.x + znpv.y*znpv.y
164;   ... f-point
165  znpf00 = fsnspp( glamf, gphif, DOUBLE = double )
166  znpf01 = fsnspp( shift(glamf, 0, 1), shift(gphif, 0, 1), DOUBLE = double )
167  znpf10 = fsnspp( shift(glamf, 1, 0), shift(gphif, 1, 0), DOUBLE = double )
168  glamf = -1 & gphif = -1; free memory
169;   ... j-direction: v-point segment direction (t-point)
170  zxvvt = znpv00.x - znpv01.x
171  zyvvt = znpv00.y - znpv01.y
172  zmnpvt = sqrt ( temporary(znnpt) * ( zxvvt*zxvvt + zyvvt*zyvvt )  )
173  znpv00 = -1; free memory
174  znpv01 = -1; free memory
175  IF keyword_set(double) THEN zmnpvt = 1.e-14 > zmnpvt $
176  ELSE zmnpvt = 1.e-6 > zmnpvt
177;   ... j-direction: f-point segment direction (u-point)
178  zxffu = znpf00.x - znpf01.x
179  zyffu = znpf00.y - znpf01.y
180  zmnpfu = sqrt ( temporary(znnpu) * ( zxffu*zxffu + zyffu*zyffu )  )
181  znpf01 = -1; free memory
182  IF keyword_set(double) THEN zmnpfu = 1.e-14 > zmnpfu $
183  ELSE zmnpfu = 1.e-6 > zmnpfu
184;   ... i-direction: f-point segment direction (v-point)
185  zxffv = znpf00.x - znpf10.x
186  zyffv = znpf00.y - znpf10.y
187  znpf00 = -1 &  znpf10 = -1; free memory
188  zmnpfv = sqrt ( temporary(znnpv) * ( zxffv*zxffv + zyffv*zyffv )  )
189  IF keyword_set(double) THEN zmnpfv = 1.e-14 > zmnpfv $
190  ELSE zmnpfv = 1.e-6 > zmnpfv
191;   ... cosinus and sinus using scalar and vectorial products
192  gsint = ( znpt.x*zyvvt - znpt.y*zxvvt ) / zmnpvt
193  gcost = ( znpt.x*zxvvt + znpt.y*zyvvt ) / zmnpvt
194;   ... cosinus and sinus using scalar and vectorial products
195  gsinu = ( znpu.x*zyffu - znpu.y*zxffu ) / zmnpfu
196  gcosu = ( znpu.x*zxffu + znpu.y*zyffu ) / zmnpfu
197;   ... cosinus and sinus using scalar and vectorial products
198;       (caution, rotation of 90 degres)
199  gsinv =  ( znpv.x*zxffv + znpv.y*zyffv ) / zmnpfv
200  gcosv = -( znpv.x*zyffv - znpv.y*zxffv ) / zmnpfv
201;
202; II. Geographic mesh
203; ===================
204;
205;       bad = where(abs(glamf-shift(glamf, 0, 1)) LT 1.e-8)
206;       IF bad[0] NE -1 THEN BEGIN
207;         gcosu[bad] = 1.
208;         gsinu[bad] = 0.
209;       ENDIF
210;       bad = where(abs(gphif-shift(gphif, 1, 0)) LT 1.e-8)
211;       IF bad[0] NE -1 THEN BEGIN
212;         gcosv[bad] = 1.
213;         gsinv[bad] = 0.
214;       ENDIF
215;
216; III. Lateral boundary conditions
217; ================================
218;
219  gcost[*, 0] = gcost[*, 1]
220  gsint[*, 0] = gsint[*, 1]
221  gcosu[*, 0] = gcosu[*, 1]
222  gsinu[*, 0] = gsinu[*, 1]
223  gcosv[0, *] = gcosv[jpj-2, *]
224  gsinv[0, *] = gsinv[jpj-2, *]
225;
226  RETURN
227END
Note: See TracBrowser for help on using the repository browser.