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

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

improvements/corrections of some *.pro headers + replace some message by some report

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