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

Last change on this file since 208 was 202, checked in by smasson, 17 years ago

add extrapsmooth + light bugfix in compute_fromirr_bilinear_weigaddr + improve some headers

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